Skip to content

Commit

Permalink
Add flow support for R3
Browse files Browse the repository at this point in the history
  • Loading branch information
AkiKurisu committed Feb 4, 2025
1 parent 068227a commit adffd60
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 16 deletions.
7 changes: 4 additions & 3 deletions Editor/Core/UIElements/Graph/CeresBlackboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,13 @@ private static bool IsSupportSerializedType(Type type)
return true;
}

if (Attribute.IsDefined(type, typeof(SerializableAttribute), false))
if (Attribute.IsDefined(type, typeof(SerializableAttribute), true))
{
return true;
}

return false;

/* Non-serializable type only visible when assigned where only in the case user want to use it */
return CeresPort.GetAssignedPortValueTypes().Contains(type);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Editor/Core/UIElements/Graph/Ports/CeresPortView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public void OnDropOutsidePort(Edge edge, Vector2 position)
Event.current.mousePosition
);

if (edge.output != null)
if (edge.output?.edgeConnector.edgeDragHelper.draggedPort != null)
{
GraphView.OpenSearch(
screenPosition,
((CeresPortElement)edge.output.edgeConnector.edgeDragHelper.draggedPort).View
);
}
else if (edge.input != null)
else if (edge.input?.edgeConnector.edgeDragHelper.draggedPort != null)
{
GraphView.OpenSearch(
screenPosition,
Expand Down
12 changes: 12 additions & 0 deletions Runtime/Core/Models/CeresAPI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;
using Debug = UnityEngine.Debug;

namespace Ceres
{
/// <summary>
Expand Down Expand Up @@ -43,24 +47,32 @@ public static LogLevelAutoScope LogScope(LogType logLevel)
return new LogLevelAutoScope(logLevel);
}

[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogWarning(string message)
{
if(LogLevel >= LogType.Warning)
Debug.LogWarning($"<color=#fcbe03>[Ceres]</color> {message}");
}

[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Log(string message)
{
if(LogLevel >= LogType.Log)
Debug.Log($"<color=#3aff48>[Ceres]</color> {message}");
}

[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogError(string message)
{
if(LogLevel >= LogType.Error)
Debug.LogError($"<color=#ff2f2f>[Ceres]</color> {message}");
}

[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Assert(bool condition, string message)
{
if (LogLevel >= LogType.Assert)
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Flow/Models/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ExecutionContext: IDisposable

private CancellationToken? _cancellationToken;

private ExecutionContext()
protected ExecutionContext()
{

}
Expand Down
14 changes: 7 additions & 7 deletions Runtime/Flow/Models/Nodes/Core/ExecutionEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public sealed class ExecutionEventUber: ExecutableEvent, ISerializationCallbackR

protected override UniTask Execute(ExecutionContext executionContext)
{
Assert.IsTrue(executionContext.GetEvent() != null);
Assert.IsNotNull(executionContext.GetEvent());
var evt = executionContext.GetEventT<ExecuteFlowEvent>();
if(evt.Args != null)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public class ExecutionEvent<T1> : ExecutionEventGeneric

protected override UniTask Execute(ExecutionContext executionContext)
{
Assert.IsTrue(executionContext.GetEvent() != null);
Assert.IsNotNull(executionContext.GetEvent());
var evt = executionContext.GetEventT<ExecuteFlowEvent<T1>>();
output1.Value = evt.Arg1;
executionContext.SetNext(exec.GetT<ExecutableNode>());
Expand All @@ -123,7 +123,7 @@ public class ExecutionEvent<T1, T2> : ExecutionEventGeneric

protected override UniTask Execute(ExecutionContext executionContext)
{
Assert.IsTrue(executionContext.GetEvent() != null);
Assert.IsNotNull(executionContext.GetEvent());
var evt = executionContext.GetEventT<ExecuteFlowEvent<T1, T2>>();
output1.Value = evt.Arg1;
output2.Value = evt.Arg2;
Expand All @@ -150,7 +150,7 @@ public class ExecutionEvent<T1, T2, T3> : ExecutionEventGeneric

protected override UniTask Execute(ExecutionContext executionContext)
{
Assert.IsTrue(executionContext.GetEvent() != null);
Assert.IsNotNull(executionContext.GetEvent());
var evt = executionContext.GetEventT<ExecuteFlowEvent<T1, T2, T3>>();
output1.Value = evt.Arg1;
output2.Value = evt.Arg2;
Expand Down Expand Up @@ -181,7 +181,7 @@ public class ExecutionEvent<T1, T2, T3, T4> : ExecutionEventGeneric

protected override UniTask Execute(ExecutionContext executionContext)
{
Assert.IsTrue(executionContext.GetEvent() != null);
Assert.IsNotNull(executionContext.GetEvent());
var evt = executionContext.GetEventT<ExecuteFlowEvent<T1, T2, T3, T4>>();
output1.Value = evt.Arg1;
output2.Value = evt.Arg2;
Expand Down Expand Up @@ -216,7 +216,7 @@ public class ExecutionEvent<T1, T2, T3, T4, T5> : ExecutionEventGeneric

protected override UniTask Execute(ExecutionContext executionContext)
{
Assert.IsTrue(executionContext.GetEvent() != null);
Assert.IsNotNull(executionContext.GetEvent());
var evt = executionContext.GetEventT<ExecuteFlowEvent<T1, T2, T3, T4, T5>>();
output1.Value = evt.Arg1;
output2.Value = evt.Arg2;
Expand Down Expand Up @@ -255,7 +255,7 @@ public class ExecutionEvent<T1, T2, T3, T4, T5, T6> : ExecutionEventGeneric

protected override UniTask Execute(ExecutionContext executionContext)
{
Assert.IsTrue(executionContext.GetEvent() != null);
Assert.IsNotNull(executionContext.GetEvent());
var evt = executionContext.GetEventT<ExecuteFlowEvent<T1, T2, T3, T4, T5, T6>>();
output1.Value = evt.Arg1;
output2.Value = evt.Arg2;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Ceres.Annotations;
using R3;

namespace Ceres.Graph.Flow.Utilities
{
[Serializable]
[CeresGroup("Utilities/Rx")]
[CeresLabel("Subscribe")]
public class FlowNode_ObservableSubscribeT<T>: FlowNode
{
[InputPort, HideInGraphEditor]
public CeresPort<Observable<T>> subject;

[InputPort]
public DelegatePort<EventDelegate<T>> onNext;

[OutputPort]
public CeresPort<IDisposable> subscription;

protected override void LocalExecute(ExecutionContext executionContext)
{
subscription.Value = subject.Value.Subscribe(onNext.Value);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Linq;
using Ceres.Graph;

namespace Ceres.Flow.Models.Nodes.Utilities.Templates
namespace Ceres.Graph.Flow.Utilities.Templates
{
public class FlowNode_MakeArrayT_Template: GenericNodeTemplate
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using Chris;
using R3;

namespace Ceres.Graph.Flow.Utilities.Templates
{
public class FlowNode_ObservableSubscribeT_Template: GenericNodeTemplate
{
public override bool RequirePort()
{
return true;
}

public override bool CanFilterPort(Type portValueType)
{
if (portValueType == null)
{
return false;
}

if (!portValueType.IsGenericType)
{
return false;
}

return ReflectionUtility.IsInheritedFromGenericDefinition(portValueType, typeof(Observable<>));
}

public override Type[] GetGenericArguments(Type portValueType, Type selectArgumentType)
{
return new[] { selectArgumentType };
}

public override Type[] GetAvailableArguments(Type portValueType)
{
return new[]{ ReflectionUtility.GetGenericArgumentType(portValueType) };
}

protected override string GetTargetName(Type[] argumentTypes)
{
var genericType = typeof(Observable<>).MakeGenericType(argumentTypes[0]);
return CeresNode.GetTargetSubtitle(genericType);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Chris;
using Chris.Resource;
namespace Ceres.Graph.Flow.Utilities
namespace Ceres.Graph.Flow.Utilities.Templates
{
public class FlowNode_SoftAssetReferenceTLoadAssetAsync_Template: GenericNodeTemplate
{
Expand Down
40 changes: 40 additions & 0 deletions Runtime/Flow/Utilities/Libraries/RxExecutableLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using Ceres.Annotations;
using Ceres.Graph.Flow.Annotations;
using R3;
using R3.Chris;
using UnityEngine;

namespace Ceres.Graph.Flow.Utilities
{
/// <summary>
/// Executable function library for R3
/// </summary>
[CeresGroup("Rx")]
public partial class RxExecutableLibrary: ExecutableFunctionLibrary
{
[ExecutableFunction(IsScriptMethod = true), CeresLabel("Dispose")]
public static void Flow_IDisposableDispose(IDisposable disposable)
{
disposable.Dispose();
}

[ExecutableFunction(IsScriptMethod = true), CeresLabel("Add to Disposable Unregister")]
public static void Flow_IDisposableAddToIDisposableUnregister(IDisposable disposable, IDisposableUnregister disposableUnregister)
{
disposable.AddTo(disposableUnregister);
}

[ExecutableFunction(IsScriptMethod = true), CeresLabel("Add to Component")]
public static void Flow_IDisposableAddToComponent(IDisposable disposable, Component component)
{
disposable.AddTo(component);
}

[ExecutableFunction(IsScriptMethod = true), CeresLabel("Add to GameObject")]
public static void Flow_IDisposableAddToGameObject(IDisposable disposable, GameObject gameObject)
{
disposable.AddTo(gameObject);
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Flow/Utilities/Libraries/RxExecutableLibrary.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit adffd60

Please sign in to comment.