|
|
|
@ -3,116 +3,25 @@ using System.Collections; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Reflection; |
|
|
|
|
using TNode.BaseViews; |
|
|
|
|
using TNode.Cache; |
|
|
|
|
using TNode.Editor.GraphBlackboard; |
|
|
|
|
using TNode.Editor; |
|
|
|
|
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 Unity.VisualScripting; |
|
|
|
|
using TNodeGraphViewImpl.Editor.GraphBlackboard; |
|
|
|
|
using TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty; |
|
|
|
|
using UnityEditor; |
|
|
|
|
using UnityEditor.Experimental.GraphView; |
|
|
|
|
using UnityEngine; |
|
|
|
|
using UnityEngine.UIElements; |
|
|
|
|
using Edge = UnityEditor.Experimental.GraphView.Edge; |
|
|
|
|
|
|
|
|
|
namespace TNode.Editor.BaseViews{ |
|
|
|
|
/* |
|
|
|
|
public class DialogueGraphView : DataGraphView<DialogueGraph>{ |
|
|
|
|
public Action<DialogueNodeView> onNodeAdded; |
|
|
|
|
public Action<DialogueNodeView> onNodeSelected; |
|
|
|
|
public Action<DialogueNodeView> onNodeRemoved; |
|
|
|
|
public Action<DialogueNodeView> onNodeUnselected; |
|
|
|
|
// public DialogueGraphView(DialogueGraph graph):base(){ |
|
|
|
|
// this.Data = graph; |
|
|
|
|
// |
|
|
|
|
// //Set background to a bit of darker |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// //Register a data context change callback |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
public override void OnGraphViewCreate(){ |
|
|
|
|
AddNode(GenerateEntryPoint()); |
|
|
|
|
RegisterCallback<ContextualMenuPopulateEvent>(evt => { |
|
|
|
|
var pos = evt.mousePosition; |
|
|
|
|
|
|
|
|
|
evt.menu.AppendAction("Add NodeAttribute", (dropMenuAction) => { |
|
|
|
|
DialogueNodeView nodeView = new DialogueNodeView{ |
|
|
|
|
GUID = Guid.NewGuid().ToString(), |
|
|
|
|
title = "New NodeAttribute" |
|
|
|
|
}; |
|
|
|
|
// make it a 200x100 box |
|
|
|
|
nodeView.SetPosition(new Rect(pos.x - 100, pos.y - 50, 200, 100)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AddNode(nodeView); |
|
|
|
|
}, DropdownMenuAction.AlwaysEnabled); |
|
|
|
|
}); |
|
|
|
|
this.OnDataChanged += OnOnDataChanged; |
|
|
|
|
} |
|
|
|
|
private void OnOnDataChanged(object sender, DataChangedEventArgs<DialogueGraph> e){ |
|
|
|
|
//clean all nodes from the graphview |
|
|
|
|
foreach (var graphViewNode in nodes){ |
|
|
|
|
RemoveElement(graphViewNode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach (var edge in edges){ |
|
|
|
|
RemoveElement(edge); |
|
|
|
|
} |
|
|
|
|
//add all nodes from the new graph |
|
|
|
|
foreach (var node in e.NewData.nodes){ |
|
|
|
|
//AddNode(node); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void AddNode(DialogueNodeData dialogueNodeData){ |
|
|
|
|
var res = InstantiateFromDialogueNodeData(dialogueNodeData); |
|
|
|
|
AddNode(res); |
|
|
|
|
} |
|
|
|
|
public void AddNode(DialogueNodeView nodeView){ |
|
|
|
|
AddElement(nodeView); |
|
|
|
|
onNodeAdded?.Invoke(nodeView); |
|
|
|
|
//Register nodeView selection callback |
|
|
|
|
nodeView.RegisterCallback<MouseDownEvent>(evt => { |
|
|
|
|
if (evt.clickCount == 1){ |
|
|
|
|
onNodeSelected?.Invoke(nodeView); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
nodeView.OnUnselect += () => { onNodeUnselected?.Invoke(nodeView); }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter) => this.ports.ToList() |
|
|
|
|
.Where(x => x != startPort && |
|
|
|
|
x.direction != startPort.direction).ToList(); |
|
|
|
|
|
|
|
|
|
public DialogueNodeView GenerateEntryPoint(){ |
|
|
|
|
var entryPoint = new DialogueNodeView{ |
|
|
|
|
title = "Entry Point", |
|
|
|
|
GUID = Guid.NewGuid().ToString(), |
|
|
|
|
EntryPoint = true |
|
|
|
|
}; |
|
|
|
|
//Add output port to the nodeView |
|
|
|
|
entryPoint.AddPort(Orientation.Horizontal, Direction.Output, "Next"); |
|
|
|
|
//Set nodeView position to top center side of screen |
|
|
|
|
entryPoint.SetPosition(new Rect(this.layout.width / 2 - 100, 0, 200, 200)); |
|
|
|
|
return entryPoint; |
|
|
|
|
} |
|
|
|
|
protected DialogueNodeView InstantiateFromDialogueNodeData(DialogueNodeData dialogueNodeData){ |
|
|
|
|
var node = new DialogueNodeView(); |
|
|
|
|
node.title = dialogueNodeData.nodeName; |
|
|
|
|
node.GUID = Guid.NewGuid().ToString(); |
|
|
|
|
//TODO:after completing the separation of the node data and the node editor data,this should be switch to the node editor data |
|
|
|
|
//node.SetPosition(dialogueNodeData.rect); |
|
|
|
|
this.AddNode(node); |
|
|
|
|
return node; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
public abstract class DataGraphView<T>:GraphView,IDataGraphView where T:GraphData{ |
|
|
|
|
namespace TNodeGraphViewImpl.Editor.NodeGraphView{ |
|
|
|
|
public abstract class BaseDataGraphView<T>:GraphView,IBaseDataGraphView where T:GraphData{ |
|
|
|
|
#region variables and properties |
|
|
|
|
private T _data; |
|
|
|
|
private bool _isInspectorOn; |
|
|
|
@ -138,11 +47,11 @@ namespace TNode.Editor.BaseViews{ |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
//A Constructor for the DataGraphView ,never to override it |
|
|
|
|
//A Constructor for the BaseDataGraphView ,never to override it |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region construct default behaviour |
|
|
|
|
public DataGraphView(){ |
|
|
|
|
public BaseDataGraphView(){ |
|
|
|
|
styleSheets.Add(Resources.Load<StyleSheet>("GraphViewBackground")); |
|
|
|
|
var grid = new GridBackground(); |
|
|
|
|
Insert(0,grid); |
|
|
|
@ -350,7 +259,7 @@ namespace TNode.Editor.BaseViews{ |
|
|
|
|
var nodeEditorData = new GraphElementEditorData{ |
|
|
|
|
pos = node.GetPosition(), |
|
|
|
|
}; |
|
|
|
|
if (node is INodeView nodeView){ |
|
|
|
|
if (node is IBaseNodeView nodeView){ |
|
|
|
|
nodeEditorData.guid = nodeView.GetNodeData().id; |
|
|
|
|
} |
|
|
|
|
graphEditorData.graphElementsData.Add(nodeEditorData); |
|
|
|
@ -366,7 +275,7 @@ namespace TNode.Editor.BaseViews{ |
|
|
|
|
private void SaveNode(){ |
|
|
|
|
|
|
|
|
|
foreach (var node in nodes){ |
|
|
|
|
if (node is INodeView nodeView){ |
|
|
|
|
if (node is IBaseNodeView nodeView){ |
|
|
|
|
var nodeData = nodeView.GetNodeData(); |
|
|
|
|
if (!_data.NodeDictionary.ContainsKey(nodeData.id)){ |
|
|
|
|
_data.NodeDictionary.Add(nodeData.id, nodeData); |
|
|
|
@ -377,8 +286,8 @@ namespace TNode.Editor.BaseViews{ |
|
|
|
|
private void SaveEdge(){ |
|
|
|
|
var links = new List<NodeLink>(); |
|
|
|
|
foreach (var edge in edges){ |
|
|
|
|
var inputNode = edge.input.node as INodeView; |
|
|
|
|
var outputNode = edge.output.node as INodeView; |
|
|
|
|
var inputNode = edge.input.node as IBaseNodeView; |
|
|
|
|
var outputNode = edge.output.node as IBaseNodeView; |
|
|
|
|
if (inputNode != null && outputNode != null){ |
|
|
|
|
var inputNodeData = inputNode.GetNodeData(); |
|
|
|
|
var outputNodeData = outputNode.GetNodeData(); |
|
|
|
@ -417,7 +326,7 @@ namespace TNode.Editor.BaseViews{ |
|
|
|
|
public virtual void OnGraphViewDestroy(){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
~DataGraphView(){ |
|
|
|
|
~BaseDataGraphView(){ |
|
|
|
|
OnGraphViewDestroy(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -434,11 +343,11 @@ namespace TNode.Editor.BaseViews{ |
|
|
|
|
if (evt.clickCount == 1){ |
|
|
|
|
if (_isInspectorOn){ |
|
|
|
|
_nodeInspector.Data = nodeData; |
|
|
|
|
_nodeInspector.NodeView = nodeView as INodeView; |
|
|
|
|
_nodeInspector.BaseNodeView = nodeView as IBaseNodeView; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
if(nodeView is INodeView nodeViewInterface){ |
|
|
|
|
if(nodeView is IBaseNodeView nodeViewInterface){ |
|
|
|
|
nodeViewInterface.SetNodeData(nodeData); |
|
|
|
|
} |
|
|
|
|
_nodeDict.Add(nodeData.id, nodeView); |
|
|
|
@ -448,7 +357,7 @@ namespace TNode.Editor.BaseViews{ |
|
|
|
|
var menu = new GenericMenu(); |
|
|
|
|
menu.AddItem(new GUIContent("Delete"), false, () => { |
|
|
|
|
RemoveElement(nodeView); |
|
|
|
|
if (nodeView is INodeView tNodeView){ |
|
|
|
|
if (nodeView is IBaseNodeView tNodeView){ |
|
|
|
|
RemoveTNode(tNodeView.GetNodeData()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -477,12 +386,6 @@ namespace TNode.Editor.BaseViews{ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public interface IDataGraphView{ |
|
|
|
|
public void AddTNode(NodeData nodeData, Rect rect); |
|
|
|
|
public void RemoveTNode(NodeData nodeData); |
|
|
|
|
|
|
|
|
|
public BlackboardData GetBlackboardData(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class DataChangedEventArgs<T>{ |
|
|
|
|
public DataChangedEventArgs(T data){ |