private static void CreateIsometricTilemap(GridLayout.CellLayout isometricLayout, string undoMessage) { var root = FindOrCreateRootGrid(); var uniqueName = GameObjectUtility.GetUniqueNameForSibling(root.transform, "Tilemap"); var tilemapGO = ObjectFactory.CreateGameObject(uniqueName, typeof(Tilemap), typeof(TilemapRenderer)); tilemapGO.transform.SetParent(root.transform); tilemapGO.transform.position = Vector3.zero; var grid = root.GetComponent <Grid>(); // Case 1071703: Do not reset cell size if adding a new Tilemap to an existing Grid of the same layout if (isometricLayout != grid.cellLayout) { grid.cellLayout = isometricLayout; grid.cellSize = new Vector3(1.0f, 0.5f, 1.0f); } var tilemapRenderer = tilemapGO.GetComponent <TilemapRenderer>(); tilemapRenderer.sortOrder = TilemapRenderer.SortOrder.TopRight; Selection.activeGameObject = tilemapGO; Undo.RegisterCreatedObjectUndo(tilemapGO, undoMessage); }
static void CreateSpriteMaskGameObject() { var go = ObjectFactory.CreateGameObject("", typeof(SpriteMask)); if (Selection.activeObject is Sprite) { go.GetComponent <SpriteMask>().sprite = (Sprite)Selection.activeObject; } else if (Selection.activeObject is Texture2D) { var assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); if (!string.IsNullOrEmpty(assetPath)) { var sprite = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath); if (sprite != null) { go.GetComponent <SpriteMask>().sprite = sprite; } } } else if (Selection.activeObject is GameObject) { var activeGO = (GameObject)Selection.activeObject; var prefabType = PrefabUtility.GetPrefabType(activeGO); if (prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab) { GameObjectUtility.SetParentAndAlign(go, activeGO); } } go.name = GameObjectUtility.GetUniqueNameForSibling(go.transform.parent, Contents.newSpriteMaskName.text); Undo.SetCurrentGroupName(Contents.createSpriteMaskUndoString.text); Selection.activeGameObject = go; }
public static GameObject CreateDragGO(Sprite frame, Vector3 position, SceneView sceneView) { string name = string.IsNullOrEmpty(frame.name) ? "Sprite" : frame.name; name = GameObjectUtility.GetUniqueNameForSibling(null, name); // ObjectFactory registers an Undo for the GameObject created, which we do not // want for the drag preview. We register an Undo only when the user does a // DragPerform to confirm the creation of the Sprite GameObject. // The GameObject is cloned and returned while the original is destroyed to // remove the Undo operation. GameObject go = ObjectFactory.CreateGameObject(name, typeof(SpriteRenderer)); GameObject cloneGO = GameObject.Instantiate(go); Object.DestroyImmediate(go); go = cloneGO; go.name = name; SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>(); spriteRenderer.sprite = frame; go.transform.position = position; go.hideFlags = HideFlags.HideInHierarchy; Scene destinationScene = GetDestinationSceneForNewGameObjectsForSceneView(sceneView); // According to how GameOjectInspector.cs moves the object into scene if (EditorApplication.isPlaying && !EditorSceneManager.IsPreviewScene(destinationScene)) { SceneManager.MoveGameObjectToScene(go, destinationScene); } return(go); }
static void CreateEmptyChild(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; if (parent == null) { var activeGO = Selection.activeGameObject; if (activeGO != null && !EditorUtility.IsPersistent(activeGO)) { parent = activeGO; } } // If selected GameObject is a Sub Scene header, place GameObject in active scene // similar to what happens when other scene headers are selected. SceneHierarchyHooks.SubSceneInfo info = SubSceneGUI.GetSubSceneInfo(parent); if (info.isValid) { parent = null; } var go = ObjectFactory.CreateGameObject("GameObject"); Place(go, parent); }
private static GameObject FindOrCreateRootGrid() { GameObject gameObject = null; if (Selection.activeObject is GameObject) { GameObject gameObject2 = (GameObject)Selection.activeObject; Grid componentInParent = gameObject2.GetComponentInParent <Grid>(); if (componentInParent != null) { gameObject = componentInParent.gameObject; } } if (gameObject == null) { gameObject = ObjectFactory.CreateGameObject("Grid", new Type[] { typeof(Grid) }); gameObject.transform.position = Vector3.zero; Grid component = gameObject.GetComponent <Grid>(); component.cellSize = new Vector3(1f, 1f, 0f); Undo.SetCurrentGroupName("Create Grid"); } return(gameObject); }
public static GameObject CreateDragGO(Sprite frame, Vector3 position, SceneView sceneView) { string name = string.IsNullOrEmpty(frame.name) ? "Sprite" : frame.name; name = GameObjectUtility.GetUniqueNameForSibling(null, name); // ObjectFactory registers an Undo for the GameObject created, which we do not // want for the drag preview. We register an Undo only when the user does a // DragPerform to confirm the creation of the Sprite GameObject. // The GameObject is cloned and returned while the original is destroyed to // remove the Undo operation. GameObject go = ObjectFactory.CreateGameObject(name, typeof(SpriteRenderer)); GameObject cloneGO = GameObject.Instantiate(go); Object.DestroyImmediate(go); go = cloneGO; go.name = name; SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>(); spriteRenderer.sprite = frame; go.transform.position = position; go.hideFlags = HideFlags.HideAndDontSave; // Ensure that the dragged gameobjects gets the correct scene culling mask so it can be rendered in the SceneView (when the SceneView camera is culling on a custom scene) if (sceneView.customScene.IsValid()) { SceneManager.MoveGameObjectToScene(go, sceneView.customScene); } return(go); }
private static GameObject FindOrCreateRootGrid() { GameObject gridGO = null; // Check if active object has a Grid and can be a parent for the Tile Map if (Selection.activeObject is GameObject) { var go = (GameObject)Selection.activeObject; var parentGrid = go.GetComponentInParent <Grid>(); if (parentGrid != null) { gridGO = parentGrid.gameObject; } } // If neither the active object nor its parent has a grid, create a grid for the tilemap if (gridGO == null) { gridGO = ObjectFactory.CreateGameObject("Grid", typeof(Grid)); gridGO.transform.position = Vector3.zero; var grid = gridGO.GetComponent <Grid>(); grid.cellSize = new Vector3(1.0f, 1.0f, 0.0f); Undo.SetCurrentGroupName("Create Grid"); } return(gridGO); }
static void CreateTrail(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var go = ObjectFactory.CreateGameObject("Trail", typeof(TrailRenderer)); go.GetComponent <TrailRenderer>().material = Material.GetDefaultLineMaterial(); Place(go, parent); }
static void CreatePointLight(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var go = ObjectFactory.CreateGameObject("Point Light", typeof(Light)); go.GetComponent <Light>().type = LightType.Point; Place(go, parent); }
static void CreateSpotLight(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var go = ObjectFactory.CreateGameObject("Spot Light", typeof(Light)); go.GetComponent <Light>().type = LightType.Spot; go.GetComponent <Transform>().SetLocalEulerAngles(new Vector3(90, 0, 0), RotationOrder.OrderZXY); Place(go, parent); }
internal static void CreateRectangularTilemap() { var root = FindOrCreateRootGrid(); var uniqueName = GameObjectUtility.GetUniqueNameForSibling(root.transform, "Tilemap"); var tilemapGO = ObjectFactory.CreateGameObject(uniqueName, typeof(Tilemap), typeof(TilemapRenderer)); Undo.SetTransformParent(tilemapGO.transform, root.transform, ""); tilemapGO.transform.position = Vector3.zero; Undo.SetCurrentGroupName("Create Tilemap"); }
static void CreateDirectionalLight(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var go = ObjectFactory.CreateGameObject("Directional Light", typeof(Light)); go.GetComponent <Light>().type = LightType.Directional; go.GetComponent <Light>().intensity = 1f; go.GetComponent <Transform>().SetLocalEulerAngles(new Vector3(50, -30, 0), RotationOrder.OrderZXY); Place(go, parent); }
static void CreateLine(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var go = ObjectFactory.CreateGameObject("Line", typeof(LineRenderer)); var line = go.GetComponent <LineRenderer>(); line.material = Material.GetDefaultLineMaterial(); line.widthMultiplier = 0.1f; line.useWorldSpace = false; Place(go, parent); }
static void CreateParticleSystem(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var go = ObjectFactory.CreateGameObject("Particle System", typeof(ParticleSystem)); go.GetComponent <Transform>().SetLocalEulerAngles(new Vector3(-90, 0, 0), RotationOrder.OrderZXY); var renderer = go.GetComponent <ParticleSystemRenderer>(); renderer.material = Material.GetDefaultParticleMaterial(); Place(go, parent); }
static void CreateParticleSystem(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var go = ObjectFactory.CreateGameObject("Particle System", typeof(ParticleSystem)); go.GetComponent <Transform>().SetLocalEulerAngles(new Vector3(-90, 0, 0), RotationOrder.OrderZXY); var renderer = go.GetComponent <ParticleSystemRenderer>(); renderer.material = Material.GetDefaultParticleMaterial(); renderer.oldTrailMaterial = Material.GetDefaultLineMaterial(); // This trick means that when enabling the trails module for the first time, there is a default material assigned Place(go, parent); }
public static GameObject CreatePrimitive(PrimitiveType type) { GameObject gameObject = ObjectFactory.CreateGameObject(type.ToString(), new Type[] { typeof(MeshFilter), typeof(MeshRenderer) }); gameObject.SetActive(false); switch (type) { case PrimitiveType.Sphere: gameObject.GetComponent <MeshFilter>().sharedMesh = Resources.GetBuiltinResource <Mesh>("New-Sphere.fbx"); ObjectFactory.AddComponent <SphereCollider>(gameObject); break; case PrimitiveType.Capsule: { gameObject.GetComponent <MeshFilter>().sharedMesh = Resources.GetBuiltinResource <Mesh>("New-Capsule.fbx"); CapsuleCollider capsuleCollider = ObjectFactory.AddComponent <CapsuleCollider>(gameObject); capsuleCollider.height = 2f; break; } case PrimitiveType.Cylinder: { gameObject.GetComponent <MeshFilter>().sharedMesh = Resources.GetBuiltinResource <Mesh>("New-Cylinder.fbx"); CapsuleCollider capsuleCollider2 = ObjectFactory.AddComponent <CapsuleCollider>(gameObject); capsuleCollider2.height = 2f; break; } case PrimitiveType.Cube: gameObject.GetComponent <MeshFilter>().sharedMesh = Resources.GetBuiltinResource <Mesh>("Cube.fbx"); ObjectFactory.AddComponent <BoxCollider>(gameObject); break; case PrimitiveType.Plane: gameObject.GetComponent <MeshFilter>().sharedMesh = Resources.GetBuiltinResource <Mesh>("New-Plane.fbx"); ObjectFactory.AddComponent <MeshCollider>(gameObject); break; case PrimitiveType.Quad: gameObject.GetComponent <MeshFilter>().sharedMesh = Resources.GetBuiltinResource <Mesh>("Quad.fbx"); ObjectFactory.AddComponent <MeshCollider>(gameObject); break; } Renderer component = gameObject.GetComponent <Renderer>(); component.material = Material.GetDefaultMaterial(); gameObject.SetActive(true); return(gameObject); }
static void Create3DText(MenuCommand command) { var parent = command.context as GameObject; var go = ObjectFactory.CreateGameObject("New Text", typeof(MeshRenderer), typeof(TextMesh)); var font = Selection.activeObject as Font ?? Font.GetDefault(); TextMesh tm = go.GetComponent <TextMesh>(); tm.text = "Hello World"; tm.font = font; go.GetComponent <MeshRenderer>().material = font.material; GOCreationCommands.Place(go, parent); }
internal static void CreateRectangularTilemap() { GameObject gameObject = TilemapEditor.FindOrCreateRootGrid(); string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(gameObject.transform, "Tilemap"); GameObject gameObject2 = ObjectFactory.CreateGameObject(uniqueNameForSibling, new Type[] { typeof(Tilemap), typeof(TilemapRenderer) }); Undo.SetTransformParent(gameObject2.transform, gameObject.transform, ""); gameObject2.transform.position = Vector3.zero; Undo.SetCurrentGroupName("Create Tilemap"); }
private static void CreateHexagonalTilemap(GridLayout.CellSwizzle swizzle, string undoMessage) { var root = FindOrCreateRootGrid(); var uniqueName = GameObjectUtility.GetUniqueNameForSibling(root.transform, "Tilemap"); var tilemapGO = ObjectFactory.CreateGameObject(uniqueName, typeof(Tilemap), typeof(TilemapRenderer)); tilemapGO.transform.SetParent(root.transform); tilemapGO.transform.position = Vector3.zero; var grid = root.GetComponent <Grid>(); grid.cellLayout = Grid.CellLayout.Hexagon; grid.cellSwizzle = swizzle; var tilemap = tilemapGO.GetComponent <Tilemap>(); tilemap.tileAnchor = Vector3.zero; Undo.RegisterCreatedObjectUndo(tilemapGO, undoMessage); }
static void CreateEmptyChild(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; if (parent == null) { var activeGO = Selection.activeGameObject; if (activeGO != null && !EditorUtility.IsPersistent(activeGO)) { parent = activeGO; } } var go = ObjectFactory.CreateGameObject("GameObject"); Place(go, parent); }
static void CreateSprite(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var go = ObjectFactory.CreateGameObject("New Sprite", typeof(SpriteRenderer)); var sprite = Selection.activeObject as Sprite; if (sprite == null) { var texture = Selection.activeObject as Texture2D; if (texture) { string path = AssetDatabase.GetAssetPath(texture); sprite = AssetDatabase.LoadAllAssetsAtPath(path) .OfType <Sprite>() .FirstOrDefault(); if (sprite == null) { var importer = AssetImporter.GetAtPath(path) as TextureImporter; if (importer != null && importer.textureType != TextureImporterType.Sprite) { EditorUtility.DisplayDialog( "Sprite could not be assigned!", "Can not assign a Sprite to the new SpriteRenderer because the selected Texture is not configured to generate Sprites.", "OK"); } } } } if (sprite != null) { go.GetComponent <SpriteRenderer>().sprite = sprite; } else { // TODO: assign a default sprite } Place(go, parent); }
private static void CreateSpriteMaskGameObject() { GameObject gameObject = ObjectFactory.CreateGameObject("", new Type[] { typeof(SpriteMask) }); if (Selection.activeObject is Sprite) { gameObject.GetComponent <SpriteMask>().sprite = (Sprite)Selection.activeObject; } else if (Selection.activeObject is Texture2D) { string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); if (!string.IsNullOrEmpty(assetPath)) { Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath); if (sprite != null) { gameObject.GetComponent <SpriteMask>().sprite = sprite; } } } else if (Selection.activeObject is GameObject) { GameObject gameObject2 = (GameObject)Selection.activeObject; PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject2); if (prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab) { GameObjectUtility.SetParentAndAlign(gameObject, gameObject2); } } gameObject.name = GameObjectUtility.GetUniqueNameForSibling(gameObject.transform.parent, SpriteMaskEditor.Contents.newSpriteMaskName.text); Undo.SetCurrentGroupName(SpriteMaskEditor.Contents.createSpriteMaskUndoString.text); Selection.activeGameObject = gameObject; }
static void CreateReflectionProbe(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; Place(ObjectFactory.CreateGameObject("Reflection Probe", typeof(ReflectionProbe)), parent); }
internal static GameObject CreateGameObject(GameObject parent, string name, params Type[] types) { return(ObjectFactory.CreateGameObject(GameObjectUtility.GetUniqueNameForSibling(parent != null ? parent.transform : null, name), types)); }
static void CreateEmpty(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; Place(ObjectFactory.CreateGameObject("GameObject"), parent); }
static void CreateCamera(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; Place(ObjectFactory.CreateGameObject("Camera", typeof(Camera), typeof(AudioListener)), parent); }
static void CreateParticleSystemForceField(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; Place(ObjectFactory.CreateGameObject("Particle System Force Field", typeof(ParticleSystemForceField)), parent); }
static void CreateVideoPlayer(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; Place(ObjectFactory.CreateGameObject("Video Player", typeof(VideoPlayer)), parent); }
static void CreateAudioReverbZone(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; Place(ObjectFactory.CreateGameObject("Audio Reverb Zone", typeof(AudioReverbZone)), parent); }
static void CreateLightProbeGroup(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; Place(ObjectFactory.CreateGameObject("Light Probe Group", typeof(LightProbeGroup)), parent); }