Merge pull request #40 from taoria/working-in-process

refactor:add comment and refactor some namespace
main
taoria 3 years ago committed by GitHub
commit bd65e2d138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      TNode/TNodeCore/Editor/Blackboard/IBlackboardView.cs
  2. 65
      TNode/TNodeCore/Editor/DeveloperHelper/CleanMissingTypeHelper.cs
  3. 33
      TNode/TNodeCore/Editor/EditorPersistence/GraphEditorData.cs
  4. 11
      TNode/TNodeCore/Editor/EditorPersistence/GraphElementEditorData.cs
  5. 3
      TNode/TNodeCore/Editor/EditorPersistence/GraphElementEditorData.cs.meta
  6. 9
      TNode/TNodeCore/Editor/EditorPersistence/IGraphViewPersistence.cs
  7. 3
      TNode/TNodeCore/Editor/EditorPersistence/IGraphViewPersistence.cs.meta
  8. 1
      TNode/TNodeCore/Editor/GraphEditor.cs
  9. 3
      TNode/TNodeCore/Editor/Inspector.meta
  10. 8
      TNode/TNodeCore/Editor/Inspector/INodeDataBinding.cs
  11. 3
      TNode/TNodeCore/Editor/Inspector/INodeDataBinding.cs.meta
  12. 8
      TNode/TNodeCore/Editor/Inspector/INodeDataBindingBase.cs
  13. 3
      TNode/TNodeCore/Editor/Inspector/INodeDataBindingBase.cs.meta
  14. 7
      TNode/TNodeCore/Editor/Models/EditorModel.cs
  15. 13
      TNode/TNodeCore/Editor/Models/GraphViewData.cs
  16. 25
      TNode/TNodeCore/Editor/Models/GraphViewModel.cs
  17. 0
      TNode/TNodeCore/Editor/Models/GraphViewModel.cs.meta
  18. 15
      TNode/TNodeCore/Editor/Models/PlacematData.cs
  19. 26
      TNode/TNodeCore/Editor/Models/PlacematModel.cs
  20. 0
      TNode/TNodeCore/Editor/Models/PlacematModel.cs.meta
  21. 53
      TNode/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs
  22. 17
      TNode/TNodeCore/Editor/NodeGraphView/IDataGraphView.cs
  23. 60
      TNode/TNodeCore/Editor/PropertyDrawer/PropertyDrawer.cs
  24. 3
      TNode/TNodeCore/Editor/PropertyDrawer/PropertyDrawer.cs.meta
  25. 2
      TNode/TNodeCore/Editor/Serialization/BlackboardDataWrapper.cs
  26. 106
      TNode/TNodeCore/Editor/Serialization/NodeDataWrapper.cs
  27. 1
      TNode/TNodeCore/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs
  28. 12
      TNode/TNodeCore/Runtime/Models/GraphData.cs
  29. 3
      TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs
  30. 6
      TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs
  31. 2
      TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs
  32. 2
      TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs
  33. 6
      TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs
  34. 43
      TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
  35. 13
      TNode/TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs
  36. 2
      TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs
  37. 2
      TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs
  38. 21
      TNode/TNodeGraphViewImpl/Editor/Placemats/PlacematView.cs
  39. 2
      TNode/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs
  40. 1
      TNode/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs

