private void CreatePlacementTool() { Selection.activeObject = null; GameObject obj = prefabBrowser.SelectedPrefab; // This method gives me the selected prefab from the window. dummyObject = PrefabUtility.InstantiatePrefab(obj) as GameObject; //dummyObject.hideFlags = HideFlags.HideInHierarchy; dummyObject.AddComponent <ClickSpawn>(); ClickSpawn clickSpawn = dummyObject.GetComponent <ClickSpawn>(); //we send transform data to ClickSpawn clickSpawn.setTransformData(tmp_position, tmp_rotation, tmp_scale); clickSpawn.setLayer(layerNames[layerSelected], layerSelected); clickSpawn.setPhysics(tmp_enable_physics); //we send parent data to ClickSpawn if (parentObject != null) { clickSpawn.setParent(ref parentObject); } clickSpawn.prefab = obj; // TO-DO // Add parameters to configure the clickspawn component // Additional transform settings //clickSpawn.layerIndex = 2; dummyObject.name = "MVDT_DummyObject"; MVDUtils.RecursiveSetLayer(dummyObject.transform, 2); MVDUtils.ChangeAllMaterials(dummyObject, Resources.Load("mtl_debug_placement") as Material); }
private void CreatePlacementTool() { Selection.activeObject = null; GameObject obj = prefabBrowser.SelectedPrefab; // This method gives me the selected prefab from the window. dummyObject = PrefabUtility.InstantiatePrefab(obj) as GameObject; //dummyObject.hideFlags = HideFlags.HideInHierarchy; dummyObject.AddComponent <ClickSpawn>(); ClickSpawn clickSpawn = dummyObject.GetComponent <ClickSpawn>(); clickSpawn.prefab = obj; // TO-DO // Add parameters to configure the clickspawn component // Additional transform settings //clickSpawn.layerIndex = 2; dummyObject.name = "MVDT_DummyObject"; MVDUtils.RecursiveSetLayer(dummyObject.transform, 2); MVDUtils.ChangeAllMaterials(dummyObject, Resources.Load("mtl_debug_placement") as Material); }
static void DisplayPanelPlacement() { EditorGUILayout.BeginVertical("Box"); { //EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(100), GUILayout.Height(100)); GUILayout.BeginHorizontal(); { GUILayout.Label("Misc settings", EditorStyles.boldLabel); } GUILayout.EndHorizontal(); GUILayout.Space(5); placementValues.physicsOn = EditorGUILayout.Toggle("Enable physics", placementValues.physicsOn); GUILayout.BeginHorizontal(); { GUILayout.Label("Layer filter ", EditorStyles.label); placementValues.currentLayer = EditorGUILayout.Popup(placementValues.currentLayer, miscValues.allLayers); } GUILayout.EndHorizontal(); placementValues.trans = (Transform)EditorGUILayout.ObjectField("Attach to parent", placementValues.trans, typeof(Transform)); GUILayout.Space(5); } GUILayout.EndVertical(); EditorGUILayout.BeginVertical("Box"); { GUILayout.BeginHorizontal(); { GUILayout.Label("Transform settings", EditorStyles.boldLabel); } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(); GUILayout.Label("Pos", EditorStyles.label); placementValues.position = EditorGUILayout.Vector3Field("", placementValues.position); if (GUILayout.Button("X")) { placementValues.position = new Vector3(0, 0, 0); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Rot", EditorStyles.label); placementValues.rotation = EditorGUILayout.Vector3Field("", placementValues.rotation); if (GUILayout.Button("R")) { placementValues.rotation = new Vector3(Random.Range(0, 90), Random.Range(0, 90), Random.Range(0, 90)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Sct", EditorStyles.label); placementValues.scale = EditorGUILayout.Vector3Field("", placementValues.scale); if (GUILayout.Button("R")) { placementValues.scale = new Vector3(Random.Range(0, 10), Random.Range(0, 10), Random.Range(0, 10)); } GUILayout.EndHorizontal(); GUILayout.Space(5); } GUILayout.EndVertical(); GUILayout.BeginVertical("Box"); { bool someOption = true; GUILayout.Label("Prefab Browser", EditorStyles.boldLabel); GUILayout.BeginHorizontal(EditorStyles.toolbar); someOption = GUILayout.Toggle(someOption, "Filter search", EditorStyles.toolbarButton); GUILayout.FlexibleSpace(); placementValues.search = EditorGUILayout.TextField(GUIContent.none, placementValues.search, "ToolbarSeachTextField", GUILayout.Height(EditorGUIUtility.singleLineHeight)); if (GUILayout.Button(GUIContent.none, string.IsNullOrEmpty(placementValues.search) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton")) { placementValues.search = string.Empty; GUI.FocusControl(""); } GUILayout.EndHorizontal(); GUILayout.BeginVertical(); { GUILayout.Space(300); GUILayout.BeginHorizontal(); GUILayout.Space(300); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); { Rect trect = GUILayoutUtility.GetLastRect(); Event current = Event.current; DrawPrefabList(trect, current); } } GUILayout.EndVertical(); // Panel access GUILayout.BeginHorizontal(); { if (!inEditionMode) { if (GUILayout.Button(raycastingToolOn, "Button")) { GameObject obj = AssetDatabase.LoadAssetAtPath(placementValues.selectedGuids.First().Value, typeof(UnityEngine.Object)) as GameObject; rootEditor = PrefabUtility.InstantiatePrefab(obj) as GameObject; rootEditor.hideFlags = HideFlags.HideInHierarchy; rootEditor.AddComponent <MeshRenderer>(); rootEditor.AddComponent <MeshFilter>(); rootEditor.AddComponent <ClickSpawn>(); rootEditor.GetComponent <ClickSpawn>().physics = placementValues.physicsOn; rootEditor.GetComponent <ClickSpawn>().parent = placementValues.trans; rootEditor.GetComponent <ClickSpawn>().scale = placementValues.scale; rootEditor.GetComponent <ClickSpawn>().rotation = placementValues.rotation; rootEditor.GetComponent <ClickSpawn>().position = placementValues.position; rootEditor.GetComponent <ClickSpawn>().layerIndex = placementValues.currentLayer; rootEditor.GetComponent <ClickSpawn>().prefab = obj; rootEditor.layer = 12; // Unpack prefab instance and change its materials. PrefabUtility.UnpackPrefabInstance(rootEditor, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); MVDUtils.ChangeAllMaterials(rootEditor, Resources.Load("Materials/RootEditor") as Material); inEditionMode = true; } } else { PlacementToolUpdate(); GUIStyle ToggleButtonStyleToggled = new GUIStyle("Button"); ToggleButtonStyleToggled.normal.background = ToggleButtonStyleToggled.active.background; if (GUILayout.Button(raycastingToolOff, ToggleButtonStyleToggled)) { DestroyImmediate(rootEditor); inEditionMode = false; } } } GUILayout.EndHorizontal(); }