Beispiel #1
0
	/// <summary>
	/// 共通コンポーネント初期化+インスタンス取得
	/// 要件メモ
	/// - CommonSceneが付いてないシーンを再生した時は自動で初期化して待機する手順を確立
	///     - シーンを読み込んでない時は自動で読み込む必要がある
	/// </summary>
	public static async UniTask<CommonScene> Initialize(){
		if (ContainsScene(COMMON_SCENE_NAME)) return instance;
		// ここで共通コンポーネントを初期化するなど
		// 分業のため、共通コンポーネントはなんらかの方法で小分けできるようにしたい
		await SceneManager.LoadSceneAsync(COMMON_SCENE_NAME,LoadSceneMode.Additive);
		await Task.Delay(Random.Range(100,500));

		instance = GameObject.Find(COMMON_SCENE_GAMEOBJECT_NAME).GetComponent<CommonScene>();
		DontDestroyOnLoad(instance);
		// DontDestroy後はシーン自体は不要
		await SceneManager.UnloadSceneAsync(COMMON_SCENE_NAME);

		Debug.Log($"CommonScene Initalize finish");
		return instance;
	}
Beispiel #2
0
	async void Start(){

		Debug.Log("実行開始!");

		var commonScene = await CommonScene.Initialize();

		Debug.Log($"commonScene method call test: {commonScene.Test()}");

		// UniRx.Asyncコードメモ
		// 参考: https://qiita.com/toRisouP/items/4445b6b9bf00e49eb147
		Debug.Log($"test {await TestAsync()}");

		async UniTask<string> TestAsync(){
			Debug.Log("delay pre");
			await Task.Delay(300);
			Debug.Log("delay post");
			return await Task.Run(() => "testtest!");
		}
	}
Beispiel #3
0
	async void Start(){

		var commonScene = await CommonScene.Initialize();
		Debug.Log($"シーン2: {commonScene.Test()}");

	}