From 49b25e755b70ec412feaaf0b898d6f7e09d2bea6 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 28 Jun 2022 09:40:37 +0800 Subject: +node example --- .../Drawers/Odin/InNodeEditorAttributeProcessor.cs | 48 +++++++++++++++++++++ .../Odin/InNodeEditorAttributeProcessor.cs.meta | 11 +++++ .../Editor/Drawers/Odin/InputAttributeDrawer.cs | 49 ++++++++++++++++++++++ .../Drawers/Odin/InputAttributeDrawer.cs.meta | 11 +++++ .../Editor/Drawers/Odin/OutputAttributeDrawer.cs | 49 ++++++++++++++++++++++ .../Drawers/Odin/OutputAttributeDrawer.cs.meta | 11 +++++ 6 files changed, 179 insertions(+) create mode 100644 Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InNodeEditorAttributeProcessor.cs create mode 100644 Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InNodeEditorAttributeProcessor.cs.meta create mode 100644 Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InputAttributeDrawer.cs create mode 100644 Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InputAttributeDrawer.cs.meta create mode 100644 Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/OutputAttributeDrawer.cs create mode 100644 Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/OutputAttributeDrawer.cs.meta (limited to 'Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin') diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InNodeEditorAttributeProcessor.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InNodeEditorAttributeProcessor.cs new file mode 100644 index 00000000..84c6d8e7 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InNodeEditorAttributeProcessor.cs @@ -0,0 +1,48 @@ +#if UNITY_EDITOR && ODIN_INSPECTOR +using System; +using System.Collections.Generic; +using System.Reflection; +using Sirenix.OdinInspector.Editor; +using UnityEngine; +using XNode; + +namespace XNodeEditor { + internal class OdinNodeInGraphAttributeProcessor : OdinAttributeProcessor where T : Node { + public override bool CanProcessSelfAttributes(InspectorProperty property) { + return false; + } + + public override bool CanProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member) { + if (!NodeEditor.inNodeEditor) + return false; + + if (member.MemberType == MemberTypes.Field) { + switch (member.Name) { + case "graph": + case "position": + case "ports": + return true; + + default: + break; + } + } + + return false; + } + + public override void ProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member, List attributes) { + switch (member.Name) { + case "graph": + case "position": + case "ports": + attributes.Add(new HideInInspector()); + break; + + default: + break; + } + } + } +} +#endif \ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InNodeEditorAttributeProcessor.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InNodeEditorAttributeProcessor.cs.meta new file mode 100644 index 00000000..15f69908 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InNodeEditorAttributeProcessor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3cf2561fbfea9a041ac81efbbb5b3e0d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InputAttributeDrawer.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InputAttributeDrawer.cs new file mode 100644 index 00000000..a384bdcf --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InputAttributeDrawer.cs @@ -0,0 +1,49 @@ +#if UNITY_EDITOR && ODIN_INSPECTOR +using Sirenix.OdinInspector; +using Sirenix.OdinInspector.Editor; +using Sirenix.Utilities.Editor; +using UnityEngine; +using XNode; + +namespace XNodeEditor { + public class InputAttributeDrawer : OdinAttributeDrawer { + protected override bool CanDrawAttributeProperty(InspectorProperty property) { + Node node = property.Tree.WeakTargets[0] as Node; + return node != null; + } + + protected override void DrawPropertyLayout(GUIContent label) { + Node node = Property.Tree.WeakTargets[0] as Node; + NodePort port = node.GetInputPort(Property.Name); + + if (!NodeEditor.inNodeEditor) { + if (Attribute.backingValue == XNode.Node.ShowBackingValue.Always || Attribute.backingValue == XNode.Node.ShowBackingValue.Unconnected && !port.IsConnected) + CallNextDrawer(label); + return; + } + + if (Property.Tree.WeakTargets.Count > 1) { + SirenixEditorGUI.WarningMessageBox("Cannot draw ports with multiple nodes selected"); + return; + } + + if (port != null) { + var portPropoerty = Property.Tree.GetUnityPropertyForPath(Property.UnityPropertyPath); + if (portPropoerty == null) { + SirenixEditorGUI.ErrorMessageBox("Port property missing at: " + Property.UnityPropertyPath); + return; + } else { + var labelWidth = Property.GetAttribute(); + if (labelWidth != null) + GUIHelper.PushLabelWidth(labelWidth.Width); + + NodeEditorGUILayout.PropertyField(portPropoerty, label == null ? GUIContent.none : label, true, GUILayout.MinWidth(30)); + + if (labelWidth != null) + GUIHelper.PopLabelWidth(); + } + } + } + } +} +#endif \ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InputAttributeDrawer.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InputAttributeDrawer.cs.meta new file mode 100644 index 00000000..12b76158 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/InputAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2fd590b2e9ea0bd49b6986a2ca9010ab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/OutputAttributeDrawer.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/OutputAttributeDrawer.cs new file mode 100644 index 00000000..ff596156 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/OutputAttributeDrawer.cs @@ -0,0 +1,49 @@ +#if UNITY_EDITOR && ODIN_INSPECTOR +using Sirenix.OdinInspector; +using Sirenix.OdinInspector.Editor; +using Sirenix.Utilities.Editor; +using UnityEngine; +using XNode; + +namespace XNodeEditor { + public class OutputAttributeDrawer : OdinAttributeDrawer { + protected override bool CanDrawAttributeProperty(InspectorProperty property) { + Node node = property.Tree.WeakTargets[0] as Node; + return node != null; + } + + protected override void DrawPropertyLayout(GUIContent label) { + Node node = Property.Tree.WeakTargets[0] as Node; + NodePort port = node.GetOutputPort(Property.Name); + + if (!NodeEditor.inNodeEditor) { + if (Attribute.backingValue == XNode.Node.ShowBackingValue.Always || Attribute.backingValue == XNode.Node.ShowBackingValue.Unconnected && !port.IsConnected) + CallNextDrawer(label); + return; + } + + if (Property.Tree.WeakTargets.Count > 1) { + SirenixEditorGUI.WarningMessageBox("Cannot draw ports with multiple nodes selected"); + return; + } + + if (port != null) { + var portPropoerty = Property.Tree.GetUnityPropertyForPath(Property.UnityPropertyPath); + if (portPropoerty == null) { + SirenixEditorGUI.ErrorMessageBox("Port property missing at: " + Property.UnityPropertyPath); + return; + } else { + var labelWidth = Property.GetAttribute(); + if (labelWidth != null) + GUIHelper.PushLabelWidth(labelWidth.Width); + + NodeEditorGUILayout.PropertyField(portPropoerty, label == null ? GUIContent.none : label, true, GUILayout.MinWidth(30)); + + if (labelWidth != null) + GUIHelper.PopLabelWidth(); + } + } + } + } +} +#endif \ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/OutputAttributeDrawer.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/OutputAttributeDrawer.cs.meta new file mode 100644 index 00000000..aa22218d --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/Drawers/Odin/OutputAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e7ebd8f2b42e2384aa109551dc46af88 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0