public override bool OnAssetsReimported( Model.NodeData nodeData, AssetReferenceStreamManager streamManager, BuildTarget target, string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { if (streamManager == null) { return(true); } var loadPath = m_loadPath[target]; // if loadPath is null/empty, loader load everything except for settings if (string.IsNullOrEmpty(loadPath)) { // ignore config file path update var notConfigFilePath = importedAssets.Where(path => !TypeUtility.IsGraphToolSystemAsset(path)); if (notConfigFilePath.Any()) { LogUtility.Logger.LogFormat(LogType.Log, "{0} is marked to revisit", nodeData.Name); return(true); } } var assetGroup = streamManager.FindAssetGroup(nodeData.OutputPoints[0]); if (assetGroup.Count > 0) { var importPath = string.Format("Assets/{0}", m_loadPath[target]); foreach (var path in importedAssets) { if (path.StartsWith(importPath)) { // if this is reimport, we don't need to redo Loader if (assetGroup["0"].Find(x => x.importFrom == path) == null) { LogUtility.Logger.LogFormat(LogType.Log, "{0} is marked to revisit", nodeData.Name); return(true); } } } foreach (var path in deletedAssets) { if (path.StartsWith(importPath)) { LogUtility.Logger.LogFormat(LogType.Log, "{0} is marked to revisit", nodeData.Name); return(true); } } foreach (var path in movedAssets) { if (path.StartsWith(importPath)) { LogUtility.Logger.LogFormat(LogType.Log, "{0} is marked to revisit", nodeData.Name); return(true); } } foreach (var path in movedFromAssetPaths) { if (path.StartsWith(importPath)) { LogUtility.Logger.LogFormat(LogType.Log, "{0} is marked to revisit", nodeData.Name); return(true); } } } return(false); }
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.", node.Id); } 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.GetTypeOfAsset(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(); } } } } } } } } }
private void DrawGeneratorSetting( GeneratorEntry entry, NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged) { var generator = entry.m_instance.Get <IAssetGenerator>(editor.CurrentEditingGroup); using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var newName = EditorGUILayout.TextField("Name", entry.m_name); if (newName != entry.m_name) { using (new RecordUndoScope("Change Name", node, true)) { entry.m_name = newName; UpdateGeneratorEntry(node.Data, entry); // event must raise to propagate change to connection associated with point NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CONNECTIONPOINT_LABELCHANGED, node, Vector2.zero, GetConnectionPoint(node.Data, entry))); onValueChanged(); } } var map = AssetGeneratorUtility.GetAttributeAssemblyQualifiedNameMap(); if (map.Count > 0) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("AssetGenerator"); var guiName = AssetGeneratorUtility.GetGUIName(entry.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 AssetGenerator class", node, true)) { generator = AssetGeneratorUtility.CreateGenerator(selectedGUIName); entry.m_instance.Set(editor.CurrentEditingGroup, generator); onValueChanged(); } } ); } } MonoScript s = TypeUtility.LoadMonoScript(entry.m_instance.ClassName); using (new EditorGUI.DisabledScope(s == null)) { if (GUILayout.Button("Edit", GUILayout.Width(50))) { AssetDatabase.OpenAsset(s, 0); } } } } else { if (!string.IsNullOrEmpty(entry.m_instance.ClassName)) { EditorGUILayout.HelpBox( string.Format( "Your AssetGenerator script {0} is missing from assembly. Did you delete script?", entry.m_instance.ClassName), MessageType.Info); } else { string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_ASSETGENERATOR.Split('/'); EditorGUILayout.HelpBox( string.Format( "You need to create at least one AssetGenerator 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, entry.m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => { if (enabled) { entry.m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup); } else { entry.m_instance.Remove(editor.CurrentEditingGroup); } onValueChanged(); }); using (disabledScope) { if (generator != null) { Action onChangedAction = () => { using (new RecordUndoScope("Change AssetGenerator Setting", node)) { entry.m_instance.Set(editor.CurrentEditingGroup, generator); onValueChanged(); } }; generator.OnInspectorGUI(onChangedAction); } } } GUILayout.Space(4); if (GUILayout.Button("Remove Generator")) { m_removingEntry = entry; } } }
private void ValidateInputSetting( Model.NodeData node, BuildTarget target, IEnumerable <PerformGraph.AssetGroups> incoming, Action <Type, Type, AssetReference> multipleAssetTypeFound, Action <Type> unsupportedType, Action <Type, Type> incomingTypeMismatch, Action <ConfigStatus> errorInConfig, Action customAssetIsNull ) { Type expectedType = TypeUtility.FindFirstIncomingAssetType(incoming); if (multipleAssetTypeFound != null) { if (expectedType != null && incoming != null) { foreach (var ag in incoming) { foreach (var assets in ag.assetGroups.Values) { foreach (var a in assets) { Type assetType = a.filterType; if (assetType != expectedType) { multipleAssetTypeFound(expectedType, assetType, a); } } } } } } if (unsupportedType != null) { if (expectedType != null) { if (expectedType == typeof(UnityEditor.TextureImporter) || expectedType == typeof(UnityEditor.ModelImporter) || expectedType == typeof(UnityEditor.AudioImporter) #if UNITY_5_6 || UNITY_5_6_OR_NEWER || expectedType == typeof(UnityEditor.VideoClipImporter) #endif ) { // good. do nothing } else { unsupportedType(expectedType); } } } var status = GetConfigStatus(node); if (errorInConfig != null) { if (status != ConfigStatus.GoodSampleFound) { errorInConfig(status); } } if (incomingTypeMismatch != null) { // if there is no incoming assets, there is no way to check if // right type of asset is coming in - so we'll just skip the test if (incoming != null && expectedType != null && status == ConfigStatus.GoodSampleFound) { Type targetType = GetReferenceAssetImporter(node, false).GetType(); if (targetType != expectedType) { incomingTypeMismatch(targetType, expectedType); } } } if (m_useCustomSettingAsset && CustomSettingAsset == null) { customAssetIsNull(); } }
public override void Prepare(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { Action <Type, Type, AssetReference> multipleAssetTypeFound = (Type expectedType, Type foundType, AssetReference foundAsset) => { throw new NodeException(string.Format("{3} :ImportSetting expect {0}, but different type of incoming asset is found({1} {2})", expectedType.FullName, foundType.FullName, foundAsset.fileNameAndExtension, node.Name), node.Id); }; Action <Type> unsupportedType = (Type unsupported) => { throw new NodeException(string.Format("{0} :Incoming asset type is not supported by ImportSetting (Incoming type:{1}). Perhaps you want to use Modifier instead?", node.Name, (unsupported != null)?unsupported.FullName:"null"), node.Id); }; Action <Type, Type> incomingTypeMismatch = (Type expectedType, Type incomingType) => { throw new NodeException(string.Format("{0} :Incoming asset type is does not match with this ImportSetting (Expected type:{1}, Incoming type:{2}).", node.Name, (expectedType != null)?expectedType.FullName:"null", (incomingType != null)?incomingType.FullName:"null"), node.Id); }; Action customConfigIsNull = () => { throw new NodeException(string.Format("{0} :You must select custom setting asset.", node.Name), node.Id); }; Action <ConfigStatus> errorInConfig = (ConfigStatus _) => { var firstAsset = TypeUtility.GetFirstIncomingAsset(incoming); if (firstAsset != null) { // give a try first in sampling file var configFilePath = FileUtility.GetImportSettingTemplateFilePath(firstAsset); SaveSampleFile(node, configFilePath); ValidateInputSetting(node, target, incoming, multipleAssetTypeFound, unsupportedType, incomingTypeMismatch, (ConfigStatus eType) => { if (eType == ConfigStatus.NoSampleFound) { throw new NodeException(node.Name + " :ImportSetting has no sampling file. Please configure it from Inspector.", node.Id); } if (eType == ConfigStatus.TooManySamplesFound) { throw new NodeException(node.Name + " :ImportSetting has too many sampling file. Please fix it from Inspector.", node.Id); } }, customConfigIsNull); } }; ValidateInputSetting(node, target, incoming, multipleAssetTypeFound, unsupportedType, incomingTypeMismatch, errorInConfig, customConfigIsNull); // ImportSettings does not add, filter or change structure of group, so just pass given group of assets if (Output != null) { var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); if (incoming != null) { foreach (var ag in incoming) { Output(dst, ag.assetGroups); } } else { Output(dst, new Dictionary <string, List <AssetReference> >()); } } }
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); GUILayout.Space(10f); // prevent inspector flicking by new Editor changing active selction node.SetActive(true); /* * importer node has no platform key. * platform key is contained by Unity's importer inspector itself. */ using (new EditorGUILayout.VerticalScope()) { Type incomingType = TypeUtility.FindFirstIncomingAssetType(streamManager, node.Data.InputPoints[0]); ImportSetting.ConfigStatus status = ImportSetting.GetConfigStatus(node.Data); if (incomingType == null) { // try to retrieve incoming type from configuration if (status == ImportSetting.ConfigStatus.GoodSampleFound) { incomingType = GetReferenceAssetImporter(node.Data, false).GetType(); } else { 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(); for (var i = 0; i < s_importerTypeList.Length; i++) { var index = i; menu.AddItem( new GUIContent(s_importerTypeList [i]), false, () => { ResetConfig(node.Data); var configFilePath = FileUtility.GetImportSettingTemplateFilePath(s_importerTypeList [index]); SaveSampleFile(node.Data, configFilePath); } ); } menu.ShowAsContext(); } } } return; } } switch (status) { case ImportSetting.ConfigStatus.NoSampleFound: // ImportSetting.Setup() must run to grab another sample to configure. EditorGUILayout.HelpBox("Press Refresh to configure.", MessageType.Info); node.Data.NeedsRevisit = true; break; case ImportSetting.ConfigStatus.GoodSampleFound: if (m_importerEditor == null) { var importer = GetReferenceAssetImporter(node.Data, true); if (importer != null) { m_importerEditor = Editor.CreateEditor(importer); } } // Custom Sprite Packing Tag if (incomingType == typeof(UnityEditor.TextureImporter)) { using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { m_overwritePackingTag = EditorGUILayout.ToggleLeft("Configure Sprite Packing Tag", m_overwritePackingTag); if (m_overwritePackingTag) { var val = m_spritePackingTagNameTemplate [editor.CurrentEditingGroup]; var newValue = EditorGUILayout.TextField("Packing Tag", val); if (newValue != val) { using (new RecordUndoScope("Change Packing Tag", node, true)) { m_spritePackingTagNameTemplate [editor.CurrentEditingGroup] = newValue; onValueChanged(); } } } EditorGUILayout.HelpBox( "You can configure packing tag name with \"*\" to include group name in your sprite tag.", MessageType.Info); } GUILayout.Space(10); } // Custom Sample Asset using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var newUseCustomAsset = EditorGUILayout.ToggleLeft("Use Custom Setting Asset", m_useCustomSettingAsset); if (newUseCustomAsset != m_useCustomSettingAsset) { using (new RecordUndoScope("Change Custom Setting Asset", node, true)) { m_useCustomSettingAsset = newUseCustomAsset; onValueChanged(); if (m_importerEditor != null) { UnityEngine.Object.DestroyImmediate(m_importerEditor); m_importerEditor = null; } } } if (m_useCustomSettingAsset) { var assetType = GetAssetTypeFromImporterType(incomingType); if (assetType != null) { var newObject = EditorGUILayout.ObjectField("Asset", CustomSettingAsset, assetType, false); if (incomingType == typeof(ModelImporter)) { // disallow selecting non-model prefab if (PrefabUtility.GetPrefabType(newObject) != PrefabType.ModelPrefab) { newObject = CustomSettingAsset; } } if (newObject != CustomSettingAsset) { using (new RecordUndoScope("Change Custom Setting Asset", node, true)) { CustomSettingAsset = newObject; onValueChanged(); if (m_importerEditor != null) { UnityEngine.Object.DestroyImmediate(m_importerEditor); m_importerEditor = null; } } } if (CustomSettingAsset != null) { using (new EditorGUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Highlight in Project Window", GUILayout.Width(180f))) { EditorGUIUtility.PingObject(CustomSettingAsset); } } } } else { EditorGUILayout.HelpBox( "Incoming asset type is not supported. Please fix issue first or clear the saved import setting.", MessageType.Error); if (m_importerEditor != null) { UnityEngine.Object.DestroyImmediate(m_importerEditor); m_importerEditor = null; } } } EditorGUILayout.HelpBox( "Custom setting asset is useful when you need specific needs for setting asset; i.e. when configuring with multiple sprite mode.", MessageType.Info); } GUILayout.Space(10); if (m_importerEditor != null) { GUILayout.Label(string.Format("Import Setting ({0})", incomingType.Name)); m_importerEditor.OnInspectorGUI(); GUILayout.Space(40); } using (new EditorGUILayout.HorizontalScope(GUI.skin.box)) { GUILayout.Space(4); 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); } } } break; case ImportSetting.ConfigStatus.TooManySamplesFound: if (GUILayout.Button("Reset Import Setting")) { ResetConfig(node.Data); } break; } } return; }