1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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<Paper> LoadPaperLevel(int level)
- {
- GameObject paperGameObject = null;
- if (papers.Asset is GameObject)
- paperGameObject = papers.Asset as GameObject;
- if (paperGameObject == null)
- {
- AsyncOperationHandle<GameObject> paperHandler = papers.LoadAssetAsync<GameObject>();
- paperGameObject = await paperHandler.Task;
- }
- return paperGameObject.GetComponent<Paper>();
- }
- private void levelComplete()
- {
- Debug.Log("Level Complete");
- }
- }
|