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; }
static void CreateTerrain(MenuCommand menuCommand) { // Create the storage for the terrain in the project // (So we can reuse it in multiple scenes) TerrainData terrainData = new TerrainData(); const int size = 1025; terrainData.heightmapResolution = size; terrainData.size = new Vector3(1000, 600, 1000); terrainData.heightmapResolution = 512; terrainData.baseMapResolution = 1024; terrainData.SetDetailResolution(1024, terrainData.detailResolutionPerPatch); AssetDatabase.CreateAsset(terrainData, AssetDatabase.GenerateUniqueAssetPath("Assets/New Terrain.asset")); var parent = menuCommand.context as GameObject; GameObject terrain = Terrain.CreateTerrainGameObject(terrainData); terrain.name = "Terrain"; GameObjectUtility.SetParentAndAlign(terrain, parent); StageUtility.PlaceGameObjectInCurrentStage(terrain); GameObjectUtility.EnsureUniqueNameForSibling(terrain); Selection.activeObject = terrain; Undo.RegisterCreatedObjectUndo(terrain, "Create terrain"); }
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; }
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; }
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; }