Exemple #1
0
    private void Awake()
    {
        if (!Application.isPlaying)
        {
            UnityEngine.Object[] obj = Resources.LoadAll("ISingletons", thisType);

            if (obj.Length == 0)
            {
                Debug.Log(thisType + " have been created.");
            }

            if (obj.Length > 0 && obj[0] != this)
            {
                WarningWindow.ShowWindow("Can't have two copies of the singleton: " + thisType.ToString(), this);

                string path = UnityEditor.AssetDatabase.GetAssetPath(GetInstanceID());

                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }

                if (System.IO.File.Exists(path + ".meta"))
                {
                    System.IO.File.Delete(path + ".meta");
                }
            }
        }
    }
    private void OnValidate()
    {
        if (gameObject.scene.name != null)
        {
            if (!Application.isPlaying)
            {
                WarningWindow.ShowWindow("A singleton can't start in a scene", gameObject);
            }
        }

        if (!Application.isPlaying && gameObject.scene.name == null)
        {
            UnityEngine.Object[] obj = Resources.LoadAll("ISingletons", thisType);

            if (obj.Length > 0 && obj[0] != this)
            {
                WarningWindow.ShowWindow("Can't have two copies of the singleton: " + thisType.ToString(), gameObject);

                string path = AssetDatabase.GetAssetPath(GetInstanceID());

                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }

                if (System.IO.File.Exists(path + ".meta"))
                {
                    System.IO.File.Delete(path + ".meta");
                }
            }
        }
    }
    protected virtual void Reset()
    {
        if (!Application.isPlaying)
        {
            if (transform != transform.root)
            {
                Debug.LogError("The component with IInitializeMain needs to be on the top gameobject in hierarchy");
                Debug.LogError(GetType().ToString() + " will be removed from " + gameObject.name);

                WarningWindow.ShowWindow("The component with IInitializeMain needs to be on the top gameobject in hierarchy", this);
            }
        }
    }
Exemple #4
0
    protected virtual void Reset()
    {
        if (!Application.isPlaying)
        {
            if (transform.root.GetComponent <IInitializeMain>() == null)
            {
                Debug.LogError("There needs to be an IInitializeMain component on the top parent for an IInitializeSub component");
                Debug.LogError(GetType().ToString() + " will be removed from " + gameObject.name);

                WarningWindow.ShowWindow("There needs to be an IInitializeMain component on the top parent for an IInitializeSub component", this);
            }

            List <IInitializeSub> list = new List <IInitializeSub>();
            list.AddRange(transform.root.GetComponentsInChildren <IInitializeSub>());
            priority = list.Count;

            if (transform.root.GetComponent <IInitializeMain>() != null)
            {
                transform.root.GetComponent <IInitializeMain>().AddInitializeSub((IInitializeSub)this, priority, true);
            }
        }
    }