protected NPVoxIModelFactory GetPreviewModelFactoryForTargetSocket(string targetSocketName) { NPVoxIMeshFactory meshFactory = GetPreviewFactoryForTargetSocket(targetSocketName); NPipeIComposite composite = meshFactory as NPipeIComposite; if (composite != null && composite.Input is NPVoxIModelFactory) { return(composite.Input as NPVoxIModelFactory); } return(null); }
public static IEnumerable <NPipeIImportable> EachSource(NPipeIImportable target) { NPipeIComposite targetComposite = target as NPipeIComposite; if (targetComposite != null) { NPipeIImportable[] sources = targetComposite.GetAllInputs(); foreach (NPipeIImportable item in sources) { yield return(item); } } }
/// <summary> /// Add Sources to List by checking the Input property ( thus also referencing other assets ). /// </summary> /// <param name="target">Target.</param> /// <param name="outList">Out list.</param> private static void AddSourcesToList(NPipeIImportable target, List <NPipeIImportable> outList) { NPipeIComposite composite = target as NPipeIComposite; if (composite == null) { outList.Add(target); return; } foreach (NPipeIImportable importable in EachSource(target)) { AddSourcesToList(importable, outList); } outList.Add(target); }
public static IEnumerable <NPipeIImportable> EachSource(NPipeIImportable target, NPipeIImportable[] importables) { NPipeIComposite targetComposite = target as NPipeIComposite; if (targetComposite != null) { NPipeIImportable[] sources = targetComposite.GetAllInputs(); foreach (NPipeIImportable item in sources) { if (ArrayUtility.Contains(importables, item)) { yield return(item); } } } }
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); }