public override void OnInspectorGUI() { if (Selection.activeObject == null) { return; } var path = AssetDatabase.GetAssetPath(Selection.activeObject); if (AssetDatabase.IsValidFolder(path) == true) { if (FlowEditorUtilities.IsValidPackage(path) == true) { this.DrawFlowFolderInspector(path); } } else { path = path.Substring(path.LastIndexOf("/") + 1); var ext = path.Substring(path.LastIndexOf(".") + 1); switch (ext) { default: this.DrawDefaultInspector(); break; } } }
public static UnityEngine.Object GetPackage(GameObject source) { if (ME.EditorUtilities.IsPrefab(source) == true) { var path = Path.GetDirectoryName(AssetDatabase.GetAssetPath(source)); var newPath = path; var iterations = path.Split(Path.DirectorySeparatorChar).Length; for (int i = 0; i < iterations; ++i) { newPath = Path.Combine(newPath, ".."); if (FlowEditorUtilities.IsValidPackage(newPath) == true) { return(AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(FlowEditorUtilities.NormalizePath(newPath))); } } } return(null); }
public void DrawWithCache(string guid, Rect rect) { Item item; if (this.cache.TryGetValue(guid, out item) == false) { item = new Item(); item.path = AssetDatabase.GUIDToAssetPath(guid); var obj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(item.path); if (obj != null) { var dirty = false; var go = obj as GameObject; if (go != null) { dirty = this.IsDirty(go.GetInstanceID()); if (dirty == false) { var comps = go.GetComponents <MonoBehaviour>(); foreach (var comp in comps) { if (comp == null) { continue; } dirty = this.IsDirty(comp.GetInstanceID()); if (dirty == true) { break; } } } } else { dirty = this.IsDirty(obj.GetInstanceID()); } item.instanceId = obj.GetInstanceID(); item.isDirty = dirty; } if (FlowEditorUtilities.IsValidPackage(item.path) == true) { item.isValidPackage = true; item.isPackage = true; } var packageDir = item.path; if (System.IO.File.Exists(packageDir) == true) { var splitted = item.path.Split('/'); packageDir = string.Join("/", splitted, 0, splitted.Length - 1); } if (FlowEditorUtilities.IsValidPackage(packageDir) == true || FlowEditorUtilities.IsValidPackage(System.IO.Path.Combine(packageDir, "..")) == true) { var last = item.path.Split('/'); if (last.Length > 0) { item.isValidPackage = true; var folder = last[last.Length - 1]; if (folder == "Screens") { item.isScreensFolder = true; } else if (folder == "Transitions") { item.isTransitionsFolder = true; } else if (folder == "Components") { item.isComponentsFolder = true; } else if (folder == "Layouts") { item.isLayoutsFolder = true; } else if (item.path.EndsWith("Base.cs") == true) { item.withSystemLabel = true; item.isBaseClass = true; } } } this.cache.Add(guid, item); } this.OnGUIItem(item.path, rect, item); }
public static void CreateTransition <T>(FD.FlowWindow windowWithScreen, FD.FlowWindow flowWindow, FD.FlowWindow toWindow, int attachIndex, string localPath, string namePrefix, System.Action <T> callback = null) where T : TransitionInputTemplateParameters { if (windowWithScreen.GetScreen() == null) { return; } var screenPath = AssetDatabase.GetAssetPath(windowWithScreen.GetScreen().Load <WindowBase>()); screenPath = System.IO.Path.GetDirectoryName(screenPath); var splitted = screenPath.Split(new string[] { "/" }, System.StringSplitOptions.RemoveEmptyEntries); var packagePath = string.Join("/", splitted, 0, splitted.Length - 1); var path = packagePath + localPath; FlowChooserFilterWindow.Show <T>( root: null, onSelect: (element) => { // Clean up previous transitions if exists var attachItem = flowWindow.GetAttachItem(toWindow.id, (x) => x.index == attachIndex); if (attachItem != null) { if (FlowSystem.GetData().modeLayer == ModeLayer.Flow) { if (attachItem.transitionParameters != null) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(attachItem.transitionParameters.gameObject)); } attachItem.transition = null; attachItem.transitionParameters = null; } else if (FlowSystem.GetData().modeLayer == ModeLayer.Audio) { if (attachItem.audioTransitionParameters != null) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(attachItem.audioTransitionParameters.gameObject)); } attachItem.audioTransition = null; attachItem.audioTransitionParameters = null; } } if (System.IO.Directory.Exists(path) == false) { System.IO.Directory.CreateDirectory(path); } if (element == null) { return; } var prefix = string.Empty; if (FlowSystem.GetData().modeLayer == ModeLayer.Flow) { prefix = "Transition-" + namePrefix; } else if (FlowSystem.GetData().modeLayer == ModeLayer.Audio) { prefix = "AudioTransition-" + namePrefix; } var elementPath = AssetDatabase.GetAssetPath(element.gameObject); var targetName = prefix + "-" + element.gameObject.name + "-" + (toWindow.IsFunction() == true ? FlowSystem.GetWindow(toWindow.functionId).directory : toWindow.directory); var targetPath = path + "/" + targetName + ".prefab"; if (AssetDatabase.CopyAsset(elementPath, targetPath) == true) { AssetDatabase.ImportAsset(targetPath); var newInstance = AssetDatabase.LoadAssetAtPath <GameObject>(targetPath); var instance = newInstance.GetComponent <T>(); instance.useDefault = false; instance.useAsTemplate = false; EditorUtility.SetDirty(instance); if (FlowSystem.GetData().modeLayer == ModeLayer.Flow) { attachItem.transition = instance.transition; attachItem.transitionParameters = instance; } else if (FlowSystem.GetData().modeLayer == ModeLayer.Audio) { attachItem.audioTransition = instance.transition; attachItem.audioTransitionParameters = instance; } if (callback != null) { callback(instance); } } }, onEveryGUI: (element) => { // on gui var style = new GUIStyle(GUI.skin.label); style.wordWrap = true; if (element != null) { GUILayout.Label(element.name, style); } else { GUILayout.Label("None", style); } }, predicate: (element) => { var elementPath = AssetDatabase.GetAssetPath(element.gameObject); var isInPackage = FlowEditorUtilities.IsValidPackage(elementPath + "/../"); if (element.transition != null && (isInPackage == true || element.useAsTemplate == true)) { var name = element.GetType().FullName; var baseName = name.Substring(0, name.IndexOf("Parameters")); var type = System.Type.GetType(baseName + ", " + element.GetType().Assembly.FullName, throwOnError: true, ignoreCase: true); if (type != null) { var attribute = type.GetCustomAttributes(inherit: true).OfType <TransitionCameraAttribute>().FirstOrDefault(); if (attribute != null) { return(true); } else { Debug.Log("No Attribute: " + baseName, element); } } else { Debug.Log("No type: " + baseName); } } return(false); }, strongType: false, directory: null, useCache: false, drawNoneOption: true, updateRedraw: true); }