using static Sandbox.Component; namespace Sandbox.ActionGraphs; /// /// A component which allows you to use action in all the usual functions. /// [Title( "Actions Invoker" ), Group( "Actions" ), Icon( "bolt" )] public sealed class ActionsInvoker : Component { [Property] public Action OnEnabledAction { get; set; } protected override void OnEnabled() { OnEnabledAction?.InvokeWithWarning(); } [Property] public Action OnUpdateAction { get; set; } protected override void OnUpdate() { OnUpdateAction?.InvokeWithWarning(); } [Property] public Action OnFixedUpdateAction { get; set; } protected override void OnFixedUpdate() { OnFixedUpdateAction?.InvokeWithWarning(); } [Property] public Action OnDisabledAction { get; set; } protected override void OnDisabled() { OnDisabledAction?.InvokeWithWarning(); } [Property] public Action OnDestroyAction { get; set; } protected override void OnDestroy() { OnDestroyAction?.InvokeWithWarning(); } } /// /// A component that only provides actions to implement with an Action Graph. /// public interface IActionComponent { } /// /// These should not exist /// [Obsolete( $"Please use the action properties in {nameof( Component )}." )] public abstract class SimpleActionComponent : Component, IActionComponent { /// /// ActionGraph to run when the relevant event occurs. /// [Property] public Action Action { get; set; } } /// [Obsolete( $"Please use \"{nameof( Component )}.{nameof( OnComponentStart )}\"." )] [Title( "Awake" ), Group( "Actions" ), Icon( "light_mode" )] public class AwakeActionComponent : SimpleActionComponent { protected override void OnAwake() { Action?.Invoke(); } } /// [Obsolete( $"Please use \"{nameof( Component )}.{nameof( OnComponentStart )}\"." )] [Title( "Start" ), Group( "Actions" ), Icon( "sports_score" )] public class StartActionComponent : SimpleActionComponent { protected override void OnStart() { Action?.Invoke(); } } /// [Obsolete( $"Please use \"{nameof( Component )}.{nameof( OnComponentEnabled )}\"." )] [Title( "Enabled" ), Group( "Actions" ), Icon( "thumb_up" )] public class EnabledActionComponent : SimpleActionComponent { protected override void OnEnabled() { Action?.Invoke(); } } /// [Obsolete( $"Please use \"{nameof( Component )}.{nameof( OnComponentDisabled )}\"." )] [Title( "Disabled" ), Group( "Actions" ), Icon( "thumb_down" )] public class DisabledActionComponent : SimpleActionComponent { protected override void OnDisabled() { Action?.Invoke(); } } /// [Obsolete( $"Please use \"{nameof( Component )}.{nameof( OnComponentUpdate )}\"." )] [Title( "Update" ), Group( "Actions" ), Icon( "update" )] public class UpdateActionComponent : SimpleActionComponent { protected override void OnUpdate() { Action?.Invoke(); } } /// [Obsolete( $"Please use \"{nameof( Component )}.{nameof( OnComponentFixedUpdate )}\"." )] [Title( "FixedUpdate" ), Group( "Actions" ), Icon( "lock_clock" )] public class FixedUpdateActionComponent : SimpleActionComponent { protected override void OnFixedUpdate() { Action?.Invoke(); } } /// [Obsolete( $"Please use \"{nameof( Component )}.{nameof( OnComponentDestroy )}\"." )] [Title( "Destroy" ), Group( "Actions" ), Icon( "delete" )] public class DestroyActionComponent : SimpleActionComponent { protected override void OnDestroy() { Action?.Invoke(); } } /// /// Reacts to collisions. /// [Obsolete( "TODO: We don't have a replacement for this yet." )] [Title( "Collision" ), Group( "Actions" ), Icon( "minor_crash" )] public class CollisionActionComponent : Component, ICollisionListener, IActionComponent { public delegate void CollisionDelegate( Collision other ); public delegate void CollisionStopDelegate( CollisionStop other ); /// [Property] public CollisionDelegate CollisionStart { get; set; } /// [Property] public CollisionDelegate CollisionUpdate { get; set; } /// [Property] public CollisionStopDelegate CollisionStop { get; set; } void ICollisionListener.OnCollisionStart( Collision other ) { CollisionStart?.Invoke( other ); } void ICollisionListener.OnCollisionUpdate( Collision other ) { CollisionUpdate?.Invoke( other ); } void ICollisionListener.OnCollisionStop( CollisionStop other ) { CollisionStop?.Invoke( other ); } } /// /// Reacts to collider triggers. /// [Obsolete( $"Please use \"{nameof( Collider )}.{nameof( Collider.OnTriggerEnter )}\" and \"{nameof( Collider )}.{nameof( Collider.OnTriggerExit )}\"." )] [Title( "Trigger" ), Group( "Actions" ), Icon( "filter_center_focus" )] public class TriggerActionComponent : Component, ITriggerListener, IActionComponent { public delegate void TriggerDelegate( Collider other ); /// [Property] public TriggerDelegate TriggerEnter { get; set; } /// [Property] public TriggerDelegate TriggerExit { get; set; } void ITriggerListener.OnTriggerEnter( Collider other ) { TriggerEnter?.Invoke( other ); } void ITriggerListener.OnTriggerExit( Collider other ) { TriggerExit?.Invoke( other ); } }