refactor: Move implementation level to another folder

main
taoria 3 years ago
parent d333dce9d2
commit 464adca5af
  1. 2
      Sample/MathGraph/Editor/MathEditor.cs
  2. 5
      Sample/MathGraph/Editor/MathGraphView.cs
  3. 4
      TNode/Attribute/Ports/InputAttribute.cs
  4. 3
      TNode/Attribute/Ports/PortAttribute.cs
  5. 3
      TNode/Editor/BaseViews.meta
  6. 28
      TNode/Editor/Cache/NodeEditorExtensions.cs
  7. 12
      TNode/Editor/GraphBlackboard/BlackboardField.cs
  8. 15
      TNode/Editor/GraphEditor.cs
  9. 3
      TNode/Editor/Inspector/InspectorImplementation.meta
  10. 21
      TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs
  11. 3
      TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs.meta
  12. 13
      TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs
  13. 3
      TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs.meta
  14. 25
      TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs
  15. 3
      TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs.meta
  16. 16
      TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs
  17. 3
      TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs.meta
  18. 14
      TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs
  19. 3
      TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs.meta
  20. 105
      TNode/Editor/Inspector/InspectorItem.cs
  21. 3
      TNode/Editor/Inspector/InspectorItem.cs.meta
  22. 45
      TNode/Editor/Inspector/InspectorItemFactory.cs
  23. 3
      TNode/Editor/Inspector/InspectorItemFactory.cs.meta
  24. 16
      TNode/Editor/Inspector/MonoScriptInspector.cs
  25. 3
      TNode/Editor/Inspector/MonoScriptInspector.cs.meta
  26. 3
      TNode/Editor/Inspector/PropertyDrawer.meta
  27. 3
      TNode/Editor/Manipulators.meta
  28. 3
      TNode/Editor/NodeGraphView.meta
  29. 11
      TNode/Editor/NodeGraphView/IBaseDataGraphView.cs
  30. 3
      TNode/Editor/NodeGraphView/IBaseDataGraphView.cs.meta
  31. 7
      TNode/Editor/NodeGraphView/IDataGraphView.cs
  32. 3
      TNode/Editor/NodeGraphView/IDataGraphView.cs.meta
  33. 11
      TNode/Editor/NodeViews/DefaultNodeView.cs
  34. 3
      TNodeGraphViewImpl.meta
  35. 3
      TNodeGraphViewImpl/Editor.meta
  36. 0
      TNodeGraphViewImpl/Editor/GraphBlackboard.meta
  37. 12
      TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs
  38. 0
      TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs.meta
  39. 0
      TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty.meta
  40. 2
      TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs
  41. 0
      TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs.meta
  42. 2
      TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs
  43. 0
      TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs.meta
  44. 2
      TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs
  45. 0
      TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs.meta
  46. 3
      TNodeGraphViewImpl/Editor/Inspector.meta
  47. 30
      TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs
  48. 0
      TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs.meta
  49. 23
      TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs
  50. 0
      TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs.meta
  51. 3
      TNodeGraphViewImpl/Editor/NodeGraphView.meta
  52. 131
      TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
  53. 0
      TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs.meta
  54. 2
      TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs
  55. 0
      TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs.meta
  56. 0
      TNodeGraphViewImpl/Editor/NodeViews.meta
  57. 10
      TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs
  58. 0
      TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs.meta
  59. 5
      TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs
  60. 0
      TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs.meta
  61. 20
      TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs
  62. 0
      TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs.meta
  63. 0
      TNodeGraphViewImpl/Editor/Search.meta
  64. 6
      TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs
  65. 0
      TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs.meta
  66. 4
      TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs
  67. 0
      TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs.meta

@ -14,7 +14,7 @@ public class MathEditor : GraphEditor<MathGraph>{
var wnd = GetWindow<MathEditor>();
wnd.titleContent = new GUIContent("MathGraph Editor");
wnd.CreateGUI();
wnd._graphView.Data = graph;
wnd.GraphView.Data = graph;
return true;
}
return false;

