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. 23
      TNode/TNodeCore/Runtime/Models/GraphData.cs
  15. 2
      TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs
  16. 4
      TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs
  17. 141
      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 TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models;
namespace TNode.GraphCreator.Runtime.Nodes{
using TNodeCore.Runtime.Models;
namespace TNode.GraphCreator.Runtime{
[GraphUsage(typeof(MetaGraph))]

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

@ -13,119 +13,166 @@ MonoBehaviour:
m_Name: New HelloGraph
m_EditorClassIdentifier:
nodeList:
- rid: 4804121563801583862
- rid: 4804121563801583947
- rid: 4804121563801583866
- rid: 4804121563801583898
- rid: 4804121563801583870
nodeLinks:
- inPort:
portEntryName: A
nodeDataId: 6ceba867-fe0d-40c3-9d30-2d5d12803b52
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
- id: 0
- id: 1
- id: 2
- id: 3
- id: 4
- id: 5
- id: 6
- id: 7
nodeLinks: []
blackboardData:
rid: 4804121563801583854
id: 8
sceneReference:
editorModels:
- id: 9
graphViewData:
id: 10
references:
version: 2
RefIds:
- rid: 4804121563801583854
type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp}
version: 1
00000000:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 0
y: 0
x: 1944
y: 205
width: 0
height: 0
HelloString: Hello World
HelloGameObject: {fileID: 0}
V3S:
- {x: 0, y: 0, z: 0}
- {x: 0, y: 0, z: 0}
- {x: 0, y: 0, z: 0}
V2S:
- {x: 0, y: 0}
- {x: 0, y: 0}
- {x: 0, y: 0}
- rid: 4804121563801583862
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
id: 74136d91-e634-401b-8c99-3c2bb351cab2
nodeName: AddNode
entryPoint: 0
isTest: 0
00000001:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 336
y: 355
x: 2045
y: 205
width: 0
height: 0
id: bae506a7-58ec-4b79-9c21-747fa2b6a7ba
nodeName:
id: 8bee0814-52ef-4068-bffb-58a786d73ec2
nodeName: AddNode
entryPoint: 0
isTest: 0
blackDragData: HelloString
isListElement: 0
- rid: 4804121563801583866
00000002:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 973.3707
y: 189.23111
x: 2146
y: 205
width: 0
height: 0
id: 6ceba867-fe0d-40c3-9d30-2d5d12803b52
id: 819d1689-d64d-41ca-a9ac-0e00d25806c0
nodeName: AddNode
entryPoint: 0
isTest: 0
- rid: 4804121563801583870
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
00000003:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 748.0001
y: 291
x: 2247
y: 205
width: 0
height: 0
id: b2ab4a52-e65d-4104-8891-dc316af217d9
nodeName:
id: b8495e41-8ec2-4015-8784-7a99c1003c6b
nodeName: AddNode
entryPoint: 0
isTest: 0
blackDragData: V2S.0
isListElement: 1
- rid: 4804121563801583898
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
00000004:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 747
y: 179
x: 2014
y: 340
width: 0
height: 0
id: ac84573e-638d-45fa-b4e2-1a81c31fa9e7
nodeName:
id: 3f27f6fe-b2db-41f2-9b3f-5e5fc468e536
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
isTest: 0
blackDragData: V3S.0
isListElement: 1
- rid: 4804121563801583947
00000006:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
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}
data:
positionInView:
serializedVersion: 2
x: 299
y: 313
x: 1944.9998
y: 475.8858
width: 0
height: 0
id: b8c1e42e-c6a3-491e-aba2-c2b6ebd1c419
id: 2f9adf6b-b40b-4fbd-9bd6-0d1ebb10992f
nodeName:
entryPoint: 0
isTest: 0
blackDragData: HelloGameObject
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{
public interface IBlackboardView{
public BlackboardData GetBlackboardData();
public void SetBlackboardData(BlackboardData data);
BlackboardData GetBlackboardData();
void SetBlackboardData(BlackboardData data);
public void AddItem();
void AddItem();
void Setup(IBaseDataGraphView graphView,EditorWindow ownerWindow);
void NotifyUpdate();
}
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{
public interface IGraphViewPersistence{
public string GetPersistenceId();
public void ResetPos(GraphEditorData editorData);
public void SavePos(GraphEditorData editorData);
string GetPersistenceId();
void ResetPos(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{
public interface INodeDataBindingBase{
public string BindingPath{ get; set; }
string BindingPath{ get; set; }
public NodeData BindingNodeData{ get; set; }
}
}

@ -1,8 +1,10 @@
using TNodeCore.Runtime.Models;
using System;
using TNodeCore.Runtime.Models;
using UnityEngine;
namespace TNodeCore.Editor.Models{
//This models are editor only
[Serializable]
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{
[Serializable]
public class Placemat:EditorModel{
public class PlacematData:EditorModel{
[SerializeReference]
public List<Model> hostModels = new List<Model>();
public int zOrder;
public string title;
}
}

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

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using TNode.TNodeCore.Editor.Models;
using TNodeCore.Editor.Models;
using UnityEditor;
using UnityEngine;
@ -44,9 +45,27 @@ namespace TNodeCore.Runtime.Models{
}
#if UNITY_EDITOR
[SerializeReference] public List<EditorModel> EditorModels = new List<EditorModel>();
[SerializeReference]
protected List<EditorModel> editorModels ;
[SerializeReference]
protected GraphViewData graphViewData;
#endif
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.Runtime.Attributes;
using TNodeCore.Runtime.Models;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
@ -278,7 +277,6 @@ namespace TNode.TNodeGraphViewImpl.Editor.Cache{
public class Launcher{
static Launcher(){
Debug.Log("NES Launched");
NodeEditorSingleton.Instance.Initialize();
}
}

@ -1,12 +1,12 @@
using System;
using System.Collections;
using System.Linq;
using System.Reflection;
using TNode.TNodeGraphViewImpl.Editor.Search;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Serialization;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models;
using Unity.VisualScripting;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEditor.UIElements;
@ -34,7 +34,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
Add(blackboardGlobalSection);
foreach (var field in data.GetType()
.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
//skip if the field is a list or Ilist
if (!typeof(IList).IsAssignableFrom(field.FieldType)&&!field.FieldType.IsArray){

@ -3,14 +3,17 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using TNode.TNodeCore.Editor.Models;
using TNode.TNodeGraphViewImpl.Editor.Cache;
using TNode.TNodeGraphViewImpl.Editor.GraphBlackboard;
using TNode.TNodeGraphViewImpl.Editor.Inspector;
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;
@ -39,6 +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;
public T Data{
get{ return _data; }
set{
@ -107,7 +111,6 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
}
else{
if (obj is GameObject gameObject){
if (gameObject.GetComponent<RuntimeGraph>() != null){
if (gameObject.GetComponent<RuntimeGraph>().graphData != null){
_runtimeGraph = gameObject.GetComponent<RuntimeGraph>();
@ -167,19 +170,6 @@ 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(){
if(Data == null){
@ -201,24 +191,43 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
var dmaPos = dma.eventInfo.mousePosition+editorPosition;
SearchWindowContext searchWindowContext = new SearchWindowContext(dmaPos,200,200);
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);
});
evt.menu.AppendAction("Create Placemat",dma=> {
evt.menu.AppendAction("Create PlacematData",dma=> {
//find placemat container
PlacematContainer placematContainer = this.Q<PlacematContainer>();
if (placematContainer == null){
placematContainer = new PlacematContainer(this);
this.Add(placematContainer);
}
var dmaPos = dma.eventInfo.mousePosition+editorPosition;
var dmaPosRect = new Rect(dmaPos,new Vector2(500,500));
placematContainer.CreatePlacemat<Placemat>(dmaPosRect,1,"Title");
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{
title = "Title",
positionInView = dmaPosRect
};
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(){
ConstructDefaultBehaviour();
@ -313,6 +322,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
#region event callbakc
private void OnDragPerform(DragPerformEvent evt){
var realPos = viewTransform.matrix.inverse.MultiplyPoint(evt.localMousePosition);
if (DragAndDrop.GetGenericData("DragSelection") is List<ISelectable> data){
if (data.Count == 0){
@ -325,7 +335,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
var dragNodeData = NodeCreator.InstantiateNodeData<BlackboardDragNodeData>();
dragNodeData.BlackboardData = GetBlackboardData();
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,11 +346,10 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
var dragNodeData = NodeCreator.InstantiateNodeData<BlackboardDragNodeData>();
dragNodeData.BlackboardData = GetBlackboardData();
dragNodeData.BlackDragData = entry.propertyPath;
AddTNode(dragNodeData,new Rect(evt.mousePosition,new Vector2(200,200)));
AddTNode(dragNodeData,new Rect(realPos,new Vector2(200,200)));
}
}
}
}
@ -355,15 +364,23 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
}
#endregion
public void ResetGraphView(){
//Clear all nodes
public void ClearAll(){
foreach (var node in nodes.ToList()){
RemoveElement(node);
}
foreach (var edge in edges.ToList()){
RemoveElement(edge);
}
foreach (var placemat in placematContainer.Placemats.ToList()){
RemoveElement(placemat);
}
}
public void ResetGraphView(){
ClearAll();
LoadPersistentGraphViewData();
if (_nodeDict == null) throw new ArgumentNullException(nameof(_nodeDict));
foreach (var dataNode in _data.NodeDictionary.Values){
@ -400,9 +417,30 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
newEdge.output?.Connect(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();
}
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){
var nodePos = dataNode.positionInView;
AddTNode(dataNode, nodePos);
@ -455,21 +493,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
}
public void SaveEditorData(GraphEditorData graphEditorData){
// graphEditorData.graphElementsData?.Clear();
// //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);
// }
//To do something later
}
public void SaveWithEditorData(GraphEditorData graphEditorData){
@ -514,12 +538,24 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
private void SaveGraphData(){
_data.NodeDictionary.Clear();
_data.NodeLinks.Clear();
_data.EditorModels.Clear();
SaveNode();
SaveEdge();
SaveBlackboard();
SaveEditorModels();
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(){
if (_data.blackboardData == null){
_data.blackboardData = NodeEditorExtensions.GetAppropriateBlackboardData(_data.GetType());
@ -591,12 +627,16 @@ 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
/// </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){
if (NodeEditorExtensions.CreateNodeViewFromNodeType(nodeData.GetType()) is Node nodeView){
//convert rect at graph space
var resPos = this.viewTransform.matrix.inverse.MultiplyPoint3x4(rect.position);
rect.position = resPos;
rect.position = rect.position;
if(nodeView is IBaseNodeView nodeViewInterface){
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){
Undo.RegisterCompleteObjectUndo(_data,"Node deletion");
@ -685,6 +729,9 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
castedBlackboard?.SetPosition(blackboardPos);
UpdateBlackboardData();
OnDataChanged+= (sender, e) => { UpdateBlackboardData(); };
if(_data.blackboardData!=null){
_data.GraphViewData.isBlackboardOn = true;
}
}
public GraphData GetGraphData(){

@ -37,7 +37,11 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{
}
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{
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 GraphView _graphView;
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;
_graphView = graphView;
_editor = editor;
_createLocation = createLocation;
}
public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context){
var nodeDataTypes = NodeEditorExtensions.GetGraphDataUsage(_graphType);
@ -46,17 +49,23 @@ namespace TNode.TNodeGraphViewImpl.Editor.Search{
}
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){
var userData = SearchTreeEntry.userData;
var relativePos = context.screenMousePosition - _editor.position.position;
var localPos = _graphView.WorldToLocal(relativePos);
if (userData is Type type){
//Check if type is derived from NodeData
if (typeof(NodeData).IsAssignableFrom(type)){
//Make an instance of the type
if (NodeCreator.InstantiateNodeData(type) is { } nodeData){
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;

Loading…
Cancel
Save