Beispiel #1
0
        public void Duplicate(GameObject[] gameObjects)
        {
            if (gameObjects == null || gameObjects.Length == 0)
            {
                return;
            }

            if (!Undo.Enabled)
            {
                for (int i = 0; i < gameObjects.Length; ++i)
                {
                    GameObject go = gameObjects[i];
                    if (go != null)
                    {
                        ExposeToEditor exposed = go.GetComponent <ExposeToEditor>();
                        if (exposed == null || exposed.CanDuplicate)
                        {
                            Instantiate(go, go.transform.position, go.transform.rotation);
                        }
                    }
                }
                return;
            }

            List <GameObject> duplicates = new List <GameObject>();

            for (int i = 0; i < gameObjects.Length; ++i)
            {
                GameObject go = gameObjects[i];
                if (go == null)
                {
                    continue;
                }

                ExposeToEditor exposed = go.GetComponent <ExposeToEditor>();
                if (exposed != null && !exposed.CanDuplicate)
                {
                    continue;
                }

                GameObject duplicate = Instantiate(go, go.transform.position, go.transform.rotation);
                duplicate.SetActive(true);
                duplicate.SetActive(go.activeSelf);
                if (go.transform.parent != null)
                {
                    duplicate.transform.SetParent(go.transform.parent, true);
                }

                duplicates.Add(duplicate);
            }

            if (duplicates.Count > 0)
            {
                ExposeToEditor[] exposeToEditor = duplicates.Select(o => o.GetComponent <ExposeToEditor>()).OrderByDescending(o => o.transform.GetSiblingIndex()).ToArray();
                Undo.BeginRecord();
                Undo.RegisterCreatedObjects(exposeToEditor);
                Selection.objects = duplicates.ToArray();
                Undo.EndRecord();
            }
        }
        public void RegisterCreatedObjects(GameObject[] gameObjects, bool select = true)
        {
            ExposeToEditor[] exposeToEditor = gameObjects.Select(o => o.GetComponent <ExposeToEditor>()).Where(o => o != null).OrderByDescending(o => o.transform.GetSiblingIndex()).ToArray();

            bool isRecording = Undo.IsRecording;

            if (!isRecording)
            {
                Undo.BeginRecord();
            }

            if (exposeToEditor.Length == 0)
            {
                Debug.LogWarning("To register created object GameObject add ExposeToEditor script to it");
            }
            else
            {
                Undo.RegisterCreatedObjects(exposeToEditor);
            }

            if (select)
            {
                Selection.objects = gameObjects;
            }

            if (!isRecording)
            {
                Undo.EndRecord();
            }

            if (ObjectsRegistered != null)
            {
                ObjectsRegistered(gameObjects);
            }
        }
Beispiel #3
0
 public void RegisterCreatedObjects(GameObject[] gameObjects)
 {
     ExposeToEditor[] exposeToEditor = gameObjects.Select(o => o.GetComponent <ExposeToEditor>()).OrderByDescending(o => o.transform.GetSiblingIndex()).ToArray();
     Undo.BeginRecord();
     Undo.RegisterCreatedObjects(exposeToEditor);
     Selection.objects = gameObjects;
     Undo.EndRecord();
 }
Beispiel #4
0
        public void Delete(GameObject[] gameObjects)
        {
            if (gameObjects == null || gameObjects.Length == 0)
            {
                return;
            }

            if (!Undo.Enabled)
            {
                for (int i = 0; i < gameObjects.Length; ++i)
                {
                    GameObject go = gameObjects[i];
                    if (go != null)
                    {
                        ExposeToEditor exposed = go.GetComponent <ExposeToEditor>();

                        if (exposed == null || exposed.CanDelete)
                        {
                            Destroy(go);
                        }
                    }
                }
                return;
            }

            ExposeToEditor[] exposeToEditor = gameObjects.Select(o => o.GetComponent <ExposeToEditor>()).Where(exposed => exposed.CanDelete).OrderByDescending(o => o.transform.GetSiblingIndex()).ToArray();
            if (exposeToEditor.Length == 0)
            {
                return;
            }

            HashSet <GameObject> removeObjectsHs = new HashSet <GameObject>(exposeToEditor.Select(exposed => exposed.gameObject));

            Undo.BeginRecord();
            if (Selection.objects != null)
            {
                List <UnityEngine.Object> selection = Selection.objects.ToList();
                for (int i = selection.Count - 1; i >= 0; --i)
                {
                    if (removeObjectsHs.Contains(selection[i]))
                    {
                        selection.RemoveAt(i);
                    }
                }

                Selection.objects = selection.ToArray();
            }

            Undo.DestroyObjects(exposeToEditor);
            Undo.EndRecord();
        }
