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:
parent
c94df25856
commit
4bbd0ae661
@ -4,7 +4,6 @@ using System;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using XNode;
|
using XNode;
|
||||||
using static XNode.Node;
|
|
||||||
|
|
||||||
namespace XNodeEditor.Odin
|
namespace XNodeEditor.Odin
|
||||||
{
|
{
|
||||||
@ -14,7 +13,7 @@ namespace XNodeEditor.Odin
|
|||||||
public Node Node { get; set; }
|
public Node Node { get; set; }
|
||||||
|
|
||||||
public bool InList { get; set; }
|
public bool InList { get; set; }
|
||||||
public ShowBackingValue BackingValue { get; set; }
|
public Node.ShowBackingValue BackingValue { get; set; }
|
||||||
|
|
||||||
public NodePort Port
|
public NodePort Port
|
||||||
{
|
{
|
||||||
@ -94,7 +93,7 @@ namespace XNodeEditor.Odin
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if ( Event.current.type == EventType.Layout )
|
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 ) )
|
using ( new AsDynamicPortScope( Attribute.Port, Attribute.InList ) )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,6 @@ using System;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using XNode;
|
using XNode;
|
||||||
using static XNode.Node;
|
|
||||||
|
|
||||||
namespace XNodeEditor.Odin
|
namespace XNodeEditor.Odin
|
||||||
{
|
{
|
||||||
@ -39,11 +38,11 @@ namespace XNodeEditor.Odin
|
|||||||
}
|
}
|
||||||
|
|
||||||
[DrawerPriority( 0.4, 0, 0 )]
|
[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 )
|
protected override bool CanDrawAttributeValueProperty( InspectorProperty property )
|
||||||
{
|
{
|
||||||
var attr = property.GetAttribute<InputAttribute>();
|
var attr = property.GetAttribute<Node.InputAttribute>();
|
||||||
if ( attr != null )
|
if ( attr != null )
|
||||||
return !attr.dynamicPortList;
|
return !attr.dynamicPortList;
|
||||||
|
|
||||||
@ -56,7 +55,7 @@ namespace XNodeEditor.Odin
|
|||||||
{
|
{
|
||||||
NodePort port = ( Property.Tree.UnitySerializedObject.targetObject as Node ).GetInputPort( Property.Name );
|
NodePort port = ( Property.Tree.UnitySerializedObject.targetObject as Node ).GetInputPort( Property.Name );
|
||||||
if ( Event.current.type == EventType.Layout )
|
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 ) )
|
using ( new AsStaticPortScope( port ) )
|
||||||
{
|
{
|
||||||
@ -69,11 +68,11 @@ namespace XNodeEditor.Odin
|
|||||||
}
|
}
|
||||||
|
|
||||||
[DrawerPriority( 0.4, 0, 0 )]
|
[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 )
|
protected override bool CanDrawAttributeValueProperty( InspectorProperty property )
|
||||||
{
|
{
|
||||||
var attr = property.GetAttribute<OutputAttribute>();
|
var attr = property.GetAttribute<Node.OutputAttribute>();
|
||||||
if ( attr != null )
|
if ( attr != null )
|
||||||
return !attr.dynamicPortList;
|
return !attr.dynamicPortList;
|
||||||
|
|
||||||
@ -86,7 +85,7 @@ namespace XNodeEditor.Odin
|
|||||||
{
|
{
|
||||||
NodePort port = ( Property.Tree.UnitySerializedObject.targetObject as Node ).GetOutputPort( Property.Name );
|
NodePort port = ( Property.Tree.UnitySerializedObject.targetObject as Node ).GetOutputPort( Property.Name );
|
||||||
if ( Event.current.type == EventType.Layout )
|
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 ) )
|
using ( new AsStaticPortScope( port ) )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,7 +8,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using XNode;
|
using XNode;
|
||||||
using static XNode.Node;
|
|
||||||
|
|
||||||
namespace XNodeEditor.Odin
|
namespace XNodeEditor.Odin
|
||||||
{
|
{
|
||||||
@ -17,11 +16,11 @@ namespace XNodeEditor.Odin
|
|||||||
{
|
{
|
||||||
protected override bool CanDrawValueProperty( InspectorProperty property )
|
protected override bool CanDrawValueProperty( InspectorProperty property )
|
||||||
{
|
{
|
||||||
var input = property.GetAttribute<InputAttribute>();
|
var input = property.GetAttribute<Node.InputAttribute>();
|
||||||
if ( input != null )
|
if ( input != null )
|
||||||
return input.dynamicPortList;
|
return input.dynamicPortList;
|
||||||
|
|
||||||
var output = property.GetAttribute<OutputAttribute>();
|
var output = property.GetAttribute<Node.OutputAttribute>();
|
||||||
if ( output != null )
|
if ( output != null )
|
||||||
return output.dynamicPortList;
|
return output.dynamicPortList;
|
||||||
|
|
||||||
@ -35,11 +34,11 @@ namespace XNodeEditor.Odin
|
|||||||
{
|
{
|
||||||
public override bool CanResolveForPropertyFilter( InspectorProperty property )
|
public override bool CanResolveForPropertyFilter( InspectorProperty property )
|
||||||
{
|
{
|
||||||
var input = property.GetAttribute<InputAttribute>();
|
var input = property.GetAttribute<Node.InputAttribute>();
|
||||||
if ( input != null )
|
if ( input != null )
|
||||||
return input.dynamicPortList;
|
return input.dynamicPortList;
|
||||||
|
|
||||||
var output = property.GetAttribute<OutputAttribute>();
|
var output = property.GetAttribute<Node.OutputAttribute>();
|
||||||
if ( output != null )
|
if ( output != null )
|
||||||
return output.dynamicPortList;
|
return output.dynamicPortList;
|
||||||
|
|
||||||
@ -64,14 +63,14 @@ namespace XNodeEditor.Odin
|
|||||||
var hideLabelAttribute = attributes.OfType<HideLabelAttribute>().SingleOrDefault();
|
var hideLabelAttribute = attributes.OfType<HideLabelAttribute>().SingleOrDefault();
|
||||||
|
|
||||||
attributes = attributes
|
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 ) ) );
|
.AppendIf( labelTextAttribute == null && hideLabelAttribute == null, new LabelTextAttribute( string.Format( "{0} {1}", Property.Name, childIndex ) ) );
|
||||||
|
|
||||||
result = InspectorPropertyInfo.CreateValue(
|
result = InspectorPropertyInfo.CreateValue(
|
||||||
name: CollectionResolverUtilities.DefaultIndexToChildName( childIndex ),
|
name: CollectionResolverUtilities.DefaultIndexToChildName( childIndex ),
|
||||||
order: childIndex,
|
order: childIndex,
|
||||||
serializationBackend: this.Property.BaseValueEntry.SerializationBackend,
|
serializationBackend: this.Property.BaseValueEntry.SerializationBackend,
|
||||||
new GetterSetter<TList, TElement>(
|
getterSetter: new GetterSetter<TList, TElement>(
|
||||||
getter: ( ref TList list ) => list[childIndex],
|
getter: ( ref TList list ) => list[childIndex],
|
||||||
setter: ( ref TList list, TElement element ) => list[childIndex] = element ),
|
setter: ( ref TList list, TElement element ) => list[childIndex] = element ),
|
||||||
attributes: attributes.ToArray() );
|
attributes: attributes.ToArray() );
|
||||||
@ -196,7 +195,7 @@ namespace XNodeEditor.Odin
|
|||||||
base.Clear( collection );
|
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
|
protected List<NodePort> ports
|
||||||
{
|
{
|
||||||
get
|
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 Node.ConnectionType connectionType { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().connectionType : Property.GetAttribute<Node.OutputAttribute>().connectionType; } }
|
||||||
public TypeConstraint typeConstraint => IsInput ? Property.GetAttribute<InputAttribute>().typeConstraint : Property.GetAttribute<OutputAttribute>().typeConstraint;
|
public Node.TypeConstraint typeConstraint { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().typeConstraint : Property.GetAttribute<Node.OutputAttribute>().typeConstraint; } }
|
||||||
public ShowBackingValue backingValue => IsInput ? Property.GetAttribute<InputAttribute>().backingValue : Property.GetAttribute<OutputAttribute>().backingValue;
|
public Node.ShowBackingValue backingValue { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().backingValue : Property.GetAttribute<Node.OutputAttribute>().backingValue; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DynamicPortListAttributeProcessor<T> : OdinAttributeProcessor<T>
|
public class DynamicPortListAttributeProcessor<T> : OdinAttributeProcessor<T>
|
||||||
@ -227,11 +226,11 @@ namespace XNodeEditor.Odin
|
|||||||
public override bool CanProcessSelfAttributes( InspectorProperty property )
|
public override bool CanProcessSelfAttributes( InspectorProperty property )
|
||||||
{
|
{
|
||||||
// We can guess that it's going to fall in here
|
// 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 )
|
if ( input != null )
|
||||||
return input.dynamicPortList;
|
return input.dynamicPortList;
|
||||||
|
|
||||||
var output = property.GetAttribute<OutputAttribute>();
|
var output = property.GetAttribute<Node.OutputAttribute>();
|
||||||
if ( output != null )
|
if ( output != null )
|
||||||
return output.dynamicPortList;
|
return output.dynamicPortList;
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,6 @@ using System.Linq;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using XNode;
|
using XNode;
|
||||||
using XNodeEditor.Odin;
|
using XNodeEditor.Odin;
|
||||||
using static XNode.Node;
|
|
||||||
|
|
||||||
namespace XNodeEditor
|
namespace XNodeEditor
|
||||||
{
|
{
|
||||||
@ -18,11 +17,11 @@ namespace XNodeEditor
|
|||||||
{
|
{
|
||||||
public override bool CanResolveForPropertyFilter( InspectorProperty property )
|
public override bool CanResolveForPropertyFilter( InspectorProperty property )
|
||||||
{
|
{
|
||||||
var input = property.GetAttribute<InputAttribute>();
|
var input = property.GetAttribute<Node.InputAttribute>();
|
||||||
if ( input != null )
|
if ( input != null )
|
||||||
return input.dynamicPortList;
|
return input.dynamicPortList;
|
||||||
|
|
||||||
var output = property.GetAttribute<OutputAttribute>();
|
var output = property.GetAttribute<Node.OutputAttribute>();
|
||||||
if ( output != null )
|
if ( output != null )
|
||||||
return output.dynamicPortList;
|
return output.dynamicPortList;
|
||||||
|
|
||||||
@ -47,14 +46,14 @@ namespace XNodeEditor
|
|||||||
var hideLabelAttribute = attributes.OfType<HideLabelAttribute>().SingleOrDefault();
|
var hideLabelAttribute = attributes.OfType<HideLabelAttribute>().SingleOrDefault();
|
||||||
|
|
||||||
attributes = attributes
|
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 ) ) );
|
.AppendIf( labelTextAttribute == null && hideLabelAttribute == null, new LabelTextAttribute( string.Format( "{0} {1}", Property.Name, childIndex ) ) );
|
||||||
|
|
||||||
result = InspectorPropertyInfo.CreateValue(
|
result = InspectorPropertyInfo.CreateValue(
|
||||||
name: CollectionResolverUtilities.DefaultIndexToChildName( childIndex ),
|
name: CollectionResolverUtilities.DefaultIndexToChildName( childIndex ),
|
||||||
order: childIndex,
|
order: childIndex,
|
||||||
serializationBackend: this.Property.BaseValueEntry.SerializationBackend,
|
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?
|
getter: ( ref TNotAList list ) => ports[childIndex], // Return absolutely nothing? Return a port?
|
||||||
setter: ( ref TNotAList list, NodePort element ) => ports[childIndex] = element ),
|
setter: ( ref TNotAList list, NodePort element ) => ports[childIndex] = element ),
|
||||||
attributes: attributes.ToArray() );
|
attributes: attributes.ToArray() );
|
||||||
@ -200,9 +199,10 @@ namespace XNodeEditor
|
|||||||
return CollectionResolverUtilities.DefaultChildNameToIndex( name );
|
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
|
protected List<NodePort> ports
|
||||||
{
|
{
|
||||||
get
|
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 Node.ConnectionType connectionType { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().connectionType : Property.GetAttribute<Node.OutputAttribute>().connectionType; } }
|
||||||
public TypeConstraint typeConstraint => IsInput ? Property.GetAttribute<InputAttribute>().typeConstraint : Property.GetAttribute<OutputAttribute>().typeConstraint;
|
public Node.TypeConstraint typeConstraint { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().typeConstraint : Property.GetAttribute<Node.OutputAttribute>().typeConstraint; } }
|
||||||
public ShowBackingValue backingValue => IsInput ? Property.GetAttribute<InputAttribute>().backingValue : Property.GetAttribute<OutputAttribute>().backingValue;
|
public Node.ShowBackingValue backingValue { get { return IsInput ? Property.GetAttribute<Node.InputAttribute>().backingValue : Property.GetAttribute<Node.OutputAttribute>().backingValue; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -7,7 +7,6 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using XNode;
|
using XNode;
|
||||||
using XNodeEditor.Odin;
|
using XNodeEditor.Odin;
|
||||||
using static XNode.Node;
|
|
||||||
|
|
||||||
namespace XNodeEditor
|
namespace XNodeEditor
|
||||||
{
|
{
|
||||||
@ -46,7 +45,12 @@ namespace XNodeEditor
|
|||||||
nodeType.FindMember()
|
nodeType.FindMember()
|
||||||
.IsFieldOrProperty()
|
.IsFieldOrProperty()
|
||||||
.TryGetMembers( out fieldsAndProperties, out error );
|
.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 )
|
foreach ( var port in node.DynamicPorts )
|
||||||
{
|
{
|
||||||
@ -57,7 +61,7 @@ namespace XNodeEditor
|
|||||||
infos.AddValue( port.fieldName, () => new Nothing(), value => { },
|
infos.AddValue( port.fieldName, () => new Nothing(), value => { },
|
||||||
new AsDynamicPortNoDataAtribute()
|
new AsDynamicPortNoDataAtribute()
|
||||||
{
|
{
|
||||||
BackingValue = ShowBackingValue.Never,
|
BackingValue = Node.ShowBackingValue.Never,
|
||||||
FieldName = port.fieldName,
|
FieldName = port.fieldName,
|
||||||
InList = false,
|
InList = false,
|
||||||
Node = node
|
Node = node
|
||||||
|
|||||||
@ -38,7 +38,6 @@ namespace XNodeEditor {
|
|||||||
// serializedObject.Update(); must go at the start of an inspector gui, and
|
// serializedObject.Update(); must go at the start of an inspector gui, and
|
||||||
// serializedObject.ApplyModifiedProperties(); goes at the end.
|
// serializedObject.ApplyModifiedProperties(); goes at the end.
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
string[] excludes = { "m_Script", "graph", "position", "ports" };
|
|
||||||
|
|
||||||
#if ODIN_INSPECTOR
|
#if ODIN_INSPECTOR
|
||||||
InspectorUtilities.BeginDrawPropertyTree(objectTree, true);
|
InspectorUtilities.BeginDrawPropertyTree(objectTree, true);
|
||||||
@ -47,6 +46,7 @@ namespace XNodeEditor {
|
|||||||
InspectorUtilities.EndDrawPropertyTree(objectTree);
|
InspectorUtilities.EndDrawPropertyTree(objectTree);
|
||||||
GUIHelper.PopLabelWidth();
|
GUIHelper.PopLabelWidth();
|
||||||
#else
|
#else
|
||||||
|
string[] excludes = { "m_Script", "graph", "position", "ports" };
|
||||||
|
|
||||||
// Iterate through serialized properties and draw them like the Inspector (But with ports)
|
// Iterate through serialized properties and draw them like the Inspector (But with ports)
|
||||||
SerializedProperty iterator = serializedObject.GetIterator();
|
SerializedProperty iterator = serializedObject.GetIterator();
|
||||||
@ -65,7 +65,7 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
|
||||||
#if ODIN_INSPECTOR
|
#if ODIN_INSPECTOR
|
||||||
// Call repaint so that the graph window elements respond properly to layout changes coming from Odin
|
// Call repaint so that the graph window elements respond properly to layout changes coming from Odin
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user