diff --git a/TNode/Attribute/BlackboardSection.cs b/TNode/Attribute/BlackboardSection.cs deleted file mode 100644 index bbefd7a..0000000 --- a/TNode/Attribute/BlackboardSection.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using JetBrains.Annotations; - -namespace TNode.Attribute{ - - /// - /// Use this attribute to declare a blackboard section ,a blackboard section is a group of variables with same types - /// - [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)] - [BaseTypeRequired(typeof(List<>))] - - public class BlackboardSection:System.Attribute{ - - } -} \ No newline at end of file diff --git a/TNode/Attribute/BlackboardSection.cs.meta b/TNode/Attribute/BlackboardSection.cs.meta deleted file mode 100644 index 1794987..0000000 --- a/TNode/Attribute/BlackboardSection.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 773d073006dc4dd488e18b38165efd5a -timeCreated: 1656942977 \ No newline at end of file diff --git a/TNode/Attribute/Ports/InputAttribute.cs b/TNode/Attribute/Ports/InputAttribute.cs index e0d4b96..3755188 100644 --- a/TNode/Attribute/Ports/InputAttribute.cs +++ b/TNode/Attribute/Ports/InputAttribute.cs @@ -5,7 +5,7 @@ namespace TNode.Attribute.Ports{ [MeansImplicitUse] [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] public class InputAttribute : PortAttribute{ - public InputAttribute(string name="", PortNameHandling nameHandling = PortNameHandling.Auto) : base(name, nameHandling){ + public InputAttribute(string name="", PortNameHandling nameHandling = PortNameHandling.Auto,TypeHandling typeHandling=TypeHandling.Declared) : base(name, nameHandling,typeHandling){ } } } \ No newline at end of file diff --git a/TNode/Attribute/Ports/OutputAttribute.cs b/TNode/Attribute/Ports/OutputAttribute.cs index a0c3908..b9c6888 100644 --- a/TNode/Attribute/Ports/OutputAttribute.cs +++ b/TNode/Attribute/Ports/OutputAttribute.cs @@ -1,6 +1,8 @@ namespace TNode.Attribute.Ports{ public class OutputAttribute:PortAttribute{ - public OutputAttribute(string name="", PortNameHandling nameHandling = PortNameHandling.Auto) : base(name, nameHandling){ + + + public OutputAttribute(string name="", PortNameHandling nameHandling = PortNameHandling.Auto,TypeHandling typeHandling = TypeHandling.Declared) : base(name, nameHandling,typeHandling){ } } } \ No newline at end of file diff --git a/TNode/Attribute/Ports/PortAttribute.cs b/TNode/Attribute/Ports/PortAttribute.cs index cc3be06..1ade1cc 100644 --- a/TNode/Attribute/Ports/PortAttribute.cs +++ b/TNode/Attribute/Ports/PortAttribute.cs @@ -9,17 +9,26 @@ namespace TNode.Attribute.Ports{ Manual, Format, MemberType + } + public enum TypeHandling{ + Declared, + Implemented, + Specified } [MeansImplicitUse] [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] public class PortAttribute:System.Attribute{ public readonly string Name; public readonly PortNameHandling NameHandling; - - public PortAttribute(string name,PortNameHandling nameHandling=PortNameHandling.Auto){ + public Type HandledType; + public TypeHandling TypeHandling{ get; set; } + public PortAttribute(string name,PortNameHandling nameHandling=PortNameHandling.Auto,TypeHandling typeHandling=TypeHandling.Declared){ this.Name = name; this.NameHandling = nameHandling; + this.TypeHandling = typeHandling; } + + } } \ No newline at end of file diff --git a/TNode/Editor/Blackboard.meta b/TNode/Editor/Blackboard.meta new file mode 100644 index 0000000..ab8049d --- /dev/null +++ b/TNode/Editor/Blackboard.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bf3b6f6e73b647e2a5421f482a0b0e8f +timeCreated: 1657686050 \ No newline at end of file diff --git a/TNode/Editor/Blackboard/IBlackboardView.cs b/TNode/Editor/Blackboard/IBlackboardView.cs new file mode 100644 index 0000000..eca1cf9 --- /dev/null +++ b/TNode/Editor/Blackboard/IBlackboardView.cs @@ -0,0 +1,19 @@ +using TNode.Editor.NodeGraphView; +using TNode.Models; +using UnityEditor; +using UnityEngine; + +namespace TNode.Editor.Blackboard{ + public interface IBlackboardView{ + public BlackboardData GetBlackboardData(); + public void SetBlackboardData(BlackboardData data); + + public void AddItem(); + + void Setup(IBaseDataGraphView graphView,EditorWindow ownerWindow); + } + public interface IBlackboardView : IBlackboardView where T : BlackboardData{ + + public T Data{ get; set; } + } +} \ No newline at end of file diff --git a/TNode/Editor/Blackboard/IBlackboardView.cs.meta b/TNode/Editor/Blackboard/IBlackboardView.cs.meta new file mode 100644 index 0000000..d57a0dd --- /dev/null +++ b/TNode/Editor/Blackboard/IBlackboardView.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9c618ca8a5b0444284489b8a1942af91 +timeCreated: 1657686059 \ No newline at end of file diff --git a/TNode/Editor/EditorPersistence/GraphEditorData.cs b/TNode/Editor/EditorPersistence/GraphEditorData.cs index 02fc71c..9c64722 100644 --- a/TNode/Editor/EditorPersistence/GraphEditorData.cs +++ b/TNode/Editor/EditorPersistence/GraphEditorData.cs @@ -1,10 +1,7 @@ using System.Collections.Generic; -using TNode.Editor.EditorPersistence; -using TNode.Editor.Model; using UnityEngine; -using UnityEngine.Serialization; -namespace TNode.Editor{ +namespace TNode.Editor.EditorPersistence{ [CreateAssetMenu(fileName = "Graph Editor Data", menuName = "TNode/Graph Editor Data")] public class GraphEditorData:ScriptableObject{ diff --git a/TNode/Editor/EditorPersistence/GraphElementEditorData.cs b/TNode/Editor/EditorPersistence/GraphElementEditorData.cs index f21170d..6c8809a 100644 --- a/TNode/Editor/EditorPersistence/GraphElementEditorData.cs +++ b/TNode/Editor/EditorPersistence/GraphElementEditorData.cs @@ -1,9 +1,7 @@ using System; -using TNode.Models; using UnityEngine; -using UnityEngine.Serialization; -namespace TNode.Editor.Model{ +namespace TNode.Editor.EditorPersistence{ [Serializable] public class GraphElementEditorData{ diff --git a/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs b/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs index e851505..16289d0 100644 --- a/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs +++ b/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs @@ -5,7 +5,11 @@ namespace TNode.Editor.NodeGraphView{ public interface IBaseDataGraphView{ public void AddTNode(NodeData nodeData, Rect rect); public void RemoveTNode(NodeData nodeData); - + + public void CreateBlackboard(); + public GraphData GetGraphData(); public BlackboardData GetBlackboardData(); + + } } \ No newline at end of file diff --git a/TNode/Editor/NodeGraphView/IDataGraphView.cs b/TNode/Editor/NodeGraphView/IDataGraphView.cs index db2d69b..e0ed67b 100644 --- a/TNode/Editor/NodeGraphView/IDataGraphView.cs +++ b/TNode/Editor/NodeGraphView/IDataGraphView.cs @@ -2,6 +2,6 @@ namespace TNode.Editor.NodeGraphView{ public interface IDataGraphView : IBaseDataGraphView where T:GraphData{ - + public T Data{ get; set; } } } \ No newline at end of file diff --git a/TNode/Editor/Serialization.meta b/TNode/Editor/Serialization.meta new file mode 100644 index 0000000..03f9a0e --- /dev/null +++ b/TNode/Editor/Serialization.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4c1e0017367a4d448a68ed34b7540782 +timeCreated: 1657690936 \ No newline at end of file diff --git a/TNode/Editor/Serialization/BlackboardDataWrapper.cs b/TNode/Editor/Serialization/BlackboardDataWrapper.cs new file mode 100644 index 0000000..5d05035 --- /dev/null +++ b/TNode/Editor/Serialization/BlackboardDataWrapper.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using TNode.Models; +using UnityEngine; + +namespace TNode.Editor.Serialization{ + public class BlackboardDataWrapper:DataWrapper{ + + } +} \ No newline at end of file diff --git a/TNode/Editor/Serialization/BlackboardDataWrapper.cs.meta b/TNode/Editor/Serialization/BlackboardDataWrapper.cs.meta new file mode 100644 index 0000000..774afc6 --- /dev/null +++ b/TNode/Editor/Serialization/BlackboardDataWrapper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ac3fada821244e69b6b9a27a7b94eeee +timeCreated: 1657691334 \ No newline at end of file diff --git a/TNode/Editor/Serialization/DataWrapper.cs b/TNode/Editor/Serialization/DataWrapper.cs new file mode 100644 index 0000000..7fed251 --- /dev/null +++ b/TNode/Editor/Serialization/DataWrapper.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using TNode.Models; +using UnityEngine; + +namespace TNode.Editor.Serialization{ + [Serializable] + public class DataWrapper:ScriptableObject where TWrapper:DataWrapper where TData:IModel,new(){ + [SerializeReference] + public TData data; + private static readonly Dictionary Cache = new (); + public static TWrapper Get(TData data){ + if (data.GetType().IsGenericType){ + return CreateInstance(); + } + if(Cache.ContainsKey(data)){ + return Cache[data]; + } + var wrapper = CreateInstance(); + wrapper.data = data; + Cache.Add(data,wrapper); + return wrapper; + } + public event Action> OnValueChanged; + + public void SetValue(string path, object value){ + var fieldInfo = data.GetType().GetField(path); + fieldInfo.SetValue(data,value); + OnValueChanged?.Invoke(this); + } + + public object GetValue(string path){ + var fieldInfo = data.GetType().GetField(path); + return fieldInfo.GetValue(data); + } + public static implicit operator TData(DataWrapper wrapper){ + if (wrapper == null) + return default(TData); + return wrapper.data; + + } + /// + /// Use this to get the wrapped data directly. + /// + /// + /// + public static implicit operator DataWrapper(TData unWrapper){ + if (unWrapper == null) + return null; + return Get(unWrapper); + } + } +} \ No newline at end of file diff --git a/TNode/Editor/Serialization/DataWrapper.cs.meta b/TNode/Editor/Serialization/DataWrapper.cs.meta new file mode 100644 index 0000000..ec3dcc7 --- /dev/null +++ b/TNode/Editor/Serialization/DataWrapper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3b4407f1670d4359b807377900c83583 +timeCreated: 1657693507 \ No newline at end of file diff --git a/TNode/Editor/Serialization/NodeDataWrapper.cs b/TNode/Editor/Serialization/NodeDataWrapper.cs new file mode 100644 index 0000000..cff0ea0 --- /dev/null +++ b/TNode/Editor/Serialization/NodeDataWrapper.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using TNode.Models; +using UnityEngine; +using UnityEngine.Serialization; + + +namespace TNode.Editor.Serialization{ + [Obsolete] + + public class NodeDataWrapper : ScriptableObject where T : NodeData{ + public T Data; + private static readonly Dictionary> Cache = new (); + public event Action> OnValueChanged; + public static NodeDataWrapper Get(T data){ + if(Cache.ContainsKey(data)){ + return Cache[data]; + } + var wrapper = ScriptableObject.CreateInstance>(); + Cache.Add(data,wrapper); + return wrapper; + } + public NodeDataWrapper(T data){ + this.Data = data; + } + + public void SetValue(string path, object value){ + var fieldInfo = Data.GetType().GetField(path); + fieldInfo.SetValue(Data,value); + OnValueChanged?.Invoke(this); + } + + public object GetValue(string path){ + var fieldInfo = Data.GetType().GetField(path); + return fieldInfo.GetValue(Data); + } + public static implicit operator T(NodeDataWrapper wrapper){ + if (wrapper == null) + return null; + return wrapper.Data; + + } + public static implicit operator NodeDataWrapper(T unWrapper){ + if (unWrapper == null) + return null; + return Get(unWrapper); + } + } + public class NodeDataWrapper:DataWrapper{ + + } + /// + /// Scriptable object wrapper enable property drawer for t-node + /// instance create automatically when using get function,generic node data is not support yet because of unity serialization system. + /// TODO : support generic node data + /// + // public class NodeDataWrapper:ScriptableObject{ + // [SerializeReference] + // public NodeData data; + // private static readonly Dictionary Cache = new (); + // public event Action OnValueChanged; + // /// + // /// Create a new wrapper or get a cached wrapper for the given data + // /// + // /// node data,an implemented type is acceptable + // /// + // public static NodeDataWrapper Get(NodeData data){ + // if (data.GetType().IsGenericType){ + // return CreateInstance(); + // } + // if(Cache.ContainsKey(data)){ + // return Cache[data]; + // } + // var wrapper = CreateInstance(); + // wrapper.data = data; + // Cache.Add(data,wrapper); + // return wrapper; + // } + // + // + // public void SetValue(string path, object value){ + // var fieldInfo = data.GetType().GetField(path); + // fieldInfo.SetValue(data,value); + // OnValueChanged?.Invoke(this); + // } + // + // public object GetValue(string path){ + // var fieldInfo = data.GetType().GetField(path); + // return fieldInfo.GetValue(data); + // } + // public static implicit operator NodeData(NodeDataWrapper wrapper){ + // if (wrapper == null) + // return null; + // return wrapper.data; + // + // } + // /// + // /// Use this to get the wrapped data directly. + // /// + // /// + // /// + // public static implicit operator NodeDataWrapper(NodeData unWrapper){ + // if (unWrapper == null) + // return null; + // return Get(unWrapper); + // } + // } + + +} \ No newline at end of file diff --git a/TNode/Tools/NodeDataWrapper.cs.meta b/TNode/Editor/Serialization/NodeDataWrapper.cs.meta similarity index 100% rename from TNode/Tools/NodeDataWrapper.cs.meta rename to TNode/Editor/Serialization/NodeDataWrapper.cs.meta diff --git a/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs b/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs index 1248939..13c2ed3 100644 --- a/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs +++ b/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs @@ -1,6 +1,6 @@ using System.IO; using System.Text.RegularExpressions; -using TNode.Editor.Model; +using TNode.Editor.EditorPersistence; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; diff --git a/TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs b/TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs index 8e4eeae..7529026 100644 --- a/TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs +++ b/TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Text.RegularExpressions; -using Microsoft.CodeAnalysis; +using System.Text.RegularExpressions; using UnityEngine; namespace TNode.Editor.Tools.GraphEditorCreator{ diff --git a/TNode/JsonSerialize.meta b/TNode/JsonSerialize.meta deleted file mode 100644 index 68eeed3..0000000 --- a/TNode/JsonSerialize.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: ec6119d082a947f58ed6402290b65596 -timeCreated: 1656817965 \ No newline at end of file diff --git a/TNode/JsonSerialize/JsonSerializeTool.cs b/TNode/JsonSerialize/JsonSerializeTool.cs deleted file mode 100644 index 58888ba..0000000 --- a/TNode/JsonSerialize/JsonSerializeTool.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; - - -namespace TNode.JsonSerialize{ - public static class JsonSerializeTool{ - class WritablePropertiesOnlyResolver : DefaultContractResolver - { - protected override IList CreateProperties(Type type, MemberSerialization memberSerialization) - { - IList props = base.CreateProperties(type, memberSerialization); - return props.Where(p => p.Writable).ToList(); - } - } - public static JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings(){ - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore, - DateFormatString = "yyyy-MM-dd HH:mm:ss", - Converters = new List { new Vector3Converter() }, - TypeNameHandling = TypeNameHandling.Auto, - ContractResolver = new WritablePropertiesOnlyResolver(), - Formatting = Formatting.Indented - - - }; - - public static JsonSerializerSettings InternalJsonSerializerSettings = new JsonSerializerSettings(){ - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore, - Formatting = Formatting.Indented - }; - } -} \ No newline at end of file diff --git a/TNode/JsonSerialize/JsonSerializeTool.cs.meta b/TNode/JsonSerialize/JsonSerializeTool.cs.meta deleted file mode 100644 index 4480c5b..0000000 --- a/TNode/JsonSerialize/JsonSerializeTool.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 14067671fe28434e9ae2e67a34074c52 -timeCreated: 1656819161 \ No newline at end of file diff --git a/TNode/JsonSerialize/NodeDataConverter.cs b/TNode/JsonSerialize/NodeDataConverter.cs deleted file mode 100644 index a3c5f26..0000000 --- a/TNode/JsonSerialize/NodeDataConverter.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Newtonsoft.Json; -using TNode.Models; -using UnityEngine; - -namespace TNode.JsonSerialize{ - public class NodeDataConverter:JsonConverter{ - public override void WriteJson(JsonWriter writer, NodeData value, JsonSerializer serializer){ - //Write node data with type information - writer.WriteStartObject(); - writer.WritePropertyName("type"); - Debug.Log(value.GetType().ToString()); - writer.WriteValue(value.GetType().Name); - writer.WritePropertyName("data"); - serializer.Serialize(writer, value, value.GetType()); - - - writer.WriteEndObject(); - - - } - - public override NodeData ReadJson(JsonReader reader, Type objectType, NodeData existingValue, bool hasExistingValue, - JsonSerializer serializer){ - //Load type info - reader.Read(); - - if (reader.Value != null){ - var type = reader.Value.ToString(); - if (type.Trim().Length==0){ - Debug.LogError(type); - throw new JsonSerializationException("Type name is empty"); - } - reader.Read(); - //Load data - var data = serializer.Deserialize(reader, Type.GetType(type)); - return (NodeData) data; - } - return null; - } - } -} \ No newline at end of file diff --git a/TNode/JsonSerialize/NodeDataConverter.cs.meta b/TNode/JsonSerialize/NodeDataConverter.cs.meta deleted file mode 100644 index e29d3c5..0000000 --- a/TNode/JsonSerialize/NodeDataConverter.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6f960539f2744729b35ff3011677d8ba -timeCreated: 1656857829 \ No newline at end of file diff --git a/TNode/JsonSerialize/Vector3Converter.cs b/TNode/JsonSerialize/Vector3Converter.cs deleted file mode 100644 index 00d4f93..0000000 --- a/TNode/JsonSerialize/Vector3Converter.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Numerics; -using Newtonsoft.Json; -namespace TNode.JsonSerialize{ - - public class Vector3Converter:JsonConverter{ - public override void WriteJson(JsonWriter writer, Vector3 value, JsonSerializer serializer){ - writer.WriteStartArray(); - writer.WriteValue(value.X); - writer.WriteValue(value.Y); - writer.WriteValue(value.Z); - writer.WriteEndArray(); - } - - public override Vector3 ReadJson(JsonReader reader, Type objectType, Vector3 existingValue, bool hasExistingValue, JsonSerializer serializer){ - if (reader.TokenType == JsonToken.Null){ - return default(Vector3); - } - else{ - var array = serializer.Deserialize(reader); - - if (array != null) return new Vector3(array[0], array[1], array[2]); - } - return default(Vector3); - - } - } -} \ No newline at end of file diff --git a/TNode/JsonSerialize/Vector3Converter.cs.meta b/TNode/JsonSerialize/Vector3Converter.cs.meta deleted file mode 100644 index dbbbc50..0000000 --- a/TNode/JsonSerialize/Vector3Converter.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: fecb77054ad348239341a58c50549879 -timeCreated: 1656817975 \ No newline at end of file diff --git a/TNode/Models/BlackboardData.cs b/TNode/Models/BlackboardData.cs index fc0b66a..14cff62 100644 --- a/TNode/Models/BlackboardData.cs +++ b/TNode/Models/BlackboardData.cs @@ -1,5 +1,7 @@ -namespace TNode.Models{ +using System; +namespace TNode.Models{ + [Serializable] public class BlackboardData:IModel{ } diff --git a/TNode/Models/BlackboardDragNodeData.cs b/TNode/Models/BlackboardDragNodeData.cs index 6b1680b..3fb0891 100644 --- a/TNode/Models/BlackboardDragNodeData.cs +++ b/TNode/Models/BlackboardDragNodeData.cs @@ -4,15 +4,18 @@ using Newtonsoft.Json; using TNode.Attribute; using TNode.Attribute.Ports; using TNode.RuntimeCache; +using UnityEngine; +using UnityEngine.Serialization; namespace TNode.Models{ - public class BlackboardDragNodeData:NodeData{ - private string _blackDragData; - [JsonIgnore] - private BlackboardData _blackboardData; + [Serializable] + public class BlackboardDragNodeData:NodeData{ + public string blackDragData; + [SerializeReference] + public BlackboardData blackboardData; - [Output("",PortNameHandling.MemberType)] - public T Value => _blackboardData.GetValue(_blackDragData); + [Output("",PortNameHandling.MemberType,TypeHandling.Implemented)] + public object Value => blackboardData.GetValue(blackDragData); public BlackboardDragNodeData(){ diff --git a/TNode/Models/GraphData.cs b/TNode/Models/GraphData.cs index 3937714..d5c01e4 100644 --- a/TNode/Models/GraphData.cs +++ b/TNode/Models/GraphData.cs @@ -1,38 +1,45 @@ using System; using System.Collections.Generic; -using UnityEngine; using Newtonsoft.Json; -using TNode.Editor; -using TNode.JsonSerialize; -using UnityEditor.Experimental.GraphView; +using UnityEngine; using UnityEngine.Serialization; namespace TNode.Models{ [Serializable] public class GraphData:ScriptableObject,ISerializationCallbackReceiver{ - [SerializeField] public Dictionary NodeDictionary = new Dictionary(); - public List nodeLinks = new(); - public BlackboardData blackboardData = new(); - [TextArea(1,10)] + + [SerializeReference] + public List nodeList = new List(); + [SerializeField] - //[HideInInspector] - private string jsonObject; - [TextArea(1,10)] - [SerializeField] - private string jsonBlackboard; + protected List nodeLinks; + [SerializeReference] + public BlackboardData blackboardData; + + public List NodeLinks{ + get{ + return nodeLinks ??= new List(); + + } + set => nodeLinks = value; + } + + public void OnBeforeSerialize(){ - jsonObject = JsonConvert.SerializeObject(NodeDictionary,JsonSerializeTool.JsonSerializerSettings); - jsonBlackboard = JsonConvert.SerializeObject(blackboardData,JsonSerializeTool.JsonSerializerSettings); + + + nodeList.Clear(); + foreach(var node in NodeDictionary.Values){ + nodeList.Add(node); + } } public void OnAfterDeserialize(){ - //Deserialize node dictionary - var deserializedData = JsonConvert.DeserializeObject>(jsonObject,JsonSerializeTool.JsonSerializerSettings); - NodeDictionary = deserializedData; - //Deserialize blackboard data - var deserializedBlackboard = JsonConvert.DeserializeObject(jsonBlackboard,JsonSerializeTool.JsonSerializerSettings); - blackboardData = deserializedBlackboard; - + NodeDictionary.Clear(); + foreach(var node in nodeList){ + NodeDictionary.Add(node.id,node); + } } + } } \ No newline at end of file diff --git a/TNode/RuntimeCache/RuntimeCache.cs b/TNode/RuntimeCache/RuntimeCache.cs index 4310a3e..b46593a 100644 --- a/TNode/RuntimeCache/RuntimeCache.cs +++ b/TNode/RuntimeCache/RuntimeCache.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using EasyRandomGenerator.Blackboard; using JetBrains.Annotations; using TNode.Models; using Unity.VisualScripting; @@ -21,6 +22,10 @@ namespace TNode.RuntimeCache{ new (); private static readonly string[] ExcludedAssemblies = new string[]{"Microsoft", "UnityEngine","UnityEditor","mscorlib","System"}; + + public RuntimeCache(){ + RegisterRuntimeBlackboard(typeof(EasyBlackboardData)); + } public void RegisterRuntimeBlackboard(Type type){ if(!CachedDelegatesForGettingValue.ContainsKey(type)){ CachedDelegatesForGettingValue.Add(type, new Dictionary()); diff --git a/TNode/Tools.meta b/TNode/Tools.meta deleted file mode 100644 index 15e65f1..0000000 --- a/TNode/Tools.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 206b9a7ba6b54706b02c6aa2cb9a18b0 -timeCreated: 1656762017 \ No newline at end of file diff --git a/TNode/Tools/NodeDataWrapper.cs b/TNode/Tools/NodeDataWrapper.cs deleted file mode 100644 index 1170590..0000000 --- a/TNode/Tools/NodeDataWrapper.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections.Generic; -using TNode.Models; -using UnityEngine; - -namespace TNode.Editor{ - /// - /// Scriptable object wrapper enable property drawer for t-node - /// - public class NodeDataWrapper : ScriptableObject where T : NodeData{ - public T Data; - private static readonly Dictionary> Cache = new (); - public event Action> OnValueChanged; - public static NodeDataWrapper Get(T data){ - if(Cache.ContainsKey(data)){ - return Cache[data]; - } - var wrapper = ScriptableObject.CreateInstance>(); - Cache.Add(data,wrapper); - return wrapper; - } - public NodeDataWrapper(T data){ - this.Data = data; - } - - public void SetValue(string path, object value){ - var fieldInfo = Data.GetType().GetField(path); - fieldInfo.SetValue(Data,value); - OnValueChanged?.Invoke(this); - } - - public object GetValue(string path){ - var fieldInfo = Data.GetType().GetField(path); - return fieldInfo.GetValue(Data); - } - public static implicit operator T(NodeDataWrapper wrapper){ - if (wrapper == null) - return null; - return wrapper.Data; - - } - public static implicit operator NodeDataWrapper(T unWrapper){ - if (unWrapper == null) - return null; - return Get(unWrapper); - } - } - - public class NodeDataWrapper:ScriptableObject{ - [SerializeReference] - public NodeData Data; - private static readonly Dictionary Cache = new (); - public event Action OnValueChanged; - public static NodeDataWrapper Get(NodeData data){ - if (data.GetType().IsGenericType){ - return ScriptableObject.CreateInstance(); - } - if(Cache.ContainsKey(data)){ - return Cache[data]; - } - var wrapper = ScriptableObject.CreateInstance(); - wrapper.Data = data; - Cache.Add(data,wrapper); - return wrapper; - } - - - public void SetValue(string path, object value){ - var fieldInfo = Data.GetType().GetField(path); - fieldInfo.SetValue(Data,value); - OnValueChanged?.Invoke(this); - } - - public object GetValue(string path){ - var fieldInfo = Data.GetType().GetField(path); - return fieldInfo.GetValue(Data); - } - public static implicit operator NodeData(NodeDataWrapper wrapper){ - if (wrapper == null) - return null; - return wrapper.Data; - - } - public static implicit operator NodeDataWrapper(NodeData unWrapper){ - if (unWrapper == null) - return null; - return Get(unWrapper); - } - } -} \ No newline at end of file diff --git a/TNode/Editor/Cache.meta b/TNodeGraphViewImpl/Editor/Cache.meta similarity index 100% rename from TNode/Editor/Cache.meta rename to TNodeGraphViewImpl/Editor/Cache.meta diff --git a/TNode/Editor/Cache/NodeEditorExtensions.cs b/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs similarity index 94% rename from TNode/Editor/Cache/NodeEditorExtensions.cs rename to TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs index 4f2de04..f8fe8b6 100644 --- a/TNode/Editor/Cache/NodeEditorExtensions.cs +++ b/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs @@ -3,16 +3,16 @@ using System.Collections.Generic; using System.Linq; using TNode.Attribute; using TNode.Editor; -using TNode.Editor.Inspector; +using TNode.Editor.Blackboard; using TNode.Editor.NodeViews; using TNode.Models; using TNodeGraphViewImpl.Editor.GraphBlackboard; using TNodeGraphViewImpl.Editor.NodeGraphView; +using TNodeGraphViewImpl.Editor.NodeViews; using UnityEditor.Experimental.GraphView; using UnityEngine; -using UnityEngine.TestTools.Utils; -namespace TNode.Cache{ +namespace TNodeGraphViewImpl.Editor.Cache{ /// /// Internal singleton class for caching TNode reflection Data. /// @@ -153,14 +153,14 @@ namespace TNode.Cache{ return null; } - public static Blackboard CreateBlackboardDataFromBlackboardDataType(Type t){ + public static IBlackboardView CreateBlackboardDataFromBlackboardDataType(Type t){ var type = typeof(GraphBlackboardView<>).MakeGenericType(t); - var res = CreateViewComponentFromBaseType(type) as Blackboard; + var res = CreateViewComponentFromBaseType(type) as IBlackboardView; return res ?? new DefaultGraphBlackboardView(); } - public static Blackboard CreateBlackboardWithGraphData(GraphData graphData){ + public static IBlackboardView CreateBlackboardWithGraphData(GraphData graphData){ var graphType = graphData.GetType(); if (NodeEditorSingleton.Instance.GraphBlackboard.ContainsKey(graphType)){ var type = NodeEditorSingleton.Instance.GraphBlackboard[graphType]; @@ -169,7 +169,7 @@ namespace TNode.Cache{ } return null; } - public static Blackboard CreateBlackboardWithGraphData(Type graphType){ + public static IBlackboardView CreateBlackboardWithGraphData(Type graphType){ if (NodeEditorSingleton.Instance.GraphBlackboard.ContainsKey(graphType)){ var type = NodeEditorSingleton.Instance.GraphBlackboard[graphType]; return CreateBlackboardDataFromBlackboardDataType(type); @@ -201,7 +201,6 @@ namespace TNode.Cache{ //Check the generic type of BaseNodeView by t if (t.IsGenericType){ - Debug.Log($"A generic type {t} is detected"); //AKA if BlackboardDragNodeData is pulled //Get BlackboardDragNodeData as generic type @@ -210,14 +209,12 @@ namespace TNode.Cache{ //What you want is a BaseNodeView> 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 if (NodeEditorSingleton.Instance.FromGenericToSpecific.ContainsKey(genericViewType)){ var implementedType = NodeEditorSingleton.Instance.FromGenericToSpecific[genericViewType]; //The implementedType is still a generic type ,so we make it a specific type by using MakeGenericType - Debug.Log($"{implementedType}"); //Get argument type of t var argumentType = t.GetGenericArguments()[0]; var instance = Activator.CreateInstance(implementedType.MakeGenericType(argumentType)); diff --git a/TNode/Editor/Cache/NodeEditorExtensions.cs.meta b/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs.meta similarity index 100% rename from TNode/Editor/Cache/NodeEditorExtensions.cs.meta rename to TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs.meta diff --git a/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs index 2ed561f..69ffebc 100644 --- a/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs +++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs @@ -1,17 +1,62 @@ -using TNode.Attribute; +using System.Collections; +using System.Reflection; +using TNode.Attribute; +using TNode.Editor.NodeGraphView; +using TNode.Editor.Search; +using TNode.Editor.Serialization; using TNode.Models; +using UnityEditor; +using UnityEditor.Experimental.GraphView; +using UnityEditor.UIElements; +using UnityEngine; +using UnityEngine.UIElements; namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ [ViewComponent] public class DefaultGraphBlackboardView:GraphBlackboardView{ - public DefaultGraphBlackboardView(){ - + public DefaultGraphBlackboardView():base(){ + //the label and the field gap smaller + styleSheets.Add( Resources.Load("GraphViewPropertyField")); + } - public void ConstructView(){ - - } - public void AddParameter(){ - + protected override void UpdateBlackboard(BlackboardData data){ + var serializedObject = new SerializedObject((BlackboardDataWrapper)data); + foreach (var field in data.GetType() + .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)){ + //if the field is MonoBehaviour,add a property field for blackboard + //skip if the field is a list or Ilist + if (!typeof(IList).IsAssignableFrom(field.FieldType)){ + VisualElement visualElement = new VisualElement(); + var propertyField = new BlackboardPropertyField(new BlackboardProperty.BlackboardProperty(field.Name,field.FieldType)); + var foldoutData = new Foldout{ + text = field.Name + }; + var drawer = new PropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),field.Name); + drawer.Bind(serializedObject); + foldoutData.Add(drawer); + visualElement.Add(propertyField); + visualElement.Add(foldoutData); + this.Add(visualElement); + + } + else{ + var blackboardList = new BlackboardSection{ + title = field.Name + }; + this.Add(blackboardList); + } + } + addItemRequested = (sender) => { + var res = ScriptableObject.CreateInstance(); + + //Get right top corner of the blackboard + var blackboardPos = GetPosition().position+OwnerWindow.position.position; + var searchWindowContext = new SearchWindowContext(blackboardPos,200,200); + //Call search window + res.Setup(Owner.GetGraphData().GetType(),Owner,OwnerWindow); + SearchWindow.Open(searchWindowContext, res); + }; } + } } \ No newline at end of file diff --git a/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs index 05fe3f5..8c2644d 100644 --- a/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs +++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs @@ -1,15 +1,52 @@ -using TNode.Models; +using TNode.Editor.Blackboard; +using TNode.Editor.NodeGraphView; +using TNode.Editor.Search; +using TNode.Models; +using UnityEditor; using UnityEditor.Experimental.GraphView; +using UnityEngine; namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ /// /// Implement this class to create graph black board for specified graph /// - public class GraphBlackboardView:Blackboard where T:BlackboardData{ - public T BlackboardData; + public class GraphBlackboardView:Blackboard,IBlackboardView where T:BlackboardData{ + protected IBaseDataGraphView Owner; + protected EditorWindow OwnerWindow; + private T _data; - public GraphBlackboardView() : base(){ + public void Setup(IBaseDataGraphView graphView,EditorWindow ownerWindow){ + Owner = graphView; + OwnerWindow = ownerWindow; + } + + + + public new void SetPosition(Rect rect){ } + + protected virtual void UpdateBlackboard(BlackboardData data){ + + } + public T Data{ + get => (T) _data; + + set{ + _data = value; + UpdateBlackboard(value); + } + } + public BlackboardData GetBlackboardData(){ + return _data; + } + + public void SetBlackboardData(BlackboardData data){ + Data = (T) data; + } + + public void AddItem(){ + + } } } \ No newline at end of file diff --git a/TNode/Editor/GraphEditor.cs b/TNodeGraphViewImpl/Editor/GraphEditor.cs similarity index 97% rename from TNode/Editor/GraphEditor.cs rename to TNodeGraphViewImpl/Editor/GraphEditor.cs index 93a272e..ade213b 100644 --- a/TNode/Editor/GraphEditor.cs +++ b/TNodeGraphViewImpl/Editor/GraphEditor.cs @@ -1,8 +1,8 @@ using Codice.CM.Common; -using TNode.Cache; +using TNode.Editor.EditorPersistence; using TNode.Editor.Inspector; -using TNode.Editor.Model; using TNode.Models; +using TNodeGraphViewImpl.Editor.Cache; using TNodeGraphViewImpl.Editor.NodeGraphView; using UnityEditor; using UnityEditor.Experimental.GraphView; diff --git a/TNode/Editor/GraphEditor.cs.meta b/TNodeGraphViewImpl/Editor/GraphEditor.cs.meta similarity index 100% rename from TNode/Editor/GraphEditor.cs.meta rename to TNodeGraphViewImpl/Editor/GraphEditor.cs.meta diff --git a/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs b/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs index 0367625..96c833e 100644 --- a/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs +++ b/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs @@ -5,6 +5,7 @@ using TNode.Attribute; using TNode.Editor.NodeViews; using TNode.Models; using TNodeGraphViewImpl.Editor.NodeGraphView; +using TNodeGraphViewImpl.Editor.NodeViews; using Unity.VisualScripting; using UnityEditor; using UnityEditor.Experimental.GraphView; diff --git a/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs b/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs index de375a1..e016bfe 100644 --- a/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs +++ b/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs @@ -1,5 +1,6 @@ using System.Reflection; using TNode.Attribute; +using TNode.Editor.Serialization; using TNode.Models; using UnityEditor; using UnityEditor.UIElements; @@ -37,7 +38,7 @@ namespace TNode.Editor.Inspector{ private void RefreshPropertyDrawer(){ //Check if the data's type is a generic type of BlackboardDragNodeData<> - if (_data.GetType().IsSubclassOf(typeof(BlackboardDragNodeData<>))){ + if (_data.GetType().IsSubclassOf(typeof(BlackboardDragNodeData))){ return; } var serializedObject = new SerializedObject((NodeDataWrapper)_data); @@ -47,11 +48,11 @@ namespace TNode.Editor.Inspector{ var showInNodeViewAttribute = field.GetCustomAttribute() != null; if (!showInNodeViewAttribute) continue; - var drawer = new PropertyField(serializedObject.FindProperty("Data").FindPropertyRelative(field.Name),field.Name); - Debug.Log(serializedObject.FindProperty("Data")); + var drawer = new PropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),field.Name); drawer.Bind(serializedObject); Add(drawer); } } + } } \ No newline at end of file diff --git a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index bcc280c..ae5d75a 100644 --- a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs +++ b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -3,17 +3,19 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; -using TNode.Cache; using TNode.Editor; +using TNode.Editor.Blackboard; +using TNode.Editor.EditorPersistence; 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 TNodeGraphViewImpl.Editor.Cache; using TNodeGraphViewImpl.Editor.GraphBlackboard; using TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty; +using TNodeGraphViewImpl.Editor.NodeViews; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; @@ -21,7 +23,7 @@ using UnityEngine.UIElements; using Edge = UnityEditor.Experimental.GraphView.Edge; namespace TNodeGraphViewImpl.Editor.NodeGraphView{ - public abstract class BaseDataGraphView:GraphView,IBaseDataGraphView where T:GraphData{ + public abstract class BaseDataGraphView:GraphView,IDataGraphView where T:GraphData{ #region variables and properties private T _data; private bool _isInspectorOn; @@ -29,7 +31,7 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ private NodeInspector _nodeInspector; public GraphEditor Owner; private Dictionary _nodeDict = new(); - private Blackboard _blackboard; + private IBlackboardView _blackboard; public T Data{ get{ return _data; } set{ @@ -103,11 +105,10 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ foreach (var selectable in blackboardFields){ if(selectable is { } field) { //Make a constructor of BlackboardDragNodeData by reflection - var specifiedType = - typeof(BlackboardDragNodeData<>).MakeGenericType(field.BlackboardProperty.PropertyType); - //Create a new instance of specified type - var dragNodeData = NodeCreator.InstantiateNodeData(specifiedType); - this.AddTNode(dragNodeData,new Rect(evt.mousePosition,new Vector2(200,200))); + var dragNodeData = NodeCreator.InstantiateNodeData(); + dragNodeData.blackboardData = _data.blackboardData; + dragNodeData.blackDragData = field.BlackboardProperty.PropertyName; + AddTNode(dragNodeData,new Rect(evt.mousePosition,new Vector2(200,200))); } } @@ -155,7 +156,7 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ AddTNode(dataNode,nodePos); } - foreach (var edge in _data.nodeLinks){ + foreach (var edge in _data.NodeLinks){ var inputNode = _data.NodeDictionary[edge.inPort.nodeDataId]; var outputNode = _data.NodeDictionary[edge.outPort.nodeDataId]; var inputNodeView = _nodeDict[inputNode.id]; @@ -191,47 +192,15 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ miniMap.SetPosition(rect); } - public virtual void CreateBlackboard(){ - - _blackboard = NodeEditorExtensions.CreateBlackboardWithGraphData(typeof(T)); - - _blackboard.SetPosition(new Rect(0,0,200,600)); - Add(_blackboard); - - OnDataChanged+= (sender, e) => { BlackboardUpdate(); }; - - } private void BlackboardUpdate(){ - if (_data.blackboardData == null || _data.blackboardData.GetType() == typeof(BlackboardData)){ + if (_data.blackboardData == null || _data.blackboardData.GetType()==(typeof(BlackboardData))){ _data.blackboardData = NodeEditorExtensions.GetAppropriateBlackboardData(_data.GetType()); if (_data.blackboardData == null) return; - } - - //Iterate field of the blackboard and add a button for each field - foreach (var field in _data.blackboardData.GetType() - .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)){ - //if the field is MonoBehaviour,add a property field for blackboard - //skip if the field is a list or Ilist - if (!typeof(IList).IsAssignableFrom(field.FieldType)){ - var propertyField = new BlackboardPropertyField(new BlackboardProperty(field.Name,field.FieldType)); - _blackboard.Add(propertyField); - } - - } - _blackboard.addItemRequested = (sender) => { - var res = ScriptableObject.CreateInstance(); - - //Get right top corner of the blackboard - var blackboardPos = _blackboard.GetPosition().position; - var searchWindowContext = new SearchWindowContext(blackboardPos,200,200); - //Call search window - res.Setup(typeof(T),this,Owner); - - SearchWindow.Open(searchWindowContext, res); - }; + } + _blackboard.SetBlackboardData(_data.blackboardData); } public virtual void DestroyInspector(){ @@ -304,17 +273,23 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ } - _data.nodeLinks = links; + _data.NodeLinks = links; } private void SaveGraphData(){ _data.NodeDictionary.Clear(); - _data.nodeLinks.Clear(); + _data.NodeLinks.Clear(); SaveNode(); SaveEdge(); + SaveBlackboard(); EditorUtility.SetDirty(_data); } - + private void SaveBlackboard(){ + if (_data.blackboardData == null){ + _data.blackboardData = NodeEditorExtensions.GetAppropriateBlackboardData(_data.GetType()); + } + } + public override List GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter){ return ports.Where(x => x.portType == startPort.portType).ToList(); @@ -330,10 +305,7 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ OnGraphViewDestroy(); } - public bool IsDroppable(){ - return true; - } - + #region implement interfaces public void AddTNode(NodeData nodeData, Rect rect){ if (NodeEditorExtensions.CreateNodeViewFromNodeType(nodeData.GetType()) is Node nodeView){ nodeView.SetPosition(rect); @@ -381,9 +353,30 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ Owner.graphEditorData.graphElementsData.RemoveAll(x => x.guid == nodeData.id); } + public void CreateBlackboard(){ + _blackboard = NodeEditorExtensions.CreateBlackboardWithGraphData(typeof(T)); + _blackboard.Setup(this,Owner); + + var castedBlackboard = _blackboard as Blackboard; + + Add(castedBlackboard); + + Rect blackboardPos = new Rect(0,0,300,700); + castedBlackboard?.SetPosition(blackboardPos); + + + OnDataChanged+= (sender, e) => { BlackboardUpdate(); }; + } + + public GraphData GetGraphData(){ + return _data; + } + + public BlackboardData GetBlackboardData(){ return this._data.blackboardData; } + #endregion } diff --git a/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs b/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs index caec25e..285ce31 100644 --- a/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs +++ b/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs @@ -1,5 +1,6 @@ using TNode.Editor.NodeViews; using TNode.Models; +using TNodeGraphViewImpl.Editor.NodeViews; namespace TNode.Editor{ diff --git a/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs b/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs index dbcd21c..ad80fae 100644 --- a/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs +++ b/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs @@ -1,13 +1,12 @@ using TNode.Attribute; using TNode.Models; +using TNodeGraphViewImpl.Editor.NodeViews; namespace TNode.Editor.NodeViews{ [ViewComponent] - public class DragBaseNodeView:BaseNodeView>{ + public class DragBaseNodeView:BaseNodeView{ public DragBaseNodeView() : base(){ - //Make capsule like style - - this.titleContainer.visible = false; + this.titleContainer.visible = false; this.titleContainer.RemoveFromHierarchy(); } } diff --git a/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs b/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs index 5cdc716..cdbf1ba 100644 --- a/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs +++ b/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs @@ -1,15 +1,15 @@ using System; using System.Linq; using System.Reflection; -using TNode.Attribute; using TNode.Attribute.Ports; using TNode.Editor.Inspector; +using TNode.Editor.Serialization; using TNode.Models; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; -namespace TNode.Editor.NodeViews{ +namespace TNodeGraphViewImpl.Editor.NodeViews{ public abstract class BaseNodeView : Node,INodeView where T:NodeData,new(){ protected T _data; @@ -28,10 +28,9 @@ namespace TNode.Editor.NodeViews{ } } - private void OnDataValueChanged(NodeDataWrapper obj){ + private void OnDataValueChanged(DataWrapper obj){ Refresh(); } - public sealed override string title{ get => base.title; set => base.title = value; @@ -77,6 +76,18 @@ namespace TNode.Editor.NodeViews{ throw new ArgumentOutOfRangeException(); } } + protected virtual Type BuildPortType(PortAttribute portAttribute,PropertyInfo propertyInfo){ + switch (portAttribute.TypeHandling){ + case TypeHandling.Declared : + return propertyInfo.PropertyType; + case TypeHandling.Implemented: + return propertyInfo.GetValue(_data)?.GetType(); + case TypeHandling.Specified: + return portAttribute.HandledType??typeof(object); + default: + throw new ArgumentOutOfRangeException(); + } + } /// /// of course you can override this method to build your own port builder /// @@ -85,7 +96,7 @@ namespace TNode.Editor.NodeViews{ foreach (var propertyInfo in propertyInfos){ if (propertyInfo.GetCustomAttributes(typeof(OutputAttribute),true).FirstOrDefault() is OutputAttribute attribute){ - Port port = InstantiatePort(Orientation.Horizontal, Direction.Output,Port.Capacity.Multi,propertyInfo.PropertyType); + Port port = InstantiatePort(Orientation.Horizontal, Direction.Output,Port.Capacity.Multi,BuildPortType(attribute,propertyInfo)); this.outputContainer.Add(port); var portName = BuildPortName(attribute,propertyInfo); port.portName = portName; @@ -94,7 +105,7 @@ namespace TNode.Editor.NodeViews{ } foreach (var propertyInfo in propertyInfos){ if(propertyInfo.GetCustomAttributes(typeof(InputAttribute),true).FirstOrDefault() is InputAttribute attribute){ - Port port = InstantiatePort(Orientation.Horizontal, Direction.Input,Port.Capacity.Single,propertyInfo.PropertyType); + Port port = InstantiatePort(Orientation.Horizontal, Direction.Input,Port.Capacity.Single,BuildPortType(attribute,propertyInfo)); this.inputContainer.Add(port); var portName = BuildPortName(attribute,propertyInfo); port.portName = portName; diff --git a/TNodeGraphViewImpl/Editor/Resources.meta b/TNodeGraphViewImpl/Editor/Resources.meta new file mode 100644 index 0000000..f5dfec6 --- /dev/null +++ b/TNodeGraphViewImpl/Editor/Resources.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7d628735dd6d477c88ed608b684c50b4 +timeCreated: 1657702172 \ No newline at end of file diff --git a/TNodeGraphViewImpl/Editor/Resources/GraphViewPropertyField.uss b/TNodeGraphViewImpl/Editor/Resources/GraphViewPropertyField.uss new file mode 100644 index 0000000..69a2c57 --- /dev/null +++ b/TNodeGraphViewImpl/Editor/Resources/GraphViewPropertyField.uss @@ -0,0 +1,5 @@ +.unity-property-field__label { + width: 75px; + min-width: 100px; + max-width: 150px; +} \ No newline at end of file diff --git a/TNodeGraphViewImpl/Editor/Resources/GraphViewPropertyField.uss.meta b/TNodeGraphViewImpl/Editor/Resources/GraphViewPropertyField.uss.meta new file mode 100644 index 0000000..74ae713 --- /dev/null +++ b/TNodeGraphViewImpl/Editor/Resources/GraphViewPropertyField.uss.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2b84790a3a0445f894b9c496ad1e716b +timeCreated: 1657702197 \ No newline at end of file diff --git a/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs b/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs index 058d07b..5ef4ced 100644 --- a/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs +++ b/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using TNode.Cache; using TNode.Editor.NodeGraphView; using TNode.Editor.Tools.NodeCreator; using TNode.Models; +using TNodeGraphViewImpl.Editor.Cache; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine;