public static GameObject PlacePrefabInScene() { // Make sure target parent is referenced ReferenceTargetParent(); if (MAST_Placement_Visualizer.visualizerOnGrid && MAST_Placement_Visualizer.GetGameObject() != null && MAST_Placement_Visualizer.GetGameObject() != null) { // If drawing continuous and an object was just drawn here, exit without drawing if (MAST_Placement_Interface.placementMode == MAST_Placement_Interface.PlacementMode.DrawContinuous) { if (lastPosition == MAST_Placement_Visualizer.GetGameObject().transform.position) { return(null); } } // If GameObject already exists here, exit without placing the block if (GameObjectAlreadyHere()) { return(null); } // Instantiate the prefab GameObject newPrefab = (GameObject)PrefabUtility.InstantiatePrefab(MAST_Palette.GetSelectedPrefab()); // Correct GameObject transform and name "to remove (clone)" newPrefab.transform.rotation = MAST_Placement_Visualizer.GetGameObject().transform.rotation; newPrefab.transform.localScale = MAST_Placement_Visualizer.GetGameObject().transform.localScale; newPrefab.transform.position = MAST_Placement_Visualizer.GetGameObject().transform.position; newPrefab.name = MAST_Palette.GetSelectedPrefab().name; // Make new prefab child of the target parent newPrefab.transform.parent = targetParent.transform; // Add MAST script to GameObject if it was missing it if (!newPrefab.GetComponent <MAST_Prefab_Component>()) { newPrefab.AddComponent <MAST_Prefab_Component>(); } // Randomize the seed after placement if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 3) { MAST_Placement_Randomizer.GenerateNewRandomSeed(); } // Save this GameObject position lastPosition = MAST_Placement_Visualizer.GetGameObject().transform.position; // Make this an Undo point, just after placing the prefab Undo.RegisterCreatedObjectUndo(newPrefab, "Placed new Prefab"); // Return with newly created GameObject return(newPrefab); } return(null); }
// Change visualizer prefab when a new item is selected in the palette menu public static void ChangeSelectedPrefab() { // Get reference to the MAST script attached to the GameObject MAST_Placement_Helper.mastScript = MAST_Palette.GetSelectedPrefab().GetComponent <MAST_Prefab_Component>(); // Remove any existing visualizer MAST_Placement_Visualizer.RemoveVisualizer(); // Create a new visualizer MAST_Placement_Visualizer.CreateVisualizer(MAST_Palette.GetSelectedPrefab()); }