From c838416b7349aa0084eb33af711e4aa8611244cf Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Tue, 16 Aug 2022 09:49:10 +0800 Subject: [PATCH] update:fix bug with BlackboardDragNode.cs --- Samples/Editor/HelloEditor.asset | 17 ------- Samples/Editor/HelloEditor.asset.meta | 8 --- Samples/Editor/HelloEditor.cs.meta | 4 +- Samples/New HelloGraph.asset | 50 +++++-------------- .../Runtime/Attributes/Ports/PortAttribute.cs | 16 +++++- .../Runtime/Models/BlackboardDragNode.cs | 16 +++--- .../Editor/NodeGraphView/DataGraphView.cs | 2 + .../Editor/NodeViews/NodeView.cs | 22 ++++++++ 8 files changed, 59 insertions(+), 76 deletions(-) delete mode 100644 Samples/Editor/HelloEditor.asset delete mode 100644 Samples/Editor/HelloEditor.asset.meta diff --git a/Samples/Editor/HelloEditor.asset b/Samples/Editor/HelloEditor.asset deleted file mode 100644 index d60be1a..0000000 --- a/Samples/Editor/HelloEditor.asset +++ /dev/null @@ -1,17 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 99ad0af56b40495cb6bd6165e652266c, type: 3} - m_Name: HelloEditor - m_EditorClassIdentifier: - graphElementsData: [] - graphImplType: 0 - autoUpdate: 0 diff --git a/Samples/Editor/HelloEditor.asset.meta b/Samples/Editor/HelloEditor.asset.meta deleted file mode 100644 index 0fd1ea2..0000000 --- a/Samples/Editor/HelloEditor.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 060ae44fcac9b534f9bdca3c3e5f1484 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Samples/Editor/HelloEditor.cs.meta b/Samples/Editor/HelloEditor.cs.meta index ec0600b..b7ac422 100644 --- a/Samples/Editor/HelloEditor.cs.meta +++ b/Samples/Editor/HelloEditor.cs.meta @@ -5,8 +5,8 @@ MonoImporter: serializedVersion: 2 defaultReferences: - m_ViewDataDictionary: {instanceID: 0} - - mVisualTreeAsset: {fileID: 9197481963319205126, guid: b67f6dcbe2361b649ad2b7845207321b, type: 3} - - graphEditorData: {fileID: 11400000, guid: 060ae44fcac9b534f9bdca3c3e5f1484, type: 2} + - mVisualTreeAsset: {instanceID: 0} + - graphEditorData: {fileID: 11400000, guid: 26c77e8bb72228e4d81789ee852ada41, type: 2} executionOrder: 0 icon: {instanceID: 0} userData: diff --git a/Samples/New HelloGraph.asset b/Samples/New HelloGraph.asset index 6668a6c..b714366 100644 --- a/Samples/New HelloGraph.asset +++ b/Samples/New HelloGraph.asset @@ -18,26 +18,26 @@ MonoBehaviour: blackboardData: id: 1 sceneReference: - editorModels: - - id: 2 - - id: 3 + editorModels: [] graphViewModel: - id: 4 + id: 2 references: version: 1 00000000: - type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} + type: {class: BlackboardDragNode, ns: TNodeCore.Runtime.Models, asm: TNodeCore} data: positionInView: serializedVersion: 2 - x: 479 - y: 295 + x: 54.89991 + y: 86.95003 width: 0 height: 0 - id: b2634d94-1655-4674-9b1c-b1c2e9ab3f6b - nodeName: AddNode + id: 2c26caec-abd2-4034-b68e-28a2843d347e + nodeName: entryPoint: 0 isTest: 0 + blackDragData: HelloGameObject + isListElement: 0 00000001: type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp} data: @@ -53,33 +53,7 @@ MonoBehaviour: V3S: [] V2S: [] 00000002: - type: {class: PlacematModel, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly} - data: - positionInView: - serializedVersion: 2 - x: 443 - y: 177 - width: 500 - height: 500 - id: - hostModels: [] - zOrder: 0 - title: Title - 00000003: - type: {class: Comment, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly} - data: - positionInView: - serializedVersion: 2 - x: 0 - y: 0 - width: 0 - height: 0 - id: - CommentedModel: - id: 0 - CommentText: ddd - 00000004: - type: {class: GraphViewModel, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly} + type: {class: GraphViewModel, ns: TNode.TNodeCore.Editor.Models, asm: TNodeCore} data: positionInView: serializedVersion: 2 @@ -89,5 +63,5 @@ MonoBehaviour: height: 0 id: persistScale: 1 - persistOffset: {x: 0, y: -5} - isBlackboardOn: 0 + persistOffset: {x: 441, y: 254} + isBlackboardOn: 1 diff --git a/TNodeCore/Runtime/Attributes/Ports/PortAttribute.cs b/TNodeCore/Runtime/Attributes/Ports/PortAttribute.cs index cb6f4ba..7aad3cc 100644 --- a/TNodeCore/Runtime/Attributes/Ports/PortAttribute.cs +++ b/TNodeCore/Runtime/Attributes/Ports/PortAttribute.cs @@ -14,9 +14,22 @@ namespace TNodeCore.Runtime.Attributes.Ports{ } public enum TypeHandling{ + /// + /// What's declared in the field is what port type is + /// Declared, + /// + /// What's the real type of the watched field is what port type is + /// Implemented, - Specified + /// + /// Specify the port type + /// + Specified, + /// + /// Search the node's path to find the proper type + /// + Path } [MeansImplicitUse] [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] @@ -25,6 +38,7 @@ namespace TNodeCore.Runtime.Attributes.Ports{ public readonly PortNameHandling NameHandling; public Type HandledType; public bool Multiple = true; + public string TypePath; public TypeHandling TypeHandling{ get; set; } public PortAttribute(string name,PortNameHandling nameHandling=PortNameHandling.Auto,TypeHandling typeHandling=TypeHandling.Declared){ diff --git a/TNodeCore/Runtime/Models/BlackboardDragNode.cs b/TNodeCore/Runtime/Models/BlackboardDragNode.cs index c28dcb0..216c9cd 100644 --- a/TNodeCore/Runtime/Models/BlackboardDragNode.cs +++ b/TNodeCore/Runtime/Models/BlackboardDragNode.cs @@ -2,7 +2,6 @@ using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Attributes.Ports; using TNodeCore.Runtime.RuntimeCache; -using UnityEngine; namespace TNodeCore.Runtime.Models{ [Serializable] @@ -17,13 +16,15 @@ namespace TNodeCore.Runtime.Models{ } } } - - public string blackDragData; /// - /// it's very hacky way to get blackboard data ,even when the value is null,type info is not null! + /// /// + public Type BlackboardDragType{ get; set; } + + public string blackDragData; + /// TODO : The type handling in a safer way in the future - [Output("",PortNameHandling.MemberType,TypeHandling.Implemented)] + [Output("",PortNameHandling.MemberType,TypeHandling.Path,TypePath = "BlackboardDragType")] public object Value{ get{ if (!isListElement){ @@ -32,7 +33,6 @@ namespace TNodeCore.Runtime.Models{ else{ var split = BlackDragData.Split('.'); var index = int.Parse(split[1]); - return BlackboardData.GetListValue(split[0],index); } @@ -40,9 +40,5 @@ namespace TNodeCore.Runtime.Models{ } public bool isListElement=false; - public BlackboardDragNode(){ - - } - } } \ No newline at end of file diff --git a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index e1ed731..a0c866d 100644 --- a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs +++ b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -373,6 +373,8 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ //Make a constructor of BlackboardDragNode by reflection var dragNodeData = NodeCreator.InstantiateNodeData(); dragNodeData.BlackboardData = GetBlackboardData(); + dragNodeData.BlackboardDragType = entry.propertyType; + Debug.Log(entry.propertyType); dragNodeData.BlackDragData = entry.propertyPath; AddTNode(dragNodeData,new Rect(realPos,new Vector2(200,200))); } diff --git a/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs b/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs index c9f3a77..6b972d4 100644 --- a/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs +++ b/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs @@ -124,6 +124,26 @@ namespace TNodeGraphViewImpl.Editor.NodeViews{ throw new ArgumentOutOfRangeException(); } } + + private Type GetDataType(string path){ + //Access the member by given path + var memberInfo = _data.GetType().GetMember(path).FirstOrDefault(); + + if (memberInfo == null){ + return null; + } + if (memberInfo is PropertyInfo propertyInfo){ + + return propertyInfo.GetValue(_data) as Type; + } + + //Check if the member is a field + if (memberInfo is FieldInfo fieldInfo){ + return _data.GetType().GetField(path)?.GetValue(_data) as Type; + } + + throw new Exception("Member is not a property or field"); + } protected virtual Type BuildPortType(PortAttribute portAttribute,PropertyInfo propertyInfo){ switch (portAttribute.TypeHandling){ case TypeHandling.Declared : @@ -132,6 +152,8 @@ namespace TNodeGraphViewImpl.Editor.NodeViews{ return propertyInfo.GetValue(_data)?.GetType(); case TypeHandling.Specified: return portAttribute.HandledType??typeof(object); + case TypeHandling.Path: + return GetDataType(portAttribute.TypePath); default: throw new ArgumentOutOfRangeException(); }