From 07384a387b84ee36b92a14e4db6080d7afe9f4b7 Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Tue, 9 Aug 2022 19:09:27 +0800 Subject: [PATCH] feature:start building comment block --- TNode/Samples/New HelloGraph.asset | 147 +++++------------- TNode/Samples/New HelloGraph.asset.meta | 2 +- TNode/TNodeCore/Editor/Binding.meta | 3 + .../TNodeCore/Editor/Binding/IModelBinding.cs | 7 + .../Editor/Binding/IModelBinding.cs.meta | 3 + TNode/TNodeCore/Editor/CommentView.meta | 3 + .../Editor/CommentView/CommentView.cs | 29 ++++ .../Editor/CommentView/CommentView.cs.meta | 3 + TNode/TNodeCore/Editor/Models/Comment.cs | 8 + TNode/TNodeCore/Editor/Models/Comment.cs.meta | 3 + TNode/TNodeCore/Runtime/Models/Model.cs | 9 +- TNode/TNodeCore/Runtime/Models/NodeData.cs | 3 +- .../DefaultGraphBlackboardView.cs | 4 +- .../Editor/NodeGraphView/DataGraphView.cs | 22 ++- 14 files changed, 129 insertions(+), 117 deletions(-) create mode 100644 TNode/TNodeCore/Editor/Binding.meta create mode 100644 TNode/TNodeCore/Editor/Binding/IModelBinding.cs create mode 100644 TNode/TNodeCore/Editor/Binding/IModelBinding.cs.meta create mode 100644 TNode/TNodeCore/Editor/CommentView.meta create mode 100644 TNode/TNodeCore/Editor/CommentView/CommentView.cs create mode 100644 TNode/TNodeCore/Editor/CommentView/CommentView.cs.meta create mode 100644 TNode/TNodeCore/Editor/Models/Comment.cs create mode 100644 TNode/TNodeCore/Editor/Models/Comment.cs.meta diff --git a/TNode/Samples/New HelloGraph.asset b/TNode/Samples/New HelloGraph.asset index bf972ef..3d9051f 100644 --- a/TNode/Samples/New HelloGraph.asset +++ b/TNode/Samples/New HelloGraph.asset @@ -16,128 +16,71 @@ MonoBehaviour: - id: 0 - id: 1 - id: 2 - - id: 3 - - id: 4 - - id: 5 - - id: 6 - - id: 7 - nodeLinks: [] + nodeLinks: + - inPort: + portEntryName: A + nodeDataId: 3e72627f-af97-4056-b89c-04d4f2f127f5 + outPort: + portEntryName: Value + nodeDataId: 4414d05b-da96-465e-a593-2e3dcfceaf23 + - inPort: + portEntryName: B + nodeDataId: 3e72627f-af97-4056-b89c-04d4f2f127f5 + outPort: + portEntryName: Value + nodeDataId: 1a4fd419-5584-4d43-a8c3-bebcad63a337 blackboardData: - id: 8 + id: 3 sceneReference: - editorModels: - - id: 9 - graphViewData: - id: 10 + editorModels: [] + graphViewModel: + id: 4 references: version: 1 00000000: - type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} + type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly} data: positionInView: serializedVersion: 2 - x: 1944 - y: 205 + x: 297 + y: 280 width: 0 height: 0 - id: 74136d91-e634-401b-8c99-3c2bb351cab2 - nodeName: AddNode + id: 4414d05b-da96-465e-a593-2e3dcfceaf23 + nodeName: entryPoint: 0 isTest: 0 + blackDragData: V3S.0 + isListElement: 1 00000001: type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} data: positionInView: serializedVersion: 2 - x: 2045 - y: 205 + x: 454 + y: 280 width: 0 height: 0 - id: 8bee0814-52ef-4068-bffb-58a786d73ec2 + id: 3e72627f-af97-4056-b89c-04d4f2f127f5 nodeName: AddNode entryPoint: 0 isTest: 0 00000002: - type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} - data: - positionInView: - serializedVersion: 2 - x: 2146 - y: 205 - width: 0 - height: 0 - id: 819d1689-d64d-41ca-a9ac-0e00d25806c0 - nodeName: AddNode - entryPoint: 0 - isTest: 0 - 00000003: - type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} - data: - positionInView: - serializedVersion: 2 - x: 2247 - y: 205 - width: 0 - height: 0 - id: b8495e41-8ec2-4015-8784-7a99c1003c6b - nodeName: AddNode - entryPoint: 0 - isTest: 0 - 00000004: - type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} - data: - positionInView: - serializedVersion: 2 - x: 2014 - y: 340 - width: 0 - height: 0 - 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 - 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: 1944.9998 - y: 475.8858 + x: 225 + y: 382 width: 0 height: 0 - id: 2f9adf6b-b40b-4fbd-9bd6-0d1ebb10992f + id: 1a4fd419-5584-4d43-a8c3-bebcad63a337 nodeName: entryPoint: 0 isTest: 0 - blackDragData: HelloGameObject - isListElement: 0 - 00000008: + blackDragData: V2S.0 + isListElement: 1 + 00000003: type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp} data: positionInView: @@ -146,26 +89,14 @@ MonoBehaviour: y: 0 width: 0 height: 0 - HelloString: hello - HelloGameObject: {fileID: 3675195758153116951, guid: 35a9f7ccd0ed7d744b85580016a0aab5, type: 3} + HelloString: + HelloGameObject: {fileID: 0} 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} + 00000004: + type: {class: GraphViewModel, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly} data: positionInView: serializedVersion: 2 @@ -173,6 +104,6 @@ MonoBehaviour: y: 0 width: 0 height: 0 - persistScale: 0.8695652 - persistOffset: {x: -878, y: -29} + persistScale: 0.57175326 + persistOffset: {x: 343, y: 15} isBlackboardOn: 1 diff --git a/TNode/Samples/New HelloGraph.asset.meta b/TNode/Samples/New HelloGraph.asset.meta index e631b0a..7a32317 100644 --- a/TNode/Samples/New HelloGraph.asset.meta +++ b/TNode/Samples/New HelloGraph.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 490933fc590be444780d73cd9f777ed4 +guid: f55ebad0b05015a4f873ac78896d95d3 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/TNode/TNodeCore/Editor/Binding.meta b/TNode/TNodeCore/Editor/Binding.meta new file mode 100644 index 0000000..2ffcc8b --- /dev/null +++ b/TNode/TNodeCore/Editor/Binding.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 919363d9cb9c43a1a14fb12abc76a53b +timeCreated: 1660042822 \ No newline at end of file diff --git a/TNode/TNodeCore/Editor/Binding/IModelBinding.cs b/TNode/TNodeCore/Editor/Binding/IModelBinding.cs new file mode 100644 index 0000000..90527cd --- /dev/null +++ b/TNode/TNodeCore/Editor/Binding/IModelBinding.cs @@ -0,0 +1,7 @@ +namespace TNode.TNodeCore.Editor.Binding{ + public interface IModelBinding{ + public T Data{ get; } + public void Bind(T data); + public void OnChange(); + } +} \ No newline at end of file diff --git a/TNode/TNodeCore/Editor/Binding/IModelBinding.cs.meta b/TNode/TNodeCore/Editor/Binding/IModelBinding.cs.meta new file mode 100644 index 0000000..a15bdb6 --- /dev/null +++ b/TNode/TNodeCore/Editor/Binding/IModelBinding.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c25080540d844798a8c71e2b8feadf93 +timeCreated: 1660042832 \ No newline at end of file diff --git a/TNode/TNodeCore/Editor/CommentView.meta b/TNode/TNodeCore/Editor/CommentView.meta new file mode 100644 index 0000000..d18e2bf --- /dev/null +++ b/TNode/TNodeCore/Editor/CommentView.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a5166d364fc64b82bce9580b4411c83e +timeCreated: 1660042541 \ No newline at end of file diff --git a/TNode/TNodeCore/Editor/CommentView/CommentView.cs b/TNode/TNodeCore/Editor/CommentView/CommentView.cs new file mode 100644 index 0000000..a9a9a9a --- /dev/null +++ b/TNode/TNodeCore/Editor/CommentView/CommentView.cs @@ -0,0 +1,29 @@ +using TNode.TNodeCore.Editor.Binding; +using TNode.TNodeCore.Editor.Models; +using UnityEditor.Experimental.GraphView; +using UnityEngine.UIElements; + +namespace TNode.TNodeCore.Editor.CommentView{ + public class CommentView:GraphElement,IModelBinding{ + public Comment Data => _data; + private Comment _data; + public void Bind(Comment data){ + _data = data; + OnChange(); + } + + public CommentView(){ + var txtField = new TextField(); + this.Add(txtField); + txtField.RegisterValueChangedCallback(evt => { + if (_data != null){ + _data.CommentText = evt.newValue; + } + }); + } + public void OnChange(){ + var str = this._data.CommentText; + this.Q().value = str; + } + } +} \ No newline at end of file diff --git a/TNode/TNodeCore/Editor/CommentView/CommentView.cs.meta b/TNode/TNodeCore/Editor/CommentView/CommentView.cs.meta new file mode 100644 index 0000000..a7e079d --- /dev/null +++ b/TNode/TNodeCore/Editor/CommentView/CommentView.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e0f3542295fd4138967335f3ce44b5f2 +timeCreated: 1660042529 \ No newline at end of file diff --git a/TNode/TNodeCore/Editor/Models/Comment.cs b/TNode/TNodeCore/Editor/Models/Comment.cs new file mode 100644 index 0000000..c0b6854 --- /dev/null +++ b/TNode/TNodeCore/Editor/Models/Comment.cs @@ -0,0 +1,8 @@ +using TNodeCore.Runtime.Models; + +namespace TNode.TNodeCore.Editor.Models{ + public class Comment:EditorModel{ + public Model CommentedModel; + public string CommentText; + } +} \ No newline at end of file diff --git a/TNode/TNodeCore/Editor/Models/Comment.cs.meta b/TNode/TNodeCore/Editor/Models/Comment.cs.meta new file mode 100644 index 0000000..be2bc3c --- /dev/null +++ b/TNode/TNodeCore/Editor/Models/Comment.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a7a79224e74245789ccaa833d12b833d +timeCreated: 1660041914 \ No newline at end of file diff --git a/TNode/TNodeCore/Runtime/Models/Model.cs b/TNode/TNodeCore/Runtime/Models/Model.cs index 6571aa0..429daa8 100644 --- a/TNode/TNodeCore/Runtime/Models/Model.cs +++ b/TNode/TNodeCore/Runtime/Models/Model.cs @@ -10,10 +10,17 @@ namespace TNodeCore.Runtime.Models{ [HideInBlackboard] public Rect positionInView; #endif - + [DisableOnInspector] + public string id; + [NonSerialized] + private int _fastAccessId=0; public object Clone(){ var memberwiseClone = this.MemberwiseClone(); return memberwiseClone; } + /// + /// Record and map the node by a string is cost.converted it to an integer to speed the process. + /// + public int FastAccessId => _fastAccessId==0?_fastAccessId=GetHashCode():_fastAccessId; } } \ No newline at end of file diff --git a/TNode/TNodeCore/Runtime/Models/NodeData.cs b/TNode/TNodeCore/Runtime/Models/NodeData.cs index f685a13..f286180 100644 --- a/TNode/TNodeCore/Runtime/Models/NodeData.cs +++ b/TNode/TNodeCore/Runtime/Models/NodeData.cs @@ -18,8 +18,7 @@ namespace TNodeCore.Runtime.Models{ //Object Registration } - [DisableOnInspector] - public string id; + public string nodeName; public bool entryPoint; diff --git a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs index 6f5a3f2..ed707bb 100644 --- a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs @@ -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("model"); + var property = serializedObject.FindProperty("data"); 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("model").FindPropertyRelative(field.Name), + new GraphBlackboardPropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name), isRuntimeGraph); drawer.Bind(serializedObject); foldoutData.Add(drawer); diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index 93462a0..fcf6b38 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -211,9 +211,26 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ AddPlacemat(placematData); }); + if (this.selection.Any()){ + evt.menu.AppendAction("Comment", dma => { + BuildCommentForSelected(); + }); + evt.menu.AppendAction("Delete", dma => { + DeleteSelected(); + }); + + } }); } + private void BuildCommentForSelected(){ + throw new NotImplementedException(); + } + + private void DeleteSelected(){ + throw new NotImplementedException(); + } + private void AddPlacemat(PlacematModel model){ _data.EditorModels.Add(model); } @@ -294,7 +311,9 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ text = "Run Once" }; runButton.RegisterCallback(evt => { + Debug.Log(IsRuntimeGraph); if (IsRuntimeGraph){ + _runtimeGraph.TraverseAll(); AfterGraphResolved?.Invoke(); } @@ -379,10 +398,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ ClearAll(); LoadPersistentGraphViewData(); - - if (_nodeDict == null) throw new ArgumentNullException(nameof(_nodeDict)); - foreach (var dataNode in _data.NodeDictionary.Values){ if(dataNode==null) continue;