|
|
@ -1,14 +1,19 @@ |
|
|
|
using System.Reflection; |
|
|
|
using System; |
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.Reflection; |
|
|
|
using TNode.BaseViews; |
|
|
|
using TNode.BaseViews; |
|
|
|
using TNode.Editor.BaseViews; |
|
|
|
using TNode.Editor.BaseViews; |
|
|
|
using TNode.Models; |
|
|
|
using TNode.Models; |
|
|
|
|
|
|
|
using Unity.VisualScripting; |
|
|
|
|
|
|
|
using UnityEditor; |
|
|
|
|
|
|
|
using UnityEditor.Experimental.GraphView; |
|
|
|
|
|
|
|
using UnityEditor.UIElements; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.UIElements; |
|
|
|
using UnityEngine.UIElements; |
|
|
|
|
|
|
|
|
|
|
|
namespace TNode.Editor.Inspector{ |
|
|
|
namespace TNode.Editor.Inspector{ |
|
|
|
public class NodeInspector:SimpleGraphSubWindow{ |
|
|
|
public class NodeInspector:SimpleGraphSubWindow{ |
|
|
|
private NodeData _data; |
|
|
|
private NodeData _data; |
|
|
|
|
|
|
|
|
|
|
|
public NodeData Data{ |
|
|
|
public NodeData Data{ |
|
|
|
get => _data; |
|
|
|
get => _data; |
|
|
|
set{ |
|
|
|
set{ |
|
|
@ -26,6 +31,7 @@ namespace TNode.Editor.Inspector{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public NodeInspector(){ |
|
|
|
public NodeInspector(){ |
|
|
|
|
|
|
|
this.capabilities |= Capabilities.Resizable; |
|
|
|
style.position = new StyleEnum<Position>(Position.Absolute); |
|
|
|
style.position = new StyleEnum<Position>(Position.Absolute); |
|
|
|
var visualTreeAsset = Resources.Load<VisualTreeAsset>("NodeInspector"); |
|
|
|
var visualTreeAsset = Resources.Load<VisualTreeAsset>("NodeInspector"); |
|
|
|
Debug.Log(visualTreeAsset); |
|
|
|
Debug.Log(visualTreeAsset); |
|
|
@ -33,20 +39,21 @@ namespace TNode.Editor.Inspector{ |
|
|
|
BuildWindow(visualTreeAsset); |
|
|
|
BuildWindow(visualTreeAsset); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void RefreshInspector(){ |
|
|
|
private void RefreshInspector(){ |
|
|
|
//iterate field of data and get name of every fields,create a new inspector item of appropriate type and add it to the inspector for each field |
|
|
|
//iterate field of data and get name of every fields,create a new inspector item of appropriate type and add it to the inspector for each field |
|
|
|
var body = this.Q("InspectorBody"); |
|
|
|
var body = this.Q("InspectorBody"); |
|
|
|
body.Clear(); |
|
|
|
body.Clear(); |
|
|
|
body.Add(new Label(_data.nodeName)); |
|
|
|
body.StretchToParentSize(); |
|
|
|
foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){ |
|
|
|
foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){ |
|
|
|
var bindingPath = field.Name; |
|
|
|
var bindingPath = field.Name; |
|
|
|
var type = field.FieldType; |
|
|
|
var type = field.FieldType; |
|
|
|
DefaultInspectorItemFactory defaultInspectorItemFactory = new DefaultInspectorItemFactory(); |
|
|
|
InspectorItemFactory inspectorItemFactory = new InspectorItemFactory(); |
|
|
|
//Invoke generic function Create<> of default inspector item factory to create an inspector item of appropriate type by reflection |
|
|
|
//Invoke generic function Create<> of default inspector item factory to create an inspector item of appropriate type by reflection |
|
|
|
MethodInfo methodInfo = defaultInspectorItemFactory.GetType().GetMethod("Create", BindingFlags.Instance | BindingFlags.Public); |
|
|
|
MethodInfo methodInfo = inspectorItemFactory.GetType().GetMethod("Create", BindingFlags.Instance | BindingFlags.Public); |
|
|
|
if (methodInfo != null){ |
|
|
|
if (methodInfo != null){ |
|
|
|
var genericMethod = methodInfo.MakeGenericMethod(type); |
|
|
|
var genericMethod = methodInfo.MakeGenericMethod(type); |
|
|
|
var createdItem = genericMethod.Invoke(defaultInspectorItemFactory,null) as VisualElement; |
|
|
|
var createdItem = genericMethod.Invoke(inspectorItemFactory,null) as VisualElement; |
|
|
|
|
|
|
|
|
|
|
|
body.Add(createdItem); |
|
|
|
body.Add(createdItem); |
|
|
|
if (createdItem is INodeDataBindingBase castedItem){ |
|
|
|
if (createdItem is INodeDataBindingBase castedItem){ |
|
|
@ -55,8 +62,6 @@ namespace TNode.Editor.Inspector{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |