From 4bbd0ae6616b89287afad46ce395d005dbcc30f9 Mon Sep 17 00:00:00 2001 From: Kailey Joanette Date: Sun, 3 Nov 2019 07:44:04 -0500 Subject: [PATCH] Cleaned up C# 4 compatibility --- .../Drawers/Odin/AsDynamicPortAttributes.cs | 5 ++-- .../Drawers/Odin/AsStaticPortAttributes.cs | 13 +++++---- .../Odin/DynamicPortListBackedResolver.cs | 27 +++++++++---------- .../Odin/DynamicPortListNoDataResolver.cs | 22 +++++++-------- .../Odin/FullyDynamicPortPropertyResolver.cs | 10 ++++--- Scripts/Editor/NodeEditor.cs | 4 +-- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/Scripts/Editor/Drawers/Odin/AsDynamicPortAttributes.cs b/Scripts/Editor/Drawers/Odin/AsDynamicPortAttributes.cs index 1bd3b43..7566a35 100644 --- a/Scripts/Editor/Drawers/Odin/AsDynamicPortAttributes.cs +++ b/Scripts/Editor/Drawers/Odin/AsDynamicPortAttributes.cs @@ -4,7 +4,6 @@ using System; using UnityEditor; using UnityEngine; using XNode; -using static XNode.Node; namespace XNodeEditor.Odin { @@ -14,7 +13,7 @@ namespace XNodeEditor.Odin public Node Node { get; set; } public bool InList { get; set; } - public ShowBackingValue BackingValue { get; set; } + public Node.ShowBackingValue BackingValue { get; set; } public NodePort Port { @@ -94,7 +93,7 @@ namespace XNodeEditor.Odin return; if ( Event.current.type == EventType.Layout ) - drawData = Attribute.BackingValue == ShowBackingValue.Always || Attribute.BackingValue == ShowBackingValue.Unconnected && !Attribute.Port.IsConnected; + drawData = Attribute.BackingValue == Node.ShowBackingValue.Always || Attribute.BackingValue == Node.ShowBackingValue.Unconnected && !Attribute.Port.IsConnected; using ( new AsDynamicPortScope( Attribute.Port, Attribute.InList ) ) { diff --git a/Scripts/Editor/Drawers/Odin/AsStaticPortAttributes.cs b/Scripts/Editor/Drawers/Odin/AsStaticPortAttributes.cs index 69592c6..2c853fe 100644 --- a/Scripts/Editor/Drawers/Odin/AsStaticPortAttributes.cs +++ b/Scripts/Editor/Drawers/Odin/AsStaticPortAttributes.cs @@ -4,7 +4,6 @@ using System; using UnityEditor; using UnityEngine; using XNode; -using static XNode.Node; namespace XNodeEditor.Odin { @@ -39,11 +38,11 @@ namespace XNodeEditor.Odin } [DrawerPriority( 0.4, 0, 0 )] - internal class InputAttributeDrawer : OdinAttributeDrawer + internal class InputAttributeDrawer : OdinAttributeDrawer { protected override bool CanDrawAttributeValueProperty( InspectorProperty property ) { - var attr = property.GetAttribute(); + var attr = property.GetAttribute(); if ( attr != null ) return !attr.dynamicPortList; @@ -56,7 +55,7 @@ namespace XNodeEditor.Odin { NodePort port = ( Property.Tree.UnitySerializedObject.targetObject as Node ).GetInputPort( Property.Name ); if ( Event.current.type == EventType.Layout ) - drawData = Attribute.backingValue == ShowBackingValue.Always || Attribute.backingValue == ShowBackingValue.Unconnected && !port.IsConnected; + drawData = Attribute.backingValue == Node.ShowBackingValue.Always || Attribute.backingValue == Node.ShowBackingValue.Unconnected && !port.IsConnected; using ( new AsStaticPortScope( port ) ) { @@ -69,11 +68,11 @@ namespace XNodeEditor.Odin } [DrawerPriority( 0.4, 0, 0 )] - internal class OutputAttributeDrawer : OdinAttributeDrawer + internal class OutputAttributeDrawer : OdinAttributeDrawer { protected override bool CanDrawAttributeValueProperty( InspectorProperty property ) { - var attr = property.GetAttribute(); + var attr = property.GetAttribute(); if ( attr != null ) return !attr.dynamicPortList; @@ -86,7 +85,7 @@ namespace XNodeEditor.Odin { NodePort port = ( Property.Tree.UnitySerializedObject.targetObject as Node ).GetOutputPort( Property.Name ); if ( Event.current.type == EventType.Layout ) - drawData = Attribute.backingValue == ShowBackingValue.Always || Attribute.backingValue == ShowBackingValue.Unconnected && !port.IsConnected; + drawData = Attribute.backingValue == Node.ShowBackingValue.Always || Attribute.backingValue == Node.ShowBackingValue.Unconnected && !port.IsConnected; using ( new AsStaticPortScope( port ) ) { diff --git a/Scripts/Editor/Drawers/Odin/DynamicPortListBackedResolver.cs b/Scripts/Editor/Drawers/Odin/DynamicPortListBackedResolver.cs index 4b98412..a51db30 100644 --- a/Scripts/Editor/Drawers/Odin/DynamicPortListBackedResolver.cs +++ b/Scripts/Editor/Drawers/Odin/DynamicPortListBackedResolver.cs @@ -8,7 +8,6 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; using XNode; -using static XNode.Node; namespace XNodeEditor.Odin { @@ -17,11 +16,11 @@ namespace XNodeEditor.Odin { protected override bool CanDrawValueProperty( InspectorProperty property ) { - var input = property.GetAttribute(); + var input = property.GetAttribute(); if ( input != null ) return input.dynamicPortList; - var output = property.GetAttribute(); + var output = property.GetAttribute(); if ( output != null ) return output.dynamicPortList; @@ -35,11 +34,11 @@ namespace XNodeEditor.Odin { public override bool CanResolveForPropertyFilter( InspectorProperty property ) { - var input = property.GetAttribute(); + var input = property.GetAttribute(); if ( input != null ) return input.dynamicPortList; - var output = property.GetAttribute(); + var output = property.GetAttribute(); if ( output != null ) return output.dynamicPortList; @@ -64,14 +63,14 @@ namespace XNodeEditor.Odin var hideLabelAttribute = attributes.OfType().SingleOrDefault(); attributes = attributes - .Append( GetPortAttribute( Property.Name, childIndex ) ) + .AppendIf( true, GetPortAttribute( Property.Name, childIndex ) ) .AppendIf( labelTextAttribute == null && hideLabelAttribute == null, new LabelTextAttribute( string.Format( "{0} {1}", Property.Name, childIndex ) ) ); result = InspectorPropertyInfo.CreateValue( name: CollectionResolverUtilities.DefaultIndexToChildName( childIndex ), order: childIndex, serializationBackend: this.Property.BaseValueEntry.SerializationBackend, - new GetterSetter( + getterSetter: new GetterSetter( getter: ( ref TList list ) => list[childIndex], setter: ( ref TList list, TElement element ) => list[childIndex] = element ), attributes: attributes.ToArray() ); @@ -196,7 +195,7 @@ namespace XNodeEditor.Odin base.Clear( collection ); } - protected Node node => ( Property.Tree.UnitySerializedObject.targetObject as Node ); + protected Node node { get { return ( Property.Tree.UnitySerializedObject.targetObject as Node ); } } protected List ports { get @@ -215,11 +214,11 @@ namespace XNodeEditor.Odin } } - protected bool IsInput => Property.GetAttribute() != null; + protected bool IsInput { get { return Property.GetAttribute() != null; } } - public ConnectionType connectionType => IsInput ? Property.GetAttribute().connectionType : Property.GetAttribute().connectionType; - public TypeConstraint typeConstraint => IsInput ? Property.GetAttribute().typeConstraint : Property.GetAttribute().typeConstraint; - public ShowBackingValue backingValue => IsInput ? Property.GetAttribute().backingValue : Property.GetAttribute().backingValue; + public Node.ConnectionType connectionType { get { return IsInput ? Property.GetAttribute().connectionType : Property.GetAttribute().connectionType; } } + public Node.TypeConstraint typeConstraint { get { return IsInput ? Property.GetAttribute().typeConstraint : Property.GetAttribute().typeConstraint; } } + public Node.ShowBackingValue backingValue { get { return IsInput ? Property.GetAttribute().backingValue : Property.GetAttribute().backingValue; } } } public class DynamicPortListAttributeProcessor : OdinAttributeProcessor @@ -227,11 +226,11 @@ namespace XNodeEditor.Odin public override bool CanProcessSelfAttributes( InspectorProperty property ) { // We can guess that it's going to fall in here - var input = property.GetAttribute(); + var input = property.GetAttribute(); if ( input != null ) return input.dynamicPortList; - var output = property.GetAttribute(); + var output = property.GetAttribute(); if ( output != null ) return output.dynamicPortList; diff --git a/Scripts/Editor/Drawers/Odin/DynamicPortListNoDataResolver.cs b/Scripts/Editor/Drawers/Odin/DynamicPortListNoDataResolver.cs index f65d40a..8e8e873 100644 --- a/Scripts/Editor/Drawers/Odin/DynamicPortListNoDataResolver.cs +++ b/Scripts/Editor/Drawers/Odin/DynamicPortListNoDataResolver.cs @@ -9,7 +9,6 @@ using System.Linq; using UnityEngine; using XNode; using XNodeEditor.Odin; -using static XNode.Node; namespace XNodeEditor { @@ -18,11 +17,11 @@ namespace XNodeEditor { public override bool CanResolveForPropertyFilter( InspectorProperty property ) { - var input = property.GetAttribute(); + var input = property.GetAttribute(); if ( input != null ) return input.dynamicPortList; - var output = property.GetAttribute(); + var output = property.GetAttribute(); if ( output != null ) return output.dynamicPortList; @@ -47,14 +46,14 @@ namespace XNodeEditor var hideLabelAttribute = attributes.OfType().SingleOrDefault(); attributes = attributes - .Append( GetPortAttribute( Property.Name, childIndex ) ) + .AppendIf( true, GetPortAttribute( Property.Name, childIndex ) ) .AppendIf( labelTextAttribute == null && hideLabelAttribute == null, new LabelTextAttribute( string.Format( "{0} {1}", Property.Name, childIndex ) ) ); result = InspectorPropertyInfo.CreateValue( name: CollectionResolverUtilities.DefaultIndexToChildName( childIndex ), order: childIndex, serializationBackend: this.Property.BaseValueEntry.SerializationBackend, - new GetterSetter( + getterSetter: new GetterSetter( getter: ( ref TNotAList list ) => ports[childIndex], // Return absolutely nothing? Return a port? setter: ( ref TNotAList list, NodePort element ) => ports[childIndex] = element ), attributes: attributes.ToArray() ); @@ -200,9 +199,10 @@ namespace XNodeEditor return CollectionResolverUtilities.DefaultChildNameToIndex( name ); } - public override Type ElementType => typeof( NodePort ); + public override Type ElementType { get { return typeof( NodePort ); } } + + protected Node node { get { return ( Property.Tree.UnitySerializedObject.targetObject as Node ); } } - protected Node node => ( Property.Tree.UnitySerializedObject.targetObject as Node ); protected List ports { get @@ -221,11 +221,11 @@ namespace XNodeEditor } } - protected bool IsInput => Property.GetAttribute() != null; + protected bool IsInput { get { return Property.GetAttribute() != null; } } - public ConnectionType connectionType => IsInput ? Property.GetAttribute().connectionType : Property.GetAttribute().connectionType; - public TypeConstraint typeConstraint => IsInput ? Property.GetAttribute().typeConstraint : Property.GetAttribute().typeConstraint; - public ShowBackingValue backingValue => IsInput ? Property.GetAttribute().backingValue : Property.GetAttribute().backingValue; + public Node.ConnectionType connectionType { get { return IsInput ? Property.GetAttribute().connectionType : Property.GetAttribute().connectionType; } } + public Node.TypeConstraint typeConstraint { get { return IsInput ? Property.GetAttribute().typeConstraint : Property.GetAttribute().typeConstraint; } } + public Node.ShowBackingValue backingValue { get { return IsInput ? Property.GetAttribute().backingValue : Property.GetAttribute().backingValue; } } } } #endif \ No newline at end of file diff --git a/Scripts/Editor/Drawers/Odin/FullyDynamicPortPropertyResolver.cs b/Scripts/Editor/Drawers/Odin/FullyDynamicPortPropertyResolver.cs index 9f1ec59..8d1ffe1 100644 --- a/Scripts/Editor/Drawers/Odin/FullyDynamicPortPropertyResolver.cs +++ b/Scripts/Editor/Drawers/Odin/FullyDynamicPortPropertyResolver.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Reflection; using XNode; using XNodeEditor.Odin; -using static XNode.Node; namespace XNodeEditor { @@ -46,7 +45,12 @@ namespace XNodeEditor nodeType.FindMember() .IsFieldOrProperty() .TryGetMembers( out fieldsAndProperties, out error ); - var attributedMembers = fieldsAndProperties?.Where( x => x.GetAttribute() != null || x.GetAttribute() != null ); + + IEnumerable attributedMembers; + if ( fieldsAndProperties != null ) + attributedMembers = fieldsAndProperties.Where( x => x.GetAttribute() != null || x.GetAttribute() != null ); + else + attributedMembers = Enumerable.Empty(); foreach ( var port in node.DynamicPorts ) { @@ -57,7 +61,7 @@ namespace XNodeEditor infos.AddValue( port.fieldName, () => new Nothing(), value => { }, new AsDynamicPortNoDataAtribute() { - BackingValue = ShowBackingValue.Never, + BackingValue = Node.ShowBackingValue.Never, FieldName = port.fieldName, InList = false, Node = node diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index 7df07cb..33db5eb 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -38,7 +38,6 @@ namespace XNodeEditor { // serializedObject.Update(); must go at the start of an inspector gui, and // serializedObject.ApplyModifiedProperties(); goes at the end. serializedObject.Update(); - string[] excludes = { "m_Script", "graph", "position", "ports" }; #if ODIN_INSPECTOR InspectorUtilities.BeginDrawPropertyTree(objectTree, true); @@ -47,6 +46,7 @@ namespace XNodeEditor { InspectorUtilities.EndDrawPropertyTree(objectTree); GUIHelper.PopLabelWidth(); #else + string[] excludes = { "m_Script", "graph", "position", "ports" }; // Iterate through serialized properties and draw them like the Inspector (But with ports) SerializedProperty iterator = serializedObject.GetIterator(); @@ -65,7 +65,7 @@ namespace XNodeEditor { } #endif - serializedObject.ApplyModifiedProperties(); + serializedObject.ApplyModifiedProperties(); #if ODIN_INSPECTOR // Call repaint so that the graph window elements respond properly to layout changes coming from Odin