Beispiel #5
0
        public void Duplicate()
        {
            GameObject[] selection = Selection.gameObjects;
            if (selection == null)
            {
                return;
            }

            Undo.BeginRecord();
            for (int i = 0; i < selection.Length; ++i)
            {
                GameObject selectedObj = selection[i];
                if (selectedObj != null)
                {
                    Transform  p    = selectedObj.transform.parent;
                    GameObject copy = Instantiate(selectedObj, selectedObj.transform.position, selectedObj.transform.rotation);
                    copy.transform.SetParent(p, true);

                    selection[i] = copy;
                    Undo.BeginRegisterCreateObject(copy);
                }
            }
            Undo.RecordSelection();
            Undo.EndRecord();

            bool isEnabled = Undo.Enabled;

            Undo.Enabled      = false;
            Selection.objects = selection;
            Undo.Enabled      = isEnabled;

            Undo.BeginRecord();

            for (int i = 0; i < selection.Length; ++i)
            {
                GameObject selectedObj = selection[i];
                if (selectedObj != null)
                {
                    Undo.RegisterCreatedObject(selectedObj);
                }
            }
            Undo.RecordSelection();
            Undo.EndRecord();
        }
Beispiel #6
0
        public void Delete(GameObject[] gameObjects)
        {
            if (gameObjects == null || gameObjects.Length == 0)
            {
                return;
            }

            if (!Undo.Enabled)
            {
                for (int i = 0; i < gameObjects.Length; ++i)
                {
                    GameObject go = gameObjects[i];
                    if (go != null)
                    {
                        Destroy(go);
                    }
                }
                return;
            }

            ExposeToEditor[] exposeToEditor = gameObjects.Select(o => o.GetComponent <ExposeToEditor>()).OrderByDescending(o => o.transform.GetSiblingIndex()).ToArray();
            Undo.BeginRecord();

            if (Selection.objects != null)
            {
                List <UnityEngine.Object> selection = Selection.objects.ToList();
                for (int i = selection.Count - 1; i >= 0; --i)
                {
                    if (selection[i] == gameObjects[i])
                    {
                        selection.RemoveAt(i);
                        //NADI:
//                        Destroy(gameObjects[i]);
                    }
                }

                Selection.objects = selection.ToArray();
            }

            Undo.DestroyObjects(exposeToEditor);
            Undo.EndRecord();
        }
Beispiel #7
0
        public void Delete()
        {
            GameObject[] selection = Selection.gameObjects;
            if (selection == null)
            {
                return;
            }

            Undo.BeginRecord();
            for (int i = 0; i < selection.Length; ++i)
            {
                GameObject selectedObj = selection[i];
                if (selectedObj != null)
                {
                    Undo.BeginDestroyObject(selectedObj);
                }
            }
            Undo.RecordSelection();
            Undo.EndRecord();

            bool isEnabled = Undo.Enabled;

            Undo.Enabled      = false;
            Selection.objects = null;
            Undo.Enabled      = isEnabled;

            Undo.BeginRecord();

            for (int i = 0; i < selection.Length; ++i)
            {
                GameObject selectedObj = selection[i];
                if (selectedObj != null)
                {
                    Undo.DestroyObject(selectedObj);
                }
            }
            Undo.RecordSelection();
            Undo.EndRecord();
        }