update:fix bug with BlackboardDragNode.cs

main
taoria 3 years ago
parent ec0372dd51
commit c838416b73
  1. 17
      Samples/Editor/HelloEditor.asset
  2. 8
      Samples/Editor/HelloEditor.asset.meta
  3. 4
      Samples/Editor/HelloEditor.cs.meta
  4. 50
      Samples/New HelloGraph.asset
  5. 16
      TNodeCore/Runtime/Attributes/Ports/PortAttribute.cs
  6. 16
      TNodeCore/Runtime/Models/BlackboardDragNode.cs
  7. 2
      TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
  8. 22
      TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs

@ -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

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 060ae44fcac9b534f9bdca3c3e5f1484
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

@ -5,8 +5,8 @@ MonoImporter:
serializedVersion: 2 serializedVersion: 2
defaultReferences: defaultReferences:
- m_ViewDataDictionary: {instanceID: 0} - m_ViewDataDictionary: {instanceID: 0}
- mVisualTreeAsset: {fileID: 9197481963319205126, guid: b67f6dcbe2361b649ad2b7845207321b, type: 3} - mVisualTreeAsset: {instanceID: 0}
- graphEditorData: {fileID: 11400000, guid: 060ae44fcac9b534f9bdca3c3e5f1484, type: 2} - graphEditorData: {fileID: 11400000, guid: 26c77e8bb72228e4d81789ee852ada41, type: 2}
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:

@ -18,26 +18,26 @@ MonoBehaviour:
blackboardData: blackboardData:
id: 1 id: 1
sceneReference: sceneReference:
editorModels: editorModels: []
- id: 2
- id: 3
graphViewModel: graphViewModel:
id: 4 id: 2
references: references:
version: 1 version: 1
00000000: 00000000:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} type: {class: BlackboardDragNode, ns: TNodeCore.Runtime.Models, asm: TNodeCore}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 479 x: 54.89991
y: 295 y: 86.95003
width: 0 width: 0
height: 0 height: 0
id: b2634d94-1655-4674-9b1c-b1c2e9ab3f6b id: 2c26caec-abd2-4034-b68e-28a2843d347e
nodeName: AddNode nodeName:
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
blackDragData: HelloGameObject
isListElement: 0
00000001: 00000001:
type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp} type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp}
data: data:
@ -53,33 +53,7 @@ MonoBehaviour:
V3S: [] V3S: []
V2S: [] V2S: []
00000002: 00000002:
type: {class: PlacematModel, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly} type: {class: GraphViewModel, ns: TNode.TNodeCore.Editor.Models, asm: TNodeCore}
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}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
@ -89,5 +63,5 @@ MonoBehaviour:
height: 0 height: 0
id: id:
persistScale: 1 persistScale: 1
persistOffset: {x: 0, y: -5} persistOffset: {x: 441, y: 254}
isBlackboardOn: 0 isBlackboardOn: 1

@ -14,9 +14,22 @@ namespace TNodeCore.Runtime.Attributes.Ports{
} }
public enum TypeHandling{ public enum TypeHandling{
/// <summary>
/// What's declared in the field is what port type is
/// </summary>
Declared, Declared,
/// <summary>
/// What's the real type of the watched field is what port type is
/// </summary>
Implemented, Implemented,
Specified /// <summary>
/// Specify the port type
/// </summary>
Specified,
/// <summary>
/// Search the node's path to find the proper type
/// </summary>
Path
} }
[MeansImplicitUse] [MeansImplicitUse]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
@ -25,6 +38,7 @@ namespace TNodeCore.Runtime.Attributes.Ports{
public readonly PortNameHandling NameHandling; public readonly PortNameHandling NameHandling;
public Type HandledType; public Type HandledType;
public bool Multiple = true; public bool Multiple = true;
public string TypePath;
public TypeHandling TypeHandling{ get; set; } public TypeHandling TypeHandling{ get; set; }
public PortAttribute(string name,PortNameHandling nameHandling=PortNameHandling.Auto,TypeHandling typeHandling=TypeHandling.Declared){ public PortAttribute(string name,PortNameHandling nameHandling=PortNameHandling.Auto,TypeHandling typeHandling=TypeHandling.Declared){

@ -2,7 +2,6 @@
using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Attributes.Ports; using TNodeCore.Runtime.Attributes.Ports;
using TNodeCore.Runtime.RuntimeCache; using TNodeCore.Runtime.RuntimeCache;
using UnityEngine;
namespace TNodeCore.Runtime.Models{ namespace TNodeCore.Runtime.Models{
[Serializable] [Serializable]
@ -17,13 +16,15 @@ namespace TNodeCore.Runtime.Models{
} }
} }
} }
public string blackDragData;
/// <summary> /// <summary>
/// it's very hacky way to get blackboard data ,even when the value is null,type info is not null! ///
/// </summary> /// </summary>
public Type BlackboardDragType{ get; set; }
public string blackDragData;
/// TODO : The type handling in a safer way in the future /// 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{ public object Value{
get{ get{
if (!isListElement){ if (!isListElement){
@ -32,7 +33,6 @@ namespace TNodeCore.Runtime.Models{
else{ else{
var split = BlackDragData.Split('.'); var split = BlackDragData.Split('.');
var index = int.Parse(split[1]); var index = int.Parse(split[1]);
return BlackboardData.GetListValue(split[0],index); return BlackboardData.GetListValue(split[0],index);
} }
@ -40,9 +40,5 @@ namespace TNodeCore.Runtime.Models{
} }
public bool isListElement=false; public bool isListElement=false;
public BlackboardDragNode(){
}
} }
} }

@ -373,6 +373,8 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{
//Make a constructor of BlackboardDragNode<field.PropertyType > by reflection //Make a constructor of BlackboardDragNode<field.PropertyType > by reflection
var dragNodeData = NodeCreator.InstantiateNodeData<BlackboardDragNode>(); var dragNodeData = NodeCreator.InstantiateNodeData<BlackboardDragNode>();
dragNodeData.BlackboardData = GetBlackboardData(); dragNodeData.BlackboardData = GetBlackboardData();
dragNodeData.BlackboardDragType = entry.propertyType;
Debug.Log(entry.propertyType);
dragNodeData.BlackDragData = entry.propertyPath; dragNodeData.BlackDragData = entry.propertyPath;
AddTNode(dragNodeData,new Rect(realPos,new Vector2(200,200))); AddTNode(dragNodeData,new Rect(realPos,new Vector2(200,200)));
} }

@ -124,6 +124,26 @@ namespace TNodeGraphViewImpl.Editor.NodeViews{
throw new ArgumentOutOfRangeException(); 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){ protected virtual Type BuildPortType(PortAttribute portAttribute,PropertyInfo propertyInfo){
switch (portAttribute.TypeHandling){ switch (portAttribute.TypeHandling){
case TypeHandling.Declared : case TypeHandling.Declared :
@ -132,6 +152,8 @@ namespace TNodeGraphViewImpl.Editor.NodeViews{
return propertyInfo.GetValue(_data)?.GetType(); return propertyInfo.GetValue(_data)?.GetType();
case TypeHandling.Specified: case TypeHandling.Specified:
return portAttribute.HandledType??typeof(object); return portAttribute.HandledType??typeof(object);
case TypeHandling.Path:
return GetDataType(portAttribute.TypePath);
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }

Loading…
Cancel
Save