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)
        {
            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();
        }