virtual public string GetDisplayName(NPipeIImportable importable) { if (importable.GetInstanceName() != null && importable.GetInstanceName().Length > 0) { return(importable.GetInstanceName() + " (" + importable.GetTypeName() + ")"); } else { return(importable.GetTypeName()); } }
public static NPipeIImportable CreateSeparatedPipe(string originalPath, NPipeIImportable pipe) { string path = originalPath.Substring(0, originalPath.Length - 6) + "_" + pipe.GetTypeName() + ".asset"; CreatePipeContainer <NPipeContainer>(path); return(CreateAttachedPipe(path, pipe)); }
public static NPipeIImportable CreateAttachedPipe(string path, NPipeIImportable pipe) { UnityEngine.Object obj = pipe as UnityEngine.Object; obj.hideFlags = HideFlags.HideInHierarchy; NPipeIImportable importable = obj as NPipeIImportable; obj.name = importable.GetTypeName(); AssetDatabase.AddObjectToAsset(obj, path); UnityEditor.EditorUtility.SetDirty(pipe as UnityEngine.Object); // AssetDatabase.SaveAssets(); // AssetDatabase.Refresh(); // UnityEditor.Selection.activeObject = createdFactory; return(importable); }
public static string GetPipelineDebugString(NPipeIImportable element, bool withTimes = false) { string prefix = ""; if (element is NPipeIComposite) { prefix = GetPipelineDebugString(((NPipeIComposite)element).Input, withTimes); } string cur = (!string.IsNullOrEmpty(element.GetInstanceName()) ? element.GetInstanceName() : element.GetTypeName()); if (withTimes) { cur += " (" + (int)(EditorApplication.timeSinceStartup - element.GetLastInvalidatedTime()) + ") "; } return(prefix + " / " + cur); }
private void drawPipeEditor(string assetPath) { NPipeIImportable importable = editingImportable as NPipeIImportable; if (importable == null) { return; } //==================================================================================================================== // Selected Importable(s) Label //==================================================================================================================== NPipeIImportable[] multiInstanceEditingImportables = null; if (isMultiInstance) { string warningMessage = ""; multiInstanceEditingImportables = NPipelineUtils.GetSimiliarPipes(this.targets, this.target as NPipeContainer, this.editingImportable as NPipeIImportable, out warningMessage); GUILayout.Space(10f); GUILayout.Label(string.Format("Selected: {0} ( {1} instances )", editingImportable.GetTypeName(), multiInstanceEditingImportables.Length), EditorStyles.boldLabel); if (warningMessage.Length > 0) { // GUI.backgroundColor = Color.yellow; GUILayout.Label("WARNING: " + warningMessage); } } else { GUILayout.Space(10f); GUILayout.Label("Selected: " + editingImportable.GetTypeName(), EditorStyles.boldLabel); } //==================================================================================================================== // Selected Importable(s) Editor Inspectors //==================================================================================================================== NPipeIEditable editable = editingImportable as NPipeIEditable; if (editable != null) { GUILayout.Label("Edit:"); if (isMultiInstance) { editable.DrawMultiInstanceEditor(~NPipeEditFlags.TOOLS, NPipelineUtils.GetUntypedFactories <NPipeIImportable>(multiInstanceEditingImportables)); } else { editable.DrawInspector(~NPipeEditFlags.TOOLS); } } GUILayout.Space(10f); GUILayout.BeginVertical(); GUILayout.Space(10f); //==================================================================================================================== // append other pipes //==================================================================================================================== if (!isMultiInstance) { GUILayout.BeginHorizontal(); List <System.Type> allTypes = new List <System.Type>(); List <NPipeAppendableAttribute> allAttrsa = new List <NPipeAppendableAttribute>(); List <string> allLabels = new List <string>(); foreach (Type factoryType in NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeAppendableAttribute))) { NPipeAppendableAttribute attr = (NPipeAppendableAttribute)factoryType.GetCustomAttributes(typeof(NPipeAppendableAttribute), true)[0]; if (!attr.sourceType.IsAssignableFrom(importable.GetType())) { continue; } allTypes.Add(factoryType); allAttrsa.Add(attr); allLabels.Add(attr.name); } if (allTypes.Count > 0) { GUILayout.Label("Append: "); selectedAppendIndex = EditorGUILayout.Popup(selectedAppendIndex, allLabels.ToArray()); if (selectedAppendIndex >= 0 && selectedAppendIndex < allTypes.Count) { NPipeAppendableAttribute pipe = allAttrsa[selectedAppendIndex]; NPipeIComposite newImportable = null; if (pipe.attached && GUILayout.Button("This Container")) { newImportable = NPipelineUtils.CreateAttachedPipe(assetPath, allTypes[selectedAppendIndex], importable) as NPipeIComposite; editingImportable = newImportable; lastEditingImportable = newImportable; confirmDeletion = false; } if (pipe.separate && GUILayout.Button("New Container")) { newImportable = NPipelineUtils.CreateSeparatedPipe(assetPath, allTypes[selectedAppendIndex], importable) as NPipeIComposite; } if (newImportable != null) { AssetDatabase.SaveAssets(); UnityEditor.Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(newImportable as UnityEngine.Object)); } } else { selectedAppendIndex = 0; } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); }
protected string DrawPipelineElements(string assetPath, NPipeIImportable importable, HashSet <NPipeIImportable> visited, bool hasNext, string nextAssetPath = "") { string thisAssetPath = AssetDatabase.GetAssetPath(importable as UnityEngine.Object); bool thisIsInContainer = thisAssetPath == assetPath; bool nextIsInContainer = nextAssetPath == assetPath; //==================================================================================================================== // Recursion for parent elements //==================================================================================================================== GUILayout.BeginVertical(); NPipeIComposite composite = importable as NPipeIComposite; bool isSource = true; bool parentIsInDifferentAsset = false; if (composite != null) { NPipeIImportable[] sources = composite.GetAllInputs(); GUILayout.BeginHorizontal(); if (sources != null) { foreach (NPipeIImportable source in sources) { isSource = false; if (source != null) { if (thisAssetPath != DrawPipelineElements(assetPath, source, visited, true, thisAssetPath)) { parentIsInDifferentAsset = true; } } else { GUILayout.Label("NULL !"); } } } GUILayout.EndHorizontal(); } //==================================================================================================================== // Background Color //==================================================================================================================== if ((!thisIsInContainer && parentIsInDifferentAsset) || (isSource && !thisIsInContainer && thisAssetPath != null)) { GUILayout.BeginHorizontal(); GUI.backgroundColor = GetColorForAssetPath(thisAssetPath); EditorGUILayout.ObjectField(AssetDatabase.LoadMainAssetAtPath(thisAssetPath), typeof(NPipeContainer), false); GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); if (visited.Contains(importable)) { GUILayout.Label(importable.GetTypeName()); } else { visited.Add(importable); //==================================================================================================================== // Action Buttons //==================================================================================================================== if (!thisIsInContainer) { GUI.backgroundColor = GetColorForAssetPath(thisAssetPath); } else { GUI.backgroundColor = isMultiInstance ? thisContainerMultiColor : thisContainerColor; } //==================================================================================================================== // Delete Editiable //==================================================================================================================== if (editingImportable == importable && this.targets.Length < 2) { if (this.targets.Length < 2) { if (!confirmDeletion && GUILayout.Button("Delete")) { confirmDeletion = true; } else if (confirmDeletion && GUILayout.Button("Sure?")) { editingImportable = null; lastEditingImportable = null; Delete(assetPath, importable); AssetDatabase.SaveAssets(); } } } //==================================================================================================================== // Edit Editiable //==================================================================================================================== if (editingImportable == importable) { if (GUILayout.Button("Close", GUILayout.Width(40))) { editingImportable = null; lastEditingImportable = null; } } else { if (thisIsInContainer && GUILayout.Button("Edit", GUILayout.Width(40))) { editingImportable = importable; lastEditingImportable = importable; confirmDeletion = false; } } //==================================================================================================================== // Editable Label //==================================================================================================================== GUIStyle style = normalStyle; if (editingImportable == importable) { style = boldStyle; } string n = ((NPipeContainer)target).GetDisplayName(importable); GUILayout.Label(n, style); } GUILayout.EndHorizontal(); if (hasNext) { if (thisIsInContainer || nextIsInContainer) { DrawArrow(GUI.backgroundColor = isMultiInstance ? thisContainerMultiColor : thisContainerColor); } else if (nextAssetPath != thisAssetPath) { DrawArrow(GetColorForAssetPath(nextAssetPath)); } } GUI.backgroundColor = Color.white; GUILayout.EndVertical(); return(thisAssetPath); }