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

fix:fix placemat bug and node create in correct position.further more…
main
taoria 3 years ago committed by GitHub
commit 739b79d5e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      TNode/GraphCreator/Runtime/Nodes/GraphMetaNode.cs
  2. 1
      TNode/Samples/AddNode.cs
  3. 181
      TNode/Samples/New HelloGraph.asset
  4. 8
      TNode/TNodeCore/Editor/Blackboard/IBlackboardView.cs
  5. 8
      TNode/TNodeCore/Editor/EditorPersistence/IGraphViewPersistence.cs
  6. 2
      TNode/TNodeCore/Editor/Inspector/INodeDataBinding.cs
  7. 2
      TNode/TNodeCore/Editor/Inspector/INodeDataBindingBase.cs
  8. 4
      TNode/TNodeCore/Editor/Models/EditorModel.cs
  9. 13
      TNode/TNodeCore/Editor/Models/GraphViewData.cs
  10. 3
      TNode/TNodeCore/Editor/Models/GraphViewData.cs.meta
  11. 5
      TNode/TNodeCore/Editor/Models/PlacematData.cs
  12. 0
      TNode/TNodeCore/Editor/Models/PlacematData.cs.meta
  13. 1
      TNode/TNodeCore/Runtime/Logger/NodeLogger.cs
  14. 25
      TNode/TNodeCore/Runtime/Models/GraphData.cs
  15. 2
      TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs
  16. 4
      TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs
  17. 151
      TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
  18. 6
      TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs
  19. 39
      TNode/TNodeGraphViewImpl/Editor/Placemats/PlacematView.cs
  20. 17
      TNode/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs

