/// <summary> /// Gets the matching pipes in all input containers that follow the same path (used for multiinstance editing) /// </summary> /// <returns>The matching pipes.</returns> /// <param name="InputContainers">Input containers.</param> /// <param name="lookup">Lookup.</param> public static NPipeIImportable[] GetSimiliarPipes(UnityEngine.Object[] inputContainers, NPipeContainer referenceContainer, NPipeIImportable lookup, out string warningMessage) { // TODO: check for exact matchin structure, there may be cases where we have multiple pipes in a container warningMessage = ""; List <NPipeIImportable> result = new List <NPipeIImportable>(); bool bFoundMultiple = false; bool bNotFound = false; foreach (UnityEngine.Object container in inputContainers) { NPipeIImportable[] instances2 = GetByType <NPipeIImportable>(container); bool bFound = false; foreach (NPipeIImportable item in instances2) { if (item.GetType() == lookup.GetType()) { result.Add(item); if (bFound) { bFoundMultiple = true; } bFound = true; } } if (!bFound) { bNotFound = true; } } if (bFoundMultiple) { warningMessage += "Found Multiple Occurences in some containers. "; } if (bNotFound) { warningMessage += "Not foundt in some containers. "; } return(result.ToArray()); }
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(); }