protected void DrawUnityEvent(string label = "Unity Events") { VariableEditorUtility.DrawCustomList( graphUnityEvents, label, drawElement: (position, index, element) => { EditorGUI.LabelField(position, element.ToString()); }, addAction: (pos) => { GenericMenu menu = new GenericMenu(); var values = Enum.GetValues(typeof(UnityEventType)) as UnityEventType[]; for (int i = 0; i < values.Length; i++) { var value = values[i]; if (graphUnityEvents.Contains(value)) { continue; } menu.AddItem(new GUIContent(value.ToString()), false, () => { graphUnityEvents.Add(value); }); } menu.ShowAsContext(); }, removeAction: (index) => { graphUnityEvents.RemoveAt(index); } ); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (fieldInfo.IsDefined(typeof(TooltipAttribute), true)) { label.tooltip = ((TooltipAttribute)fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), true)[0]).tooltip; } EditorGUI.BeginProperty(position, label, property); VariableEditorUtility.DrawMultipurposeMember(position, property, label); EditorGUI.EndProperty(); }
public override void OnInspectorGUI() { Nodes.MultiORNode node = target as MultiORNode; DrawDefaultInspector(); VariableEditorUtility.DrawMembers(new GUIContent("Targets"), node.targets, node, new FilterAttribute(typeof(bool)), (obj) => { node.targets = obj; }, () => { uNodeEditorUtility.RegisterUndo(node); node.targets.Add(new MemberData(true)); }); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (fieldInfo.IsDefined(typeof(TooltipAttribute), true)) { label.tooltip = ((TooltipAttribute)fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), true)[0]).tooltip; } var value = PropertyDrawerUtility.GetActualObjectForSerializedProperty <FunctionModifier>(property); EditorGUI.BeginProperty(position, label, property); uNodeGUIUtility.EditValue(position, label, value, null, new uNodeUtility.EditValueSettings() { unityObject = property.serializedObject.targetObject, }); VariableEditorUtility.DrawMultipurposeMember(position, property, label); EditorGUI.EndProperty(); }
public override void OnGUI() { DrawNamespaces(); enumName = EditorGUILayout.TextField("Name", enumName); VariableEditorUtility.DrawCustomList( enumeratorList, "Enumerator List", drawElement: (position, index, element) => { element.name = EditorGUI.TextField(position, element.name); }, addAction: (pos) => { enumeratorList.Add(new EnumData.Element()); }, removeAction: (index) => { enumeratorList.RemoveAt(index); } ); }
protected void DrawOverrideMembers(string label = "Override Members") { Type type = graphInheritFrom.Get <Type>(); if (type == null) { return; } VariableEditorUtility.DrawCustomList( graphOverrideMembers, label, drawElement: (position, index, element) => { EditorGUI.LabelField(position, NodeBrowser.GetRichMemberName(element)); }, addAction: (pos) => { var members = EditorReflectionUtility.GetOverrideMembers(type); GenericMenu menu = new GenericMenu(); for (int i = 0; i < members.Count; i++) { var member = members[i]; if (member is PropertyInfo) { menu.AddItem(new GUIContent("Properties/" + NodeBrowser.GetRichMemberName(member)), graphOverrideMembers.Contains(member), () => { graphOverrideMembers.Add(member); }); } else { menu.AddItem(new GUIContent("Methods/" + NodeBrowser.GetRichMemberName(member)), graphOverrideMembers.Contains(member), () => { graphOverrideMembers.Add(member); }); } } menu.ShowAsContext(); }, removeAction: (index) => { graphOverrideMembers.RemoveAt(index); } ); }
public override void OnInspectorGUI() { uNodeInterface asset = target as uNodeInterface; DrawDefaultInspector(); EditorGUI.BeginChangeCheck(); VariableEditorUtility.DrawNamespace("Using Namespaces", asset.usingNamespaces, asset, (ns) => { asset.usingNamespaces = ns as List <string> ?? ns.ToList(); }); VariableEditorUtility.DrawInterfaceFunction(asset.functions, asset, (val) => { asset.functions = val.ToArray(); }); VariableEditorUtility.DrawInterfaceProperty(asset.properties, asset, (val) => { asset.properties = val.ToArray(); }); if (EditorGUI.EndChangeCheck()) { var runtimeType = ReflectionUtils.GetRuntimeType(asset) as RuntimeGraphInterface; if (runtimeType != null) { runtimeType.RebuildMembers(); } } }
public override void OnInspectorGUI() { uNodeData comp = target as uNodeData; EditorGUI.BeginChangeCheck(); base.OnInspectorGUI(); EditorGUI.BeginDisabledGroup(uNodeEditorUtility.IsPrefab(comp)); VariableEditorUtility.DrawNamespace("Using Namespaces", comp.generatorSettings.usingNamespace.ToList(), comp, (arr) => { comp.generatorSettings.usingNamespace = arr.ToArray(); uNodeEditorUtility.MarkDirty(comp); }); EditorGUI.EndDisabledGroup(); if (EditorGUI.EndChangeCheck()) { uNodeGUIUtility.GUIChanged(comp); } if (comp.GetComponent <uNodeRoot>() == null) { if (GUILayout.Button(new GUIContent("Open uNode Editor", "Open uNode Editor to edit this uNode"), EditorStyles.toolbarButton)) { uNodeEditor.ChangeTarget(comp, true); } } }
protected void DrawUsingNamespaces(string label = "Using Namespaces") { VariableEditorUtility.DrawNamespace(label, graphUsingNamespaces, null, (val) => { graphUsingNamespaces = val.ToList(); }); }
void OnGUI() { if (targetField == null && targetObject != null) { FindTargetField(); } if (targetField == null || targetObject == null) { ShowNotification(new GUIContent("No target")); return; } if (targetField != null && targetObject != null) { scrollPos = EditorGUILayout.BeginScrollView(scrollPos); if (targetField is UnityEngine.Object) { uNodeGUIUtility.EditUnityObject(targetField as UnityEngine.Object); } else { uNodeGUIUtility.ShowFields(targetField, targetObject); if (targetField is InterfaceFunction) { var iFunc = targetField as InterfaceFunction; VariableEditorUtility.DrawParameter(iFunc.parameters, targetObject, null, (PD) => { iFunc.parameters = PD; }); if (targetObject is uNodeRoot) { var system = GraphUtility.GetGraphSystem(targetObject as uNodeRoot); if (system.supportGeneric) { VariableEditorUtility.DrawGenericParameter(iFunc.genericParameters, targetObject, (GPD) => { iFunc.genericParameters = GPD.ToArray(); }); } } else if (targetObject is uNodeData) { VariableEditorUtility.DrawGenericParameter(iFunc.genericParameters, targetObject, (GPD) => { iFunc.genericParameters = GPD.ToArray(); }); } } else if (targetField is Block) { string des = (targetField as Block).GetDescription(); if (!string.IsNullOrEmpty(des)) { EditorGUILayout.Space(); EditorGUILayout.HelpBox((targetField as Block).GetDescription(), MessageType.None, true); } } } //if(targetField is EventAction) { // System.Reflection.FieldInfo field = targetField.GetType().GetField("Name"); // uNodeEditorUtility.ShowField(field, targetField, targetObject); //} EditorGUILayout.EndScrollView(); uNodeEditorUtility.MarkDirty(targetObject); if (!focus) { GUI.FocusControl(null); EditorGUI.FocusTextInControl(null); focus = true; } if (GUI.changed) { if (onChanged != null) { onChanged(targetField); } uNodeGUIUtility.GUIChanged(targetObject); } } }
public override void OnInspectorGUI() { MultiArithmeticNode node = target as MultiArithmeticNode; DrawDefaultInspector(); VariableEditorUtility.DrawMembers(new GUIContent("Targets"), node.targets, node, new FilterAttribute(typeof(object)), (obj) => { node.targets = obj; }, () => { uNodeEditorUtility.RegisterUndo(node); var type = node.ReturnType(); if (type != typeof(object) && ReflectionUtils.CanCreateInstance(type)) { node.targets.Add(new MemberData(ReflectionUtils.CreateInstance(type))); } else if (node.targets.Count > 0) { node.targets.Add(new MemberData(node.targets[node.targets.Count - 1])); } else { node.targets.Add(new MemberData()); } }); if (GUILayout.Button(new GUIContent("Change Operator"))) { var customItems = new List <ItemSelector.CustomItem>(); { //Primitives customItems.AddRange(GetCustomItemForPrimitives(node, typeof(int))); customItems.AddRange(GetCustomItemForPrimitives(node, typeof(float))); } var ns = NodeGraph.GetOpenedGraphUsingNamespaces(); var preference = uNodePreference.GetPreference(); var assemblies = EditorReflectionUtility.GetAssemblies(); var includedAssemblies = uNodePreference.GetIncludedAssemblies(); foreach (var assembly in assemblies) { if (!includedAssemblies.Contains(assembly.GetName().Name)) { continue; } var operators = EditorReflectionUtility.GetOperators(assembly, (op) => { return(ns == null || ns.Contains(op.DeclaringType.Namespace)); }); if (operators.Count > 0) { foreach (var op in operators) { switch (op.Name) { case "op_Addition": { var parameters = op.GetParameters(); customItems.Add(GetCustomItem(node, parameters[0].ParameterType, parameters[1].ParameterType, op.DeclaringType, op.ReturnType, ArithmeticType.Add)); break; } case "op_Subtraction": { var parameters = op.GetParameters(); customItems.Add(GetCustomItem(node, parameters[0].ParameterType, parameters[1].ParameterType, op.DeclaringType, op.ReturnType, ArithmeticType.Subtract)); break; } case "op_Division": { var parameters = op.GetParameters(); customItems.Add(GetCustomItem(node, parameters[0].ParameterType, parameters[1].ParameterType, op.DeclaringType, op.ReturnType, ArithmeticType.Divide)); break; } case "op_Multiply": { var parameters = op.GetParameters(); customItems.Add(GetCustomItem(node, parameters[0].ParameterType, parameters[1].ParameterType, op.DeclaringType, op.ReturnType, ArithmeticType.Multiply)); break; } case "op_Modulus": { var parameters = op.GetParameters(); customItems.Add(GetCustomItem(node, parameters[0].ParameterType, parameters[1].ParameterType, op.DeclaringType, op.ReturnType, ArithmeticType.Modulo)); break; } } } } } customItems.Sort((x, y) => { if (x.category == y.category) { return(string.Compare(x.name, y.name)); } return(string.Compare(x.category, y.category)); }); if (customItems.Count > 0) { ItemSelector.ShowWindow(null, null, null, false, customItems). ChangePosition( GUIUtility.GUIToScreenRect(GUILayoutUtility.GetLastRect()) ).displayDefaultItem = false; } } }
public override void OnInspectorGUI() { uNodeAssetInstance script = target as uNodeAssetInstance; serializedObject.UpdateIfRequiredOrScript(); var position = uNodeGUIUtility.GetRect(); var bPos = position; bPos.x += position.width - 20; bPos.width = 20; if (GUI.Button(bPos, "", EditorStyles.label)) { var items = ItemSelector.MakeCustomItemsForInstancedType(new System.Type[] { typeof(uNodeClassAsset) }, (val) => { script.target = val as uNodeClassAsset; uNodeEditorUtility.MarkDirty(script); }, uNodeEditorUtility.IsSceneObject(script)); ItemSelector.ShowWindow(null, null, null, null, items).ChangePosition(bPos.ToScreenRect()).displayDefaultItem = false; Event.current.Use(); } EditorGUI.PropertyField(position, serializedObject.FindProperty(nameof(script.target)), new GUIContent("Graph", "The target graph reference")); serializedObject.ApplyModifiedProperties(); if (script.target != null) { if (!Application.isPlaying || script.runtimeAsset == null) { EditorGUI.BeginChangeCheck(); VariableEditorUtility.DrawLinkedVariables(script, script.target, ""); if (EditorGUI.EndChangeCheck()) { uNodeEditorUtility.MarkDirty(script); } } else if (script.runtimeAsset != null) { Editor editor = Editor.CreateEditor(script.runtimeAsset); if (editor != null) { EditorGUI.DropShadowLabel(uNodeGUIUtility.GetRect(), "Runtime Asset"); editor.OnInspectorGUI(); } else { uNodeGUIUtility.ShowFields(script.runtimeAsset, script.runtimeAsset); } } if (script.target is IClassAsset) { if (!Application.isPlaying) { var type = script.target.GeneratedTypeName.ToType(false); if (type != null) { EditorGUILayout.HelpBox("Run using Native C#", MessageType.Info); } else { EditorGUILayout.HelpBox("Run using Reflection", MessageType.Info); } } } else { EditorGUILayout.HelpBox("The target graph is not supported.", MessageType.Warning); } if (!Application.isPlaying || script.runtimeAsset == null) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Edit Target", ""), EditorStyles.toolbarButton)) { uNodeEditor.ChangeTarget(script.target, false); } if (Application.isPlaying && script.runtimeInstance != null) { if (GUILayout.Button(new GUIContent("Debug Target", ""), EditorStyles.toolbarButton)) { uNodeEditor.ChangeTarget(script.runtimeInstance, false); } } EditorGUILayout.EndHorizontal(); } } else { EditorGUILayout.HelpBox("Please assign the target graph", MessageType.Error); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); NodeComponent comp = target as NodeComponent; if (comp == null) { return; } EditorGUI.BeginChangeCheck(); if (comp is MacroNode) { MacroNode node = comp as MacroNode; VariableEditorUtility.DrawVariable(node.variables, node, (v) => { node.variables = v; }, null); VariableEditorUtility.DrawCustomList( node.inputFlows, "Input Flows", (position, index, element) => { //Draw Element EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)))); }, null, null); VariableEditorUtility.DrawCustomList( node.outputFlows, "Output Flows", (position, index, element) => { //Draw Element EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)))); }, null, null); VariableEditorUtility.DrawCustomList( node.inputValues, "Input Values", (position, index, element) => { //Draw Element position.width -= EditorGUIUtility.labelWidth; EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType()))); position.x += EditorGUIUtility.labelWidth; uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element); }, null, null); VariableEditorUtility.DrawCustomList( node.outputValues, "Output Values", (position, index, element) => { //Draw Element position.width -= EditorGUIUtility.labelWidth; EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType()))); position.x += EditorGUIUtility.labelWidth; uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element); }, null, null); } else if (comp is LinkedMacroNode) { LinkedMacroNode node = comp as LinkedMacroNode; if (node.macroAsset != null) { VariableEditorUtility.DrawLinkedVariables(node, node.macroAsset, publicOnly: false); EditorGUI.BeginDisabledGroup(true); VariableEditorUtility.DrawCustomList( node.inputFlows, "Input Flows", (position, index, element) => { //Draw Element EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)))); }, null, null); VariableEditorUtility.DrawCustomList( node.outputFlows, "Output Flows", (position, index, element) => { //Draw Element EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)))); }, null, null); VariableEditorUtility.DrawCustomList( node.inputValues, "Input Values", (position, index, element) => { //Draw Element position.width -= EditorGUIUtility.labelWidth; EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType()))); position.x += EditorGUIUtility.labelWidth; uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element); }, null, null); VariableEditorUtility.DrawCustomList( node.outputValues, "Output Values", (position, index, element) => { //Draw Element position.width -= EditorGUIUtility.labelWidth; EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType()))); position.x += EditorGUIUtility.labelWidth; uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element); }, null, null); EditorGUI.EndDisabledGroup(); } } uNodeGUIUtility.ShowField("comment", comp, comp); if (comp.GetType().GetCustomAttributes(typeof(DescriptionAttribute), false).Length > 0) { DescriptionAttribute descriptionEvent = (DescriptionAttribute)comp.GetType().GetCustomAttributes(typeof(DescriptionAttribute), false)[0]; if (descriptionEvent.description != null && descriptionEvent != null) { GUI.backgroundColor = Color.yellow; EditorGUILayout.HelpBox("Description: " + descriptionEvent.description, MessageType.None); GUI.backgroundColor = Color.white; } } if (EditorGUI.EndChangeCheck()) { uNodeEditorUtility.MarkDirty(comp); uNodeGUIUtility.GUIChanged(comp); } }