@ -1,8 +1,9 @@
using TNode.Models;
using TNode.Attribute;
using TNode.Editor.BaseViews;
using TNodeGraphViewImpl.Editor.NodeGraphView;
[ViewComponent]
public class MathGraphView : DataGraphView<MathGraph>{
public class MathGraphView : BaseDataGraphView<MathGraph>{

@ -1,9 +1,7 @@
using System;
using JetBrains.Annotations;
using TNode.Models;
using UnityEditor.Experimental.GraphView;
namespace TNode.Attribute{
namespace TNode.Attribute.Ports{
[MeansImplicitUse]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class InputAttribute : PortAttribute{

@ -1,8 +1,7 @@
using System;
using JetBrains.Annotations;
using UnityEditor.Experimental.GraphView;
namespace TNode.Attribute{
namespace TNode.Attribute.Ports{
public enum PortNameHandling{
Auto,

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: be6b702224dc40098aadadb3749d8c81
timeCreated: 1655394343

@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using TNode.Attribute;
using TNode.BaseViews;
using TNode.Editor;
using TNode.Editor.BaseViews;
using TNode.Editor.GraphBlackboard;
using TNode.Editor.Inspector;
using TNode.Editor.NodeViews;
using TNode.Models;
using TNodeGraphViewImpl.Editor.GraphBlackboard;
using TNodeGraphViewImpl.Editor.NodeGraphView;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.TestTools.Utils;
@ -99,13 +99,13 @@ namespace TNode.Cache{
}
}
}
private readonly Type[] _acceptedTypesForGenericToSpecific = new Type[]{typeof(NodeView<>),typeof(DataGraphView<>),typeof(GraphBlackboardView<>)};
private readonly Type[] _defaultTypes = new []{typeof(DefaultNodeView),typeof(DefaultGraphBlackboardView)};
private readonly Type[] _acceptedTypesForGenericToSpecific = new Type[]{typeof(BaseNodeView<>),typeof(BaseDataGraphView<>),typeof(GraphBlackboardView<>)};
private readonly Type[] _defaultTypes = new []{typeof(DefaultBaseNodeView),typeof(DefaultGraphBlackboardView)};
private void SetViewComponentAttribute(Type type){
foreach (var attribute in type.GetCustomAttributes(typeof(ViewComponentAttribute), false)){
//fetch this type 's parent class
var parent = type.BaseType;
//Check if this type is a generic type and is a generic type of NodeView or DataGraphView,
//Check if this type is a generic type and is a generic type of BaseNodeView or BaseDataGraphView,
//Two level generic definition is now supported by TNode
//Deeper nested generic definition is not supported by TNode
if (parent is{IsGenericType: true} &&
@ -146,8 +146,8 @@ namespace TNode.Cache{
}
//check if t is a generic type node view
if (t is{IsGenericType: true} && t.GetGenericTypeDefinition() == typeof(NodeView<>)){
var instance = Activator.CreateInstance(typeof(NodeView<NodeData>));
if (t is{IsGenericType: true} && t.GetGenericTypeDefinition() == typeof(BaseNodeView<>)){
var instance = Activator.CreateInstance(typeof(BaseNodeView<NodeData>));
return instance;
}
return null;
@ -198,7 +198,7 @@ namespace TNode.Cache{
return null;
}
public static object CreateNodeViewFromNodeType(Type t){
//Check the generic type of NodeView by t
//Check the generic type of BaseNodeView by t
if (t.IsGenericType){
Debug.Log($"A generic type {t} is detected");
@ -208,8 +208,8 @@ namespace TNode.Cache{
var genericTypeDefinition = t.GetGenericTypeDefinition();
//What you want is a NodeView<BlackboardDragNodeData<T>> to be created
var genericViewType = typeof(NodeView<>).MakeGenericType(genericTypeDefinition);
//What you want is a BaseNodeView<BlackboardDragNodeData<T>> to be created
var genericViewType = typeof(BaseNodeView<>).MakeGenericType(genericTypeDefinition);
Debug.Log($"The generic view type is {genericViewType}");
//search for the specific type of genericViewType in the dictionary
@ -226,11 +226,11 @@ namespace TNode.Cache{
}
else{
return new DefaultNodeView();
return new DefaultBaseNodeView();
}
}
var type = typeof(NodeView<>).MakeGenericType(t);
var type = typeof(BaseNodeView<>).MakeGenericType(t);
if (NodeEditorSingleton.Instance.FromGenericToSpecific.ContainsKey(type)){
var implementedType = NodeEditorSingleton.Instance.FromGenericToSpecific[type];
@ -239,7 +239,7 @@ namespace TNode.Cache{
}
else{
return new DefaultNodeView();
return new DefaultBaseNodeView();
}
}

@ -1,12 +0,0 @@
using UnityEditor.Experimental.GraphView;
namespace TNode.Editor.GraphBlackboard{
public class BlackboardPropertyField:BlackboardField{
public BlackboardProperty BlackboardProperty;
public BlackboardPropertyField(BlackboardProperty blackboardProperty):base(null,blackboardProperty.PropertyName,null){
BlackboardProperty = blackboardProperty;
}
}
}

@ -1,10 +1,9 @@
using Codice.CM.Common;
using TNode.BaseViews;
using TNode.Cache;
using TNode.Editor.BaseViews;
using TNode.Editor.Inspector;
using TNode.Editor.Model;
using TNode.Models;
using TNodeGraphViewImpl.Editor.NodeGraphView;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
@ -15,7 +14,7 @@ namespace TNode.Editor{
public abstract class GraphEditor<T> : EditorWindow where T:GraphData{
protected DataGraphView<T> _graphView;
protected BaseDataGraphView<T> GraphView;
[SerializeField]
private VisualTreeAsset mVisualTreeAsset = default;
//Persist editor data ,such as node position,node size ,etc ,in this script object
@ -36,9 +35,9 @@ namespace TNode.Editor{
}
private void BuildGraphView(){
_graphView = NodeEditorExtensions.CreateViewComponentFromBaseType<DataGraphView<T>>();
rootVisualElement.Add(_graphView);
_graphView.StretchToParentSize();
GraphView = NodeEditorExtensions.CreateViewComponentFromBaseType<BaseDataGraphView<T>>();
rootVisualElement.Add(GraphView);
GraphView.StretchToParentSize();
}
private void DefineGraphEditorActions(){
@ -54,7 +53,7 @@ namespace TNode.Editor{
private void Save(){
//if no graph is loaded ,create a file save dialogue
if (_graphView.Data == null)
if (GraphView.Data == null)
{
string path = EditorUtility.SaveFilePanel("Save Graph", "", "", "asset");
if (path.Length != 0){
@ -66,7 +65,7 @@ namespace TNode.Editor{
}
}
else{
_graphView.SaveWithEditorData(graphEditorData);
GraphView.SaveWithEditorData(graphEditorData);
AssetDatabase.Refresh();
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 4cdebd0430794d32918ba8c63d71d0cc
timeCreated: 1656142311

@ -1,21 +0,0 @@
using System;
using TNode.Attribute;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.Editor.Inspector.InspectorImplementation{
[ViewComponent]
[Obsolete]
public class EnumFieldItem:InspectorItem<Enum>{
public EnumFieldItem() : base(){
var field = new EnumField();
Debug.Log("An Enum Field is created");
CreateBindable(field);
OnDataChanged += () => {
field.Init(Value);
Debug.Log(Value.GetType());
};
}
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 6eb83a1255d545e5998c7b3efd1b0d69
timeCreated: 1657193097

@ -1,13 +0,0 @@
using System;
using TNode.Attribute;
using UnityEngine.UIElements;
namespace TNode.Editor.Inspector.InspectorImplementation{
[Obsolete]
[ViewComponent]
public class FloatFieldItem:InspectorItem<float>{
public FloatFieldItem():base(){
CreateBindable(new FloatField());
}
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 932de5e7a487475aa764dd819cc33aa0
timeCreated: 1656583186

@ -1,25 +0,0 @@
using System;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;
namespace TNode.Editor.Inspector.InspectorImplementation{
[Obsolete]
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);
};
}
}
}

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

@ -1,16 +0,0 @@
using System;
using TNode.Attribute;
using UnityEngine.UIElements;
namespace TNode.Editor.Inspector.InspectorImplementation{
[Obsolete]
/// <summary>
/// Force these element to bind native c# property
/// </summary>
[ViewComponent]
public class StringFieldItem:InspectorItem<string>{
public StringFieldItem():base(){
CreateBindable(new TextField());
}
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 6b4f88e6c094449280ba5e38cb508287
timeCreated: 1656143219

@ -1,14 +0,0 @@
using System;
using TNode.Attribute;
using UnityEngine.UIElements;
namespace TNode.Editor.Inspector.InspectorImplementation{
[Obsolete]
[ViewComponent]
public class ToggleFieldItem:InspectorItem<bool>{
public ToggleFieldItem(){
CreateBindable(new Toggle());
}
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: d009d4819d604971976932b1d8f40bad
timeCreated: 1656580623

@ -1,105 +0,0 @@
using System;
using TNode.BaseViews;
using TNode.Models;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.Editor.Inspector{
[Obsolete]
public abstract class InspectorItem<T>:VisualElement,INodeDataBinding<T> {
protected NodeData _bindingNodeData;
protected string _bindingFieldName;
protected BaseField<T> Bindable;
protected event System.Action OnDataChanged;
public string BindingPath{
get => _bindingFieldName;
set{
_bindingFieldName = value;
if(_bindingFieldName!=null&&_bindingNodeData!=null){
OnDataChanged?.Invoke();
}
}
}
public NodeData BindingNodeData{
get => _bindingNodeData;
set{
var oldWrapper = ((NodeDataWrapper) _bindingNodeData);
if(oldWrapper!=null){
oldWrapper.OnValueChanged -= OnNodeDataValueChanged;
}
_bindingNodeData = value;
if(_bindingFieldName!=null&&_bindingNodeData!=null){
OnDataChanged?.Invoke();
}
if(_bindingNodeData!=null)
((NodeDataWrapper) _bindingNodeData).OnValueChanged += OnNodeDataValueChanged;
}
}
private T GetValue(){
var fieldInfo = _bindingNodeData.GetType().GetField(BindingPath, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (fieldInfo == null){
throw new Exception("Null field info");
}
if (fieldInfo.FieldType == typeof(T)){
return (T)fieldInfo.GetValue(BindingNodeData);
}
if (fieldInfo.FieldType.IsEnum){
return (T)fieldInfo.GetValue(BindingNodeData);
}
Debug.LogError("Wrong Type for current node data");
return default;
}
protected T Value => GetValue();
protected void SetValue(T value){
NodeDataWrapper wrapper = _bindingNodeData;
wrapper.SetValue(BindingPath,value);
}
public InspectorItem(){
OnDataChanged+= OnDataChangedHandler;
}
/*
* e => {
SetValue(e.newValue);
}
*/
private void OnInspectorItemValueChanged(ChangeEvent<T> e){
SetValue(e.newValue);
}
public void CreateBindable(BaseField<T> bindable){
if (Bindable != null){
Bindable.Clear();
Bindable.UnregisterValueChangedCallback(OnInspectorItemValueChanged);
}
Bindable = bindable;
Add(Bindable);
Bindable?.RegisterValueChangedCallback(OnInspectorItemValueChanged);
}
private void OnDataChangedHandler(){
Bindable = this.Q<BaseField<T>>();
if(Bindable!= null){
Bindable.value = Value;
Bindable.label = BindingPath;
}
}
private void OnNodeDataValueChanged(NodeDataWrapper wrapper){
var value = (T) wrapper.GetValue(BindingPath) ;
if(Bindable!=null){
Bindable.value = value;
}
}
~InspectorItem(){
OnDataChanged-= OnDataChangedHandler;
}
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 82902f281e4642f2be8b742866d38839
timeCreated: 1656126272

@ -1,45 +0,0 @@
using System;
using TNode.Cache;
using TNode.Editor.Inspector.InspectorImplementation;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.Editor.Inspector{
[Obsolete]
public class InspectorItemFactory{
public InspectorItem<T> Create<T>(){
//Check type of GraphDataType
var hasSpecificType = NodeEditorExtensions.HasSpecificTypeComponent<InspectorItem<T>>();
if (hasSpecificType){
return NodeEditorExtensions.CreateViewComponentFromBaseType<InspectorItem<T>>();
}
if (typeof(T).IsEnum){
return NodeEditorExtensions.CreateViewComponentFromBaseType(typeof(InspectorItem<Enum>)) as InspectorItem<T>;
}
return null;
}
public INodeDataBindingBase Create(Type t){
var genericType = typeof(InspectorItem<>).MakeGenericType(t);
var hasSpecificType = NodeEditorExtensions.HasSpecificTypeComponent(genericType);
if (hasSpecificType){
return NodeEditorExtensions.CreateViewComponentFromBaseType(genericType) as INodeDataBindingBase;
}
if (t.IsEnum){
return NodeEditorExtensions.CreateViewComponentFromBaseType(typeof(InspectorItem<Enum>)) as INodeDataBindingBase;
}
return null;
}
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 83b9e37f79cf4a18b265e3e22e7e3ced
timeCreated: 1656142463

@ -1,16 +0,0 @@
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine;
namespace TNode.Editor.Inspector{
// [CustomEditor(typeof(MonoImporter))]
// public class MonoScriptInspector:AssetImporterEditor{
// public override void OnInspectorGUI(){
// base.OnInspectorGUI();
// if(GUILayout.Button("Open")){
// EditorUtility.OpenWithDefaultApp(AssetDatabase.GetAssetPath(target));
// }
// }
// }
//
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 192a51f6578144c5bbddb5cf77685c71
timeCreated: 1656214219

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: cc8c20a304714599959643305857c804
timeCreated: 1657486909

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 400542f3cec140e2b55e2bcf637b2d9b
timeCreated: 1657009018

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9e377285943b43278ea539231483fe6f
timeCreated: 1657683945

@ -0,0 +1,11 @@
using TNode.Models;
using UnityEngine;
namespace TNode.Editor.NodeGraphView{
public interface IBaseDataGraphView{
public void AddTNode(NodeData nodeData, Rect rect);
public void RemoveTNode(NodeData nodeData);
public BlackboardData GetBlackboardData();
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9839105141d14b3aac3891bcaaa3fe50
timeCreated: 1657684189

@ -0,0 +1,7 @@
using TNode.Models;
namespace TNode.Editor.NodeGraphView{
public interface IDataGraphView<T> : IBaseDataGraphView where T:GraphData{
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b0f8421124864a7d993bcbfb419987dd
timeCreated: 1657684182

@ -1,11 +0,0 @@
using TNode.BaseViews;
using TNode.Editor.BaseViews;
using TNode.Models;
namespace TNode.Editor{
public class DefaultNodeView:NodeView<NodeData>{
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 792d2c6b4dca441981787b922b385f0a
timeCreated: 1657684260

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1e6ee4cc74d84496a099ac0624bda536
timeCreated: 1657684324

@ -0,0 +1,12 @@
using UnityEditor.Experimental.GraphView;
namespace TNodeGraphViewImpl.Editor.GraphBlackboard{
public class BlackboardPropertyField:BlackboardField{
public BlackboardProperty.BlackboardProperty BlackboardProperty;
public BlackboardPropertyField(BlackboardProperty.BlackboardProperty blackboardProperty):base(null,blackboardProperty.PropertyName,null){
BlackboardProperty = blackboardProperty;
}
}
}

@ -1,6 +1,6 @@
using System;
namespace TNode.Editor.GraphBlackboard{
namespace TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty{
public class BlackboardProperty{
public string PropertyName;
public Type PropertyType;

@ -1,7 +1,7 @@
using TNode.Attribute;
using TNode.Models;
namespace TNode.Editor.GraphBlackboard{
namespace TNodeGraphViewImpl.Editor.GraphBlackboard{
[ViewComponent]
public class DefaultGraphBlackboardView:GraphBlackboardView<BlackboardData>{
public DefaultGraphBlackboardView(){

@ -1,7 +1,7 @@
using TNode.Models;
using UnityEditor.Experimental.GraphView;
namespace TNode.Editor.GraphBlackboard{
namespace TNodeGraphViewImpl.Editor.GraphBlackboard{
/// <summary>
/// Implement this class to create graph black board for specified graph
/// </summary>

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 152e46659fee4d2fb09bc06f18d54c98
timeCreated: 1657684641

@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Reflection;
using TNode.Attribute;
using TNode.BaseViews;
using TNode.Editor.BaseViews;
using TNode.Editor.NodeViews;
using TNode.Models;
using TNodeGraphViewImpl.Editor.NodeGraphView;
using Unity.VisualScripting;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
@ -24,7 +24,7 @@ namespace TNode.Editor.Inspector{
}
}
public INodeView NodeView;
public IBaseNodeView BaseNodeView;
private void UpdateData(){
Debug.Log(_data);
if (_data != null){
@ -46,18 +46,18 @@ namespace TNode.Editor.Inspector{
var body = this.Q("InspectorBody");
body.Clear();
body.StretchToParentSize();
foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){
var bindingPath = field.Name;
var type = field.FieldType;
InspectorItemFactory inspectorItemFactory = new InspectorItemFactory();
//Invoke generic function Create<> of default inspector item factory to create an inspector item of appropriate type by reflection
var createdItem = inspectorItemFactory.Create(type);
if (createdItem is { } castedItem){
castedItem.BindingNodeData = _data;
castedItem.BindingPath = bindingPath;
}
Add((VisualElement)createdItem);
}
// foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){
// var bindingPath = field.Name;
// var type = field.FieldType;
// InspectorItemFactory inspectorItemFactory = new InspectorItemFactory();
// //Invoke generic function Create<> of default inspector item factory to create an inspector item of appropriate type by reflection
// var createdItem = inspectorItemFactory.Create(type);
// if (createdItem is { } castedItem){
// castedItem.BindingNodeData = _data;
// castedItem.BindingPath = bindingPath;
// }
// Add((VisualElement)createdItem);
// }
}
}
}

@ -40,9 +40,6 @@ namespace TNode.Editor.Inspector{
if (_data.GetType().IsSubclassOf(typeof(BlackboardDragNodeData<>))){
return;
}
var serializedObject = new SerializedObject((NodeDataWrapper)_data);
foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public|BindingFlags.NonPublic)){
//Create corresponding property field
@ -53,28 +50,8 @@ namespace TNode.Editor.Inspector{
var drawer = new PropertyField(serializedObject.FindProperty("Data").FindPropertyRelative(field.Name),field.Name);
Debug.Log(serializedObject.FindProperty("Data"));
drawer.Bind(serializedObject);
Add(drawer);
}
}
private void RefreshItems(){
InspectorItemFactory inspectorItemFactory = new InspectorItemFactory();
foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){
var bindingPath = field.Name;
var type = field.FieldType;
//check if the field has ShowInNodeView attribute
var showInNodeViewAttribute = field.GetCustomAttribute<ShowInNodeViewAttribute>() != null;
if (!showInNodeViewAttribute)
continue;
var createdItem = inspectorItemFactory.Create(type);
if (createdItem is{ } castedItem){
castedItem.BindingNodeData = _data;
castedItem.BindingPath = bindingPath;
}
Add((VisualElement) createdItem);
}
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 509019c594fa494dba98f9910092b63e
timeCreated: 1657684502

@ -3,116 +3,25 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using TNode.BaseViews;
using TNode.Cache;
using TNode.Editor.GraphBlackboard;
using TNode.Editor;
using TNode.Editor.Inspector;
using TNode.Editor.Model;
using TNode.Editor.NodeGraphView;
using TNode.Editor.NodeViews;
using TNode.Editor.Search;
using TNode.Editor.Tools.NodeCreator;
using TNode.Models;
using Unity.VisualScripting;
using TNodeGraphViewImpl.Editor.GraphBlackboard;
using TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
using Edge = UnityEditor.Experimental.GraphView.Edge;
namespace TNode.Editor.BaseViews{
/*
public class DialogueGraphView : DataGraphView<DialogueGraph>{
public Action<DialogueNodeView> onNodeAdded;
public Action<DialogueNodeView> onNodeSelected;
public Action<DialogueNodeView> onNodeRemoved;
public Action<DialogueNodeView> onNodeUnselected;
// public DialogueGraphView(DialogueGraph graph):base(){
// this.Data = graph;
//
// //Set background to a bit of darker
//
//
// //Register a data context change callback
//
// }
public override void OnGraphViewCreate(){
AddNode(GenerateEntryPoint());
RegisterCallback<ContextualMenuPopulateEvent>(evt => {
var pos = evt.mousePosition;
evt.menu.AppendAction("Add NodeAttribute", (dropMenuAction) => {
DialogueNodeView nodeView = new DialogueNodeView{
GUID = Guid.NewGuid().ToString(),
title = "New NodeAttribute"
};
// make it a 200x100 box
nodeView.SetPosition(new Rect(pos.x - 100, pos.y - 50, 200, 100));
AddNode(nodeView);
}, DropdownMenuAction.AlwaysEnabled);
});
this.OnDataChanged += OnOnDataChanged;
}
private void OnOnDataChanged(object sender, DataChangedEventArgs<DialogueGraph> e){
//clean all nodes from the graphview
foreach (var graphViewNode in nodes){
RemoveElement(graphViewNode);
}
foreach (var edge in edges){
RemoveElement(edge);
}
//add all nodes from the new graph
foreach (var node in e.NewData.nodes){
//AddNode(node);
}
}
public void AddNode(DialogueNodeData dialogueNodeData){
var res = InstantiateFromDialogueNodeData(dialogueNodeData);
AddNode(res);
}
public void AddNode(DialogueNodeView nodeView){
AddElement(nodeView);
onNodeAdded?.Invoke(nodeView);
//Register nodeView selection callback
nodeView.RegisterCallback<MouseDownEvent>(evt => {
if (evt.clickCount == 1){
onNodeSelected?.Invoke(nodeView);
}
});
nodeView.OnUnselect += () => { onNodeUnselected?.Invoke(nodeView); };
}
public override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter) => this.ports.ToList()
.Where(x => x != startPort &&
x.direction != startPort.direction).ToList();
public DialogueNodeView GenerateEntryPoint(){
var entryPoint = new DialogueNodeView{
title = "Entry Point",
GUID = Guid.NewGuid().ToString(),
EntryPoint = true
};
//Add output port to the nodeView
entryPoint.AddPort(Orientation.Horizontal, Direction.Output, "Next");
//Set nodeView position to top center side of screen
entryPoint.SetPosition(new Rect(this.layout.width / 2 - 100, 0, 200, 200));
return entryPoint;
}
protected DialogueNodeView InstantiateFromDialogueNodeData(DialogueNodeData dialogueNodeData){
var node = new DialogueNodeView();
node.title = dialogueNodeData.nodeName;
node.GUID = Guid.NewGuid().ToString();
//TODO:after completing the separation of the node data and the node editor data,this should be switch to the node editor data
//node.SetPosition(dialogueNodeData.rect);
this.AddNode(node);
return node;
}
}
*/
public abstract class DataGraphView<T>:GraphView,IDataGraphView where T:GraphData{
namespace TNodeGraphViewImpl.Editor.NodeGraphView{
public abstract class BaseDataGraphView<T>:GraphView,IBaseDataGraphView where T:GraphData{
#region variables and properties
private T _data;
private bool _isInspectorOn;
@ -138,11 +47,11 @@ namespace TNode.Editor.BaseViews{
#endregion
//A Constructor for the DataGraphView ,never to override it
//A Constructor for the BaseDataGraphView ,never to override it
#region construct default behaviour
public DataGraphView(){
public BaseDataGraphView(){
styleSheets.Add(Resources.Load<StyleSheet>("GraphViewBackground"));
var grid = new GridBackground();
Insert(0,grid);
@ -350,7 +259,7 @@ namespace TNode.Editor.BaseViews{
var nodeEditorData = new GraphElementEditorData{
pos = node.GetPosition(),
};
if (node is INodeView nodeView){
if (node is IBaseNodeView nodeView){
nodeEditorData.guid = nodeView.GetNodeData().id;
}
graphEditorData.graphElementsData.Add(nodeEditorData);
@ -366,7 +275,7 @@ namespace TNode.Editor.BaseViews{
private void SaveNode(){
foreach (var node in nodes){
if (node is INodeView nodeView){
if (node is IBaseNodeView nodeView){
var nodeData = nodeView.GetNodeData();
if (!_data.NodeDictionary.ContainsKey(nodeData.id)){
_data.NodeDictionary.Add(nodeData.id, nodeData);
@ -377,8 +286,8 @@ namespace TNode.Editor.BaseViews{
private void SaveEdge(){
var links = new List<NodeLink>();
foreach (var edge in edges){
var inputNode = edge.input.node as INodeView;
var outputNode = edge.output.node as INodeView;
var inputNode = edge.input.node as IBaseNodeView;
var outputNode = edge.output.node as IBaseNodeView;
if (inputNode != null && outputNode != null){
var inputNodeData = inputNode.GetNodeData();
var outputNodeData = outputNode.GetNodeData();
@ -417,7 +326,7 @@ namespace TNode.Editor.BaseViews{
public virtual void OnGraphViewDestroy(){
}
~DataGraphView(){
~BaseDataGraphView(){
OnGraphViewDestroy();
}
@ -434,11 +343,11 @@ namespace TNode.Editor.BaseViews{
if (evt.clickCount == 1){
if (_isInspectorOn){
_nodeInspector.Data = nodeData;
_nodeInspector.NodeView = nodeView as INodeView;
_nodeInspector.BaseNodeView = nodeView as IBaseNodeView;
}
}
});
if(nodeView is INodeView nodeViewInterface){
if(nodeView is IBaseNodeView nodeViewInterface){
nodeViewInterface.SetNodeData(nodeData);
}
_nodeDict.Add(nodeData.id, nodeView);
@ -448,7 +357,7 @@ namespace TNode.Editor.BaseViews{
var menu = new GenericMenu();
menu.AddItem(new GUIContent("Delete"), false, () => {
RemoveElement(nodeView);
if (nodeView is INodeView tNodeView){
if (nodeView is IBaseNodeView tNodeView){
RemoveTNode(tNodeView.GetNodeData());
}
});
@ -477,12 +386,6 @@ namespace TNode.Editor.BaseViews{
}
}
public interface IDataGraphView{
public void AddTNode(NodeData nodeData, Rect rect);
public void RemoveTNode(NodeData nodeData);
public BlackboardData GetBlackboardData();
}
public class DataChangedEventArgs<T>{
public DataChangedEventArgs(T data){

@ -5,7 +5,7 @@ using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine.UIElements;
namespace TNode.BaseViews{
namespace TNodeGraphViewImpl.Editor.NodeGraphView{
public class SimpleGraphSubWindow:GraphElement,IGraphViewPersistence{
private readonly Dragger _dragger = new Dragger();

@ -0,0 +1,10 @@
using TNode.Editor.NodeViews;
using TNode.Models;
namespace TNode.Editor{
public class DefaultBaseNodeView:BaseNodeView<NodeData>{
}
}

@ -1,11 +1,10 @@
using TNode.Attribute;
using TNode.Editor.BaseViews;
using TNode.Models;
namespace TNode.Editor.NodeViews{
[ViewComponent]
public class DragNodeView<T>:NodeView<BlackboardDragNodeData<T>>{
public DragNodeView() : base(){
public class DragBaseNodeView<T>:BaseNodeView<BlackboardDragNodeData<T>>{
public DragBaseNodeView() : base(){
//Make capsule like style
this.titleContainer.visible = false;

@ -5,17 +5,13 @@ using TNode.Attribute;
using TNode.Attribute.Ports;
using TNode.Editor.Inspector;
using TNode.Models;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.Editor.BaseViews{
namespace TNode.Editor.NodeViews{
//A NodeAttribute monitor some type of node in the graph
public abstract class NodeView<T> : Node,INodeView where T:NodeData,new(){
public abstract class BaseNodeView<T> : Node,INodeView<T> where T:NodeData,new(){
protected T _data;
private readonly NodeInspectorInNode _nodeInspectorInNode;
@ -42,7 +38,7 @@ namespace TNode.Editor.BaseViews{
}
public event System.Action<T> OnDataChanged;
protected NodeView(){
protected BaseNodeView(){
OnDataChanged+=OnDataChangedHandler;
_nodeInspectorInNode = new NodeInspectorInNode(){
@ -69,10 +65,8 @@ namespace TNode.Editor.BaseViews{
switch (portAttribute.NameHandling){
case PortNameHandling.Auto:
return portAttribute.Name.Trim(' ').Length>0?portAttribute.Name:propertyInfo.Name;
break;
case PortNameHandling.Manual:
return portAttribute.Name;
break;
case PortNameHandling.MemberName:
return propertyInfo.Name;
case PortNameHandling.Format:
@ -169,11 +163,15 @@ namespace TNode.Editor.BaseViews{
}
}
public interface INodeView{
public interface IBaseNodeView{
public void SetNodeData(NodeData nodeData);
public NodeData GetNodeData();
public void OnDataModified();
}
public interface INodeView<T>:IBaseNodeView where T:NodeData,new(){
public T Data{ get; set; }
}
}

@ -1,7 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TNode.Editor.BaseViews;
using TNode.Editor.NodeGraphView;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
@ -9,7 +9,7 @@ using UnityEngine;
namespace TNode.Editor.Search{
public class BlackboardSearchWindowProvider:ScriptableObject,ISearchWindowProvider{
private Type _graphType;
private IDataGraphView _graphView;
private IBaseDataGraphView _graphView;
private EditorWindow _editor;
private struct InternalSearchTreeUserData{
@ -60,7 +60,7 @@ namespace TNode.Editor.Search{
return false;
}
public void Setup(Type graph,IDataGraphView graphView,EditorWindow editor){
public void Setup(Type graph,IBaseDataGraphView graphView,EditorWindow editor){
_graphType = graph;
_graphView = graphView;
_editor = editor;

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using TNode.Cache;
using TNode.Editor.BaseViews;
using TNode.Editor.NodeGraphView;
using TNode.Editor.Tools.NodeCreator;
using TNode.Models;
using UnityEditor;
@ -48,7 +48,7 @@ namespace TNode.Editor.Search{
//Make an instance of the type
if (NodeCreator.InstantiateNodeData(type) is { } nodeData){
nodeData.nodeName = $"New {type.Name}";
((IDataGraphView) _graphView).AddTNode(nodeData, new Rect(localPos.x, localPos.y, 100, 100));
((IBaseDataGraphView) _graphView).AddTNode(nodeData, new Rect(localPos.x, localPos.y, 100, 100));
}
}
return true;
Loading…
Cancel
Save