Update basic sample
parent
83f6dc2f76
commit
77080b3934
|
@ -22,8 +22,8 @@ public class GameScene1 : MonoBehaviour
|
||||||
// 初始化窗口
|
// 初始化窗口
|
||||||
InitWindow();
|
InitWindow();
|
||||||
|
|
||||||
// 异步加载背景音乐
|
// 加载背景音乐
|
||||||
AsyncLoadMusic();
|
LoadMusic();
|
||||||
}
|
}
|
||||||
void OnDestroy()
|
void OnDestroy()
|
||||||
{
|
{
|
||||||
|
@ -176,9 +176,8 @@ public class GameScene1 : MonoBehaviour
|
||||||
var btn = CanvasRoot.transform.Find("load_rawfile/btn").GetComponent<Button>();
|
var btn = CanvasRoot.transform.Find("load_rawfile/btn").GetComponent<Button>();
|
||||||
btn.onClick.AddListener(() =>
|
btn.onClick.AddListener(() =>
|
||||||
{
|
{
|
||||||
string savePath = $"{YooAssets.GetSandboxRoot()}/config1.txt";
|
var handle = YooAssets.LoadRawFileSync("config1");
|
||||||
RawFileOperation operation = YooAssets.GetRawFileAsync("config1", savePath);
|
handle.Completed += OnRawFile_Completed;
|
||||||
operation.Completed += OnRawFile_Completed;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,24 +208,23 @@ public class GameScene1 : MonoBehaviour
|
||||||
var icon = CanvasRoot.transform.Find("load_tp_atlas/icon").GetComponent<Image>();
|
var icon = CanvasRoot.transform.Find("load_tp_atlas/icon").GetComponent<Image>();
|
||||||
icon.sprite = handle.GetSubAssetObject<Sprite>("Icon_Shield_128");
|
icon.sprite = handle.GetSubAssetObject<Sprite>("Icon_Shield_128");
|
||||||
}
|
}
|
||||||
private void OnRawFile_Completed(AsyncOperationBase operation)
|
private void OnRawFile_Completed(RawFileOperationHandle handle)
|
||||||
{
|
{
|
||||||
var hint = CanvasRoot.transform.Find("load_rawfile/icon/hint").GetComponent<Text>();
|
var hint = CanvasRoot.transform.Find("load_rawfile/icon/hint").GetComponent<Text>();
|
||||||
RawFileOperation op = operation as RawFileOperation;
|
hint.text = handle.GetRawFileText();
|
||||||
hint.text = op.LoadFileText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载背景音乐
|
/// 异步加载背景音乐
|
||||||
/// </summary>
|
/// </summary>
|
||||||
async void AsyncLoadMusic()
|
void LoadMusic()
|
||||||
{
|
{
|
||||||
// 加载背景音乐
|
// 加载背景音乐
|
||||||
{
|
{
|
||||||
var audioSource = CanvasRoot.transform.Find("music").GetComponent<AudioSource>();
|
var audioSource = CanvasRoot.transform.Find("music").GetComponent<AudioSource>();
|
||||||
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("music_town");
|
AssetOperationHandle handle = YooAssets.LoadAssetSync<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;
|
||||||
audioSource.Play();
|
audioSource.Play();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue