Update Basic Sample

pull/40/head
hevinci 2022-09-22 14:29:24 +08:00
parent 2381b67312
commit 7c1e1ab593
19 changed files with 13 additions and 13 deletions

View File

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -6,7 +6,7 @@ using UnityEngine.U2D;
using UnityEngine.UI; using UnityEngine.UI;
using YooAsset; using YooAsset;
public class Game1Scene : MonoBehaviour public class GameScene1 : MonoBehaviour
{ {
public GameObject CanvasRoot; public GameObject CanvasRoot;
@ -72,7 +72,7 @@ public class Game1Scene : MonoBehaviour
#if UNITY_WEBGL #if UNITY_WEBGL
{ {
var rawImage = CanvasRoot.transform.Find("background").GetComponent<RawImage>(); var rawImage = CanvasRoot.transform.Find("background").GetComponent<RawImage>();
AssetOperationHandle handle = YooAssets.LoadAssetAsync<Texture>("bg"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<Texture>("tex_bg");
_cachedAssetOperationHandles.Add(handle); _cachedAssetOperationHandles.Add(handle);
handle.Completed += (AssetOperationHandle obj) => handle.Completed += (AssetOperationHandle obj) =>
{ {
@ -82,7 +82,7 @@ public class Game1Scene : MonoBehaviour
#else #else
{ {
var rawImage = CanvasRoot.transform.Find("background").GetComponent<RawImage>(); var rawImage = CanvasRoot.transform.Find("background").GetComponent<RawImage>();
AssetOperationHandle handle = YooAssets.LoadAssetSync<Texture>("bg"); AssetOperationHandle handle = YooAssets.LoadAssetSync<Texture>("tex_bg");
_cachedAssetOperationHandles.Add(handle); _cachedAssetOperationHandles.Add(handle);
rawImage.texture = handle.AssetObject as Texture; rawImage.texture = handle.AssetObject as Texture;
} }
@ -92,7 +92,7 @@ public class Game1Scene : MonoBehaviour
#if UNITY_WEBGL #if UNITY_WEBGL
{ {
var logoImage = CanvasRoot.transform.Find("title/logo").GetComponent<Image>(); var logoImage = CanvasRoot.transform.Find("title/logo").GetComponent<Image>();
AssetOperationHandle handle = YooAssets.LoadAssetAsync<Sprite>("logo"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<Sprite>("tex_logo");
_cachedAssetOperationHandles.Add(handle); _cachedAssetOperationHandles.Add(handle);
handle.Completed += (AssetOperationHandle obj) => handle.Completed += (AssetOperationHandle obj) =>
{ {
@ -102,7 +102,7 @@ public class Game1Scene : MonoBehaviour
#else #else
{ {
var logoImage = CanvasRoot.transform.Find("title/logo").GetComponent<Image>(); var logoImage = CanvasRoot.transform.Find("title/logo").GetComponent<Image>();
AssetOperationHandle handle = YooAssets.LoadAssetSync<Sprite>("logo"); AssetOperationHandle handle = YooAssets.LoadAssetSync<Sprite>("tex_logo");
_cachedAssetOperationHandles.Add(handle); _cachedAssetOperationHandles.Add(handle);
logoImage.sprite = handle.AssetObject as Sprite; logoImage.sprite = handle.AssetObject as Sprite;
} }
@ -185,7 +185,7 @@ public class Game1Scene : MonoBehaviour
var btn = CanvasRoot.transform.Find("load_scene").GetComponent<Button>(); var btn = CanvasRoot.transform.Find("load_scene").GetComponent<Button>();
btn.onClick.AddListener(() => btn.onClick.AddListener(() =>
{ {
YooAssets.LoadSceneAsync("Game2"); YooAssets.LoadSceneAsync("GameScene2");
}); });
} }
} }
@ -215,7 +215,7 @@ public class Game1Scene : MonoBehaviour
// 加载背景音乐 // 加载背景音乐
{ {
var audioSource = CanvasRoot.transform.Find("music").GetComponent<AudioSource>(); var audioSource = CanvasRoot.transform.Find("music").GetComponent<AudioSource>();
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("town"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("music_town");
_cachedAssetOperationHandles.Add(handle); _cachedAssetOperationHandles.Add(handle);
await handle.Task; await handle.Task;
audioSource.clip = handle.AssetObject as AudioClip; audioSource.clip = handle.AssetObject as AudioClip;

View File

@ -6,7 +6,7 @@ using UnityEngine.U2D;
using UnityEngine.UI; using UnityEngine.UI;
using YooAsset; using YooAsset;
public class Game2Scene : MonoBehaviour public class GameScene2 : MonoBehaviour
{ {
public GameObject CanvasRoot; public GameObject CanvasRoot;
private readonly List<AssetOperationHandle> _cachedAssetOperationHandles = new List<AssetOperationHandle>(1000); private readonly List<AssetOperationHandle> _cachedAssetOperationHandles = new List<AssetOperationHandle>(1000);
@ -41,7 +41,7 @@ public class Game2Scene : MonoBehaviour
#if UNITY_WEBGL #if UNITY_WEBGL
{ {
var rawImage = CanvasRoot.transform.Find("background").GetComponent<RawImage>(); var rawImage = CanvasRoot.transform.Find("background").GetComponent<RawImage>();
AssetOperationHandle handle = YooAssets.LoadAssetAsync<Texture>("bg"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<Texture>("tex_bg");
_cachedAssetOperationHandles.Add(handle); _cachedAssetOperationHandles.Add(handle);
handle.Completed += (AssetOperationHandle obj) => handle.Completed += (AssetOperationHandle obj) =>
{ {
@ -51,7 +51,7 @@ public class Game2Scene : MonoBehaviour
#else #else
{ {
var rawImage = CanvasRoot.transform.Find("background").GetComponent<RawImage>(); var rawImage = CanvasRoot.transform.Find("background").GetComponent<RawImage>();
AssetOperationHandle handle = YooAssets.LoadAssetSync<Texture>("bg"); AssetOperationHandle handle = YooAssets.LoadAssetSync<Texture>("tex_bg");
_cachedAssetOperationHandles.Add(handle); _cachedAssetOperationHandles.Add(handle);
rawImage.texture = handle.AssetObject as Texture; rawImage.texture = handle.AssetObject as Texture;
} }
@ -62,7 +62,7 @@ public class Game2Scene : MonoBehaviour
var btn = CanvasRoot.transform.Find("load_scene").GetComponent<Button>(); var btn = CanvasRoot.transform.Find("load_scene").GetComponent<Button>();
btn.onClick.AddListener(() => btn.onClick.AddListener(() =>
{ {
YooAssets.LoadSceneAsync("Game1"); YooAssets.LoadSceneAsync("GameScene1");
}); });
} }
@ -98,7 +98,7 @@ public class Game2Scene : MonoBehaviour
// 加载背景音乐 // 加载背景音乐
{ {
var audioSource = CanvasRoot.transform.Find("music").GetComponent<AudioSource>(); var audioSource = CanvasRoot.transform.Find("music").GetComponent<AudioSource>();
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("town"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("music_town");
_cachedAssetOperationHandles.Add(handle); _cachedAssetOperationHandles.Add(handle);
yield return handle; yield return handle;
audioSource.clip = handle.AssetObject as AudioClip; audioSource.clip = handle.AssetObject as AudioClip;

View File

@ -11,7 +11,7 @@ internal class FsmPatchDone : IFsmNode
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.PatchDone); PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.PatchDone);
Debug.Log("补丁流程更新完毕!"); Debug.Log("补丁流程更新完毕!");
YooAsset.YooAssets.LoadSceneAsync("Game1"); YooAsset.YooAssets.LoadSceneAsync("GameScene1");
} }
void IFsmNode.OnUpdate() void IFsmNode.OnUpdate()
{ {