1.finish editor data partly

main
taoria 3 years ago
parent 4c6f83ddf3
commit 462be05c2e
  1. 116
      TNode/Editor/BaseViews/DataGraphView.cs
  2. 2
      TNode/Editor/BaseViews/NodeView.cs
  3. 2
      TNode/Editor/BaseViews/SimpleGraphSubWindow.cs
  4. 8
      TNode/Editor/EditorPersistence/GraphEditorData.cs
  5. 6
      TNode/Editor/EditorPersistence/GraphElementEditorData.cs
  6. 0
      TNode/Editor/EditorPersistence/GraphElementEditorData.cs.meta
  7. 13
      TNode/Editor/GraphEditor.cs
  8. 3
      TNode/Models/GraphData.cs
  9. 15
      TNode/Runtime/RuntimeGraph.cs
  10. 19
      TNode/Runtime/RuntimeNode.cs
  11. 15
      TNode/RuntimeCache/RuntimeCache.cs

@ -126,7 +126,51 @@ namespace TNode.Editor.BaseViews{
ResetGraphView();
}
}
public event DataChangedEventHandler OnDataChanged;
public delegate void DataChangedEventHandler(object sender, DataChangedEventArgs<T> e);
//A Constructor for the DataGraphView ,never to override it
public DataGraphView(){
styleSheets.Add(Resources.Load<StyleSheet>("GraphViewBackground"));
var grid = new GridBackground();
Insert(0,grid);
grid.StretchToParentSize();
this.AddManipulator(new ContentDragger());
this.AddManipulator(new SelectionDragger());
this.AddManipulator(new RectangleSelector());
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
OnInit();
}
private void ConstructDefaultBehaviour(){
//Register a right click context menu
ConstructViewContextualMenu();
}
public void ConstructViewContextualMenu(){
//Rebuild the contextual menu
this.RegisterCallback<ContextualMenuPopulateEvent>(evt => {
Vector2 editorPosition = Owner.position.position;
//Remove all the previous menu items
evt.menu.MenuItems().Clear();
evt.menu.AppendAction("Create Node", dma => {
var dmaPos = dma.eventInfo.mousePosition+editorPosition;
SearchWindowContext searchWindowContext = new SearchWindowContext(dmaPos,200,200);
var searchWindow = ScriptableObject.CreateInstance<SearchWindowProvider>();
searchWindow.Setup(typeof(T),this,Owner);
SearchWindow.Open(searchWindowContext, searchWindow);
});
});
}
private void OnInit(){
ConstructDefaultBehaviour();
OnGraphViewCreate();
}
public void ResetGraphView(){
//Clear all nodes
foreach (var node in nodes){
@ -145,8 +189,8 @@ namespace TNode.Editor.BaseViews{
var nodeType = dataNode.GetType();
//Get the derived type of NodeAttribute View from the node type
var nodePos = Owner.graphEditorData.nodesData.
FirstOrDefault(x => x.nodeGuid == dataNode.id)?.nodePos??new Rect(0,0,200,200);
var nodePos = Owner.graphEditorData.graphElementsData.
FirstOrDefault(x => x.guid == dataNode.id)?.pos??new Rect(0,0,200,200);
AddTNode(dataNode,nodePos);
}
@ -166,37 +210,11 @@ namespace TNode.Editor.BaseViews{
}
_nodeDict.Clear();
}
//A Constructor for the DataGraphView ,never to override it
public DataGraphView(){
styleSheets.Add(Resources.Load<StyleSheet>("GraphViewBackground"));
var grid = new GridBackground();
Insert(0,grid);
grid.StretchToParentSize();
this.AddManipulator(new ContentDragger());
this.AddManipulator(new SelectionDragger());
this.AddManipulator(new RectangleSelector());
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
OnInit();
}
//OnDataChanged event
public event DataChangedEventHandler OnDataChanged;
public delegate void DataChangedEventHandler(object sender, DataChangedEventArgs<T> e);
private void ConstructDefaultBehaviour(){
//Register a right click context menu
//ConstructContextualMenuOption();
}
public void ConstructViewContextualMenu(EventCallback<ContextualMenuPopulateEvent> callback){
RegisterCallback<ContextualMenuPopulateEvent>(callback);
}
private void OnInit(){
ConstructDefaultBehaviour();
OnGraphViewCreate();
}
public virtual void CreateInspector(){
NodeInspector nodeInspector = new NodeInspector();
@ -234,19 +252,19 @@ namespace TNode.Editor.BaseViews{
}
public void SaveEditorData(GraphEditorData graphEditorData){
graphEditorData.nodesData?.Clear();
graphEditorData.graphElementsData?.Clear();
//iterator nodes
if (graphEditorData.nodesData == null){
graphEditorData.nodesData = new List<NodeEditorData>();
if (graphEditorData.graphElementsData == null){
graphEditorData.graphElementsData = new List<GraphElementEditorData>();
}
foreach (var node in this.nodes){
var nodeEditorData = new NodeEditorData{
nodePos = node.GetPosition(),
var nodeEditorData = new GraphElementEditorData{
pos = node.GetPosition(),
};
if (node is INodeView nodeView){
nodeEditorData.nodeGuid = nodeView.GetNodeData().id;
nodeEditorData.guid = nodeView.GetNodeData().id;
}
graphEditorData.nodesData.Add(nodeEditorData);
graphEditorData.graphElementsData.Add(nodeEditorData);
EditorUtility.SetDirty(graphEditorData);
}
}
@ -335,6 +353,32 @@ namespace TNode.Editor.BaseViews{
nodeViewInterface.SetNodeData(nodeData);
}
_nodeDict.Add(nodeData.id, nodeView);
//register an callback ,when right click context menu
nodeView.RegisterCallback<ContextClickEvent>(evt => {
var menu = new GenericMenu();
menu.AddItem(new GUIContent("Delete"), false, () => {
RemoveElement(nodeView);
if (nodeView is INodeView tNodeView){
var nodeData1 = tNodeView.GetNodeData();
_data.NodeDictionary.Remove(nodeData1.id);
_nodeDict.Remove(nodeData1.id);
//Break all edges connected to this node
foreach (var edge in edges){
if (edge.input.node == nodeView || edge.output.node == nodeView){
RemoveElement(edge);
}
}
Owner.graphEditorData.graphElementsData.RemoveAll(x => x.guid == nodeData1.id);
}
});
menu.ShowAsContext();
});
}
}

@ -15,7 +15,7 @@ namespace TNode.Editor.BaseViews{
public abstract class NodeView<T> : Node,INodeView where T:NodeData,new(){
protected T _data;
private readonly NodeInspectorInNode _nodeInspectorInNode;
public T Data{
get => _data;
set{

@ -41,7 +41,7 @@ namespace TNode.BaseViews{
}
public void ResetPos(GraphEditorData editorData){
var res = editorData.subWindowPos.FirstOrDefault(x => x.nodeGuid == this.GetPersistenceId());
var res = editorData.graphElementsData.FirstOrDefault(x => x.guid == this.GetPersistenceId());
}
public void SavePos(GraphEditorData editorData){

@ -2,14 +2,12 @@
using TNode.Editor.EditorPersistence;
using TNode.Editor.Model;
using UnityEngine;
using UnityEngine.Serialization;
namespace TNode.Editor{
[CreateAssetMenu(fileName = "NodeAttribute Editor Config", menuName = "TNode/NodeAttribute Editor Config")]
[CreateAssetMenu(fileName = "Graph Editor Data", menuName = "TNode/Graph Editor Data")]
public class GraphEditorData:ScriptableObject{
public List<NodeEditorData> nodesData;
public List<NodeEditorData> subWindowPos;
public List<IGraphViewPersistence> graphViewPersistence;
public List<GraphElementEditorData> graphElementsData;
}
}

@ -6,8 +6,8 @@ using UnityEngine.Serialization;
namespace TNode.Editor.Model{
[Serializable]
public class NodeEditorData{
public string nodeGuid;
public Rect nodePos;
public class GraphElementEditorData{
public string guid;
public Rect pos;
}
}

@ -39,19 +39,6 @@ namespace TNode.Editor{
_graphView = NodeEditorExtensions.CreateInstance<DataGraphView<T>>();
rootVisualElement.Add(_graphView);
_graphView.StretchToParentSize();
_graphView.ConstructViewContextualMenu(evt => {
//Current issue is that the search window don't show up at the exact position of the mouse click by dma.eventInfo.mousePosition
//So I have to manually set the position of the search window to fit the mouse click position by add an offset driven by Editor's position
//Maybe a better way exists to fix this issue
Vector2 editorPosition = this.position.position;
evt.menu.AppendAction("Create Node", dma => {
var dmaPos = dma.eventInfo.mousePosition+editorPosition;
SearchWindowContext searchWindowContext = new SearchWindowContext(dmaPos,200,200);
var searchWindow = CreateInstance<SearchWindowProvider>();
searchWindow.Setup(typeof(T),_graphView,this);
SearchWindow.Open(searchWindowContext, searchWindow);
});
});
}
private void DefineGraphEditorActions(){

@ -12,9 +12,8 @@ namespace TNode.Models{
public Dictionary<string,NodeData> NodeDictionary = new Dictionary<string,NodeData>();
public List<NodeLink> nodeLinks = new List<NodeLink>();
[HideInInspector]
[SerializeField]
[TextArea]
//[HideInInspector]
private string jsonObject;

@ -1,9 +1,22 @@
using TNode.Models;
using System.Collections;
using System.Collections.Generic;
using TNode.Models;
using UnityEngine;
namespace TNode.Runtime{
public class RuntimeGraph:MonoBehaviour{
public GraphData graphData;
public SortedSet<RuntimeNode> _sortedSet;
public void StartProcessNode(ProcessingStrategy strategy){
}
}
public enum ProcessingStrategy{
BreadthFirst,
DepthFirst
}
}

@ -5,17 +5,22 @@ using System.Linq;
using TNode.Models;
namespace TNode.Runtime{
public class RuntimeNode<T> where T:NodeData{
public T NodeData{ get; set; }
public abstract class RuntimeNode{
public object NodeData;
public List<NodeLink> NodeLinks;
public void ProcessThisNode(){
}
}
public class RuntimeNode<T>:RuntimeNode where T:NodeData{
public new T NodeData{ get; set; }
//Links related to runtime node,for fast access.only remember out links
public List<NodeLink> NodeLinks;
public void Process(){
var outputPorts = NodeLinks.Select(x => x.outPort.portName);
public void OnCreate(){
RuntimeCache.RuntimeCache.Instance.RegisterRuntimeNode<T>();
}
}
}

@ -34,13 +34,18 @@ namespace TNode.RuntimeCache{
var type = typeof(T);
if(!CachedDelegatesForGettingValue.ContainsKey(type)){
CachedDelegatesForGettingValue.Add(type, new List<GetValueDelegate>());
var properties = type.GetProperties();
foreach(var property in properties){
var getValueDelegate = GetValueDelegateForProperty(property);
CachedDelegatesForGettingValue[type].Add(getValueDelegate);
}
}
//iterate properties of the nodeData and add them to the cache
var properties = type.GetProperties();
foreach(var property in properties){
var getValueDelegate = GetValueDelegateForProperty(property);
CachedDelegatesForGettingValue[type].Add(getValueDelegate);
else{
//Cache already exists for this type
}
}

Loading…
Cancel
Save