コード例 #1
0
ファイル: T4_Singleton.cs プロジェクト: Fallshadow/-
    public static void CreateInstance()
    {
        if (s_instance != null)
        {
            return;
        }

        GameObject singletonObject = SingletonGameObject.getObject();

        if (singletonObject == null)
        {
            return;
        }

        DontDestroyOnLoad(singletonObject);

        T[] objList = GameObject.FindObjectsOfType(typeof(T)) as T[];
        if (objList.Length == 0)
        {
            singletonObject.AddComponent <T>();
        }
        else if (objList.Length > 1)
        {
            //act.debug.PrintSystem.Log("You have more than one " + typeof(T).Name + " in the scene. You only need 1, it's a singleton!");
            foreach (T item in objList)
            {
                Destroy(item);
            }
        }
    }
コード例 #2
0
    public static void CreateInstance()
    {
        if (s_instance != null)
        {
            return;
        }

        GameObject singletonObject = SingletonGameObject.getObject();

        if (singletonObject == null)
        {
            return;
        }

        DontDestroyOnLoad(singletonObject);

        T[] objList = GameObject.FindObjectsOfType(typeof(T)) as T[];
        if (objList.Length == 0)
        {
            singletonObject.AddComponent <T>();
        }
        else if (objList.Length > 1)
        {
            foreach (T item in objList)
            {
                Destroy(item);
            }
        }
    }