using System; using System.Collections; using System.Collections.Generic; using Cysharp.Threading.Tasks; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; public class TestLevel : MonoBehaviour { [SerializeField] private AssetReference papers; [SerializeField] private FoldLinesGeneratorNew foldLinesGenerator; private Paper currentPaper; public delegate void OnPaperInstantiated(Paper paper); public static OnPaperInstantiated onPaperInstantiated; async void Start() { onPaperInstantiated += foldLinesGenerator.DrawFoldingLines; await this.SpawnLevel(); } // Update is called once per frame public async UniTask SpawnLevel() { Paper levelPrefab = await LoadPaperLevel(0); currentPaper = Instantiate(levelPrefab, transform); onPaperInstantiated?.Invoke(currentPaper); currentPaper.setPaperCallBack(this.levelComplete); } private async UniTask LoadPaperLevel(int level) { GameObject paperGameObject = null; if (papers.Asset is GameObject) paperGameObject = papers.Asset as GameObject; if (paperGameObject == null) { AsyncOperationHandle paperHandler = papers.LoadAssetAsync(); paperGameObject = await paperHandler.Task; } return paperGameObject.GetComponent(); } private void levelComplete() { Debug.Log("Level Complete"); } }