@ -1,8 +1,9 @@
using System; using System;
using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models;
namespace TNode.GraphCreator.Runtime.Nodes{ namespace TNode.GraphCreator.Runtime.Nodes{
using TNodeCore.Runtime.Models;
namespace TNode.GraphCreator.Runtime{ namespace TNode.GraphCreator.Runtime{
[GraphUsage(typeof(MetaGraph))] [GraphUsage(typeof(MetaGraph))]

@ -17,6 +17,7 @@ namespace Samples{
public override void Process(){ public override void Process(){
Res = A + (Vector3)B; Res = A + (Vector3)B;
Debug.Log(Res);
this.Log(Res.ToString()); this.Log(Res.ToString());
} }
} }

@ -13,119 +13,166 @@ MonoBehaviour:
m_Name: New HelloGraph m_Name: New HelloGraph
m_EditorClassIdentifier: m_EditorClassIdentifier:
nodeList: nodeList:
- rid: 4804121563801583862 - id: 0
- rid: 4804121563801583947 - id: 1
- rid: 4804121563801583866 - id: 2
- rid: 4804121563801583898 - id: 3
- rid: 4804121563801583870 - id: 4
nodeLinks: - id: 5
- inPort: - id: 6
portEntryName: A - id: 7
nodeDataId: 6ceba867-fe0d-40c3-9d30-2d5d12803b52 nodeLinks: []
outPort:
portEntryName: Value
nodeDataId: ac84573e-638d-45fa-b4e2-1a81c31fa9e7
- inPort:
portEntryName: A
nodeDataId: 6ceba867-fe0d-40c3-9d30-2d5d12803b52
outPort:
portEntryName: Value
nodeDataId: b2ab4a52-e65d-4104-8891-dc316af217d9
blackboardData: blackboardData:
rid: 4804121563801583854 id: 8
sceneReference: sceneReference:
editorModels:
- id: 9
graphViewData:
id: 10
references: references:
version: 2 version: 1
RefIds: 00000000:
- rid: 4804121563801583854 type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 1944
y: 0 y: 205
width: 0 width: 0
height: 0 height: 0
HelloString: Hello World id: 74136d91-e634-401b-8c99-3c2bb351cab2
HelloGameObject: {fileID: 0} nodeName: AddNode
V3S: entryPoint: 0
- {x: 0, y: 0, z: 0} isTest: 0
- {x: 0, y: 0, z: 0} 00000001:
- {x: 0, y: 0, z: 0} type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
V2S:
- {x: 0, y: 0}
- {x: 0, y: 0}
- {x: 0, y: 0}
- rid: 4804121563801583862
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 336 x: 2045
y: 355 y: 205
width: 0 width: 0
height: 0 height: 0
id: bae506a7-58ec-4b79-9c21-747fa2b6a7ba id: 8bee0814-52ef-4068-bffb-58a786d73ec2
nodeName: nodeName: AddNode
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
blackDragData: HelloString 00000002:
isListElement: 0
- rid: 4804121563801583866
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 973.3707 x: 2146
y: 189.23111 y: 205
width: 0 width: 0
height: 0 height: 0
id: 6ceba867-fe0d-40c3-9d30-2d5d12803b52 id: 819d1689-d64d-41ca-a9ac-0e00d25806c0
nodeName: AddNode nodeName: AddNode
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
- rid: 4804121563801583870 00000003:
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly} type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 748.0001 x: 2247
y: 291 y: 205
width: 0 width: 0
height: 0 height: 0
id: b2ab4a52-e65d-4104-8891-dc316af217d9 id: b8495e41-8ec2-4015-8784-7a99c1003c6b
nodeName: nodeName: AddNode
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
blackDragData: V2S.0 00000004:
isListElement: 1 type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
- rid: 4804121563801583898
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 747 x: 2014
y: 179 y: 340
width: 0 width: 0
height: 0 height: 0
id: ac84573e-638d-45fa-b4e2-1a81c31fa9e7 id: 3f27f6fe-b2db-41f2-9b3f-5e5fc468e536
nodeName: nodeName: AddNode
entryPoint: 0
isTest: 0
00000005:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 2130
y: 340
width: 0
height: 0
id: 6500c6c2-3551-4930-8338-afd02a49105b
nodeName: AddNode
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
blackDragData: V3S.0 00000006:
isListElement: 1 type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
- rid: 4804121563801583947 data:
positionInView:
serializedVersion: 2
x: 2247
y: 340
width: 0
height: 0
id: 002de40a-5ef5-4e99-8373-2628d189d6c9
nodeName: AddNode
entryPoint: 0
isTest: 0
00000007:
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly} type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 299 x: 1944.9998
y: 313 y: 475.8858
width: 0 width: 0
height: 0 height: 0
id: b8c1e42e-c6a3-491e-aba2-c2b6ebd1c419 id: 2f9adf6b-b40b-4fbd-9bd6-0d1ebb10992f
nodeName: nodeName:
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
blackDragData: HelloGameObject blackDragData: HelloGameObject
isListElement: 0 isListElement: 0
00000008:
type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
HelloString: hello
HelloGameObject: {fileID: 3675195758153116951, guid: 35a9f7ccd0ed7d744b85580016a0aab5, type: 3}
V3S:
- {x: 0, y: 0, z: 0}
V2S:
- {x: 0, y: 0}
00000009:
type: {class: PlacematData, ns: TNodeCore.Editor.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
x: 1903.9056
y: 75.76817
width: 500
height: 500
hostModels: []
zOrder: 0
title: Title
0000000A:
type: {class: GraphViewData, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
persistScale: 0.8695652
persistOffset: {x: -878, y: -29}
isBlackboardOn: 1

@ -4,16 +4,16 @@ using UnityEditor;
namespace TNodeCore.Editor.Blackboard{ namespace TNodeCore.Editor.Blackboard{
public interface IBlackboardView{ public interface IBlackboardView{
public BlackboardData GetBlackboardData(); BlackboardData GetBlackboardData();
public void SetBlackboardData(BlackboardData data); void SetBlackboardData(BlackboardData data);
public void AddItem(); void AddItem();
void Setup(IBaseDataGraphView graphView,EditorWindow ownerWindow); void Setup(IBaseDataGraphView graphView,EditorWindow ownerWindow);
void NotifyUpdate(); void NotifyUpdate();
} }
public interface IBlackboardView<T> : IBlackboardView where T : BlackboardData{ public interface IBlackboardView<T> : IBlackboardView where T : BlackboardData{
public T Data{ get; set; } T Data{ get; set; }
} }
} }

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

@ -3,6 +3,6 @@
public void OnBindingDataUpdate(); void OnBindingDataUpdate();
} }
} }

