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

feature: on progress,try to add blackboard support
main
taoria 3 years ago committed by GitHub
commit 239f6b2ba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      README.md
  2. 4
      TNode/Samples/HelloBlackboard.cs
  3. 37
      TNode/Samples/New HelloGraph.asset
  4. 3
      TNode/TNodeCore/Placemat.meta
  5. 8
      TNode/TNodeCore/Placemat/IPlacemat.cs
  6. 3
      TNode/TNodeCore/Placemat/IPlacemat.cs.meta
  7. 12
      TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs
  8. 1
      TNode/TNodeCore/Runtime/DataWrapper.cs
  9. 3
      TNode/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs
  10. 30
      TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
  11. 9
      TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs

@ -15,7 +15,7 @@ the main goal of the repo is to make graph creation easier and more intuitive.
# Some to-dos
* Port connectivity of two types have implicit conversion
* Node placement
* Node placemat
* Vertical node
* A universal merger handle multiple input
* Support static graph data traversal

@ -8,8 +8,8 @@ using UnityEngine;
namespace TNode.Samples{
[GraphUsage(typeof(HelloGraph))]
public class HelloBlackboard:BlackboardData{
public string HelloString = "Hello World";
public string HelloString;
public GameObject HelloGameObject;
public List<Vector3> V3S;
public List<Vector2> V2S;

@ -14,9 +14,10 @@ MonoBehaviour:
m_EditorClassIdentifier:
nodeList:
- rid: 4804121563801583862
- rid: 4804121563801583947
- rid: 4804121563801583866
- rid: 4804121563801583898
- rid: 4804121563801583870
- rid: 4804121563801583866
nodeLinks:
- inPort:
portEntryName: A
@ -25,7 +26,7 @@ MonoBehaviour:
portEntryName: Value
nodeDataId: ac84573e-638d-45fa-b4e2-1a81c31fa9e7
- inPort:
portEntryName: B
portEntryName: A
nodeDataId: 6ceba867-fe0d-40c3-9d30-2d5d12803b52
outPort:
portEntryName: Value
@ -46,6 +47,7 @@ MonoBehaviour:
width: 0
height: 0
HelloString: Hello World
HelloGameObject: {fileID: 0}
V3S:
- {x: 0, y: 0, z: 0}
- {x: 0, y: 0, z: 0}
@ -59,8 +61,8 @@ MonoBehaviour:
data:
positionInView:
serializedVersion: 2
x: 256
y: 264
x: 336
y: 355
width: 0
height: 0
id: bae506a7-58ec-4b79-9c21-747fa2b6a7ba
@ -74,8 +76,8 @@ MonoBehaviour:
data:
positionInView:
serializedVersion: 2
x: 620
y: 234
x: 1021.58136
y: 228.81656
width: 0
height: 0
id: 6ceba867-fe0d-40c3-9d30-2d5d12803b52
@ -87,8 +89,8 @@ MonoBehaviour:
data:
positionInView:
serializedVersion: 2
x: 469.00006
y: 336
x: 758.5814
y: 309.81662
width: 0
height: 0
id: b2ab4a52-e65d-4104-8891-dc316af217d9
@ -102,8 +104,8 @@ MonoBehaviour:
data:
positionInView:
serializedVersion: 2
x: 469
y: 213
x: 758.5814
y: 195.81656
width: 0
height: 0
id: ac84573e-638d-45fa-b4e2-1a81c31fa9e7
@ -112,3 +114,18 @@ MonoBehaviour:
isTest: 0
blackDragData: V3S.0
isListElement: 1
- rid: 4804121563801583947
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
x: 299
y: 313
width: 0
height: 0
id: b8c1e42e-c6a3-491e-aba2-c2b6ebd1c419
nodeName:
entryPoint: 0
isTest: 0
blackDragData: HelloGameObject
isListElement: 0

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6dbc9136434544f1b339c618729e0422
timeCreated: 1659774798

@ -0,0 +1,8 @@
using System.Collections.Generic;
using TNodeCore.Runtime.Models;
namespace TNodeCore.Placemat{
public interface IPlacemat{
public List<Model> HoldModels{get;set;}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5e52755cad2a44d3bc705de2bbbca544
timeCreated: 1659774811

@ -253,7 +253,7 @@ namespace TNodeCore.Runtime.Components{
_graphTool.RunNodeDependently(Get(startNode));
return true;
}
public bool ResolveDependency(){
public bool TraverseAll(){
if(!_build)
Build();
if (_graphTool == null)
@ -342,6 +342,16 @@ namespace TNodeCore.Runtime.Components{
if(isCaching)
_graphTool.EndCachingPort();
}
public void RunNodesOfType<T>(bool isCaching= false){
var nodes = GetRuntimeNodesOfType<T>();
if(isCaching)
_graphTool.StartCachingPort();
foreach (var runtimeNode in nodes){
RunOnDependency(runtimeNode.NodeData);
}
if(isCaching)
_graphTool.EndCachingPort();
}
/// <summary>
/// Run some nodes ,if the node is not in the graph ,then pass

@ -5,6 +5,7 @@ using UnityEngine;
namespace TNodeCore.Runtime{
[Serializable]
public class DataWrapper<TWrapper,TData>:ScriptableObject where TWrapper:DataWrapper<TWrapper,TData>,new(){
public const string DataPath = "data";
[SerializeReference]
public TData data;
protected static readonly Dictionary<TData,TWrapper> Cache = new ();

@ -209,12 +209,15 @@ namespace TNodeCore.Runtime.RuntimeCache{
//This inner cache method would only run once,so add a guard to prevent it run again,even though the function itself has a guard statement.
if(HasImplicitConversion(from,to)){
CachingImplicitConversion(from,to);
return CachedPortConverters[from][to].Convert(value);
}
return value;
}
if(!CachedPortConverters[from].ContainsKey(to)){
//Just like above, this function should be checked in here too
if(HasImplicitConversion(from,to)){
CachingImplicitConversion(from,to);
return CachedPortConverters[from][to].Convert(value);
}
return value;
}

@ -161,7 +161,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
await Task.Delay(TimeSpan.FromSeconds(RefreshRate));
if(_runtimeGraph != null){
if (AutoUpdate){
_runtimeGraph.ResolveDependency();
_runtimeGraph.TraverseAll();
AfterGraphResolved?.Invoke();
}
}
@ -171,7 +171,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
// if(_runtimeGraph != null){
// if (_runtimeGraphUpdate){
// _runtimeGraphUpdate = false;
// _runtimeGraph.ResolveDependency();
// _runtimeGraph.TraverseAll();
//
// AfterGraphResolved?.Invoke();
// }
@ -204,6 +204,30 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
searchWindow.Setup(typeof(T),this,Owner);
SearchWindow.Open(searchWindowContext, searchWindow);
});
evt.menu.AppendAction("Create Placemat",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");
// Placemat placemat = new Placemat{
// Collapsed = false,
// title = "Placemat",
// visible = true
// };
// placemat.style.minWidth = 500;
// placemat.style.minHeight = 500;
// var dmaPos = dma.eventInfo.mousePosition+editorPosition;
// placemat.SetPosition(new Rect(dmaPos,new Vector2(500,500)));
// AddElement(placemat);
// Debug.Log(placemat);
});
});
}
@ -274,7 +298,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
};
runButton.RegisterCallback<ClickEvent>(evt => {
if (IsRuntimeGraph){
_runtimeGraph.ResolveDependency();
_runtimeGraph.TraverseAll();
AfterGraphResolved?.Invoke();
}
});

@ -25,10 +25,12 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{
SerializedProperty serializedProperty = null;
if (arrayElement){
var part = obj.BlackDragData.Split('.');
serializedProperty = serializedData.FindProperty("data").FindPropertyRelative(part[0]).GetArrayElementAtIndex(int.Parse(part[1]));
serializedProperty = serializedData.FindProperty(BlackboardDataWrapper.DataPath)
.FindPropertyRelative(part[0])
.GetArrayElementAtIndex(int.Parse(part[1]));
}
else{
serializedProperty = serializedData.FindProperty("data").FindPropertyRelative(obj.BlackDragData);
serializedProperty = serializedData.FindProperty(BlackboardDataWrapper.DataPath).FindPropertyRelative(obj.BlackDragData);
}
label.text = ObjectNames.NicifyVariableName(obj.BlackDragData);
//Get serialized property's icon
@ -38,6 +40,9 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{
icon = AssetPreview.GetMiniThumbnail(value);
}
else{
if (serializedProperty.boxedValue == null){
return;
}
icon = AssetPreview.GetMiniTypeThumbnail(serializedProperty.boxedValue.GetType());
}

Loading…
Cancel
Save