public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged) { EditorGUILayout.HelpBox("Build Player: Build Player.", MessageType.Info); editor.UpdateNodeName(node); if (m_buildOptions == null) { return; } GUILayout.Space(10f); //Show target configuration tab editor.DrawPlatformSelector(node); using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var disabledScope = editor.DrawOverrideTargetToggle(node, m_buildOptions.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => { using (new RecordUndoScope("Remove Target Build Settings", node, true)) { if (enabled) { m_buildOptions[editor.CurrentEditingGroup] = m_buildOptions.DefaultValue; m_buildLocations[editor.CurrentEditingGroup] = m_buildLocations.DefaultValue; m_playerName[editor.CurrentEditingGroup] = m_playerName.DefaultValue; m_scenes[editor.CurrentEditingGroup] = m_scenes.DefaultValue; } else { m_buildOptions.Remove(editor.CurrentEditingGroup); m_buildLocations.Remove(editor.CurrentEditingGroup); m_playerName.Remove(editor.CurrentEditingGroup); m_scenes.Remove(editor.CurrentEditingGroup); } onValueChanged(); } }); using (disabledScope) { using (var scrollScope = new EditorGUILayout.ScrollViewScope(m_scroll)) { m_scroll = scrollScope.scrollPosition; GUILayout.Label("Player Build Location", "BoldLabel"); var newBuildLocation = editor.DrawFolderSelector("", "Select Build Location", m_buildLocations[editor.CurrentEditingGroup], Application.dataPath + "/../" ); if (newBuildLocation.StartsWith(Application.dataPath)) { throw new NodeException("You can not build player inside Assets directory.", "Select build location outside Assets directory.", node.Data); } if (newBuildLocation != m_buildLocations[editor.CurrentEditingGroup]) { using (new RecordUndoScope("Change Build Location", node, true)) { m_buildLocations[editor.CurrentEditingGroup] = newBuildLocation; onValueChanged(); } } GUILayout.Space(4f); var newPlayerName = EditorGUILayout.TextField("Player Name", m_playerName[editor.CurrentEditingGroup]); if (newPlayerName != m_playerName[editor.CurrentEditingGroup]) { using (new RecordUndoScope("Change Player Name", node, true)) { m_playerName[editor.CurrentEditingGroup] = newPlayerName; onValueChanged(); } } GUILayout.Space(10f); GUILayout.Label("Build Options", "BoldLabel"); int buildOptions = m_buildOptions[editor.CurrentEditingGroup]; foreach (var option in Model.Settings.BuildPlayerOptionsSettings) { // contains keyword == enabled. if not, disabled. bool isEnabled = (buildOptions & (int)option.option) != 0; var result = EditorGUILayout.ToggleLeft(option.description, isEnabled); if (result != isEnabled) { using (new RecordUndoScope("Change Build Option", node, true)) { buildOptions = (result) ? ((int)option.option | buildOptions) : (((~(int)option.option)) & buildOptions); m_buildOptions[editor.CurrentEditingGroup] = buildOptions; onValueChanged(); } } } var scenesInProject = AssetDatabase.FindAssets("t:Scene"); if (scenesInProject.Length > 0) { GUILayout.Space(10f); GUILayout.Label("Scenes", "BoldLabel"); using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var scenesSelected = m_scenes[editor.CurrentEditingGroup].Split(','); foreach (var sceneGUID in scenesInProject) { var path = AssetDatabase.GUIDToAssetPath(sceneGUID); if (string.IsNullOrEmpty(path)) { ArrayUtility.Remove(ref scenesSelected, sceneGUID); m_scenes[editor.CurrentEditingGroup] = string.Join(",", scenesSelected); onValueChanged(); continue; } var type = TypeUtility.GetMainAssetTypeAtPath(path); if (type != typeof(UnityEditor.SceneAsset)) { continue; } var selected = scenesSelected.Contains(sceneGUID); var newSelected = EditorGUILayout.ToggleLeft(path, selected); if (newSelected != selected) { using (new RecordUndoScope("Change Scene Selection", node, true)) { if (newSelected) { ArrayUtility.Add(ref scenesSelected, sceneGUID); } else { ArrayUtility.Remove(ref scenesSelected, sceneGUID); } m_scenes[editor.CurrentEditingGroup] = string.Join(",", scenesSelected); onValueChanged(); } } } } } } } } }
public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged) { EditorGUILayout.HelpBox("Create Prefab From Group: Create prefab from incoming group of assets, using assigned script.", MessageType.Info); editor.UpdateNodeName(node); var builder = m_instance.Get <IPrefabBuilder>(editor.CurrentEditingGroup); using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var map = PrefabBuilderUtility.GetAttributeAssemblyQualifiedNameMap(); if (map.Count > 0) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("PrefabBuilder"); var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(m_instance.ClassName); if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f))) { var builders = map.Keys.ToList(); if (builders.Count > 0) { NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) => { using (new RecordUndoScope("Change PrefabBuilder class", node, true)) { builder = PrefabBuilderUtility.CreatePrefabBuilder(selectedGUIName); m_instance.Set(editor.CurrentEditingGroup, builder); onValueChanged(); } } ); } } MonoScript s = TypeUtility.LoadMonoScript(m_instance.ClassName); using (new EditorGUI.DisabledScope(s == null)) { if (GUILayout.Button("Edit", GUILayout.Width(50))) { AssetDatabase.OpenAsset(s, 0); } } } ReplacePrefabOptions opt = (ReplacePrefabOptions)EditorGUILayout.EnumPopup("Prefab Replace Option", m_replacePrefabOptions, GUILayout.MinWidth(150f)); if (m_replacePrefabOptions != opt) { using (new RecordUndoScope("Change Prefab Replace Option", node, true)) { m_replacePrefabOptions = opt; onValueChanged(); } opt = m_replacePrefabOptions; } } else { if (!string.IsNullOrEmpty(m_instance.ClassName)) { EditorGUILayout.HelpBox( string.Format( "Your PrefabBuilder script {0} is missing from assembly. Did you delete script?", m_instance.ClassName), MessageType.Info); } else { string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_PREFABBUILDER.Split('/'); EditorGUILayout.HelpBox( string.Format( "You need to create at least one PrefabBuilder script to use this node. To start, select {0}>{1}>{2} menu and create new script from template.", menuNames[1], menuNames[2], menuNames[3] ), MessageType.Info); } } GUILayout.Space(10f); editor.DrawPlatformSelector(node); using (new EditorGUILayout.VerticalScope()) { var disabledScope = editor.DrawOverrideTargetToggle(node, m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => { if (enabled) { m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup); m_outputDir[editor.CurrentEditingGroup] = m_outputDir.DefaultValue; m_outputOption[editor.CurrentEditingGroup] = m_outputOption.DefaultValue; } else { m_instance.Remove(editor.CurrentEditingGroup); m_outputDir.Remove(editor.CurrentEditingGroup); m_outputOption.Remove(editor.CurrentEditingGroup); } onValueChanged(); }); using (disabledScope) { OutputOption opt = (OutputOption)m_outputOption[editor.CurrentEditingGroup]; var newOption = (OutputOption)EditorGUILayout.EnumPopup("Output Option", opt); if (newOption != opt) { using (new RecordUndoScope("Change Output Option", node, true)){ m_outputOption[editor.CurrentEditingGroup] = (int)newOption; onValueChanged(); } opt = newOption; } using (new EditorGUI.DisabledScope(opt == OutputOption.CreateInCacheDirectory)) { var newDirPath = editor.DrawFolderSelector("Output Directory", "Select Output Folder", m_outputDir[editor.CurrentEditingGroup], Application.dataPath, (string folderSelected) => { string basePath = Application.dataPath; if (basePath == folderSelected) { folderSelected = string.Empty; } else { var index = folderSelected.IndexOf(basePath); if (index >= 0) { folderSelected = folderSelected.Substring(basePath.Length + index); if (folderSelected.IndexOf('/') == 0) { folderSelected = folderSelected.Substring(1); } } } return(folderSelected); } ); if (newDirPath != m_outputDir[editor.CurrentEditingGroup]) { using (new RecordUndoScope("Change Output Directory", node, true)){ m_outputDir[editor.CurrentEditingGroup] = newDirPath; onValueChanged(); } } var dirPath = Path.Combine(Application.dataPath, m_outputDir [editor.CurrentEditingGroup]); if (opt == OutputOption.CreateInSelectedDirectory && !string.IsNullOrEmpty(m_outputDir [editor.CurrentEditingGroup]) && !Directory.Exists(dirPath)) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.LabelField(m_outputDir[editor.CurrentEditingGroup] + " does not exist."); if (GUILayout.Button("Create directory")) { Directory.CreateDirectory(dirPath); AssetDatabase.Refresh(); } } EditorGUILayout.Space(); string parentDir = Path.GetDirectoryName(m_outputDir[editor.CurrentEditingGroup]); if (Directory.Exists(parentDir)) { EditorGUILayout.LabelField("Available Directories:"); string[] dirs = Directory.GetDirectories(parentDir); foreach (string s in dirs) { EditorGUILayout.LabelField(s); } } EditorGUILayout.Space(); } var outputDir = PrepareOutputDirectory(BuildTargetUtility.GroupToTarget(editor.CurrentEditingGroup), node.Data); using (new EditorGUI.DisabledScope(!Directory.Exists(outputDir))) { using (new EditorGUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Highlight in Project Window", GUILayout.Width(180f))) { var folder = AssetDatabase.LoadMainAssetAtPath(outputDir); EditorGUIUtility.PingObject(folder); } } } } GUILayout.Space(8f); if (builder != null) { Action onChangedAction = () => { using (new RecordUndoScope("Change PrefabBuilder Setting", node)) { m_instance.Set(editor.CurrentEditingGroup, builder); onValueChanged(); } }; builder.OnInspectorGUI(onChangedAction); } } } } }
public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged) { EditorGUILayout.HelpBox("Overwrite Import Setting: Overwrite import settings of incoming assets.", MessageType.Info); editor.UpdateNodeName(node); // prevent inspector flicking by new Editor changing active selction node.SetActive(true); using (new EditorGUILayout.VerticalScope()) { Type importerType = null; Type assetType = null; var referenceImporter = GetReferenceAssetImporter(node.Data, false); if (referenceImporter != null) { importerType = referenceImporter.GetType(); assetType = TypeUtility.GetMainAssetTypeAtPath(AssetDatabase.GUIDToAssetPath(m_referenceAssetGuid)); } else { GUILayout.Space(10f); using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { EditorGUILayout.HelpBox("Import setting type can be set by incoming asset, or you can specify by selecting.", MessageType.Info); using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.LabelField("Importer Type"); if (GUILayout.Button("", "Popup", GUILayout.MinWidth(150f))) { var menu = new GenericMenu(); var guiMap = ImporterConfiguratorUtility.GetImporterConfiguratorGuiNameTypeMap(); var guiNames = guiMap.Keys.ToArray(); for (var i = 0; i < guiNames.Length; i++) { var index = i; menu.AddItem( new GUIContent(guiNames [i]), false, () => { ResetConfig(node.Data); CreateConfigurator(node.Data, guiMap [guiNames [index]]); onValueChanged(); // call Validate NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_NODE_UPDATED, node)); } ); } menu.ShowAsContext(); } } } return; } if (importerType != null && assetType != null) { GUILayout.Space(10f); DoCustomAssetGUI(assetType, importerType, node, editor, onValueChanged); } // get reference importer again (enabling custom asset this time) referenceImporter = GetReferenceAssetImporter(node.Data, true); if (referenceImporter != null) { var configurator = m_configuratorInstance.Get <IAssetImporterConfigurator> (editor.CurrentEditingGroup); if (configurator != null) { GUILayout.Space(10f); Action onChangedAction = () => { using (new RecordUndoScope(string.Format("Change {0} Setting", node.Name), node)) { m_configuratorInstance.Set(editor.CurrentEditingGroup, configurator); onValueChanged(); } }; configurator.OnInspectorGUI(referenceImporter, editor.CurrentEditingGroup, onChangedAction); } if (m_importerEditor == null) { m_importerEditor = Editor.CreateEditor(referenceImporter); } } if (m_importerEditor != null) { GUILayout.Space(10f); GUILayout.Label(string.Format("Import Setting ({0})", importerType.Name)); GUI.changed = false; m_importerEditor.OnInspectorGUI(); #if UNITY_2018_1_OR_NEWER if (GUI.changed) { referenceImporter.SaveAndReimport(); } #endif } GUILayout.Space(40f); using (new EditorGUILayout.HorizontalScope(GUI.skin.box)) { GUILayout.Space(4f); EditorGUILayout.LabelField("Clear Saved Import Setting"); if (GUILayout.Button("Clear")) { if (EditorUtility.DisplayDialog("Clear Saved Import Setting", string.Format("Do you want to reset saved import setting for \"{0}\"? This operation is not undoable.", node.Name), "OK", "Cancel")) { ResetConfig(node.Data); onValueChanged(); } } } } }
public void DrawHeader(SerializedComponent parent) { if (s_popupIcon == null) { s_popupIcon = EditorGUIUtility.Load("icons/_Popup.png") as Texture2D; } if (s_helpIcon == null) { s_helpIcon = EditorGUIUtility.Load("icons/_Help.png") as Texture2D; } GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1)); using (new EditorGUILayout.HorizontalScope()) { var thumbnail = AssetPreview.GetMiniTypeThumbnail(m_componentType); if (thumbnail == null) { if (typeof(MonoBehaviour).IsAssignableFrom(m_componentType)) { thumbnail = AssetPreview.GetMiniTypeThumbnail(typeof(MonoScript)); } else { thumbnail = AssetPreview.GetMiniTypeThumbnail(typeof(UnityEngine.Object)); } } GUILayout.Label(thumbnail, GUILayout.Width(32f), GUILayout.Height(32f)); if (m_component is Behaviour) { Behaviour b = m_component as Behaviour; b.enabled = EditorGUILayout.ToggleLeft(m_componentType.Name, b.enabled, EditorStyles.boldLabel); } else { GUILayout.Label(m_componentType.Name, EditorStyles.boldLabel); } GUILayout.FlexibleSpace(); if (Help.HasHelpForObject(m_component)) { var tooltip = string.Format("Open Reference for {0}.", m_componentType.Name); if (GUILayout.Button(new GUIContent(s_helpIcon, tooltip), EditorStyles.miniLabel, GUILayout.Width(20f), GUILayout.Height(20f))) { Help.ShowHelpForObject(m_component); } } if (GUILayout.Button(s_popupIcon, EditorStyles.miniLabel, GUILayout.Width(20f), GUILayout.Height(20f))) { GenericMenu m = new GenericMenu(); m.AddItem(new GUIContent("Copy Component"), false, () => { UnityEditorInternal.ComponentUtility.CopyComponent(m_component); }); var pasteLabel = new GUIContent("Paste Component Values"); m.AddItem(pasteLabel, false, () => { UnityEditorInternal.ComponentUtility.PasteComponentValues(m_component); }); m.AddItem(new GUIContent("Remove Component"), false, () => { parent.RemoveComponent(this); }); MonoScript s = TypeUtility.LoadMonoScript(m_componentType.AssemblyQualifiedName); if (s != null) { m.AddSeparator(""); m.AddItem( new GUIContent("Edit Script"), false, () => { AssetDatabase.OpenAsset(s, 0); } ); } m.ShowAsContext(); } } GUILayout.Space(4f); }