@ -2,7 +2,7 @@
namespace TNodeCore.Editor.Inspector{ namespace TNodeCore.Editor.Inspector{
public interface INodeDataBindingBase{ public interface INodeDataBindingBase{
public string BindingPath{ get; set; } string BindingPath{ get; set; }
public NodeData BindingNodeData{ get; set; } public NodeData BindingNodeData{ get; set; }
} }
} }

@ -1,8 +1,10 @@
using TNodeCore.Runtime.Models; using System;
using TNodeCore.Runtime.Models;
using UnityEngine; using UnityEngine;
namespace TNodeCore.Editor.Models{ namespace TNodeCore.Editor.Models{
//This models are editor only //This models are editor only
[Serializable]
public abstract class EditorModel:Model{ public abstract class EditorModel:Model{
} }

@ -0,0 +1,13 @@
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,3 @@
fileFormatVersion: 2
guid: 1df79f038838423c914db0e2f5d4b2b0
timeCreated: 1659964614

@ -5,8 +5,11 @@ using UnityEngine;
namespace TNodeCore.Editor.Models{ namespace TNodeCore.Editor.Models{
[Serializable] [Serializable]
public class Placemat:EditorModel{ public class PlacematData:EditorModel{
[SerializeReference] [SerializeReference]
public List<Model> hostModels = new List<Model>(); public List<Model> hostModels = new List<Model>();
public int zOrder;
public string title;
} }
} }

@ -17,5 +17,6 @@ namespace TNodeCore.Runtime{
public interface INodeLoggerImpl{ public interface INodeLoggerImpl{
public void Log(string message); public void Log(string message);
void LogTexture(Texture2D texture2D);
} }
} }

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using TNode.TNodeCore.Editor.Models;
using TNodeCore.Editor.Models; using TNodeCore.Editor.Models;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
@ -44,9 +45,27 @@ namespace TNodeCore.Runtime.Models{
} }
#if UNITY_EDITOR #if UNITY_EDITOR
[SerializeReference] public List<EditorModel> EditorModels = new List<EditorModel>(); [SerializeReference]
protected List<EditorModel> editorModels ;
#endif [SerializeReference]
protected GraphViewData graphViewData;
public List<EditorModel> EditorModels{
get{
return editorModels ??= new List<EditorModel>();
}
set => editorModels = value;
}
public GraphViewData GraphViewData{
get{
return graphViewData ??= new GraphViewData();
}
set => graphViewData = value;
}
#endif
} }

