有一个游戏对象,上面挂着 3 个脚本,如下: using System.Collections; using System.Collections.Generic; using UnityEngine; public class SaveAndRead : MonoBehaviour { public static SaveAndRead instance; /// <summary> /// 保存所有 单独的DataStore /// </summary> public List
单例模式特点 1.一般用在一个脚本访问另一个脚本中的数据. 2.对于使用单例模式的类,系统中只会存在唯一一个实例,减少了内存开销. Unity中继承于MonoBehaviour的单例模式 public class AlarmLight : MonoBehaviour { //单例模式 public static AlarmLight _instance; private void Awake() { _instance = this; } } C#正常的单例模式 public class Ala