public void OnClick(GameObject[] affectedObjectsArray)
 {
     foreach (var result in MyMenu_Utils.GetOnlyTopObjects(affectedObjectsArray).Select(o => o.GetInstanceID()))
     {
         HierarchyExtensions.Utilities.SetExpandedRecursive(result, false);
     }
 }
        public void OnClick(GameObject[] affectedObjectsArray)
        {
            var ungroupedObjects = new List <GameObject>();
            var onlytop          = MyMenu_Utils.GetOnlyTopObjects(affectedObjectsArray);

            foreach (var ungroupedRoot in onlytop)
            {
                var ungroupSiblinkIndex = ungroupedRoot.transform.GetSiblingIndex();
                var ungroupParent       = ungroupedRoot.transform.parent;
                var undoName            = ungroupedRoot.name;
                for (int i = ungroupedRoot.transform.childCount - 1; i >= 0; i--)
                {
                    var o = ungroupedRoot.transform.GetChild(i);
                    Undo.SetTransformParent(o.transform, ungroupParent, "Remove " + undoName);

                    if (!Application.isPlaying)
                    {
                        Undo.RegisterFullObjectHierarchyUndo(o, "Remove " + undoName);
                    }
                    o.SetSiblingIndex(ungroupSiblinkIndex);
                    if (!Application.isPlaying)
                    {
                        EditorUtility.SetDirty(o);
                    }

                    ungroupedObjects.Add(o.gameObject);
                }
                Undo.DestroyObjectImmediate(ungroupedRoot);
            }
            Selection.objects = ungroupedObjects.ToArray();
        }
        public void OnClick(GameObject[] affectedObjectsArray)
        {
            var onlytop = MyMenu_Utils.GetOnlyTopObjects(affectedObjectsArray).OrderBy(go => go.transform.GetSiblingIndex()).ToArray();

            if (onlytop.Length == 0)
            {
                return;
            }

            var groupParent       = onlytop[0].transform.parent;
            var groupSiblingIndex = onlytop[0].transform.GetSiblingIndex();

            var groupRoot = new GameObject("GROUP " + onlytop[0].name);

            groupRoot.transform.SetParent(groupParent, false);
            groupRoot.transform.localScale = Vector3.one;
            groupRoot.transform.SetSiblingIndex(groupSiblingIndex);
            //********************************//
            Vector3 center = Vector3.zero;
            Vector3 rot    = Vector3.zero;

            foreach (var item in onlytop)
            {
                center += item.transform.position;
                rot    += item.transform.eulerAngles;
            }
            center /= onlytop.Length;
            rot    /= onlytop.Length;
            groupRoot.transform.position    = center;
            groupRoot.transform.eulerAngles = rot;
            //********************************//

            MyMenu_Utils.AssignUniqueName(groupRoot);                       // name
            if (groupRoot.GetComponentsInParent <Canvas>(true).Length != 0) // canvas
            {
                var rect = groupRoot.AddComponent <RectTransform>();
                rect.anchorMin = Vector2.zero;
                rect.anchorMax = Vector2.one;
                rect.offsetMin = Vector2.zero;
                rect.offsetMax = Vector2.zero;
                groupRoot.AddComponent <CanvasRenderer>();
            }

            Undo.RegisterCreatedObjectUndo(groupRoot, groupRoot.name);

            foreach (var gameObject in onlytop)
            {
                Undo.SetTransformParent(gameObject.transform, groupRoot.transform, groupRoot.name);
            }

            HierarchyExtensions.Utilities.SetExpanded(groupRoot.GetInstanceID(), true);

            Selection.objects = onlytop.ToArray();
            //Selection.objects = new[] { groubObject };
        }
 public void OnClick(GameObject[] affectedObjectsArray)
 {
     foreach (var gameObject in MyMenu_Utils.GetOnlyTopObjects(affectedObjectsArray))
     {
         var T = gameObject.transform;
         for (int i = 0; i < gameObject.transform.childCount; i++)
         {
             Undo.SetTransformParent(T.GetChild(i), T.GetChild(i).transform.parent, "Reverse Children Order");
             T.GetChild(i).SetAsFirstSibling();
         }
     }
 }
        public void OnClick(GameObject[] affectedObjectsArray)
        {
            var onlytop = MyMenu_Utils.GetOnlyTopObjects(affectedObjectsArray).OrderByDescending(o => o.transform.GetSiblingIndex());

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

            foreach (var gameObject in onlytop)
            {
                var oldSib = gameObject.transform.GetSiblingIndex();
                Selection.objects = new[] { gameObject };
                HierarchyExtensions.Utilities.DuplicateSelection();
                var clonedObject = Selection.activeGameObject;
                MyMenu_Utils.AssignUniqueName(clonedObject);
                clonedObject.transform.SetSiblingIndex(oldSib + 1);
                clonedObjects.Add(clonedObject);
            }

            Selection.objects = clonedObjects.ToArray();
        }
 public void OnClick(GameObject[] affectedObjectsArray)
 {
     Selection.objects = MyMenu_Utils.GetOnlyTopObjects(affectedObjectsArray);
 }
        public void OnClick(GameObject[] affectedObjectsArray)
        {
            var onlytop = MyMenu_Utils.GetOnlyTopObjects(affectedObjectsArray).OrderBy(go => go.transform.GetSiblingIndex()).ToArray();

            if (onlytop.Length == 0)
            {
                return;
            }

            var center_object = onlytop[onlytop.Length - 1];

            var groupParent       = center_object.transform.parent;
            var groupSiblingIndex = center_object.transform.GetSiblingIndex();

            var reference = center_object;
            var NEW_NAME  = reference.name + " Group";

            // Save Previous Name Variant
            // CustomModule.SHOW_StringInput( "Group Name:", EditorPrefs.GetString( "EModules/MultyRenamer/GroupName", NEW_NAME ) , ( name ) =>
            // {   EditorPrefs.SetString( "EModules/MultyRenamer/GroupName", name );

            // Top Object Name Variant
            CustomModule.SHOW_StringInput("Group Name:", NEW_NAME, (name) =>
            {
                var groupRoot = new GameObject(name);
                groupRoot.transform.SetParent(groupParent, false);
                //groupRoot.transform.localScale = Vector3.one;
                groupRoot.transform.SetSiblingIndex(groupSiblingIndex);
                //********************************//
                //groupRoot.transform.position = center_object.transform.position;
                //groupRoot.transform.rotation = center_object.transform.rotation;
                //********************************//

                //MyMenu_Utils.AssignUniqueName( groupRoot ); // name
                if (reference.GetComponent <RectTransform>())            // canvas
                {
                    var source              = reference.GetComponent <RectTransform>();
                    var dest                = groupRoot.AddComponent <RectTransform>();
                    dest.sizeDelta          = source.sizeDelta;
                    dest.pivot              = source.pivot;
                    dest.anchoredPosition3D = source.anchoredPosition3D;
                    dest.localRotation      = source.localRotation;
                    dest.localScale         = source.localScale;
                    dest.anchorMin          = source.anchorMin;
                    dest.anchorMax          = source.anchorMax;
                    dest.offsetMin          = source.offsetMin;
                    dest.offsetMax          = source.offsetMax;
                    groupRoot.AddComponent <CanvasRenderer>();
                }

                /*  if ( groupRoot.GetComponentsInParent<Canvas>( true ).Length != 0 )     // canvas
                 * {   var rect = groupRoot.AddComponent<RectTransform>();
                 *    rect.anchorMin = Vector2.zero;
                 *    rect.anchorMax = Vector2.one;
                 *    rect.offsetMin = Vector2.zero;
                 *    rect.offsetMax = Vector2.zero;
                 *    groupRoot.AddComponent<CanvasRenderer>();
                 * }*/

                Undo.RegisterCreatedObjectUndo(groupRoot, groupRoot.name);

                foreach (var gameObject in onlytop)
                {
                    Undo.SetTransformParent(gameObject.transform, groupRoot.transform, groupRoot.name);
                }

                HierarchyExtensions.Utilities.SetExpanded(groupRoot.GetInstanceID(), true);

                Selection.objects = onlytop.ToArray();
            });

            //Selection.objects = new[] { groubObject };
        }
        public void OnClick(GameObject[] affectedObjectsArray)
        {
            var onlytop = MyMenu_Utils.GetOnlyTopObjects(affectedObjectsArray).OrderBy(go => go.transform.GetSiblingIndex()).ToArray();

            if (onlytop.Length == 0)
            {
                return;
            }

            var last_object = onlytop[onlytop.Length - 1];

            var groupParent       = onlytop[0].transform.parent;
            var groupSiblingIndex = onlytop[0].transform.GetSiblingIndex();


            var NEW_NAME = last_object.name + " Group";


            // Save Previous Name Variant
            // CustomModule.SHOW_StringInput( "Group Name:", EditorPrefs.GetString( "EModules/MultyRenamer/GroupName", NEW_NAME ) , ( name ) =>
            // {   EditorPrefs.SetString( "EModules/MultyRenamer/GroupName", name );

            // Top Object Name Variant
            CustomModule.SHOW_StringInput("Group Name:", NEW_NAME, (name) =>
            {
                var groupRoot = new GameObject(name);
                groupRoot.transform.SetParent(groupParent, false);
                groupRoot.transform.localScale = Vector3.one;
                groupRoot.transform.SetSiblingIndex(groupSiblingIndex);
                //********************************//
                Vector3 center = Vector3.zero;
                Vector3 rot    = Vector3.zero;

                foreach (var item in onlytop)
                {
                    center += item.transform.position;
                    rot    += item.transform.eulerAngles;
                }

                center /= onlytop.Length;
                rot    /= onlytop.Length;
                groupRoot.transform.position    = center;
                groupRoot.transform.eulerAngles = rot;
                //********************************//

                //MyMenu_Utils.AssignUniqueName( groupRoot ); // name
                if (groupRoot.GetComponentsInParent <Canvas>(true).Length != 0)            // canvas
                {
                    var rect       = groupRoot.AddComponent <RectTransform>();
                    rect.anchorMin = Vector2.zero;
                    rect.anchorMax = Vector2.one;
                    rect.offsetMin = Vector2.zero;
                    rect.offsetMax = Vector2.zero;
                    groupRoot.AddComponent <CanvasRenderer>();
                }

                Undo.RegisterCreatedObjectUndo(groupRoot, groupRoot.name);

                foreach (var gameObject in onlytop)
                {
                    Undo.SetTransformParent(gameObject.transform, groupRoot.transform, groupRoot.name);
                }

                HierarchyExtensions.Utilities.SetExpanded(groupRoot.GetInstanceID(), true);

                Selection.objects = onlytop.ToArray();
            });
            //Selection.objects = new[] { groubObject };
        }