@ -10,7 +10,6 @@ using TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models; using TNodeCore.Runtime.Models;
using Unity.VisualScripting;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
@ -278,7 +277,6 @@ namespace TNode.TNodeGraphViewImpl.Editor.Cache{
public class Launcher{ public class Launcher{
static Launcher(){ static Launcher(){
Debug.Log("NES Launched");
NodeEditorSingleton.Instance.Initialize(); NodeEditorSingleton.Instance.Initialize();
} }
} }

@ -1,12 +1,12 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Linq;
using System.Reflection; using System.Reflection;
using TNode.TNodeGraphViewImpl.Editor.Search; using TNode.TNodeGraphViewImpl.Editor.Search;
using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Serialization; using TNodeCore.Editor.Serialization;
using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models; using TNodeCore.Runtime.Models;
using Unity.VisualScripting;
using UnityEditor; using UnityEditor;
using UnityEditor.Experimental.GraphView; using UnityEditor.Experimental.GraphView;
using UnityEditor.UIElements; using UnityEditor.UIElements;
@ -34,7 +34,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
Add(blackboardGlobalSection); Add(blackboardGlobalSection);
foreach (var field in data.GetType() foreach (var field in data.GetType()
.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)){ .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)){
if(field.HasAttribute(typeof(HideInBlackboard))) continue; if(field.GetCustomAttributes(typeof(HideInBlackboard)).Count()!=0) continue;
//if the field is MonoBehaviour,add a property field for blackboard //if the field is MonoBehaviour,add a property field for blackboard
//skip if the field is a list or Ilist //skip if the field is a list or Ilist
if (!typeof(IList).IsAssignableFrom(field.FieldType)&&!field.FieldType.IsArray){ if (!typeof(IList).IsAssignableFrom(field.FieldType)&&!field.FieldType.IsArray){

@ -3,14 +3,17 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using TNode.TNodeCore.Editor.Models;
using TNode.TNodeGraphViewImpl.Editor.Cache; using TNode.TNodeGraphViewImpl.Editor.Cache;
using TNode.TNodeGraphViewImpl.Editor.GraphBlackboard; using TNode.TNodeGraphViewImpl.Editor.GraphBlackboard;
using TNode.TNodeGraphViewImpl.Editor.Inspector; using TNode.TNodeGraphViewImpl.Editor.Inspector;
using TNode.TNodeGraphViewImpl.Editor.NodeViews; using TNode.TNodeGraphViewImpl.Editor.NodeViews;
using TNode.TNodeGraphViewImpl.Editor.Placemats;
using TNode.TNodeGraphViewImpl.Editor.Search; using TNode.TNodeGraphViewImpl.Editor.Search;
using TNodeCore.Editor; using TNodeCore.Editor;
using TNodeCore.Editor.Blackboard; using TNodeCore.Editor.Blackboard;
using TNodeCore.Editor.EditorPersistence; using TNodeCore.Editor.EditorPersistence;
using TNodeCore.Editor.Models;
using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Tools.NodeCreator; using TNodeCore.Editor.Tools.NodeCreator;
@ -39,6 +42,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
private Dictionary<string,Node> _nodeDict = new Dictionary<string,Node>(); private Dictionary<string,Node> _nodeDict = new Dictionary<string,Node>();
private IBlackboardView _blackboard; private IBlackboardView _blackboard;
private bool _loaded; private bool _loaded;
private GraphViewData _graphViewData;
public T Data{ public T Data{
get{ return _data; } get{ return _data; }
set{ set{
@ -107,7 +111,6 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
else{ else{
if (obj is GameObject gameObject){ if (obj is GameObject gameObject){
if (gameObject.GetComponent<RuntimeGraph>() != null){ if (gameObject.GetComponent<RuntimeGraph>() != null){
if (gameObject.GetComponent<RuntimeGraph>().graphData != null){ if (gameObject.GetComponent<RuntimeGraph>().graphData != null){
_runtimeGraph = gameObject.GetComponent<RuntimeGraph>(); _runtimeGraph = gameObject.GetComponent<RuntimeGraph>();
@ -167,20 +170,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
} }
} }
// private void UpdateRuntimeGraphBehaviour(){
// if(_runtimeGraph != null){
// if (_runtimeGraphUpdate){
// _runtimeGraphUpdate = false;
// _runtimeGraph.TraverseAll();
//
// AfterGraphResolved?.Invoke();
// }
// }
// else{
// EditorApplication.update -= UpdateRuntimeGraphBehaviour;
// }
// }
private void CheckDataAfterInit(){ private void CheckDataAfterInit(){
if(Data == null){ if(Data == null){
WaitingForAGraph(); WaitingForAGraph();
@ -201,24 +191,43 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
var dmaPos = dma.eventInfo.mousePosition+editorPosition; var dmaPos = dma.eventInfo.mousePosition+editorPosition;
SearchWindowContext searchWindowContext = new SearchWindowContext(dmaPos,200,200); SearchWindowContext searchWindowContext = new SearchWindowContext(dmaPos,200,200);
var searchWindow = ScriptableObject.CreateInstance<NodeSearchWindowProvider>(); var searchWindow = ScriptableObject.CreateInstance<NodeSearchWindowProvider>();
searchWindow.Setup(typeof(T),this,Owner); var targetPos = this.viewTransform.matrix.inverse.MultiplyPoint(dma.eventInfo.localMousePosition);
searchWindow.Setup(typeof(T),this,Owner,targetPos);
Debug.Log(targetPos);
SearchWindow.Open(searchWindowContext, searchWindow); SearchWindow.Open(searchWindowContext, searchWindow);
}); });
evt.menu.AppendAction("Create Placemat",dma=> { evt.menu.AppendAction("Create PlacematData",dma=> {
//find placemat container //find placemat container
PlacematContainer placematContainer = this.Q<PlacematContainer>(); var placematContainer = GetPlacematContainer();
if (placematContainer == null){ var targetPos = this.viewTransform.matrix.inverse.MultiplyPoint(dma.eventInfo.localMousePosition);
placematContainer = new PlacematContainer(this); var dmaPosRect = new Rect(targetPos,new Vector2(500,500));
this.Add(placematContainer); var placemat = placematContainer.CreatePlacemat<PlacematView>(dmaPosRect,1,"Title");
} var placematData = new PlacematData{
var dmaPos = dma.eventInfo.mousePosition+editorPosition; title = "Title",
var dmaPosRect = new Rect(dmaPos,new Vector2(500,500)); positionInView = dmaPosRect
placematContainer.CreatePlacemat<Placemat>(dmaPosRect,1,"Title"); };
placemat.PlacematData = placematData;
AddPlacemat(placematData);
}); });
}); });
} }
private void AddPlacemat(PlacematData data){
_data.EditorModels.Add(data);
}
private PlacematContainer GetPlacematContainer(){
if (this.placematContainer == null){
PlacematContainer container = new PlacematContainer(this){
name = "PlacematContainer"
};
this.Add(container);
}
return this.placematContainer;
}
private void OnInit(){ private void OnInit(){
ConstructDefaultBehaviour(); ConstructDefaultBehaviour();
@ -251,7 +260,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
public virtual void AfterEditorLoadGraphView(){ public virtual void AfterEditorLoadGraphView(){
} }
protected void CreateMenu(){ protected void CreateMenu(){
if (this.Q("TopMenu") != null) return; if (this.Q("TopMenu") != null) return;
var visualElement = new VisualElement{ var visualElement = new VisualElement{
@ -313,6 +322,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
#region event callbakc #region event callbakc
private void OnDragPerform(DragPerformEvent evt){ private void OnDragPerform(DragPerformEvent evt){
var realPos = viewTransform.matrix.inverse.MultiplyPoint(evt.localMousePosition);
if (DragAndDrop.GetGenericData("DragSelection") is List<ISelectable> data){ if (DragAndDrop.GetGenericData("DragSelection") is List<ISelectable> data){
if (data.Count == 0){ if (data.Count == 0){
@ -325,7 +335,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
var dragNodeData = NodeCreator.InstantiateNodeData<BlackboardDragNodeData>(); var dragNodeData = NodeCreator.InstantiateNodeData<BlackboardDragNodeData>();
dragNodeData.BlackboardData = GetBlackboardData(); dragNodeData.BlackboardData = GetBlackboardData();
dragNodeData.BlackDragData = field.BlackboardProperty.PropertyName; dragNodeData.BlackDragData = field.BlackboardProperty.PropertyName;
AddTNode(dragNodeData,new Rect(evt.mousePosition,new Vector2(200,200))); AddTNode(dragNodeData,new Rect(realPos,new Vector2(200,200)));
} }
} }
@ -336,10 +346,9 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
var dragNodeData = NodeCreator.InstantiateNodeData<BlackboardDragNodeData>(); var dragNodeData = NodeCreator.InstantiateNodeData<BlackboardDragNodeData>();
dragNodeData.BlackboardData = GetBlackboardData(); dragNodeData.BlackboardData = GetBlackboardData();
dragNodeData.BlackDragData = entry.propertyPath; dragNodeData.BlackDragData = entry.propertyPath;
AddTNode(dragNodeData,new Rect(evt.mousePosition,new Vector2(200,200))); AddTNode(dragNodeData,new Rect(realPos,new Vector2(200,200)));
} }
} }
} }
} }
@ -354,18 +363,26 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
#endregion #endregion
public void ResetGraphView(){ public void ClearAll(){
//Clear all nodes
foreach (var node in nodes.ToList()){ foreach (var node in nodes.ToList()){
RemoveElement(node); RemoveElement(node);
} }
foreach (var edge in edges.ToList()){ foreach (var edge in edges.ToList()){
RemoveElement(edge); RemoveElement(edge);
} }
foreach (var placemat in placematContainer.Placemats.ToList()){
RemoveElement(placemat);
}
}
public void ResetGraphView(){
ClearAll();
LoadPersistentGraphViewData();
if (_nodeDict == null) throw new ArgumentNullException(nameof(_nodeDict)); if (_nodeDict == null) throw new ArgumentNullException(nameof(_nodeDict));
foreach (var dataNode in _data.NodeDictionary.Values){ foreach (var dataNode in _data.NodeDictionary.Values){
if(dataNode==null) if(dataNode==null)
continue; continue;
@ -400,9 +417,30 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
newEdge.output?.Connect(newEdge); newEdge.output?.Connect(newEdge);
AddElement(newEdge); AddElement(newEdge);
} }
var placemats = _data.EditorModels.OfType<PlacematData>();
foreach (var placemat in placemats){
var container = GetPlacematContainer();
var res = container.CreatePlacemat<PlacematView>(placemat.positionInView, 0, placemat.title);
res.PlacematData = placemat;
}
_nodeDict.Clear(); _nodeDict.Clear();
} }
private void LoadPersistentGraphViewData(){
var r= _data.GraphViewData;
this.viewTransformChanged-=OnViewTransformChanged;
this.UpdateViewTransform(r.persistOffset,new Vector3(r.persistScale,r.persistScale,1));
this.viewTransformChanged+=OnViewTransformChanged;
}
private void OnViewTransformChanged(GraphView graphview){
if (_data == null) return;
_data.GraphViewData.persistOffset = graphview.viewTransform.position;
_data.GraphViewData.persistScale = graphview.viewTransform.scale.x;
}
private void AddPersistentNode(NodeData dataNode){ private void AddPersistentNode(NodeData dataNode){
var nodePos = dataNode.positionInView; var nodePos = dataNode.positionInView;
AddTNode(dataNode, nodePos); AddTNode(dataNode, nodePos);
@ -455,21 +493,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
public void SaveEditorData(GraphEditorData graphEditorData){ public void SaveEditorData(GraphEditorData graphEditorData){
// graphEditorData.graphElementsData?.Clear(); //To do something later
// //iterator nodes
// if (graphEditorData.graphElementsData == null){
// graphEditorData.graphElementsData = new List<GraphElementEditorData>();
// }
// foreach (var node in this.nodes){
// var nodeEditorData = new GraphElementEditorData{
// pos = node.GetPosition(),
// };
// if (node is IBaseNodeView nodeView){
// nodeEditorData.guid = nodeView.GetNodeData().id;
// }
// graphEditorData.graphElementsData.Add(nodeEditorData);
// EditorUtility.SetDirty(graphEditorData);
// }
} }
public void SaveWithEditorData(GraphEditorData graphEditorData){ public void SaveWithEditorData(GraphEditorData graphEditorData){
@ -514,12 +538,24 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
private void SaveGraphData(){ private void SaveGraphData(){
_data.NodeDictionary.Clear(); _data.NodeDictionary.Clear();
_data.NodeLinks.Clear(); _data.NodeLinks.Clear();
_data.EditorModels.Clear();
SaveNode(); SaveNode();
SaveEdge(); SaveEdge();
SaveBlackboard(); SaveBlackboard();
SaveEditorModels();
EditorUtility.SetDirty(_data); EditorUtility.SetDirty(_data);
} }
private void SaveEditorModels(){
var placemats = placematContainer.Placemats.ToList();
Debug.Log(placemats.Count);
foreach (var placemat in placemats){
if (placemat is PlacematView placematView){
_data.EditorModels.Add(placematView.PlacematData);
}
}
}
private void SaveBlackboard(){ private void SaveBlackboard(){
if (_data.blackboardData == null){ if (_data.blackboardData == null){
_data.blackboardData = NodeEditorExtensions.GetAppropriateBlackboardData(_data.GetType()); _data.blackboardData = NodeEditorExtensions.GetAppropriateBlackboardData(_data.GetType());
@ -591,12 +627,16 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
#region implement interfaces #region implement interfaces
/// <summary>
/// Simultaneously add the node to the graph data 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>
public void AddTNode(NodeData nodeData, Rect rect){ public void AddTNode(NodeData nodeData, Rect rect){
if (NodeEditorExtensions.CreateNodeViewFromNodeType(nodeData.GetType()) is Node nodeView){ if (NodeEditorExtensions.CreateNodeViewFromNodeType(nodeData.GetType()) is Node nodeView){
//convert rect at graph space //convert rect at graph space
var resPos = this.viewTransform.matrix.inverse.MultiplyPoint3x4(rect.position); rect.position = rect.position;
rect.position = resPos;
if(nodeView is IBaseNodeView nodeViewInterface){ if(nodeView is IBaseNodeView nodeViewInterface){
nodeViewInterface.SetNodeData(nodeData); nodeViewInterface.SetNodeData(nodeData);
} }
@ -637,6 +677,10 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
} }
/// <summary>
/// Remove node from
/// </summary>
/// <param name="nodeData"></param>
public void RemoveTNode(NodeData nodeData){ public void RemoveTNode(NodeData nodeData){
Undo.RegisterCompleteObjectUndo(_data,"Node deletion"); Undo.RegisterCompleteObjectUndo(_data,"Node deletion");
@ -685,6 +729,9 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
castedBlackboard?.SetPosition(blackboardPos); castedBlackboard?.SetPosition(blackboardPos);
UpdateBlackboardData(); UpdateBlackboardData();
OnDataChanged+= (sender, e) => { UpdateBlackboardData(); }; OnDataChanged+= (sender, e) => { UpdateBlackboardData(); };
if(_data.blackboardData!=null){
_data.GraphViewData.isBlackboardOn = true;
}
} }
public GraphData GetGraphData(){ public GraphData GetGraphData(){

@ -37,7 +37,11 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{
} }
loggerArea.multiline = true; loggerArea.multiline = true;
loggerArea.value = message; loggerArea.value += message;
}
public void LogTexture(Texture2D texture2D){
} }
} }

@ -1,7 +1,44 @@
using UnityEditor.Experimental.GraphView; 
using TNodeCore.Editor.Models;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.TNodeGraphViewImpl.Editor.Placemats{ namespace TNode.TNodeGraphViewImpl.Editor.Placemats{
public class PlacematView:Placemat{ public class PlacematView:Placemat{
public PlacematData PlacematData{
get => _placematData;
set{
_placematData = value;
UpdatePlacematData();
}
}
private PlacematData _placematData;
public int zOrder {get;set;}
public PlacematView(){
var title = this.Q<TextField>();
title.RegisterValueChangedCallback(evt => {
PlacematData.title = title.value;
});
}
public virtual void UpdatePlacematData(){
SetPosition(_placematData.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){
return;
}
_placematData.positionInView = newPos;
}
public virtual void Collapse(){
this.Collapsed = true;
}
} }
} }

@ -16,10 +16,13 @@ namespace TNode.TNodeGraphViewImpl.Editor.Search{
private Type _graphType; private Type _graphType;
private GraphView _graphView; private GraphView _graphView;
private EditorWindow _editor; private EditorWindow _editor;
public void Setup(Type graph,GraphView graphView,EditorWindow editor){ private Vector2 _createLocation;
public void Setup(Type graph,GraphView graphView,EditorWindow editor,Vector2 createLocation=default){
_graphType = graph; _graphType = graph;
_graphView = graphView; _graphView = graphView;
_editor = editor; _editor = editor;
_createLocation = createLocation;
} }
public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context){ public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context){
var nodeDataTypes = NodeEditorExtensions.GetGraphDataUsage(_graphType); var nodeDataTypes = NodeEditorExtensions.GetGraphDataUsage(_graphType);
@ -46,17 +49,23 @@ namespace TNode.TNodeGraphViewImpl.Editor.Search{
} }
return list; return list;
} }
public Vector2 FromScreenToViewPos(VisualElement visualElement,Vector2 screenPos){
var vector = visualElement.worldTransform.inverse.MultiplyVector(screenPos);
return vector;
}
public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context){ public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context){
var userData = SearchTreeEntry.userData; var userData = SearchTreeEntry.userData;
var relativePos = context.screenMousePosition - _editor.position.position;
var localPos = _graphView.WorldToLocal(relativePos);
if (userData is Type type){ if (userData is Type type){
//Check if type is derived from NodeData //Check if type is derived from NodeData
if (typeof(NodeData).IsAssignableFrom(type)){ if (typeof(NodeData).IsAssignableFrom(type)){
//Make an instance of the type //Make an instance of the type
if (NodeCreator.InstantiateNodeData(type) is { } nodeData){ if (NodeCreator.InstantiateNodeData(type) is { } nodeData){
nodeData.nodeName = $"{type.Name}"; nodeData.nodeName = $"{type.Name}";
((IBaseDataGraphView) _graphView).AddTNode(nodeData, new Rect(localPos.x, localPos.y, 100, 100)); ((IBaseDataGraphView) _graphView).AddTNode(nodeData, new Rect(_createLocation.x, _createLocation.y, 100, 100));
} }
} }
return true; return true;

Loading…
Cancel
Save