MicroSoftinterface (C# リファレンス)
未確認飛行 C様インターフェース
サムライエンジニアブログ様【C#】インターフェースって何?基礎からしっかり解説してみた!
<= クリックすると開きます。
/// <summary> /// ゲーム内の初期処理の実行用インターフェース /// </summary> public interface IEntryRun { public void EntryRun(); }
インターフェースは Serialize を行ってもインスペクターには表示されません。
using UnityEngine; using System.Collections.Generic; using TNRD; // SerializableInterface を利用するための宣言の追加 public class EntryPoint : MonoBehaviour { // ゲーム起動時に順番に実行したい各クラスの登録用リスト public List<SerializableInterface<IEntryRun>> entryList = new(); void Awake() { // 指定した順番に各クラスの初期設定を行う foreach (var entry in entryList) { entry.Value?.EntryRun(); } } }
entry.Value?.EntryRun();
using System.Collections; using UnityEngine; using DG.Tweening; /// <summary> /// 音管理クラス /// </summary> public class SoundManager : MonoBehaviour, IEntryRun { public static SoundManager instance; /// <summary> /// ゲーム起動時の処理 /// </summary> public void EntryRun() { if (instance == null) { instance = this; DontDestroyOnLoad(this.gameObject); Init(); } else { Destroy(this.gameObject); } Debug.Log("SoundManager Entry 終了"); } /// <summary> /// 初期設定 /// </summary> /// <param name="newMasterVolume"></param> public void Init (float newMasterVolume) { // TODO 書記設定の処理を記述する // DOTween の初期化(DOTween をインポートしてない場合には、この処理は削除してください) DOTween.Init(); Debug.Log("SoundManager Init"); } }
using UnityEngine; public class UserData : MonoBehaviour, IEntryRun { public static UserData instance; /// <summary> /// ゲーム起動時の処理 /// </summary> public void EntryRun() { if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } Debug.Log("UserData Entry 終了"); } }