fix:fix a blackboard error

main
taoria 3 years ago
parent 8bdc6afbb3
commit 7fc1ebafdb
  1. 23
      TNode/Samples/AddNode.cs
  2. 3
      TNode/Samples/AddNode.cs.meta
  3. 5
      TNode/Samples/Editor/HelloEditor.cs
  4. 17
      TNode/Samples/HelloBlackboard.cs
  5. 3
      TNode/Samples/HelloBlackboard.cs.meta
  6. 11
      TNode/Samples/HelloGraph.cs
  7. 100
      TNode/Samples/New HelloGraph.asset
  8. 1
      TNode/TNodeCore/Editor/GraphEditor.cs
  9. 5
      TNode/TNodeCore/Runtime/Models/BlackboardData.cs
  10. 7
      TNode/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs
  11. 24
      TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs
  12. 13
      TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs
  13. 69
      TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
  14. 1
      TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs
  15. 10
      TNode/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs

@ -0,0 +1,23 @@

using TNodeCore.Runtime;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Attributes.Ports;
using TNodeCore.Runtime.Models;
using UnityEngine;
namespace Samples{
[GraphUsage(typeof(HelloGraph),"Math")]
public class AddNode:NodeData{
[Input]
public Vector3 A{ get; set; }
[Input]
public Vector2 B{ get; set; }
[Output]
public Vector3 Res{ get; set; }
public override void Process(){
Res = A + (Vector3)B;
this.Log(Res.ToString());
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f9814ff421124feda824b77793cf24f2
timeCreated: 1659705932

@ -1,3 +1,4 @@
using Samples;
using UnityEditor; using UnityEditor;
using UnityEditor.Callbacks; using UnityEditor.Callbacks;
using UnityEngine; using UnityEngine;
@ -8,7 +9,7 @@ public class HelloEditor : GraphEditor<HelloGraph>{
var graph = EditorUtility.InstanceIDToObject(instanceID) as HelloGraph; var graph = EditorUtility.InstanceIDToObject(instanceID) as HelloGraph;
if (graph != null) { if (graph != null) {
var wnd = GetWindow<HelloEditor>(); var wnd = GetWindow<HelloEditor>();
wnd.titleContent = new GUIContent("EasyGraph Editor"); wnd.titleContent = new GUIContent("HelloGraph Editor");
wnd.Show(); wnd.Show();
wnd.SetupNonRuntime(graph); wnd.SetupNonRuntime(graph);
return true; return true;
@ -18,7 +19,7 @@ public class HelloEditor : GraphEditor<HelloGraph>{
[MenuItem("Window/HelloEditor")] [MenuItem("Window/HelloEditor")]
public static void ShowWindow(){ public static void ShowWindow(){
var res = GetWindow<HelloEditor>(); var res = GetWindow<HelloEditor>();
res.titleContent = new GUIContent("EasyGraph Editor"); res.titleContent = new GUIContent("HelloGraph Editor");
res.Show(); res.Show();
} }

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using Samples;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models;
using UnityEngine;
namespace TNode.Samples{
[GraphUsage(typeof(HelloGraph))]
public class HelloBlackboard:BlackboardData{
public string HelloString = "Hello World";
public List<Vector3> V3S;
public List<Vector2> V2S;
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: edaf56bfb57443eb85ecadd142c4ce7d
timeCreated: 1659706002

@ -1,8 +1,11 @@
using UnityEngine;
using System; using System;
using TNodeCore.Runtime.Models; using TNodeCore.Runtime.Models;
[CreateAssetMenu(fileName = "New HelloGraph", menuName = "TNode/HelloGraph")] using UnityEngine;
[Serializable]
public class HelloGraph : GraphData{ namespace Samples{
[CreateAssetMenu(fileName = "New HelloGraph", menuName = "TNode/HelloGraph")]
[Serializable]
public class HelloGraph : GraphData{
}
} }

@ -12,13 +12,103 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2051a0adbd1ba974084a535dd06ab7d7, type: 3} m_Script: {fileID: 11500000, guid: 2051a0adbd1ba974084a535dd06ab7d7, type: 3}
m_Name: New HelloGraph m_Name: New HelloGraph
m_EditorClassIdentifier: m_EditorClassIdentifier:
nodeList: [] nodeList:
nodeLinks: [] - rid: 4804121563801583862
- rid: 4804121563801583898
- rid: 4804121563801583870
- rid: 4804121563801583866
nodeLinks:
- inPort:
portEntryName: A
nodeDataId: 6ceba867-fe0d-40c3-9d30-2d5d12803b52
outPort:
portEntryName: Value
nodeDataId: ac84573e-638d-45fa-b4e2-1a81c31fa9e7
- inPort:
portEntryName: B
nodeDataId: 6ceba867-fe0d-40c3-9d30-2d5d12803b52
outPort:
portEntryName: Value
nodeDataId: b2ab4a52-e65d-4104-8891-dc316af217d9
blackboardData: blackboardData:
rid: -2 rid: 4804121563801583854
sceneReference: sceneReference:
references: references:
version: 2 version: 2
RefIds: RefIds:
- rid: -2 - rid: 4804121563801583854
type: {class: , ns: , asm: } type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
HelloString: Hello World
V3S:
- {x: 0, y: 0, z: 0}
- {x: 0, y: 0, z: 0}
- {x: 0, y: 0, z: 0}
V2S:
- {x: 0, y: 0}
- {x: 0, y: 0}
- {x: 0, y: 0}
- rid: 4804121563801583862
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
x: 256
y: 264
width: 0
height: 0
id: bae506a7-58ec-4b79-9c21-747fa2b6a7ba
nodeName:
entryPoint: 0
isTest: 0
blackDragData: HelloString
isListElement: 0
- rid: 4804121563801583866
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 620
y: 234
width: 0
height: 0
id: 6ceba867-fe0d-40c3-9d30-2d5d12803b52
nodeName: AddNode
entryPoint: 0
isTest: 0
- rid: 4804121563801583870
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
x: 469.00006
y: 336
width: 0
height: 0
id: b2ab4a52-e65d-4104-8891-dc316af217d9
nodeName:
entryPoint: 0
isTest: 0
blackDragData: V2S.0
isListElement: 1
- rid: 4804121563801583898
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
x: 469
y: 213
width: 0
height: 0
id: ac84573e-638d-45fa-b4e2-1a81c31fa9e7
nodeName:
entryPoint: 0
isTest: 0
blackDragData: V3S.0
isListElement: 1

@ -80,6 +80,7 @@ namespace TNodeCore.Editor{
GraphView.IsRuntimeGraph = false; GraphView.IsRuntimeGraph = false;
} }
private void BuildGraphView(){ private void BuildGraphView(){
GraphView = graphEditorData.GetGraphView<T>(); GraphView = graphEditorData.GetGraphView<T>();
GraphView.Owner = this; GraphView.Owner = this;

@ -7,10 +7,7 @@ namespace TNodeCore.Runtime.Models{
/// </summary> /// </summary>
[Serializable] [Serializable]
public class BlackboardData:Model,ICloneable{ public abstract class BlackboardData:Model{
} }
} }

@ -175,7 +175,7 @@ namespace TNodeCore.Runtime.RuntimeCache{
} }
} }
private readonly Dictionary<Tuple<Type,Type>,bool> _possibleImplicitConversions = new (); private readonly Dictionary<Tuple<Type,Type>,bool> _possibleImplicitConversions = new ();
private bool HasImplicitConversion(Type baseType, Type targetType){ public bool HasImplicitConversion(Type baseType, Type targetType){
var tuple = new Tuple<Type, Type>(baseType, targetType); var tuple = new Tuple<Type, Type>(baseType, targetType);
if (_possibleImplicitConversions.ContainsKey(tuple)){ if (_possibleImplicitConversions.ContainsKey(tuple)){
return _possibleImplicitConversions[tuple]; return _possibleImplicitConversions[tuple];
@ -189,6 +189,7 @@ namespace TNodeCore.Runtime.RuntimeCache{
return _possibleImplicitConversions[tuple] = res; return _possibleImplicitConversions[tuple] = res;
} }
private void CachingImplicitConversion(Type baseType, Type targetType){ private void CachingImplicitConversion(Type baseType, Type targetType){
if (HasImplicitConversion(baseType, targetType)) return; if (HasImplicitConversion(baseType, targetType)) return;
@ -201,8 +202,8 @@ namespace TNodeCore.Runtime.RuntimeCache{
CachedPortConverters[baseType].Add(targetType,typeConverter); CachedPortConverters[baseType].Add(targetType,typeConverter);
} }
public object GetConvertedValue(Type from,Type to,object value){
public object GetConvertedValue(Type from,Type to,object value){
if(!CachedPortConverters.ContainsKey(from)){ if(!CachedPortConverters.ContainsKey(from)){
//Find the cached port failed ,check if there is an implicit conversion //Find the cached port failed ,check if there is an implicit conversion
//This inner cache method would only run once,so add a guard to prevent it run again,even though the function itself has a guard statement. //This inner cache method would only run once,so add a guard to prevent it run again,even though the function itself has a guard statement.
@ -226,7 +227,7 @@ namespace TNodeCore.Runtime.RuntimeCache{
public List<Type> GetSupportedTypes(Type type){ public List<Type> GetSupportedTypes(Type type){
if(!CachedPortConverters.ContainsKey(type)){ if(!CachedPortConverters.ContainsKey(type)){
return null; return new List<Type>();
} }
return CachedPortConverters[type].Keys.ToList(); return CachedPortConverters[type].Keys.ToList();
} }

@ -10,7 +10,9 @@ using TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models; using TNodeCore.Runtime.Models;
using Unity.VisualScripting;
using UnityEditor; using UnityEditor;
using UnityEngine;
namespace TNode.TNodeGraphViewImpl.Editor.Cache{ namespace TNode.TNodeGraphViewImpl.Editor.Cache{
/// <summary> /// <summary>
@ -40,7 +42,12 @@ namespace TNode.TNodeGraphViewImpl.Editor.Cache{
get{ return _instance ??= new NodeEditorSingleton(); } get{ return _instance ??= new NodeEditorSingleton(); }
} }
private static readonly string[] ExcludedAssemblies = new string[]{"Microsoft", "UnityEngine","UnityEditor","mscorlib","System"};
private static readonly string[] ExcludedAssemblies = new[]{
"Microsoft", "UnityEngine","UnityEditor","mscorlib",
"System","Mono","PlasticPipe","unityplastic","ExCSS",
"Unity","PlayerBuildProgramLibrary","netstandard","log4net","Newtonsoft","Bee","nunit","PsdPlugin"
};
public static T CreateViewComponentFromBaseType<T>(){ public static T CreateViewComponentFromBaseType<T>(){
var implementedType = NodeEditorSingleton.Instance.FromGenericToSpecific[typeof(T)]; var implementedType = NodeEditorSingleton.Instance.FromGenericToSpecific[typeof(T)];
var instance = (T)Activator.CreateInstance(implementedType); var instance = (T)Activator.CreateInstance(implementedType);
@ -63,10 +70,12 @@ namespace TNode.TNodeGraphViewImpl.Editor.Cache{
private NodeEditorSingleton(){ private NodeEditorSingleton(){
//exclude unity ,system ,and microsoft types //exclude unity ,system ,and microsoft types
var assemblies = AppDomain. var assemblies = AppDomain.CurrentDomain.GetAssemblies();
CurrentDomain.GetAssemblies()
.Where(x=>ExcludedAssemblies.All(y=>!x.GetName().Name.Split(".")[0].Equals(y)));
assemblies = assemblies.Where(x => !ExcludedAssemblies.Contains(x.FullName.Split('.',',',' ')[0])).ToArray();
foreach (var ass in assemblies){
}
foreach(var assembly in assemblies){ foreach(var assembly in assemblies){
foreach(var type in assembly.GetTypes()){ foreach(var type in assembly.GetTypes()){
if(type.IsClass && !type.IsAbstract){ if(type.IsClass && !type.IsAbstract){
@ -91,6 +100,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.Cache{
return instance; return instance;
} }
private void SetGraphUsageAttribute(Type type){ private void SetGraphUsageAttribute(Type type){
foreach (var attribute in type.GetCustomAttributes(typeof(GraphUsageAttribute), true)){ foreach (var attribute in type.GetCustomAttributes(typeof(GraphUsageAttribute), true)){
var parent = type.BaseType; var parent = type.BaseType;
if (typeof(Model).IsAssignableFrom(type.BaseType)){ if (typeof(Model).IsAssignableFrom(type.BaseType)){
@ -205,11 +215,15 @@ namespace TNode.TNodeGraphViewImpl.Editor.Cache{
} }
public static List<string> GetGraphCategories(Type t){ public static List<string> GetGraphCategories(Type t){
if(!NodeEditorSingleton.Instance.GraphDataUsage.ContainsKey(t)){
return new List<string>();
}
var list = NodeEditorSingleton.Instance.GraphDataUsage[t]; var list = NodeEditorSingleton.Instance.GraphDataUsage[t];
//Merge same category //Merge same category
var res = list.Select(x=>x.GetCustomAttribute<GraphUsageAttribute>().Category).Distinct().ToList(); var res = list.Select(x=>x.GetCustomAttribute<GraphUsageAttribute>().Category).Distinct().ToList();
return res; return res;
} }
//TODO Move this method to runtime place
public static BlackboardData GetAppropriateBlackboardData(Type t){ public static BlackboardData GetAppropriateBlackboardData(Type t){
if (NodeEditorSingleton.Instance.GraphBlackboard.ContainsKey(t)){ if (NodeEditorSingleton.Instance.GraphBlackboard.ContainsKey(t)){
return (BlackboardData)Activator.CreateInstance(NodeEditorSingleton.Instance.GraphBlackboard[t]); return (BlackboardData)Activator.CreateInstance(NodeEditorSingleton.Instance.GraphBlackboard[t]);
@ -261,8 +275,10 @@ namespace TNode.TNodeGraphViewImpl.Editor.Cache{
} }
} }
[InitializeOnLoad] [InitializeOnLoad]
public class Launcher{ public class Launcher{
static Launcher(){ static Launcher(){
Debug.Log("NES Launched");
NodeEditorSingleton.Instance.Initialize(); NodeEditorSingleton.Instance.Initialize();
} }
} }

@ -50,24 +50,24 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
blackboardList.Add(foldout); blackboardList.Add(foldout);
Add(blackboardList); Add(blackboardList);
if(field.GetValue(data)==null) continue;
if (field.GetValue(data) is IList list){ if (field.GetValue(data) is IList list){
for (var i = 0; i < list.Count; i++){ for (var i = 0; i < list.Count; i++){
CreateBlackboardDataEntryForListItem(field, serializedObject, isRuntimeGraph, blackboardList, i); CreateBlackboardDataEntryForListItem(field, serializedObject, isRuntimeGraph, blackboardList, i);
} }
} }
if (field.GetValue(data).GetType().IsArray){ if (field.GetValue(data).GetType().IsArray){
var array = (Array)field.GetValue(data); var array = (Array)field.GetValue(data);
if(array==null) continue;
for (var i = 0; i < array.Length; i++){ for (var i = 0; i < array.Length; i++){
CreateBlackboardDataEntryForListItem(field, serializedObject, isRuntimeGraph, blackboardList, i); CreateBlackboardDataEntryForListItem(field, serializedObject, isRuntimeGraph, blackboardList, i);
} }
} }
} }
} }
addItemRequested += (sender) => { addItemRequested = (sender) => {
var res = ScriptableObject.CreateInstance<BlackboardSearchWindowProvider>(); var res = ScriptableObject.CreateInstance<BlackboardSearchWindowProvider>();
Debug.Log(res);
//Get right top corner of the blackboard //Get right top corner of the blackboard
var blackboardPos = GetPosition().position+OwnerWindow.position.position; var blackboardPos = GetPosition().position+OwnerWindow.position.position;
@ -80,14 +80,14 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
SearchWindow.Open(searchWindowContext, res); SearchWindow.Open(searchWindowContext, res);
}; };
} }
private static void CreateBlackboardDataEntryForListItem(FieldInfo field, SerializedObject serializedObject, private static void CreateBlackboardDataEntryForListItem(FieldInfo field, SerializedObject serializedObject,
bool isRuntimeGraph, bool isRuntimeGraph,
BlackboardSection blackboardSection, int index){ BlackboardSection blackboardSection, int index){
var property =serializedObject.FindProperty("data").FindPropertyRelative(field.Name).GetArrayElementAtIndex(index); var property = serializedObject.FindProperty("data");
property = property.FindPropertyRelative(field.Name).GetArrayElementAtIndex(index);
BlackboardDataEntry entry = new BlackboardDataEntry(field.FieldType){ BlackboardDataEntry entry = new BlackboardDataEntry(field.FieldType){
propertyPath = field.Name+"."+index, propertyPath = field.Name+"."+index,
@ -102,6 +102,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
} }
private static void CreateBlackboardDataEntry(FieldInfo field, SerializedObject serializedObject, bool isRuntimeGraph, private static void CreateBlackboardDataEntry(FieldInfo field, SerializedObject serializedObject, bool isRuntimeGraph,
BlackboardSection blackboardSection){ BlackboardSection blackboardSection){
BlackboardDataEntry entry = new BlackboardDataEntry(field.FieldType){ BlackboardDataEntry entry = new BlackboardDataEntry(field.FieldType){

@ -145,6 +145,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
if (Data != null){ if (Data != null){
visualElement.RemoveFromHierarchy(); visualElement.RemoveFromHierarchy();
} }
CreateMenu();
}; };
} }
@ -219,7 +220,6 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
SetDetachedFromPanel(); SetDetachedFromPanel();
} }
private void SetDetachedFromPanel(){ private void SetDetachedFromPanel(){
@ -241,6 +241,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
protected void CreateMenu(){ protected void CreateMenu(){
if (this.Q("TopMenu") != null) return;
var visualElement = new VisualElement{ var visualElement = new VisualElement{
name = "TopMenu" name = "TopMenu"
}; };
@ -278,6 +279,16 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
}); });
visualElement.Add(runButton); visualElement.Add(runButton);
var blackboardButton = new Button{
name = "blackboardButton",
text = "Blackboard"
};
blackboardButton.RegisterCallback<ClickEvent>(evt => {
if(_blackboard==null)
CreateBlackboard();
});
visualElement.Add(blackboardButton);
} }
public void RegisterDragEvent(){ public void RegisterDragEvent(){
@ -399,12 +410,14 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
private void BlackboardUpdate(){ private void UpdateBlackboardData(){
if (_data == null) return;
if (_data.blackboardData == null || _data.blackboardData.GetType()==(typeof(BlackboardData))){ if (_data.blackboardData == null || _data.blackboardData.GetType()==(typeof(BlackboardData))){
_data.blackboardData = NodeEditorExtensions.GetAppropriateBlackboardData(_data.GetType());
_data.blackboardData = NodeEditorExtensions.GetAppropriateBlackboardData(_data.GetType());
Debug.Log(_data.blackboardData);
if (_data.blackboardData == null) return; if (_data.blackboardData == null) return;
} }
_blackboard.SetBlackboardData(GetBlackboardData()); _blackboard.SetBlackboardData(GetBlackboardData());
} }
@ -506,15 +519,45 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
}); });
} }
public override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter){ public override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter){
var supportedTypes = RuntimeCache.Instance.GetSupportedTypes(startPort.portType);
var compatiblePorts = ports.Where(x => startPort != x && var compatiblePorts = ports.Where(x => startPort != x &&
(x.portType == startPort.portType || (x.portType == startPort.portType ||
x.portType.IsAssignableFrom(startPort.portType) x.portType.IsAssignableFrom(startPort.portType)
)).ToList(); )).ToList();
if (supportedTypes != null){ if(startPort.direction==Direction.Input){
compatiblePorts.AddRange(ports.Where(x => supportedTypes.Contains(x.portType)).ToList()); //Search output to find ports with type that have implicit conversion or define converter that convert to type of the startPort
var outputPorts = ports.Where(x => x.direction == Direction.Output).ToList();
foreach (var outputPort in outputPorts){
//Want a port type that can convert to to the type of the startPort
if (HasImplicitConversion(outputPort.portType,startPort.portType)){
compatiblePorts.Add(outputPort);
}
if (RuntimeCache.Instance.GetSupportedTypes(outputPort.portType).Contains(startPort.portType)){
compatiblePorts.Add(outputPort);
}
}
} }
else{
var inputPorts = ports.Where(x => x.direction == Direction.Input).ToList();
foreach (var inputPort in inputPorts){
//check if start port could implicitly convert to input port type
if (HasImplicitConversion(startPort.portType,inputPort.portType)){
compatiblePorts.Add(inputPort);
}
//Check if input port type is supported by output port type
if (RuntimeCache.Instance.GetSupportedTypes(startPort.portType).Contains(inputPort.portType)){
compatiblePorts.Add(inputPort);
}
}
}
return compatiblePorts; return compatiblePorts;
@ -607,6 +650,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
get=>Owner.graphEditorData.autoUpdate; set=>Owner.graphEditorData.autoUpdate = value; get=>Owner.graphEditorData.autoUpdate; set=>Owner.graphEditorData.autoUpdate = value;
} }
public override EventPropagation DeleteSelection(){ public override EventPropagation DeleteSelection(){
Undo.RegisterCompleteObjectUndo(_data,"Delete Selection"); Undo.RegisterCompleteObjectUndo(_data,"Delete Selection");
var res = base.DeleteSelection(); var res = base.DeleteSelection();
@ -616,13 +660,14 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
public void CreateBlackboard(){ public void CreateBlackboard(){
_blackboard = NodeEditorExtensions.CreateBlackboardWithGraphData(typeof(T)); _blackboard = NodeEditorExtensions.CreateBlackboardWithGraphData(typeof(T)) ;
_blackboard.Setup(this,Owner); _blackboard.Setup(this,Owner);
var castedBlackboard = _blackboard as Blackboard; var castedBlackboard = _blackboard as Blackboard;
Add(castedBlackboard); Add(castedBlackboard);
Rect blackboardPos = new Rect(0,0,300,700); Rect blackboardPos = new Rect(0,0,300,700);
castedBlackboard?.SetPosition(blackboardPos); castedBlackboard?.SetPosition(blackboardPos);
OnDataChanged+= (sender, e) => { BlackboardUpdate(); }; UpdateBlackboardData();
OnDataChanged+= (sender, e) => { UpdateBlackboardData(); };
} }
public GraphData GetGraphData(){ public GraphData GetGraphData(){

@ -33,6 +33,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{
label.text = ObjectNames.NicifyVariableName(obj.BlackDragData); label.text = ObjectNames.NicifyVariableName(obj.BlackDragData);
//Get serialized property's icon //Get serialized property's icon
Texture2D icon = null; Texture2D icon = null;
if (serializedProperty == null) return;
if (serializedProperty.boxedValue is Object value){ if (serializedProperty.boxedValue is Object value){
icon = AssetPreview.GetMiniThumbnail(value); icon = AssetPreview.GetMiniThumbnail(value);
} }

@ -31,17 +31,21 @@ namespace TNode.TNodeGraphViewImpl.Editor.Search{
if (list == null) throw new ArgumentNullException(nameof(list)); if (list == null) throw new ArgumentNullException(nameof(list));
//search fields with List type //search fields with List type
Texture2D icon = new Texture2D(2,2); Texture2D icon = new Texture2D(2,2);
foreach (var field in type.GetFields()){ foreach (var field in type.GetFields()){
if (field.FieldType.IsGenericType){ if (field.FieldType.IsGenericType){
var genericType = field.FieldType.GetGenericTypeDefinition(); var genericType = field.FieldType.GetGenericTypeDefinition();
if (genericType == typeof(List<>)){ if (genericType == typeof(List<>)){
var castedList = field.GetValue(blackboardData) as IList;
if (castedList == null){
field.SetValue(blackboardData, Activator.CreateInstance(field.FieldType));
}
list.Add(new SearchTreeEntry(new GUIContent(field.Name,icon)){ list.Add(new SearchTreeEntry(new GUIContent(field.Name,icon)){
level = 1, level = 1,
userData = new InternalSearchTreeUserData(){ userData = new InternalSearchTreeUserData(){
List = field.GetValue(blackboardData) as IList, List = field.GetValue(blackboardData) as IList,
Type = field.FieldType.GetGenericArguments()[0] Type = field.FieldType.GetGenericArguments()[0]
} }
}); });
} }
} }
@ -64,7 +68,9 @@ namespace TNode.TNodeGraphViewImpl.Editor.Search{
if (userData is InternalSearchTreeUserData){ if (userData is InternalSearchTreeUserData){
var list = ((InternalSearchTreeUserData) userData).List; var list = ((InternalSearchTreeUserData) userData).List;
Debug.Log(list); if (list == null){
}
var type = ((InternalSearchTreeUserData) userData).Type; var type = ((InternalSearchTreeUserData) userData).Type;
if (!typeof(Object).IsAssignableFrom(type)){ if (!typeof(Object).IsAssignableFrom(type)){
var newItem = Activator.CreateInstance(type); var newItem = Activator.CreateInstance(type);

Loading…
Cancel
Save