コード例 #1
0
        internal static void Place(GameObject go, GameObject parent)
        {
            if (parent != null)
            {
                var transform = go.transform;
                Undo.SetTransformParent(transform, parent.transform, "Reparenting");
                transform.localPosition = Vector3.zero;
                transform.localRotation = Quaternion.identity;
                transform.localScale    = Vector3.one;
                go.layer = parent.layer;

                if (parent.GetComponent <RectTransform>())
                {
                    ObjectFactory.AddComponent <RectTransform>(go);
                }
            }
            else
            {
                SceneView.PlaceGameObjectInFrontOfSceneView(go);
                StageUtility.PlaceGameObjectInCurrentStage(go); // may change parent
            }

            // Only at this point do we know the actual parent of the object and can mopdify its name accordingly.
            GameObjectUtility.EnsureUniqueNameForSibling(go);
            Undo.SetCurrentGroupName("Create " + go.name);

            EditorWindow.FocusWindowIfItsOpen <SceneHierarchyWindow>();
            Selection.activeGameObject = go;
        }
コード例 #2
0
        internal static void Place(GameObject go, GameObject parent)
        {
            Transform defaultObjectTransform = SceneView.GetDefaultParentObjectIfSet();

            if (parent != null)
            {
                SetGameObjectParent(go, parent.transform);
            }
            else if (defaultObjectTransform != null)
            {
                SetGameObjectParent(go, defaultObjectTransform);
            }
            else
            {
                // When creating a 3D object without a parent, this option puts it at the world origin instead of scene pivot.
                if (placeObjectsAtWorldOrigin)
                {
                    go.transform.position = Vector3.zero;
                }
                else
                {
                    SceneView.PlaceGameObjectInFrontOfSceneView(go);
                }

                StageUtility.PlaceGameObjectInCurrentStage(go); // may change parent
            }

            // Only at this point do we know the actual parent of the object and can modify its name accordingly.
            GameObjectUtility.EnsureUniqueNameForSibling(go);
            Undo.SetCurrentGroupName("Create " + go.name);

            EditorWindow.FocusWindowIfItsOpen <SceneHierarchyWindow>();
            Selection.activeGameObject = go;
        }
コード例 #3
0
        internal static void Place(GameObject go, GameObject parent, bool ignoreSceneViewPosition = true)
        {
            Transform defaultObjectTransform = SceneView.GetDefaultParentObjectIfSet();

            if (parent != null)
            {
                // At this point, RecordStructureChange is already ongoing (from the CreatePrimitive call through the CreateAndPlacePrimitive method). We need to flush the stack to finalise the RecordStructureChange before the
                // following SetTransformParent call takes place.
                Undo.FlushTrackedObjects();

                SetGameObjectParent(go, parent.transform);
            }
            else if (defaultObjectTransform != null)
            {
                // At this point, RecordStructureChange is already ongoing (from the CreatePrimitive call through the CreateAndPlacePrimitive method). We need to flush the stack to finalise the RecordStructureChange before the
                // following SetTransformParent call takes place.
                Undo.FlushTrackedObjects();

                SetGameObjectParent(go, defaultObjectTransform);
            }
            else
            {
                // When creating a 3D object without a parent, this option puts it at the world origin instead of scene pivot.
                if (placeObjectsAtWorldOrigin)
                {
                    go.transform.position = Vector3.zero;
                }
                else if (ignoreSceneViewPosition)
                {
                    SceneView.PlaceGameObjectInFrontOfSceneView(go);
                }

                StageUtility.PlaceGameObjectInCurrentStage(go); // may change parent
            }

            // Only at this point do we know the actual parent of the object and can modify its name accordingly.
            GameObjectUtility.EnsureUniqueNameForSibling(go);
            Undo.SetCurrentGroupName("Create " + go.name);

            var sh = SceneHierarchyWindow.GetSceneHierarchyWindowToFocusForNewGameObjects();

            if (sh != null)
            {
                sh.Focus();
            }

            Selection.activeGameObject = go;
        }
コード例 #4
0
 internal static void Place(GameObject go, GameObject parent)
 {
     if (parent != null)
     {
         Transform transform = go.transform;
         transform.SetParent(parent.transform, false);
         transform.localPosition = Vector3.zero;
         transform.localRotation = Quaternion.identity;
         transform.localScale    = Vector3.one;
         go.layer = parent.layer;
         if (parent.GetComponent <RectTransform>())
         {
             ObjectFactory.AddComponent <RectTransform>(go);
         }
     }
     SceneView.PlaceGameObjectInFrontOfSceneView(go);
     EditorWindow.FocusWindowIfItsOpen <SceneHierarchyWindow>();
     Selection.activeGameObject = go;
 }
コード例 #5
0
        internal static void Place(GameObject go, GameObject parent)
        {
            if (parent != null)
            {
                var transform = go.transform;
                Undo.SetTransformParent(transform, parent.transform, "Reparenting");
                transform.localPosition = Vector3.zero;
                transform.localRotation = Quaternion.identity;
                transform.localScale    = Vector3.one;
                go.layer = parent.layer;

                if (parent.GetComponent <RectTransform>())
                {
                    ObjectFactory.AddComponent <RectTransform>(go);
                }
            }
            else
            {
                // When creating a 3D object without a parent, this option puts it at the world origin instead of scene pivot.
                if (EditorPrefs.GetBool("Create3DObject.PlaceAtWorldOrigin", false))
                {
                    go.transform.position = Vector3.zero;
                }
                else
                {
                    SceneView.PlaceGameObjectInFrontOfSceneView(go);
                }

                StageUtility.PlaceGameObjectInCurrentStage(go); // may change parent
            }

            // Only at this point do we know the actual parent of the object and can modify its name accordingly.
            GameObjectUtility.EnsureUniqueNameForSibling(go);
            Undo.SetCurrentGroupName("Create " + go.name);

            EditorWindow.FocusWindowIfItsOpen <SceneHierarchyWindow>();
            Selection.activeGameObject = go;
        }