Add new feature.
Added ILogger; Added IGraphProcessor; Changed return type of OnExecute method in BaseNode from void to bool;
This commit is contained in:
3
Sample/Runtime/Models.meta
Normal file
3
Sample/Runtime/Models.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a05fdef25de94879a769c2dc457bd59e
|
||||
timeCreated: 1730561124
|
||||
35
Sample/Runtime/Models/BackTraceGraphProcessor.cs
Normal file
35
Sample/Runtime/Models/BackTraceGraphProcessor.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Misaki.GraphView.Sample
|
||||
{
|
||||
public class BackTraceGraphProcessor : IGraphProcessor
|
||||
{
|
||||
private bool _isRunning;
|
||||
|
||||
public bool IsRunning => _isRunning;
|
||||
|
||||
public void UpdateComputeOrder()
|
||||
{
|
||||
}
|
||||
|
||||
public void Execute(ReadOnlyCollection<BaseNode> nodes)
|
||||
{
|
||||
_isRunning = true;
|
||||
nodes.ClearAllExecuteFlag();
|
||||
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (node is OutputNode outputNode)
|
||||
{
|
||||
outputNode.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Break()
|
||||
{
|
||||
_isRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Sample/Runtime/Models/BackTraceGraphProcessor.cs.meta
Normal file
3
Sample/Runtime/Models/BackTraceGraphProcessor.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13065a6e26d040a4b3e73e1d66e6cf4f
|
||||
timeCreated: 1730564245
|
||||
30
Sample/Runtime/Models/Logger.cs
Normal file
30
Sample/Runtime/Models/Logger.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Misaki.GraphView.Sample
|
||||
{
|
||||
public class Logger : ILogger
|
||||
{
|
||||
private readonly List<string> _logs = new ();
|
||||
|
||||
public Action<BaseNode, string, LogType> OnLog { get; set; }
|
||||
|
||||
public void LogInfo(BaseNode node, string message)
|
||||
{
|
||||
_logs.Add($"Log Info from node {node.GetType().Name}: {message}");
|
||||
OnLog?.Invoke(node, message, LogType.Info);
|
||||
}
|
||||
|
||||
public void LogWarning(BaseNode node, string message)
|
||||
{
|
||||
_logs.Add($"Log Warning from node {node.GetType().Name}: {message}");
|
||||
OnLog?.Invoke(node, message, LogType.Warning);
|
||||
}
|
||||
|
||||
public void LogError(BaseNode node, string message)
|
||||
{
|
||||
_logs.Add($"Log Error from node {node.GetType().Name}: {message}");
|
||||
OnLog?.Invoke(node, message, LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Sample/Runtime/Models/Logger.cs.meta
Normal file
3
Sample/Runtime/Models/Logger.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da3c5b7d66754f948efd7f895b5a4b21
|
||||
timeCreated: 1730561133
|
||||
@@ -22,9 +22,11 @@ namespace Misaki.GraphView.Sample
|
||||
[NodeOutput]
|
||||
private float _result;
|
||||
|
||||
protected override void OnExecute()
|
||||
protected override bool OnExecute()
|
||||
{
|
||||
_result = a + b;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,11 @@ namespace Misaki.GraphView.Sample
|
||||
[NodeInput]
|
||||
private float _input;
|
||||
|
||||
protected override void OnExecute()
|
||||
protected override bool OnExecute()
|
||||
{
|
||||
Debug.Log(_input);
|
||||
GraphObject.Logger.LogInfo(this, $"{_input}");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,10 @@ namespace Misaki.GraphView.Sample
|
||||
[CreateAssetMenu(fileName = "GraphAsset", menuName = "Scriptable Objects/GraphAsset")]
|
||||
public class SampleGraphAsset : GraphObject
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
Nodes.ClearAllExecuteFlag();
|
||||
|
||||
foreach (var node in Nodes)
|
||||
{
|
||||
if (node is OutputNode outputNode)
|
||||
{
|
||||
outputNode.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
private readonly Logger _logger = new Logger();
|
||||
private readonly BackTraceGraphProcessor _processor = new BackTraceGraphProcessor();
|
||||
|
||||
public override ILogger Logger => _logger;
|
||||
public override IGraphProcessor GraphProcessor => _processor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user