using System; using System.Reflection; namespace Editor; public static partial class EditorEvent { /// /// Called every frame for tools /// public class FrameAttribute : EventAttribute { public FrameAttribute() : base( "tool.frame" ) { } } public class HotloadAttribute : EventAttribute { public HotloadAttribute() : base( "hotloaded" ) { } } static Sandbox.Internal.EventSystem eventManager; internal static void Init() { eventManager?.Dispose(); eventManager = new Sandbox.Internal.EventSystem(); } /// /// Register an assembly. If old assembly is valid, we try to remove all of the old event hooks /// from this assembly, while retaining a list of objects. /// internal static void UnregisterAssembly( Assembly outgoing ) { eventManager.UnregisterAssembly( outgoing ); } /// /// Register an assembly. If old assembly is valid, we try to remove all of the old event hooks /// from this assembly, while retaining a list of objects. /// internal static void RegisterAssembly( Assembly incoming ) { eventManager.RegisterAssembly( incoming ); } /// /// Register an object, start receiving events /// public static void Register( object obj ) => eventManager?.Register( obj ); /// /// Unregister an object, stop receiving events /// public static void Unregister( object obj ) => eventManager?.Unregister( obj ); /// /// Run an event. /// public static void Run( string name ) => eventManager?.Run( name ); /// /// Run an event with an argument of arbitrary type. /// /// Arbitrary type for the argument. /// Name of the event to run. /// Argument to pass down to event handlers. public static void Run( string name, T arg0 ) { eventManager?.Run( name, arg0 ); } /// /// Run an event with 2 arguments of arbitrary type. /// /// Arbitrary type for the first argument. /// Arbitrary type for the second argument. /// Name of the event to run. /// First argument to pass down to event handlers. /// Second argument to pass down to event handlers. public static void Run( string name, T arg0, U arg1 ) { eventManager?.Run( name, arg0, arg1 ); } /// /// Run an interface based event /// public static void RunInterface( Action action ) { eventManager?.RunInterface( action ); } /// /// Run an event with 3 arguments of arbitrary type. /// /// Arbitrary type for the first argument. /// Arbitrary type for the second argument. /// Arbitrary type for the third argument. /// Name of the event to run. /// First argument to pass down to event handlers. /// Second argument to pass down to event handlers. /// Third argument to pass down to event handlers. public static void Run( string name, T arg0, U arg1, V arg2 ) { eventManager?.Run( name, arg0, arg1, arg2 ); } public interface IEventListener; public interface ISceneEdited : IEventListener { /// /// Called when a property on a is about to be edited, so the old value can be inspected. /// void GameObjectPreEdited( GameObject go, string propertyName ) { } /// /// Called when a has been edited, so the new value can be inspected. /// void GameObjectEdited( GameObject go, string propertyName ); /// /// Called when a property on a is about to be edited, so the old value can be inspected. /// void ComponentPreEdited( Component cmp, string propertyName ) { } /// /// Called when a has been edited, so the new value can be inspected. /// void ComponentEdited( Component cmp, string propertyName ); } /// /// Event args for events. /// /// Scene editor session that the context menu is being opened for. /// Context menu being opened. Feel free to add options to it in your handler. /// Cursor ray when right-click was pressed. /// Trace result if we hit an object in the scene when right-clicking. public sealed record ShowContextMenuEvent( SceneEditorSession Session, Menu Menu, Ray CursorRay, SceneTraceResult? Trace ); /// /// Allows tools to inject behaviour in the scene editor. /// public interface ISceneView : IEventListener { /// /// Called when a scene editor viewport is drawing gizmos. /// /// Scene that gizmos are being drawn for. void DrawGizmos( Scene scene ) { } /// /// Called when a scene editor viewport wants to show a context menu. /// /// Event arguments describing what the context menu was opened on. void ShowContextMenu( ShowContextMenuEvent ev ) { } } }