feat:work around another way to inspect properties

main
taoria 3 years ago
parent 6bacdb9eb4
commit 0572478a0e
  1. 23
      TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs
  2. 3
      TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs.meta
  3. 15
      TNode/Editor/Inspector/NodeInspector.cs
  4. 11
      TNode/Editor/Inspector/NodeInspectorInNode.cs
  5. 12
      TNode/Editor/Search/BlackboardSearchWindowProvider.cs

@ -0,0 +1,23 @@
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.Editor.Inspector.InspectorImplementation{
public class PropertyFieldItem:InspectorItem<Object>{
public PropertyFieldItem(){
OnDataChanged += () => {
var data = new SerializedObject(Value as Object);
var testProperty = data.GetIterator().GetArrayElementAtIndex(0);
PropertyField propertyField = new PropertyField(testProperty);
this.Q<PropertyField>()?.RemoveFromHierarchy();
this.Add(propertyField);
};
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 98769c8b285d438197820fa366568fee
timeCreated: 1657280625

@ -51,21 +51,12 @@ namespace TNode.Editor.Inspector{
var type = field.FieldType; var type = field.FieldType;
InspectorItemFactory inspectorItemFactory = new InspectorItemFactory(); 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 = inspectorItemFactory.GetType().GetMethod("Create", BindingFlags.Instance | BindingFlags.Public); var createdItem = inspectorItemFactory.Create(type);
if (methodInfo != null){ if (createdItem is { } castedItem){
var genericMethod = methodInfo.MakeGenericMethod(type);
var createdItem = genericMethod.Invoke(inspectorItemFactory,null) as VisualElement;
body.Add(createdItem);
if (createdItem is INodeDataBindingBase castedItem){
castedItem.BindingNodeData = _data; castedItem.BindingNodeData = _data;
castedItem.BindingPath = bindingPath; castedItem.BindingPath = bindingPath;
} }
Add((VisualElement)createdItem);
//Check if field has DisableOnInspector attribute and if so,disable it
if (field.GetCustomAttribute<DisableOnInspectorAttribute>() != null){
createdItem?.SetEnabled(false);
}
}
} }
} }
} }

@ -32,22 +32,13 @@ namespace TNode.Editor.Inspector{
var showInNodeViewAttribute = field.GetCustomAttribute<ShowInNodeViewAttribute>()!=null; var showInNodeViewAttribute = field.GetCustomAttribute<ShowInNodeViewAttribute>()!=null;
if(!showInNodeViewAttribute) if(!showInNodeViewAttribute)
continue; continue;
//Invoke generic function Create<> of default inspector item factory to create an inspector item of appropriate type by reflection
var createdItem = inspectorItemFactory.Create(type); var createdItem = inspectorItemFactory.Create(type);
if (createdItem is { } castedItem){ if (createdItem is { } castedItem){
castedItem.BindingNodeData = _data; castedItem.BindingNodeData = _data;
castedItem.BindingPath = bindingPath; castedItem.BindingPath = bindingPath;
} }
Add((VisualElement)createdItem); Add((VisualElement)createdItem);
// MethodInfo methodInfo = inspectorItemFactory.GetType().GetMethod("Create", BindingFlags.Instance | BindingFlags.Public);
// if (methodInfo != null){
// var genericMethod = methodInfo.MakeGenericMethod(type);
// Debug.Log(genericMethod);
// var createdItem = genericMethod.Invoke(inspectorItemFactory,null) as VisualElement;
// Add(createdItem);
// Debug.Log(createdItem?.GetType());
//
// }
} }
} }
} }

@ -1,15 +1,19 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Experimental.GraphView; using UnityEditor.Experimental.GraphView;
namespace TNode.Editor{ namespace TNode.Editor{
public class BlackboardSearchWindowProvider:ISearchWindowProvider{ public class BlackboardSearchWindowProvider:ISearchWindowProvider{
private Type _graphType;
private GraphView _graphView;
private EditorWindow _editor;
public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context){ public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context){
throw new System.NotImplementedException(); return null;
} }
public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context){ public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context){
throw new System.NotImplementedException(); return false;
} }
} }

Loading…
Cancel
Save