Пример #1
0
 private void Awake()
 {
     if (!Application.isPlaying)
     {
         DestructionWindow.OpenWindow("A self creating scriptable object singleton should not have an instance on editor time, it will now be destroyed ", new Object[] { this });
     }
 }
    /// <summary>
    /// Method for opening the window
    /// </summary>
    /// <returns></returns>
    public static void OpenWindow(string msg, UnityEngine.Object[] toBeDestroyed)
    {
        _msg           = msg;
        _toBeDestroyed = toBeDestroyed;
        _window        = GetWindow <DestructionWindow>("Destroying");

        _window.minSize = new Vector2(500, 60);
    }
Пример #3
0
            /// <summary>
            /// Called when this object is inspected through the OnInspectGameObject editor script, this has to be private
            /// </summary>
            private void OnInspect()
            {
                if (!Application.isPlaying)
                {
                    var instancesOfMytype = Resources.LoadAll <T>("Singletons");

                    if (instancesOfMytype.Length > 1)
                    {
                        var toBeDestroyed = new System.Collections.Generic.List <Object>();

                        for (int i = 0; i < instancesOfMytype.Length; i++)
                        {
                            if (instancesOfMytype[i].GetInstanceID() != GetInstanceID())
                            {
                                toBeDestroyed.Add(instancesOfMytype[i]);
                            }
                        }

                        DestructionWindow.OpenWindow("There shouldn't be multiple singletons in a hierarchy on a resource singleton object, it will now be destroyed on: ", toBeDestroyed.ToArray());
                    }

                    if (this != null && gameObject != null)
                    {
                        for (int i = 0; i < UnityEditor.SceneManagement.EditorSceneManager.sceneCount; i++)
                        {
                            var activeScene = UnityEditor.SceneManagement.EditorSceneManager.GetSceneAt(i);

                            var gobs = activeScene.GetRootGameObjects();

                            for (int t = 0; t < gobs.Length; t++)
                            {
                                if (gobs[t] == gameObject)
                                {
                                    Debug.LogError("The resource singletons should be in the Resources Singletons folder please move: " + gameObject.name + " to the folder");
                                }

                                foreach (Transform item in gobs[t].transform)
                                {
                                    if (item.gameObject == gameObject)
                                    {
                                        Debug.LogError("The resource singletons should be in the Resources Singletons folder please move: " + gameObject.name + " to the folder");
                                    }
                                }
                            }

                            if (GetComponentsInChildren <ISingleton>().Length > 1)
                            {
                                DestructionWindow.OpenWindow("There shouldn't be multiple singletons in a hierarchy on a resource singleton object, it will now be destroyed on: ", new Object[] { this });
                            }
                        }
                    }
                }
            }
Пример #4
0
    /// <summary>
    /// Called when inspecting a gameobject
    /// </summary>
    private void OnInspect()
    {
        if (!Application.isPlaying)
        {
            var isAsset = true;

            if (this != null && gameObject != null)
            {
                for (int i = 0; i < UnityEditor.SceneManagement.EditorSceneManager.sceneCount; i++)
                {
                    var activeScene = UnityEditor.SceneManagement.EditorSceneManager.GetSceneAt(i);

                    var gobs = activeScene.GetRootGameObjects();

                    for (int t = 0; t < gobs.Length; t++)
                    {
                        if (gobs[t] == gameObject)
                        {
                            isAsset = false;
                        }

                        foreach (Transform item in gobs[t].transform)
                        {
                            if (item.gameObject == gameObject)
                            {
                                isAsset = false;
                            }
                        }
                    }

                    if (GetComponentsInChildren <ISingleton>().Length > 1)
                    {
                        DestructionWindow.OpenWindow("There shouldn't be multiple singletons in a hierarchy on a resource singleton object, it will now be destroyed on: ", new Object[] { this });
                    }
                }
            }

            if (isAsset)
            {
                DestructionWindow.OpenWindow("This is a scene singleton and should only be in a scene: ", new Object[] { gameObject });
            }
        }
    }
Пример #5
0
            /// <summary>
            /// Called by the OnInspectSOInspector editor script, this method has to be private
            /// </summary>
            private void OnInspect()
            {
                if (!Application.isPlaying)
                {
                    var instancesOfMytype = Resources.LoadAll <T>("Singletons");

                    if (instancesOfMytype.Length > 1)
                    {
                        var toBeDestroyed = new System.Collections.Generic.List <Object>();

                        for (int i = 0; i < instancesOfMytype.Length; i++)
                        {
                            if (instancesOfMytype[i].GetInstanceID() != GetInstanceID())
                            {
                                toBeDestroyed.Add(instancesOfMytype[i]);
                            }
                        }

                        DestructionWindow.OpenWindow("There shouldn't be multiple singletons in a hierarchy on a resource singleton object, it will now be destroyed on: ", toBeDestroyed.ToArray());
                    }
                }
            }
 /// <summary>
 /// Method called by the unity editor when this object is added to a game object
 /// </summary>
 private void Reset()
 {
     DestructionWindow.OpenWindow("A self creating singleton can't be added to a gameobject on edit time, it will now be destroyed on: ", new Object[] { this });
 }