1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Cleaned up C# 4 compatibility

This commit is contained in:
Kailey Joanette 2019-11-03 07:44:04 -05:00
parent c94df25856
commit 4bbd0ae661
6 changed files with 41 additions and 40 deletions

View File

@ -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 ) )
{

View File

@ -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<T> : OdinAttributeDrawer<InputAttribute, T>
internal class InputAttributeDrawer<T> : OdinAttributeDrawer<Node.InputAttribute, T>
{
protected override bool CanDrawAttributeValueProperty( InspectorProperty property )
{
var attr = property.GetAttribute<InputAttribute>();
var attr = property.GetAttribute<Node.InputAttribute>();
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<T> : OdinAttributeDrawer<OutputAttribute, T>
internal class OutputAttributeDrawer<T> : OdinAttributeDrawer<Node.OutputAttribute, T>
{
protected override bool CanDrawAttributeValueProperty( InspectorProperty property )
{
var attr = property.GetAttribute<OutputAttribute>();
var attr = property.GetAttribute<Node.OutputAttribute>();
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 ) )
{

View File

@ -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<InputAttribute>();
var input = property.GetAttribute<Node.InputAttribute>();
if ( input != null )
return input.dynamicPortList;
var output = property.GetAttribute<OutputAttribute>();
var output = property.GetAttribute<Node.OutputAttribute>();
if ( output != null )
return output.dynamicPortList;
@ -35,11 +34,11 @@ namespace XNodeEditor.Odin
{
public override bool CanResolveForPropertyFilter( InspectorProperty property )
{
var input = property.GetAttribute<InputAttribute>();
var input = property.GetAttribute<Node.InputAttribute>();
if ( input != null )
return input.dynamicPortList;
var output = property.GetAttribute<OutputAttribute>();
var output = property.GetAttribute<Node.OutputAttribute>();
if ( output != null )
return output.dynamicPortList;
@ -64,14 +63,14 @@ namespace XNodeEditor.Odin
var hideLabelAttribute = attributes.OfType<HideLabelAttribute>().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<TList, TElement>(
getterSetter: new GetterSetter<TList, TElement>(
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<NodePort> ports
{
get
@ -215,11 +214,11 @@ namespace XNodeEditor.Odin
}
}
protected bool IsInput => Property.GetAttribute<InputAttribute>() != null;
protected bool IsInput { get { return Property.GetAttribute<Node.InputAttribute>() != null; } }
public ConnectionType connectionType => IsInput ? Property.GetAttribute<InputAttribute>().connectionType : Property.GetAttribute<OutputAttribute>().connectionType;
public TypeConstraint typeConstraint => IsInput ? Property.GetAttribute<InputAttribute>().typeConstraint : Property.GetAttribute<OutputAttribute>().typeConstraint;
public ShowBackingValue backingValue => IsInput ? Property.GetAttribute<InputAttribute>().backingValue : Property.GetAttribute<OutputAttribute>().backingValue;
public Node.ConnectionType connectionType { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().connectionType : Property.GetAttribute<Node.OutputAttribute>().connectionType; } }
public Node.TypeConstraint typeConstraint { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().typeConstraint : Property.GetAttribute<Node.OutputAttribute>().typeConstraint; } }
public Node.ShowBackingValue backingValue { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().backingValue : Property.GetAttribute<Node.OutputAttribute>().backingValue; } }
}
public class DynamicPortListAttributeProcessor<T> : OdinAttributeProcessor<T>
@ -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<InputAttribute>();
var input = property.GetAttribute<Node.InputAttribute>();
if ( input != null )
return input.dynamicPortList;
var output = property.GetAttribute<OutputAttribute>();
var output = property.GetAttribute<Node.OutputAttribute>();
if ( output != null )
return output.dynamicPortList;

View File

@ -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<InputAttribute>();
var input = property.GetAttribute<Node.InputAttribute>();
if ( input != null )
return input.dynamicPortList;
var output = property.GetAttribute<OutputAttribute>();
var output = property.GetAttribute<Node.OutputAttribute>();
if ( output != null )
return output.dynamicPortList;
@ -47,14 +46,14 @@ namespace XNodeEditor
var hideLabelAttribute = attributes.OfType<HideLabelAttribute>().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<TNotAList, NodePort>(
getterSetter: new GetterSetter<TNotAList, NodePort>(
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<NodePort> ports
{
get
@ -221,11 +221,11 @@ namespace XNodeEditor
}
}
protected bool IsInput => Property.GetAttribute<InputAttribute>() != null;
protected bool IsInput { get { return Property.GetAttribute<Node.InputAttribute>() != null; } }
public ConnectionType connectionType => IsInput ? Property.GetAttribute<InputAttribute>().connectionType : Property.GetAttribute<OutputAttribute>().connectionType;
public TypeConstraint typeConstraint => IsInput ? Property.GetAttribute<InputAttribute>().typeConstraint : Property.GetAttribute<OutputAttribute>().typeConstraint;
public ShowBackingValue backingValue => IsInput ? Property.GetAttribute<InputAttribute>().backingValue : Property.GetAttribute<OutputAttribute>().backingValue;
public Node.ConnectionType connectionType { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().connectionType : Property.GetAttribute<Node.OutputAttribute>().connectionType; } }
public Node.TypeConstraint typeConstraint { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().typeConstraint : Property.GetAttribute<Node.OutputAttribute>().typeConstraint; } }
public Node.ShowBackingValue backingValue { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().backingValue : Property.GetAttribute<Node.OutputAttribute>().backingValue; } }
}
}
#endif

View File

@ -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<InputAttribute>() != null || x.GetAttribute<OutputAttribute>() != null );
IEnumerable<MemberInfo> attributedMembers;
if ( fieldsAndProperties != null )
attributedMembers = fieldsAndProperties.Where( x => x.GetAttribute<Node.InputAttribute>() != null || x.GetAttribute<Node.OutputAttribute>() != null );
else
attributedMembers = Enumerable.Empty<MemberInfo>();
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

View File

@ -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