Пример #1
0
        public static GameObject GetPrefab(Object instance)
        {
            GameObject go = UnityUtils.GetGameObject(instance);

            if (!go)
            {
                return(null);
            }
            GameObject root = PrefabUtility.FindRootGameObjectWithSameParentPrefab(go);

            if (!root)
            {
                return(null);
            }
            return(PrefabUtility.GetPrefabParent(root) as GameObject);
        }
 /// <summary>
 ///   Destroys all the children of a transform.
 /// </summary>
 /// <param name="transform">The transform containing the children to destroy.</param>
 public static void DestroyAllChildren(this Transform transform)
 {
     if (!transform)
     {
         return;
     }
     for (int i = transform.childCount - 1; i >= 0; i--)
     {
         Transform t = transform.GetChild(i);
         if (!t)
         {
             continue;
         }
         UnityUtils.DestroyObject(t);
     }
 }
Пример #3
0
        public static void GroupSelected()
        {
            if (!Selection.activeTransform)
            {
                return;
            }
            GameObject go = new GameObject(Selection.activeTransform.name + " Group");

            Undo.RegisterCreatedObjectUndo(go, "Group Selected");
            go.transform.SetParent(Selection.activeTransform.parent, false);
            go.transform.SetSiblingIndex(Selection.activeTransform.GetSiblingIndex());
            go.transform.position = Selection.transforms.Length == 1
                                                                                                                                ? Selection.transforms[0].position
                                                                                                                                : UnityUtils.GetCenter(Selection.transforms);
            foreach (Transform transform in Selection.transforms)
            {
                Undo.SetTransformParent(transform, go.transform, "Group Selected");
            }
            Selection.activeGameObject = go;
        }