@ -2,16 +2,40 @@
using TNodeCore.Runtime.Models;
using UnityEditor;
namespace TNodeCore.Editor.Blackboard{
namespace TNode.TNodeCore.Editor.Blackboard{
/// <summary>
/// View of the blackboard,different in each implementation,but the same in the interface.
/// </summary>
public interface IBlackboardView{
/// <summary>
/// Get the blackboard data model watched by this view.
/// </summary>
/// <returns></returns>
BlackboardData GetBlackboardData();
/// <summary>
/// Set the blackboard data model watched by this view.
/// </summary>
/// <param name="data"></param>
void SetBlackboardData(BlackboardData data);
void AddItem();
/// <summary>
/// Add a new entry for the blackboard.currently no such use.
/// </summary>
void AddItem();
/// <summary>
/// Setup the blackboard view from the given Editor and graphview
/// </summary>
/// <param name="graphView"></param>
/// <param name="ownerWindow"></param>
void Setup(IBaseDataGraphView graphView,EditorWindow ownerWindow);
/// <summary>
/// Notify update the blackboard view's content by the watched blackboard data.
/// </summary>
void NotifyUpdate();
}
//A generic implementation of the blackboard view.
public interface IBlackboardView<T> : IBlackboardView where T : BlackboardData{
T Data{ get; set; }

@ -3,8 +3,12 @@ using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace TNodeCore.Editor.DeveloperHelper{
public class CleanMissingTypeHelper
namespace TNode.TNodeCore.Editor.DeveloperHelper{
/// <summary>
/// Helper options works on 2021.3 on newer unity versions only.call this in the early version may not work
/// </summary>
public static class CleanMissingTypeHelper
{
[MenuItem("TNode/CleanMissingType/CleanScriptObjects")]
public static void CleanMissingTypesOnScriptableObjects()
@ -18,15 +22,17 @@ namespace TNodeCore.Editor.DeveloperHelper{
Object obj = AssetDatabase.LoadMainAssetAtPath(path);
if (obj != null)
{
// if (SerializationUtility.ClearAllManagedReferencesWithMissingTypes(obj))
// {
//
// report.Append("Cleared missing types from ").Append(path).AppendLine();
// }
// else
// {
// report.Append("No missing types to clear on ").Append(path).AppendLine();
// }
#if UNITY_2021_3_OR_NEWER
if (SerializationUtility.ClearAllManagedReferencesWithMissingTypes(obj))
{
report.Append("Cleared missing types from ").Append(path).AppendLine();
}
else
{
report.Append("No missing types to clear on ").Append(path).AppendLine();
}
#endif
}
}
Debug.Log(report.ToString());
@ -39,25 +45,28 @@ namespace TNodeCore.Editor.DeveloperHelper{
SceneManager.GetActiveScene().GetRootGameObjects();
foreach (GameObject root in SceneManager.GetActiveScene().GetRootGameObjects()){
foreach (var o in root.transform){
// if (SerializationUtility.ClearAllManagedReferencesWithMissingTypes(o as Object))
// {
// report.Append("Cleared missing types from ").Append(root.name).AppendLine();
// }
// else
// {
// report.Append("No missing types to clear on ").Append(root.name).AppendLine();
// }
#if UNITY_2021_3_OR_NEWER
if (SerializationUtility.ClearAllManagedReferencesWithMissingTypes(o as Object))
{
report.Append("Cleared missing types from ").Append(root.name).AppendLine();
}
else
{
report.Append("No missing types to clear on ").Append(root.name).AppendLine();
}
#endif
}
// if (SerializationUtility.ClearAllManagedReferencesWithMissingTypes(root))
// {
// report.Append("Cleared missing types from ").Append(root.name).AppendLine();
// }
// else
// {
// report.Append("No missing types to clear on ").Append(root.name).AppendLine();
// }
#if UNITY_2021_3_OR_NEWER
if (SerializationUtility.ClearAllManagedReferencesWithMissingTypes(root))
{
report.Append("Cleared missing types from ").Append(root.name).AppendLine();
}
else
{
report.Append("No missing types to clear on ").Append(root.name).AppendLine();
}
#endif
}
Debug.Log(report.ToString());

@ -1,22 +1,39 @@
using System;
using System.Collections.Generic;
using TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Runtime.Models;
using UnityEngine;
using UnityEngine.Serialization;
namespace TNodeCore.Editor.EditorPersistence{
namespace TNode.TNodeCore.Editor.EditorPersistence{
/// <summary>
/// Graph Editor Data hold the config of a type of graph.
/// it's used by a graph editor to determine which implementation to use and some other config may be stored in here some days later.
/// </summary>
[CreateAssetMenu(fileName = "Graph Editor Data", menuName = "TNode/Graph Editor Data")]
public class GraphEditorData:ScriptableObject{
[HideInInspector]
public List<GraphElementEditorData> graphElementsData;
/// <summary>
/// The implementation of a graph view.experimental graphview or GTF.
/// </summary>
public GraphImplType graphImplType = GraphImplType.GraphViewImpl;
/// <summary>
/// Cached global static function to create a graph view by the given type of the graph data.it's injected by the implementation side.
/// </summary>
public static Func<Type,IBaseDataGraphView> GraphViewImplCreator;
public static Func<Type,IBaseDataGraphView> GtfImplCreator;
[FormerlySerializedAs("testMode")] public bool autoUpdate;
/// <summary>
/// set this to true to maintain the graph in auto update mode,an auto update mode only applies certain types of graph.
/// TODO: move to graph data side later.
/// </summary>
[FormerlySerializedAs("testMode")] public bool autoUpdate;
/// <summary>
/// Get the implementation of a graphview by the given type of the graph.
/// </summary>
/// <typeparam name="T">The type of the graph you want to create a view to inspect it</typeparam>
/// <returns>the corresponding graph view for the given graph data</returns>
/// <exception cref="NotImplementedException"></exception>
public IDataGraphView<T> GetGraphView<T> () where T:GraphData{
switch (graphImplType){
case GraphImplType.GraphViewImpl:{
@ -31,7 +48,9 @@ namespace TNodeCore.Editor.EditorPersistence{
}
}
/// <summary>
/// The possible implementation of a graph view by default.
/// </summary>
public enum GraphImplType{
GraphViewImpl,
GraphToolsFoundationImpl

@ -1,11 +0,0 @@
using System;
using UnityEngine;
namespace TNodeCore.Editor.EditorPersistence{
[Serializable]
public class GraphElementEditorData{
public string guid;
public Rect pos;
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: cde084f079a7426daa86ed86cb80ed1b
timeCreated: 1655969362

@ -1,9 +0,0 @@
namespace TNodeCore.Editor.EditorPersistence{
public interface IGraphViewPersistence{
string GetPersistenceId();
void ResetPos(GraphEditorData editorData);
void SavePos(GraphEditorData editorData);
void OnRemoveFromGraph(GraphEditorData editorData);
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 98a1e33328e84b9fa71241f2a1ce42a1
timeCreated: 1656924679

@ -1,3 +1,4 @@
using TNode.TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Runtime.Models;

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 71a4cdef7fcc4595bbca70ca16e06e9d
timeCreated: 1656126162

@ -1,8 +0,0 @@
namespace TNodeCore.Editor.Inspector{
public interface INodeDataBinding<out T>:INodeDataBindingBase{
void OnBindingDataUpdate();
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: b06ba4ccd201400cbabfa7b6ee092cb2
timeCreated: 1656137782

@ -1,8 +0,0 @@
using TNodeCore.Runtime.Models;
namespace TNodeCore.Editor.Inspector{
public interface INodeDataBindingBase{
string BindingPath{ get; set; }
public NodeData BindingNodeData{ get; set; }
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 2445523267fc49d3a17639a5c3ee47c7
timeCreated: 1656210915

@ -1,9 +1,10 @@
using System;
using TNodeCore.Runtime.Models;
using UnityEngine;
namespace TNodeCore.Editor.Models{
//This models are editor only
namespace TNode.TNodeCore.Editor.Models{
/// <summary>
/// Editor model that holds the editor only model.
/// </summary>
[Serializable]
public abstract class EditorModel:Model{

@ -1,13 +0,0 @@
using System;
using TNodeCore.Editor.Models;
using UnityEngine;
using UnityEngine.Serialization;
namespace TNode.TNodeCore.Editor.Models{
[Serializable]
public class GraphViewData:EditorModel{
public float persistScale = 1f;
public Vector2 persistOffset = Vector2.zero;
public bool isBlackboardOn;
}
}

@ -0,0 +1,25 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace TNode.TNodeCore.Editor.Models{
/// <summary>
/// It's called the graphview - model .not the ViewModel concept in MVVM.
/// Help graph view to persist its own data
/// </summary>
[Serializable]
public class GraphViewModel:EditorModel{
/// <summary>
/// The scaling factor of a graph view.
/// </summary>
public float persistScale = 1f;
/// <summary>
/// The offset of a graph view in the canvas
/// </summary>
public Vector2 persistOffset = Vector2.zero;
/// <summary>
///Is this graph view have a blackboard turn on.
/// </summary>
public bool isBlackboardOn;
}
}

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using TNodeCore.Runtime.Models;
using UnityEngine;
namespace TNodeCore.Editor.Models{
[Serializable]
public class PlacematData:EditorModel{
[SerializeReference]
public List<Model> hostModels = new List<Model>();
public int zOrder;
public string title;
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using TNodeCore.Runtime.Models;
using UnityEngine;
namespace TNode.TNodeCore.Editor.Models{
/// <summary>
/// Placemats hold the nodes
/// </summary>
[Serializable]
public class PlacematModel:EditorModel{
/// <summary>
/// In the experimental Graphview, no hostModels should be add.ignore it in most cases.
/// </summary>
[SerializeReference]
public List<Model> hostModels = new List<Model>();
/// <summary>
/// zOrder of the placemat
/// </summary>
public int zOrder;
/// <summary>
/// title of the placemat
/// </summary>
public string title;
}
}

@ -5,21 +5,60 @@ using TNodeCore.Runtime.Models;
using UnityEngine;
namespace TNodeCore.Editor.NodeGraphView{
/// <summary>
/// Base data graph view interface for all data graph views.its define the most behaviour of a data graph view.
/// </summary>
public interface IBaseDataGraphView{
/// <summary>
/// To add a node to the graph view
/// </summary>
/// <param name="nodeData">The node data you want to add to graph view</param>
/// <param name="rect">The position you want to add in. In most situation, calculated by the implementation.</param>
public void AddTNode(NodeData nodeData, Rect rect);
/// <summary>
/// Remove the node from the graph view.since Experimental graph view holds the reference itself.Currently no use of the this function
/// </summary>
/// <param name="nodeData"></param>
public void RemoveTNode(NodeData nodeData);
/// <summary>
/// Add a link to the graphview
/// </summary>
/// <param name="nodeLink"></param>
public void AddLink(NodeLink nodeLink);
/// <summary>
/// Remove link from a graph view.
/// </summary>
/// <param name="nodeLink"></param>
public void RemoveLink(NodeLink nodeLink);
/// <summary>
/// Is the graph view gives a auto update feature.St to true to call periodically the update function.
/// </summary>
public bool AutoUpdate{ get; set; }
/// <summary>
/// Create the blackboard view for the graph view.
/// </summary>
public void CreateBlackboard();
/// <summary>
/// Get the inspected graph data.
/// </summary>
/// <returns></returns>
public GraphData GetGraphData();
/// <summary>
/// Get the inspected blackboard data.Differs in runtime graph and static graph.
/// </summary>
/// <returns></returns>
public BlackboardData GetBlackboardData();
/// <summary>
/// Check if it's used by a runtime graph.
/// </summary>
public bool IsRuntimeGraph{ get; set; }
/// <summary>
@ -27,11 +66,21 @@ namespace TNodeCore.Editor.NodeGraphView{
/// </summary>
/// <returns></returns>
public RuntimeGraph GetRuntimeGraph();
/// <summary>
/// Edit a graph data.
/// </summary>
/// <param name="graph">The graph you want to edit,watch,update,modify</param>
public void SetGraphData(GraphData graph);
/// <summary>
/// call after a runtime graph is finished its execution
/// </summary>
public Action AfterGraphResolved{ get; set; }
/// <summary>
/// call After the editor load this current graphview
/// </summary>
void AfterEditorLoadGraphView();
//todo remove it later ,keep it now

@ -1,10 +1,25 @@
using TNodeCore.Editor.EditorPersistence;
using TNode.TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.EditorPersistence;
using TNodeCore.Runtime.Models;
namespace TNodeCore.Editor.NodeGraphView{
/// <summary>
/// A generic interface of the graph view.inherited from base data graph view.for a better operation only.
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IDataGraphView<T> : IBaseDataGraphView where T:GraphData{
/// <summary>
/// The generalized data of a graph.
/// </summary>
public T Data{ get; set; }
/// <summary>
/// Editor holds the graph view
/// </summary>
GraphEditor<T> Owner{ get; set; }
/// <summary>
/// Persist data into the graph editor data.
/// </summary>
/// <param name="graphEditorData"></param>
void SaveWithEditorData(GraphEditorData graphEditorData);
}
}

@ -1,60 +0,0 @@

// namespace TNode.Editor{
// [CustomPropertyDrawer(typeof(BlackboardData))]
// public class BlackboardDataPropertyDrawer:PropertyDrawer{
// public float height = 0;
// public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
// {
// // Using BeginProperty / EndProperty on the parent property means that
// // prefab override logic works on the entire property.
// var to = property.serializedObject.targetObject;
//
// if (to is RuntimeGraph runtimeGraph){
// var blackboardData = property.boxedValue;
// var graphType = runtimeGraph.graphData.GetType();
//
// Debug.Log(blackboardData);
//
// if (blackboardData == null || blackboardData.GetType()==typeof(BlackboardData))
// { blackboardData= NodeEditorExtensions.GetAppropriateBlackboardData(graphType);
// property.boxedValue = blackboardData;
//
// }
//
//
// var posy = position.y;
// EditorGUI.BeginProperty(position, label, property);
//
// // Draw label
// EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
// height = EditorGUIUtility.singleLineHeight;
//
// // Don't make child fields be indented
// var indent = EditorGUI.indentLevel;
// EditorGUI.indentLevel = 0;
//
// //find the blackboard data
//
// var blackboardDataFields = blackboardData.GetType().GetFields();
// posy += EditorGUIUtility.singleLineHeight;
// foreach (var blackboardDataField in blackboardDataFields){
// var newPosition = new Rect(position.x, posy, position.width, EditorGUIUtility.singleLineHeight);
// EditorGUI.PropertyField(newPosition, property.FindPropertyRelative(blackboardDataField.Name), new GUIContent(blackboardDataField.Name));
// posy += EditorGUIUtility.singleLineHeight;
// height+=EditorGUIUtility.singleLineHeight;
// }
//
// // Set indent back to what it was
// EditorGUI.indentLevel = indent;
//
// EditorGUI.EndProperty();
// }
//
//
// }
// public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
// {
// return base.GetPropertyHeight(property, label) + height;
// }
// }
// }

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: e731c94a155641f39da7e1eb47f80f01
timeCreated: 1657878003

@ -1,7 +1,7 @@
using TNodeCore.Runtime;
using TNodeCore.Runtime.Models;
namespace TNodeCore.Editor.Serialization{
namespace TNode.TNodeCore.Editor.Serialization{
public class BlackboardDataWrapper:DataWrapper<BlackboardDataWrapper,BlackboardData>{
}
}

@ -1,110 +1,8 @@
using System;
using System.Collections.Generic;
using TNodeCore.Runtime;
using TNodeCore.Runtime;
using TNodeCore.Runtime.Models;
using UnityEditor;
using UnityEngine;
namespace TNodeCore.Editor.Serialization{
// public class NodeDataWrapper<T> : ScriptableObject where T : NodeData{
// public T Data;
// private static readonly Dictionary<T,NodeDataWrapper<T>> Cache = new ();
// public event Action<NodeDataWrapper<T>> OnValueChanged;
// public static NodeDataWrapper<T> Get(T data){
// if(Cache.ContainsKey(data)){
// return Cache[data];
// }
// var wrapper = ScriptableObject.CreateInstance<NodeDataWrapper<T>>();
// 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<T> wrapper){
// if (wrapper == null)
// return null;
// return wrapper.Data;
//
// }
// public static implicit operator NodeDataWrapper<T>(T unWrapper){
// if (unWrapper == null)
// return null;
// return Get(unWrapper);
// }
// }
namespace TNode.TNodeCore.Editor.Serialization{
public class NodeDataWrapper:DataWrapper<NodeDataWrapper,NodeData>{
}
/// <summary>
/// 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
/// </summary>
// public class NodeDataWrapper:ScriptableObject{
// [SerializeReference]
// public NodeData data;
// private static readonly Dictionary<NodeData,NodeDataWrapper> Cache = new ();
// public event Action<NodeDataWrapper> OnValueChanged;
// /// <summary>
// /// Create a new wrapper or get a infoCached wrapper for the given data
// /// </summary>
// /// <param name="data">node data,an implemented type is acceptable</param>
// /// <returns></returns>
// public static NodeDataWrapper Get(NodeData data){
// if (data.GetType().IsGenericType){
// return CreateInstance<NodeDataWrapper>();
// }
// if(Cache.ContainsKey(data)){
// return Cache[data];
// }
// var wrapper = CreateInstance<NodeDataWrapper>();
// 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;
//
// }
// /// <summary>
// /// Use this to get the wrapped data directly.
// /// </summary>
// /// <param name="unWrapper"></param>
// /// <returns></returns>
// public static implicit operator NodeDataWrapper(NodeData unWrapper){
// if (unWrapper == null)
// return null;
// return Get(unWrapper);
// }
// }
}

@ -1,5 +1,6 @@
using System.IO;
using System.Text.RegularExpressions;
using TNode.TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.EditorPersistence;
using UnityEditor;
using UnityEngine;

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using TNode.TNodeCore.Editor.Models;
using TNodeCore.Editor.Models;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
namespace TNodeCore.Runtime.Models{
[Serializable]
@ -47,8 +47,8 @@ namespace TNodeCore.Runtime.Models{
#if UNITY_EDITOR
[SerializeReference]
protected List<EditorModel> editorModels ;
[SerializeReference]
protected GraphViewData graphViewData;
[FormerlySerializedAs("graphViewData")] [SerializeReference]
protected GraphViewModel graphViewModel;
public List<EditorModel> EditorModels{
@ -58,12 +58,12 @@ namespace TNodeCore.Runtime.Models{
}
set => editorModels = value;
}
public GraphViewData GraphViewData{
public GraphViewModel GraphViewModel{
get{
return graphViewData ??= new GraphViewData();
return graphViewModel ??= new GraphViewModel();
}
set => graphViewData = value;
set => graphViewModel = value;
}
#endif

@ -2,10 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using TNode.TNodeCore.Editor.Blackboard;
using TNode.TNodeCore.Editor.EditorPersistence;
using TNode.TNodeGraphViewImpl.Editor.GraphBlackboard;
using TNode.TNodeGraphViewImpl.Editor.NodeGraphView;
using TNode.TNodeGraphViewImpl.Editor.NodeViews;
using TNodeCore.Editor.Blackboard;
using TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Runtime.Attributes;

@ -2,9 +2,9 @@
using System.Collections;
using System.Linq;
using System.Reflection;
using TNode.TNodeCore.Editor.Serialization;
using TNode.TNodeGraphViewImpl.Editor.Search;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Serialization;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models;
using UnityEditor;
@ -86,7 +86,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
private static void CreateBlackboardDataEntryForListItem(FieldInfo field, SerializedObject serializedObject,
bool isRuntimeGraph,
BlackboardSection blackboardSection, int index){
var property = serializedObject.FindProperty("data");
var property = serializedObject.FindProperty("model");
property = property.FindPropertyRelative(field.Name).GetArrayElementAtIndex(index);
BlackboardDataEntry entry = new BlackboardDataEntry(field.FieldType){
@ -112,7 +112,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
var foldoutData = new Foldout{
};
var drawer =
new GraphBlackboardPropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),
new GraphBlackboardPropertyField(serializedObject.FindProperty("model").FindPropertyRelative(field.Name),
isRuntimeGraph);
drawer.Bind(serializedObject);
foldoutData.Add(drawer);

@ -1,4 +1,4 @@
using TNodeCore.Editor.Blackboard;
using TNode.TNodeCore.Editor.Blackboard;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Runtime.Models;
using UnityEditor;

@ -35,7 +35,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.Inspector{
private void RefreshInspector(){
//iterate field of data and get name of every fields,create a new inspector item of appropriate type and add it to the inspector for each field
//iterate field of model and get name of every fields,create a new inspector item of appropriate type and add it to the inspector for each field
var body = this.Q("InspectorBody");
body.Clear();
body.StretchToParentSize();

@ -1,6 +1,6 @@
using System.Reflection;
using TNode.TNodeCore.Editor.Serialization;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Serialization;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models;
using UnityEditor;
@ -38,7 +38,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.Inspector{
private void RefreshPropertyDrawer(){
//Check if the data's type is a generic type of BlackboardDragNodeData<>
//Check if the model's type is a generic type of BlackboardDragNodeData<>
if (_data.GetType().IsSubclassOf(typeof(BlackboardDragNodeData))){
return;
}
@ -49,7 +49,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.Inspector{
var showInNodeViewAttribute = field.GetCustomAttribute<ShowInNode>() != null;
if (!showInNodeViewAttribute)
continue;
var drawer = new PropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name));
var drawer = new PropertyField(serializedObject.FindProperty("model").FindPropertyRelative(field.Name));
drawer.RegisterValueChangeCallback((evt) => {
serializedObject.Update();
serializedObject.ApplyModifiedProperties();

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using TNode.TNodeCore.Editor.Blackboard;
using TNode.TNodeCore.Editor.EditorPersistence;
using TNode.TNodeCore.Editor.Models;
using TNode.TNodeGraphViewImpl.Editor.Cache;
using TNode.TNodeGraphViewImpl.Editor.GraphBlackboard;
@ -11,9 +13,7 @@ using TNode.TNodeGraphViewImpl.Editor.NodeViews;
using TNode.TNodeGraphViewImpl.Editor.Placemats;
using TNode.TNodeGraphViewImpl.Editor.Search;
using TNodeCore.Editor;
using TNodeCore.Editor.Blackboard;
using TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.Models;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Tools.NodeCreator;
@ -42,7 +42,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
private Dictionary<string,Node> _nodeDict = new Dictionary<string,Node>();
private IBlackboardView _blackboard;
private bool _loaded;
private GraphViewData _graphViewData;
private GraphViewModel _graphViewModel;
public T Data{
get{ return _data; }
set{
@ -102,7 +102,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
name = "HintLabel"
};
visualElement.RegisterCallback<DragPerformEvent>((evt) => {
//check if the dragged object is a graph data or a Game Object contains a runtime graph
//check if the dragged object is a graph model or a Game Object contains a runtime graph
var res = DragAndDrop.objectReferences;
foreach (var obj in res){
if (obj is T graphData){
@ -118,7 +118,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
BuildRuntimeGraphBehaviour();
Data = gameObject.GetComponent<RuntimeGraph>().graphData as T;
if(Data==null){
Debug.LogError($"Dragged a wrong graph data to editor,expected {typeof(T)} but got {gameObject.GetComponent<RuntimeGraph>().graphData.GetType()}");
Debug.LogError($"Dragged a wrong graph model to editor,expected {typeof(T)} but got {gameObject.GetComponent<RuntimeGraph>().graphData.GetType()}");
}
}
}
@ -127,7 +127,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
}
});
visualElement.RegisterCallback<DragUpdatedEvent>((evt) => {
//check if the dragged object is a graph data or a Game Object contains a runtime graph
//check if the dragged object is a graph model or a Game Object contains a runtime graph
var res = DragAndDrop.objectReferences;
foreach (var obj in res){
if (obj is GraphData graphData){
@ -197,25 +197,25 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
Debug.Log(targetPos);
SearchWindow.Open(searchWindowContext, searchWindow);
});
evt.menu.AppendAction("Create PlacematData",dma=> {
evt.menu.AppendAction("Create PlacematModel",dma=> {
//find placemat container
var placematContainer = GetPlacematContainer();
var targetPos = this.viewTransform.matrix.inverse.MultiplyPoint(dma.eventInfo.localMousePosition);
var dmaPosRect = new Rect(targetPos,new Vector2(500,500));
var placemat = placematContainer.CreatePlacemat<PlacematView>(dmaPosRect,1,"Title");
var placematData = new PlacematData{
var placematData = new PlacematModel{
title = "Title",
positionInView = dmaPosRect
};
placemat.PlacematData = placematData;
placemat.PlacematModel = placematData;
AddPlacemat(placematData);
});
});
}
private void AddPlacemat(PlacematData data){
_data.EditorModels.Add(data);
private void AddPlacemat(PlacematModel model){
_data.EditorModels.Add(model);
}
private PlacematContainer GetPlacematContainer(){
@ -354,7 +354,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
}
private void OnDragUpdated(DragUpdatedEvent evt){
//check if the drag data is BlackboardField
//check if the drag model is BlackboardField
if (DragAndDrop.GetGenericData("DragSelection") is List<ISelectable> data){
if (data.Count <= 0) return;
DragAndDrop.visualMode = DragAndDropVisualMode.Move;
@ -417,18 +417,18 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
newEdge.output?.Connect(newEdge);
AddElement(newEdge);
}
var placemats = _data.EditorModels.OfType<PlacematData>();
var placemats = _data.EditorModels.OfType<PlacematModel>();
foreach (var placemat in placemats){
var container = GetPlacematContainer();
var res = container.CreatePlacemat<PlacematView>(placemat.positionInView, 0, placemat.title);
res.PlacematData = placemat;
res.PlacematModel = placemat;
}
_nodeDict.Clear();
}
private void LoadPersistentGraphViewData(){
var r= _data.GraphViewData;
var r= _data.GraphViewModel;
this.viewTransformChanged-=OnViewTransformChanged;
this.UpdateViewTransform(r.persistOffset,new Vector3(r.persistScale,r.persistScale,1));
this.viewTransformChanged+=OnViewTransformChanged;
@ -437,8 +437,8 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
private void OnViewTransformChanged(GraphView graphview){
if (_data == null) return;
_data.GraphViewData.persistOffset = graphview.viewTransform.position;
_data.GraphViewData.persistScale = graphview.viewTransform.scale.x;
_data.GraphViewModel.persistOffset = graphview.viewTransform.position;
_data.GraphViewModel.persistScale = graphview.viewTransform.scale.x;
}
private void AddPersistentNode(NodeData dataNode){
@ -551,7 +551,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
Debug.Log(placemats.Count);
foreach (var placemat in placemats){
if (placemat is PlacematView placematView){
_data.EditorModels.Add(placematView.PlacematData);
_data.EditorModels.Add(placematView.PlacematModel);
}
}
}
@ -628,7 +628,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
#region implement interfaces
/// <summary>
/// Simultaneously add the node to the graph data and add the node to the graph view
/// Simultaneously add the node to the graph model and add the node to the graph view
/// </summary>
/// <param name="nodeData"></param>
/// <param name="rect">The give rect is the actual position in the graph view</param>
@ -693,8 +693,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
RemoveElement(edge);
}
}
//TODO: rect x,y move to node region
Owner.graphEditorData.graphElementsData.RemoveAll(x => x.guid == nodeData.id);
}
public void AddLink(NodeLink nodeLink){
@ -730,7 +729,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
UpdateBlackboardData();
OnDataChanged+= (sender, e) => { UpdateBlackboardData(); };
if(_data.blackboardData!=null){
_data.GraphViewData.isBlackboardOn = true;
_data.GraphViewModel.isBlackboardOn = true;
}
}

@ -1,11 +1,12 @@
using System.Linq;
using TNode.TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.EditorPersistence;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine.UIElements;
namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
public class SimpleGraphSubWindow:GraphElement,IGraphViewPersistence{
public class SimpleGraphSubWindow:GraphElement{
private readonly Dragger _dragger = new Dragger();
protected void ConstructWindowBasicSetting(){
@ -39,18 +40,8 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
throw new System.NotImplementedException();
}
public void ResetPos(GraphEditorData editorData){
var res = editorData.graphElementsData.FirstOrDefault(x => x.guid == this.GetPersistenceId());
}
public void SavePos(GraphEditorData editorData){
}
public void OnRemoveFromGraph(GraphEditorData editorData){
}
}
}

@ -1,5 +1,5 @@
using TilemapGenerator.ThirdParty.Extensions;
using TNodeCore.Editor.Serialization;
using TNode.TNodeCore.Editor.Serialization;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models;
using UnityEditor;

@ -1,10 +1,10 @@
using System;
using System.Linq;
using System.Reflection;
using TNode.TNodeCore.Editor.Serialization;
using TNode.TNodeGraphViewImpl.Editor.Inspector;
using TNode.TNodeGraphViewImpl.Editor.Ports;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Serialization;
using TNodeCore.Runtime;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Attributes.Ports;

@ -1,38 +1,35 @@

using TNodeCore.Editor.Models;
using TNode.TNodeCore.Editor.Models;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.TNodeGraphViewImpl.Editor.Placemats{
public class PlacematView:Placemat{
public PlacematData PlacematData{
get => _placematData;
public PlacematModel PlacematModel{
get => _placematModel;
set{
_placematData = value;
_placematModel = value;
UpdatePlacematData();
}
}
private PlacematData _placematData;
private PlacematModel _placematModel;
public int zOrder {get;set;}
public PlacematView(){
var title = this.Q<TextField>();
title.RegisterValueChangedCallback(evt => {
PlacematData.title = title.value;
PlacematModel.title = title.value;
});
}
public virtual void UpdatePlacematData(){
SetPosition(_placematData.positionInView);
SetPosition(_placematModel.positionInView);
this.Color = new Color(43/255.0f, 72/255.0f, 101/255.0f);
}
public sealed override void SetPosition(Rect newPos){
base.SetPosition(newPos);
if (_placematData == null){
if (_placematModel == null){
return;
}
_placematData.positionInView = newPos;
_placematModel.positionInView = newPos;
}
public virtual void Collapse(){
this.Collapsed = true;

@ -1,8 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TNode.TNodeCore.Editor.Blackboard;
using TNode.TNodeGraphViewImpl.Editor.GraphBlackboard;
using TNodeCore.Editor.Blackboard;
using TNodeCore.Editor.NodeGraphView;
using UnityEditor;
using UnityEditor.Experimental.GraphView;

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using TNode.TNodeGraphViewImpl.Editor.Cache;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Serialization;
using TNodeCore.Editor.Tools.NodeCreator;
using TNodeCore.Runtime.Models;
using UnityEditor;

Loading…
Cancel
Save