private void Awake() { editorToolsTypeContent = new GUIContent[] { new GUIContent { text = "Prefab", tooltip = "Prefab mode" }, new GUIContent { text = "Component", tooltip = "Component mode" }, }; editorPrefabToolsContent = new GUIContent[] { new GUIContent { text = "Add", tooltip = "Add prefab to prefab" }, new GUIContent { text = "Replace", tooltip = "Replace object with new prefab" }, new GUIContent { text = "ZeroParent", tooltip = "Zero parent transform to child objects" }, }; editorComponentToolsContent = new GUIContent[] { new GUIContent { text = "Add", tooltip = "Add component to object" }, new GUIContent { text = "RandomRotation", tooltip = "Apply random rotation to object" }, new GUIContent { text = "Remove", tooltip = "Remove component type" }, }; ToolType = EditorToolsType.Prefab; PrefabTool = EditorPrefabTools.ZeroParent; ComponentTool = EditorComponentTools.RandomRotation; }
private void OnGUI() { titleLabelStyle = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontSize = 14 }; subtitleLabelStyle = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontSize = 10 }; buttonStyle = new GUIStyle(GUI.skin.button); buttonStyle.onNormal.textColor = Color.white; nonProColor = new Color(0.75f, 0.75f, 0.75f); GUILayout.Space(10); EditorGUILayout.LabelField("Type", titleLabelStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(5); if (!EditorGUIUtility.isProSkin) { GUI.backgroundColor = nonProColor; } ToolType = (EditorToolsType)GUILayout.SelectionGrid((int)ToolType, editorToolsTypeContent, 2, buttonStyle); if (!EditorGUIUtility.isProSkin) { GUI.backgroundColor = Color.white; } GUILayout.Space(5); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Space(10); switch (ToolType) { case EditorToolsType.Prefab: EditorGUILayout.LabelField("Prefab Tools", titleLabelStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(5); if (!EditorGUIUtility.isProSkin) { GUI.backgroundColor = nonProColor; } PrefabTool = (EditorPrefabTools)GUILayout.SelectionGrid((int)PrefabTool, editorPrefabToolsContent, 2, buttonStyle); if (!EditorGUIUtility.isProSkin) { GUI.backgroundColor = Color.white; } GUILayout.Space(5); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Space(10); switch (PrefabTool) { case EditorPrefabTools.Add: EditorGUILayout.LabelField("Add Tool", subtitleLabelStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(10); EditorGUILayout.HelpBox("Add prefab and select the object to attach\nUseMeshCenter true = renderer.bounds.center\nUseMeshCenter false = pivot center\nPress Run", MessageType.None, true); PrefabToAdd = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Prefab to add", "This is the prefab to add"), PrefabToAdd, typeof(GameObject), true); GUILayout.Space(5); UseMeshCenter = EditorGUILayout.Toggle("Use mesh center", UseMeshCenter); GUILayout.Space(5); if (GUILayout.Button(new GUIContent("Run", "Run add prefab to prefab root"))) { AddPrefabTool(); } break; case EditorPrefabTools.Replace: EditorGUILayout.LabelField("Replace Tool", subtitleLabelStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(10); EditorGUILayout.HelpBox("Replace selection with prefab\nPress Run", MessageType.None, true); PrefabToReplace = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Prefab to replace", "This is the prefab to replace selection with"), PrefabToReplace, typeof(GameObject), true); GUILayout.Space(5); if (GUILayout.Button(new GUIContent("Run", "Run replace prefab"))) { ReplacePrefabTool(); } break; case EditorPrefabTools.ZeroParent: EditorGUILayout.LabelField("Zero Parent Tool", subtitleLabelStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(10); EditorGUILayout.HelpBox("Select child of prefab root to center prefab to\nPress Run", MessageType.None, true); if (GUILayout.Button(new GUIContent("Run", "Run zero parent to child object"))) { ZeroParentTool(); } break; } break; case EditorToolsType.Component: EditorGUILayout.LabelField("Component Tools", titleLabelStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(5); if (!EditorGUIUtility.isProSkin) { GUI.backgroundColor = nonProColor; } ComponentTool = (EditorComponentTools)GUILayout.SelectionGrid((int)ComponentTool, editorComponentToolsContent, 2, buttonStyle); if (!EditorGUIUtility.isProSkin) { GUI.backgroundColor = Color.white; } GUILayout.Space(5); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Space(10); switch (ComponentTool) { case EditorComponentTools.Add: EditorGUILayout.LabelField("Add Tool", subtitleLabelStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(10); EditorGUILayout.HelpBox("Assign script to add and select child to add to\nPress Run", MessageType.None, true); ScriptToAdd = (MonoScript)EditorGUILayout.ObjectField(new GUIContent("Script to add", "This is the script to add"), ScriptToAdd, typeof(MonoScript), true); GUILayout.Space(5); if (GUILayout.Button(new GUIContent("Run", "Run add component to prefab"))) { AddComponentTool(); } break; case EditorComponentTools.RandomRotation: EditorGUILayout.LabelField("Random Rotation Tool", subtitleLabelStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(10); break; case EditorComponentTools.Remove: EditorGUILayout.LabelField("Remove Tool", subtitleLabelStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(10); break; } break; } }