### EnemyInstaller C# Example Source: https://context7.com/starkre22/atomic/llms.txt Example of an installer class that uses the generated EntityAPI extensions to configure an entity. It demonstrates adding tags, values, and behaviours to an entity. ```csharp // Usage with generated extensions - clean, type-safe code public sealed class EnemyInstaller : SceneEntityInstaller { [SerializeField] private Transform _transform; [SerializeField] private ReactiveVariable _health = new ReactiveVariable(50); [SerializeField] private Const _moveSpeed = 3.0f; public override void Install(IEntity entity) { // Type-safe, autocomplete-friendly API entity.AddEnemyTag(); entity.AddDamageableTag(); entity.AddTransform(_transform); entity.AddHealth(_health); entity.AddMoveSpeed(_moveSpeed); entity.AddBehaviour(); } } ``` -------------------------------- ### Install GameUI Elements and Behaviours - C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Tutorials/ArchitectualConsistency.md Illustrates the installation process for GameUI entities using an EntityInstaller. This example adds countdown and score views, along with their respective presenters. ```csharp // Game UI public sealed class GameUIInstaller : EntityInstaller { [SerializeField] private CountdownView _countdown; [SerializeField] private ScoreView _score; public override void Install(GameUI ui) { // Countdown ui.AddCountdownView(_countdown); ui.AddBehaviour(); // Score ui.AddScoreView(_score); ui.AddBehaviour(); } } ``` -------------------------------- ### Implement Strongly-Typed Entity Installer Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/IEntityInstaller`1.md Demonstrates how to implement the IEntityInstaller interface for a specific entity type. This example shows how to configure tags, values, and behaviours for a character entity. ```csharp public interface ICharacterEntity : IEntity { } [Serializable] public sealed class CharacterInstaller : IEntityInstaller { [SerializeField] private Transform _transform; [SerializeField] private float _moveSpeed = 5.0f; [SerializeField] private Vector3 _moveDirection; public void Install(ICharacterEntity entity) { entity.AddTag("Character"); entity.AddTag("Moveable"); entity.AddValue("Transform", _transform); entity.AddValue("MoveSpeed", _moveSpeed); entity.AddValue("MoveDirection", _moveDirection); entity.AddBehaviour(); entity.AddBehaviour(); } } ``` -------------------------------- ### Implement a custom SceneEntityInstaller Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/SceneEntityInstaller`1.md Demonstrates how to create a concrete installer by inheriting from SceneEntityInstaller. This example shows how to add tags, values, and behaviors to a UnitEntity. ```csharp public sealed class UnitEntity : SceneEntity { } public sealed class CharacterInstaller : SceneEntityInstaller { [SerializeField] private Transform _transform; [SerializeField] private float _moveSpeed = 5.0f; protected override void Install(UnitEntity entity) { entity.AddTag("Character"); entity.AddTag("Moveable"); entity.AddValue("Transform", _transform); entity.AddValue("MoveSpeed", _moveSpeed); entity.AddValue("MoveDirection", Vector3.zero); entity.AddBehaviour(); } } ``` -------------------------------- ### Configure CharacterInstaller for Entity Setup Source: https://github.com/starkre22/atomic/blob/main/README.md An installer script used to inject data properties and behaviours into an entity. It utilizes serialized fields to configure initial values for movement speed and direction. ```csharp public sealed class CharacterInstaller : SceneEntityInstaller { [SerializeField] private Transform _transform; [SerializeField] private Const _moveSpeed = 5.0f; [SerializeField] private Variable _moveDirection = Vector3.zero; public override void Install(IEntity entity) { entity.AddTransform(_transform); entity.AddMoveSpeed(_moveSpeed); entity.AddMoveDirection(_moveDirection); entity.AddBehaviour(); entity.AddBehaviour(); } } ``` -------------------------------- ### Create ScriptableObject Installer for UnitEntity Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/ScriptableEntityInstaller`1.md Demonstrates how to create a ScriptableObject installer for the 'UnitEntity' type. This installer, 'MoveInstaller', defines installation logic usingSerializeField for configuration and overrides the Install method to add tags and values to the entity. ```csharp [CreateAssetMenu( fileName = "MoveInstaller", menuName = "Example/New MoveInstaller" )] public sealed class MoveInstaller : ScriptableEntityInstaller { [SerializeField] private Const _moveSpeed = 5.0f; public override void Install(UnitEntity entity) { entity.AddTag("Moveable"); entity.AddValue("MoveSpeed", _moveSpeed); entity.AddValue("MoveDirection", new ReactiveVariable()); } } ``` -------------------------------- ### Install Application Context Data and Controllers - C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Tutorials/ArchitectualConsistency.md Demonstrates how to set up an AppContext using a SceneEntityInstaller. This includes configuring quit functionality, level management (start, max, current level), and menu loading controllers. ```csharp // Application Context public sealed class AppContextInstaller : SceneEntityInstaller { [Header("Quit")] [SerializeField] private KeyCode _exitKey = KeyCode.Escape; [Header("Levels")] [SerializeField] private Const _startLevel; [SerializeField] private Const _maxLevel; [SerializeField] private ReactiveVariable _currentLevel = 1; public override void Install(AppContext context) { // Quit context.AddExitKeyCode(new Const(_exitKey)); context.AddBehaviour(); // Level System context.AddStartLevel(_startLevel); context.AddMaxLevel(_maxLevel); context.AddCurrentLevel(_currentLevel); context.AddBehaviour(); // Menu context.AddBehaviour(); } } ``` -------------------------------- ### Implement SceneEntityInstaller in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Entities/SceneEntityInstalling.md Demonstrates how to create a custom installer by extending SceneEntityInstaller. This allows developers to define tags and values that are applied to an entity during the installation process. ```csharp public sealed class CharacterInstaller : SceneEntityInstaller { [SerializeField] private Transform _transform; [SerializeField] private Const _moveSpeed = 5.0f; //Immutable variable [SerializeField] private ReactiveVariable _moveDirection; //Mutable variable with subscription public override void Install(IEntity entity) { //Add tags to a character entity.AddTag("Character"); entity.AddTag("Moveable"); //Add properties to a character entity.AddValue("Transform", _transform); entity.AddValue("MoveSpeed", _moveSpeed); entity.AddValue("MoveDirection", _moveDirection); } } ``` -------------------------------- ### Method: Install(E) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/IEntityInstaller`1.md Defines the installation logic for a specific entity type E, allowing for the addition of tags, values, and behaviours. ```APIDOC ## Install(E) ### Description Configures the provided entity instance of type E. This method is triggered during the entity installation process to apply specific tags, values, and behaviours. ### Method Interface Method ### Endpoint N/A (Interface implementation) ### Parameters #### Path Parameters - **entity** (E) - Required - The specific entity instance to be configured. ### Request Example ```csharp public void Install(ICharacterEntity entity) { entity.AddTag("Character"); entity.AddValue("MoveSpeed", 5.0f); entity.AddBehaviour(); } ``` ### Response #### Success Response (void) - **N/A** - This method performs side effects on the entity instance and does not return a value. ``` -------------------------------- ### Example Usage of IStartSource in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Time/IStartSource.md Demonstrates how to use the IStartSource interface in C#. This includes subscribing to OnStarted and OnStopped events, starting the source with and without a specific time, checking its running status with IsStarted(), and stopping it. ```csharp IStartSource startSource = ...; startSource.OnStarted += () => { Console.WriteLine("Source started!"); }; startSource.OnStopped += () => { Console.WriteLine("Source stopped!"); }; startSource.Start(); startSource.Start(5.0f); if (startSource.IsStarted()) { Console.WriteLine("Source is currently running."); } startSource.Stop(); ``` -------------------------------- ### Example: Manual View Management (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/UI/EntityCollectionView.md Illustrates manual control over individual entity views using Add, Get, and Remove methods of EntityCollectionView. This is useful for specific entity operations outside automatic collection binding. ```csharp // Access the collection view manually var collectionView = FindObjectOfType(); // Show a view for a specific entitycollectionView.Add(someEntity); // Retrieve the view for custom logic EntityView view = collectionView.Get(someEntity); // Remove the view when neededcollectionView.Remove(someEntity); ``` -------------------------------- ### Install All SceneEntities in Scene Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Entities/SceneEntityInstalling.md Installs all SceneEntity instances found in the given Scene that are not yet installed. This is a convenience method that calls the generic version InstallAll(scene). It skips already installed entities and null GameObjects. Throws if the scene is not valid or loaded. ```csharp public static void InstallAll(Scene scene) ``` -------------------------------- ### Setup EntityViewPool Implementation Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/UI/EntityViewPool`1.md Demonstrates how to define concrete entity types, view types, and catalogs required to implement a specific EntityViewPool. This setup allows the pool to manage specific view prefabs within a Unity scene. ```csharp public class IUnitEntity : IEntity { } public class UnitView : EntityView { } [CreateAssetMenu(fileName = "UnitViewCatalog", menuName = "Example/UnitViewCatalog")] public class UnitViewCatalog : EntityViewCatalog { } public sealed class UnitViewPool : EntityViewPool { } ``` -------------------------------- ### Install Logic from Single IEntityInstaller (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Entities/ExtensionsInstalling.md Installs logic from a single IEntityInstaller into the specified entity. This method supports chaining by returning the entity after installation. It delegates the actual installation to the IEntityInstaller.Install(IEntity) method. ```csharp public static IEntity Install(this IEntity entity, IEntityInstaller installer) { // ... implementation details ... return entity; } ``` -------------------------------- ### Implement a Custom Entity Installer in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/ScriptableEntityInstaller.md Demonstrates how to create a concrete implementation of ScriptableEntityInstaller by inheriting from the base class and overriding the Install method. This allows for declarative configuration of entity properties like tags and reactive variables. ```csharp [CreateAssetMenu( fileName = "MoveInstaller", menuName = "Example/New MoveInstaller" )] public sealed class MoveInstaller : ScriptableEntityInstaller { [SerializeField] private Const _moveSpeed = 5.0f; public override void Install(IEntity entity) { entity.AddTag("Moveable"); entity.AddValue("MoveSpeed", _moveSpeed); entity.AddValue("MoveDirection", new ReactiveVariable()); } } ``` -------------------------------- ### Installer Lifecycle Methods Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/SceneEntityInstaller`1.md Core methods for managing entity configuration, including Install, Uninstall, and the Unity-specific OnValidate hook. ```csharp public abstract void Install(E entity); public virtual void Uninstall(E entity); protected virtual void OnValidate(); ``` -------------------------------- ### Install Method Signature Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/IEntityInstaller`1.md The signature for the typed Install method used to configure an entity instance. ```csharp public void Install(E entity); ``` -------------------------------- ### Example Usage of EntityViewCatalog (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/UI/EntityViewCatalog`1.md This example shows how to load and use the EntityViewCatalog in a Unity project. It demonstrates loading the catalog from Resources and retrieving prefabs by both index and name. ```csharp // Load the catalog from Resources, for example UnitViewCatalog catalog = Resources.Load("UnitViewCatalog"); // Get a prefab by index KeyValuePair viewPrefabKV = catalog.GetPrefab(0); // Get by name UnitView viewPrefab = catalog.GetPrefab("Player"); ``` -------------------------------- ### Install Logic from Multiple IEntityInstallers (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Entities/ExtensionsInstalling.md Installs logic from multiple IEntityInstaller instances into the specified entity. This method accepts a collection of installers and iterates through them, invoking the Install(IEntity) method on each. If the provided collection is null, no installations occur. ```csharp public static void Install(this IEntity entity, IEnumerable installers) { if (installers == null) return; foreach (var installer in installers) { installer.Install(entity); } } ``` -------------------------------- ### Install Method Signature for IEntityInstaller (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/IEntityInstaller.md This C# code shows the signature of the Install method within the IEntityInstaller interface. This method is responsible for performing the actual installation of data and behaviors onto the provided entity. ```csharp public void Install(IEntity entity); ``` -------------------------------- ### Install and Uninstall Method Signatures Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/ScriptableEntityInstaller.md Defines the core lifecycle methods for entity installers. Install is mandatory for derived classes to implement, while Uninstall provides an optional hook for cleanup. ```csharp public abstract void Install(IEntity entity); public virtual void Uninstall(IEntity entity) ``` -------------------------------- ### ITimeSource Usage Example in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Time/ITimeSource.md Demonstrates how to use the ITimeSource interface in C#. It shows subscribing to the OnTimeChanged event, getting the current time, setting a new time, and resetting the time source. ```csharp using System; // Assume we have an ITimeSource instance // ITimeSource timeSource = ...; // Subscribe to the event // timeSource.OnTimeChanged += (time) => // { // Console.WriteLine($"Time changed: {time:0.00} sec"); // }; // Get current time // float currentTime = timeSource.GetTime(); // Set current time // timeSource.SetTime(1.5f); // Reset current time to default // timeSource.ResetTime(); ``` -------------------------------- ### Start Method Signature in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Time/IStartSource.md Defines the signature for the Start() method in the IStartSource interface in C#. This method starts the source using its default start time. ```csharp public void Start(); ``` -------------------------------- ### Install Logic from Generic Scene Components (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Entities/ExtensionsInstalling.md Installs logic from SceneEntityInstaller components found within a specified Unity scene for a generic entity type. This method is useful for strongly-typed or generic entity scenarios and can include inactive GameObjects. It searches root GameObjects for matching installer components. ```csharp public static void InstallFromScene(this T entity, Scene scene, bool includeInactive = true) where T : class, IEntity { // ... implementation details ... } ``` -------------------------------- ### Implement IStopwatch and Subscribe to Events in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Time/IStopwatch.md Demonstrates how to utilize the IStopwatch interface by subscribing to lifecycle events and controlling the stopwatch state through methods like Start, Pause, and Tick. This example illustrates a typical usage pattern for tracking elapsed time in a loop. ```csharp IStopwatch stopwatch = ...; // Subscribe to events stopwatch.OnStarted += () => Console.WriteLine("Stopwatch started!"); stopwatch.OnTimeChanged += t => Console.WriteLine($"Elapsed: {t:F1}s"); stopwatch.OnPaused += () => Console.WriteLine("Stopwatch paused."); stopwatch.OnResumed += () => Console.WriteLine("Stopwatch resumed."); stopwatch.OnStopped += () => Console.WriteLine("Stopwatch stopped."); // Start the stopwatch stopwatch.Start(); // Simulate ticking float deltaTime = 1f; for (int i = 0; i < 5; i++) { stopwatch.Tick(deltaTime); System.Threading.Thread.Sleep(1000); } // Pause and resume stopwatch.Pause(); stopwatch.Resume(); // Stop and reset stopwatch.Stop(); stopwatch.ResetTime(); ``` -------------------------------- ### Usage Example for EntityWorld in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Worlds/EntityWorld.md Demonstrates how to instantiate an EntityWorld, subscribe to lifecycle events, manage entity collections, and trigger update ticks. This example covers the full workflow from initialization to disposal. ```csharp EntityWorld world = new EntityWorld("GeneralWorld"); // Subscribe to events world.OnAdded += e => Console.WriteLine($"Added entity: {e.Name}"); world.OnRemoved += e => Console.WriteLine($"Removed entity: {e.Name}"); world.OnStateChanged += () => Console.WriteLine("World state changed"); world.OnEnabled += () => Console.WriteLine("World enabled"); world.OnDisabled += () => Console.WriteLine("World disabled"); world.OnTicked += deltaTime => Console.WriteLine($"Ticked: {deltaTime} seconds"); world.OnFixedTicked += deltaTime => Console.WriteLine($"FixedTicked: {deltaTime} seconds"); world.OnLateTicked += deltaTime => Console.WriteLine($"LateTicked: {deltaTime} seconds"); // Enable the world world.Enable(); // Add entities var entity1 = new Entity("Entity1"); var entity2 = new Entity("Entity2"); world.Add(entity1); world.Add(entity2); // Check existence if (world.Contains(entity1)) { Console.WriteLine($"{entity1.Name} exists in the world"); } // Tick the world (simulate frame updates) world.Tick(0.016f); // Regular update world.FixedTick(0.02f); // Fixed update (physics) world.LateTick(0.016f); // Late update // Remove an entity world.Remove(entity1); // Copy entities to an array var array = new IEntity[world.Count]; world.CopyTo(array, 0); // Iterate over entities foreach (var entity in world) { Console.WriteLine(entity.Name); } // Disable the world world.Disable(); // Dispose when done world.Dispose(); ``` -------------------------------- ### Install Method Signature for ScriptableEntityInstaller Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/ScriptableEntityInstaller`1.md Declares the abstract 'Install' method signature for 'ScriptableEntityInstaller'. Derived classes must implement this method to define the specific logic for installing data, values, or behaviors into a strongly-typed entity. ```csharp public abstract void Install(E entity); ``` -------------------------------- ### Install Logic from Scene Components (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Entities/ExtensionsInstalling.md Installs logic from all SceneEntityInstaller components found within a specified Unity scene. This method can optionally include inactive GameObjects. It iterates over root GameObjects to find and apply SceneEntityInstaller components to the target entity. ```csharp public static void InstallFromScene(this IEntity entity, Scene scene, bool includeInactive = true) { // ... implementation details ... } ``` -------------------------------- ### Implement EntityViewInstaller for GameEntity Source: https://github.com/starkre22/atomic/blob/main/Docs/Tutorials/MinimizingUnity.md Demonstrates how to create a custom installer to bind visual behaviors to a GameEntity. It manages the lifecycle of visual components by adding them during installation and removing them during uninstallation. ```csharp public sealed class CharacterViewInstaller : SceneEntityInstaller { [SerializeField] private TakeDamageViewBehaviour _takeDamageBehaviour; [SerializeField] private PositionViewBehaviour _positionBehaviour; [SerializeField] private RotationViewBehaviour _rotationBehaviour; [SerializeField] private TeamColorViewBehaviour _teamColorBehaviour; [SerializeField] private WeaponRecoilViewBehaviour _weaponRecoilBehaviour; public override void Install(GameEntity entity) { entity.AddBehaviour(_takeDamageBehaviour); entity.AddBehaviour(_positionBehaviour); entity.AddBehaviour(_rotationBehaviour); entity.AddBehaviour(_teamColorBehaviour); entity.AddBehaviour(_weaponRecoilBehaviour); } public override void Uninstall(GameEntity entity) { entity.DelBehaviour(_takeDamageBehaviour); entity.DelBehaviour(_positionBehaviour); entity.DelBehaviour(_rotationBehaviour); entity.DelBehaviour(_teamColorBehaviour); entity.DelBehaviour(_weaponRecoilBehaviour); } } ``` -------------------------------- ### POST /Install Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Installers/IEntityInstaller.md The Install method is the primary entry point for configuring an IEntity instance, allowing for the injection of components, tags, and data values. ```APIDOC ## [METHOD] Install(IEntity) ### Description Configures an IEntity instance by injecting necessary data, tags, and behaviors. This method is typically called during the entity initialization lifecycle. ### Method void ### Endpoint IEntityInstaller.Install(IEntity entity) ### Parameters #### Path Parameters - **entity** (IEntity) - Required - The target entity instance to be configured. ### Request Example ```csharp public void Install(IEntity entity) { entity.AddTag("Player"); entity.AddValue("Speed", 10.0f); entity.AddBehaviour(); } ``` ### Response #### Success Response (void) - **void** - The method performs configuration in-place on the provided entity instance. #### Response Example N/A (Method returns void) ``` -------------------------------- ### Unsubscribe Example (3 Parameters) (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Events/ExtensionsUnsubscribe.md Shows how to unsubscribe an action with three parameters from a signal. The example covers the setup, subscription, and subsequent unsubscription of the action. ```csharp ISignal attackSignal = ...; var action = new InlineAction((entity, damage, critical) => Debug.Log($"{entity.Name} dealt {damage} damage (Critical: {critical})")); attackSignal.Subscribe(action); // Later, unsubscribe attackSignal.Unsubscribe(action); ``` -------------------------------- ### Example EnemyBaker Implementation in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Baking/SceneEntityBaker`1.md An example of a concrete implementation of SceneEntityBaker for an EnemyEntity. It demonstrates custom installation logic, setting health and position, and how to use the baker in a Unity scene. ```csharp public class EnemyBaker : SceneEntityBaker { protected override void Install(EnemyEntity entity) { // Custom initialization for EnemyEntity entity.Health = 100; entity.SetPosition(this.transform.position); } } // Usage in scene EnemyBaker baker = FindObjectOfType(); EnemyEntity enemy = baker.Bake(); ``` -------------------------------- ### C# Usage Example: Invoking IFunction Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Functions/IFunction`1.md Illustrates how to use an implementation of the IFunction interface in C#. This example shows the instantiation of a custom function and calling its Invoke method to get a result. ```csharp // Assume we have two instances of some characters Character myCharacter, otherCharacter = ... // Create our function IFunction func = new IsEnemyFunction(myCharacter); // Get result bool isEnemies = func.Invoke(otherCharacter); ``` -------------------------------- ### Generated Extension Methods for Values (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/EntityAPI/Obsolete_PluginCodegen.md These are examples of C# extension methods generated by the Atomic Rider Plugin for managing entity values (components). They provide functionality to get, set, add, check for existence, remove, and try to get values, as well as get a reference if unsafe mode is enabled. ```csharp // Example for Health value: // entity.GetHealth() // entity.SetHealth(int value) // entity.AddHealth() // entity.HasHealth() // entity.DelHealth() // entity.TryGetHealth(out int value) // entity.RefHealth() // If unsafe enabled ``` -------------------------------- ### C# Period Usage Example Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Time/Periods.md Demonstrates how to create, configure, and control a Period instance in C#. It covers subscribing to events, starting, ticking, pausing, resuming, stopping, and resetting the period. This example requires the IPeriod interface and Period implementation. ```csharp IPeriod period = new Period(10f); period.OnStarted += () => Console.WriteLine("Period started!"); period.OnTimeChanged += t => Console.WriteLine($"Time: {t:F1}s"); period.OnProgressChanged += p => Console.WriteLine($"Progress: {p:P0}"); period.OnPeriod += () => Console.WriteLine("Cycle completed!"); period.OnPaused += () => Console.WriteLine("Period paused."); period.OnResumed += () => Console.WriteLine("Period resumed."); period.OnStopped += () => Console.WriteLine("Period stopped."); period.Start(); float deltaTime = 1f; for (int i = 0; i < 25; i++) { period.Tick(deltaTime); System.Threading.Thread.Sleep(1000); } period.Pause(); period.Resume(); period.Stop(); period.ResetTime(); ``` -------------------------------- ### Usage Example of SceneActionDefault in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Actions/SceneActionDefault.md Demonstrates how to use SceneActionDefault as a SceneActionAbstract in a Unity MonoBehaviour component. It shows how to serialize the action and invoke it when the game starts. ```csharp public sealed class GameStartup : MonoBehaviour { [SerializeField] private SceneActionAbstract _startup; private void Start() => _startup.Invoke(); } ``` -------------------------------- ### C# Example: Creating and Using a UnitEntityFactory Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Factories/IEntityFactory.md Demonstrates how to implement the IEntityFactory interface to create a specific type of entity (Unit) and then how to use this factory to instantiate the entity. ```csharp public sealed class UnitEntityFactory : IEntityFactory { public IEntity Create() { var entity = new Entity(); entity.AddTag("Unit"); entity.AddValue("Health", 150); entity.AddValue("Damage", 25); entity.AddBehaviour(); return entity; } } IEntityFactory factory = new UnitEntityFactory(); Entity unit = factory.Create(); ``` -------------------------------- ### Install GameContext Data and Logic - C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Tutorials/ArchitectualConsistency.md Shows how to install data and logic into a GameContext using a SceneEntityInstaller. This includes adding player data, world transform, team catalog, bullet pool, and game over events. ```csharp // Game Context public sealed class GameContextInstaller : SceneEntityInstaller { [SerializeField] private Transform _worldTransform; [SerializeField] private TeamCatalog _teamCatalog; [SerializeField] private EntityPool _bulletPool; public override void Install(GameContext context) { context.AddPlayers(new Dictionary()); context.AddWorldTransform(_worldTransform); context.AddTeamCatalog(_teamCatalog); context.AddBulletPool(_bulletPool); context.AddGameOverEvent(new BaseEvent()); } } ``` -------------------------------- ### WhenInit() Extension Method Example in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Lifecycle/Manual.md Shows the usage of the WhenInit() extension method in C# for subscribing to an entity's initialization event. It includes subscribing to the initialization and unsubscribing using the returned InitSubscription's Dispose() method. ```csharp IEntity entity = ...; InitSubscription initSubscription = entity.WhenInit(() => Console.WriteLine("Initialized!")); initSubscription.Dispose(); ``` -------------------------------- ### Example Implementation of Tank Factory and Baker Source: https://github.com/starkre22/atomic/blob/main/Docs/BestPractices/OverrideEntityFactoriesWithBakers.md Provides a concrete implementation of a Tank entity using a factory for base installation and a baker for scene-specific component overrides. ```csharp [CreateAssetMenu( fileName = "TankFactory", menuName = "Example/New TankFactory" )] public sealed class TankFactory : UnitFactory { [SerializeField] private TransformEntityInstaller _transformInstaller; [SerializeField] private MoveEntityInstaller _moveInstaller; [SerializeField] private LifeEntityInstaller _lifeInstaller; [SerializeField] private RangeCombatEntityInstaller _combatInstaller; [SerializeField] private AIEntityInstaller _aiInstaller; protected override void Install(IUnitEntity entity) { entity.AddUnitTag(); entity.AddTeam(new ReactiveVariable()); entity.Install(_transformInstaller); entity.Install(_moveInstaller); entity.Install(_lifeInstaller); entity.Install(_combatInstaller); entity.Install(_aiInstaller); } } public sealed class TankBaker : UnitBaker { [SerializeField] private LifeEntityBaker _lifeBaker; [SerializeField] private MoveEntityBaker _moveBaker; [SerializeField] private CombatEntityBaker _combatBaker; [SerializeField] private TeamEntityBaker _teamBaker; [SerializeField] private TransformEntityBaker _transformBaker; protected override void Install(IUnitEntity entity) { entity.Install(_moveBaker); entity.Install(_lifeBaker); entity.Install(_combatBaker); entity.Install(_teamBaker); entity.Install(_transformBaker); } protected override void OnValidate() { base.OnValidate(); _teamBaker.OnValidate(); } } ``` -------------------------------- ### Entity Creation and Configuration Example (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Entities/IEntity.md Demonstrates how to create, configure, and manage an IEntity instance. This includes adding tags, values, behaviors, and controlling its lifecycle through initialization, enabling, ticking, disabling, and disposal. Assumes the existence of Atomic.Elements and related types. ```csharp IEntity entity = ...; entity.Name = "Player Character"; // Add tagsentity.AddTag("Character");entity.AddTag("Moveable");entity.AddTag("Damageable"); // Add valuesentity.AddValue("Health", new ReactiveVariable(100));entity.AddValue("MoveSpeed", new ReactiveVariable(5));entity.AddValue("MoveDirection", new ReactiveVariable()); // Add a behaviourentity.AddBehaviour(); // Initialize entity after configurationentity.Init(); // Enable entity for updates (e.g., when retrieved from a pool)entity.Enable(); // Update manually (e.g., in a game loop)entity.Tick(Time.deltaTime); // Disable entity (e.g., if it moved back into a pool)entity.Disable(); // Dispose entity when game is unloadingentity.Dispose(); ``` -------------------------------- ### Configure and Use SequentialEntityNameAlgorithm in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Names/SequentialEntityNameAlgorithm.md Demonstrates how to initialize the algorithm within the application startup and generate sequential IDs for entity names. The example shows the assignment of IDs and the subsequent retrieval of names using the EntityNames utility. ```csharp public static void Main(string[] args) { // Use sequential ID generation for entity names EntityNames.SetAlgorithm(new SequentialEntityNameAlgorithm()); } // Generate IDs for some example entity names int playerId = EntityNames.NameToId("Player"); // 1 int enemyId = EntityNames.NameToId("Enemy"); // 2 // Retrieve original name by ID string name = EntityNames.IdToName(playerId); // "Player" ``` -------------------------------- ### AndExpression Usage Example Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Expressions/AndExpression`1.md Demonstrates how to create and use an AndExpression to combine multiple boolean-returning functions. It shows adding functions and then invoking the combined expression to get a single boolean result. ```csharp var attackExpression = new AndExpression(); // Assume we have a group of preconditions for attack Func isEnemy, isAlive = ... // Add some functions attackExpression.Add(isEnemy); attackExpression.Add(isAlive); // Evaluate the combined expression using Value int result = attackExpression.Invoke(); ``` -------------------------------- ### Usage Example of IPrefabEntityPool Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Pooling/IPrefabEntityPool`1.md Demonstrates how to initialize pools for specific prefabs, rent entities with different transform parameters, and return them to the pool. ```csharp public class GameEntity : SceneEntity { } // Assume we have an instance of IPrefabEntityPool IPrefabEntityPool entityPool = ...; // Initialize pool for a specific prefab entityPool.Init(orcPrefab, 5); entityPool.Init(goblinPrefab, 2); GameEntity orc = enemyPool.Rent(orcPrefab); GameEntity goblin = enemyPool.Rent(goblinPrefab, parentTransform); GameEntity troll = enemyPool.Rent(trollPrefab, new Vector3(0,0,0), Quaternion.identity, parentTransform); // Return enemies to the pool when done enemyPool.Return(orc); enemyPool.Return(goblin); enemyPool.Return(troll); // Optionally clear the pool for this prefab enemyPool.Dispose(orc); ``` -------------------------------- ### Example Player Factory Creation Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Factories/ScriptableEntityFactory.md Demonstrates how to create a ScriptableObject factory for player entities. It inherits from ScriptableEntityFactory and overrides the Install method to add specific tags, values, and behaviors to the created entity. ```csharp using UnityEngine; [CreateAssetMenu( fileName = "PlayerFactory", menuName = "Examples/PlayerFactory" )] public class PlayerScriptableFactory : ScriptableEntityFactory { protected override void Install(IEntity entity) { entity.AddTag("Player"); entity.AddValue("Health", 200); entity.AddValue("MoveSpeed", 10); entity.AddBehaviour(); } } ``` -------------------------------- ### Install Entity Configuration (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Baking/SceneEntityBaker.md The Install method is called after an entity is created to allow for custom configuration, such as adding tags, values, or behaviors. It takes an IEntity instance as input and must be implemented by derived classes. ```csharp protected abstract void Install(IEntity entity); ``` -------------------------------- ### IEntity Lifecycle Usage Example Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Entities/IEntityLifecycle.md Demonstrates how to subscribe to lifecycle events and execute state transition methods like Init, Enable, Tick, and Dispose on an IEntity instance. ```csharp IEntity entity = ...; entity.OnInitialized += () => Console.WriteLine("Entity initialized"); entity.OnDisposed += () => Console.WriteLine("Entity disposed"); entity.OnEnabled += () => Console.WriteLine("Entity enabled"); entity.OnDisabled += () => Console.WriteLine("Entity disabled"); entity.OnTicked += deltaTime => Console.WriteLine($"Tick: {deltaTime}"); entity.OnFixedTicked += deltaTime => Console.WriteLine($"FixedTick: {deltaTime}"); entity.OnLateTicked += deltaTime => Console.WriteLine($"LateTick: {deltaTime}"); entity.Init(); entity.Enable(); entity.Tick(0.016f); entity.FixedTick(0.02f); entity.LateTick(0.016f); entity.Disable(); entity.Dispose(); ``` -------------------------------- ### Restart IStartSource from default or specific time Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Time/ExtensionsIStartSource.md Demonstrates how to use the Restart extension methods to reset an IStartSource. The first example resets to the default time, while the second allows specifying a custom start time. ```csharp // Restart a countdown from its default start time countdown.Restart(); // stops and starts from default ``` ```csharp // Restart a countdown from a specific time IStartSource countdown = ...; countdown.Restart(5f); // stops and starts from 5 seconds ``` -------------------------------- ### Implement Tick-based Time Tracking in Unity Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Time/Timestamps.md Demonstrates how to initialize and monitor a FixedTimestamp within a Unity MonoBehaviour. The example shows starting a timer and checking its state during the FixedUpdate loop to handle game logic updates. ```csharp public class Example : MonoBehaviour { ITimestamp _timestamp = new FixedTimestamp(); private void Awake() { _timestamp.StartFromSeconds(5f); //_timestamp.StartFromTicks(250); (equivalent to 5 seconds) } private void FixedUpdate() { if (_timestamp.IsExpired()) Debug.Log("Timestamp expired!"); else if (_timestamp.IsPlaying()) Debug.Log("Timestamp is still running."); else if (_timestamp.IsIdle()) Debug.Log("Timestamp is idle."); } } ``` -------------------------------- ### Initialize and Configure Entity Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Behaviours/Manual.md Demonstrates the creation of an entity instance, adding tags for identification, and defining reactive properties for state management. ```csharp var character = new Entity("Character"); character.AddTag("Moveable"); character.AddValue("Position", new ReactiveVariable()); character.AddValue("MoveSpeed", new Const(3.5f)); character.AddValue("MoveDirection", new ReactiveVariable()); ``` -------------------------------- ### Example Usage of IRequest Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Requests/IRequest`1.md Demonstrates how to use the IRequest interface in C# for handling gameplay requests like applying damage. It shows invoking a request, checking if it's required, and consuming or trying to get the argument. ```csharp IRequest damageRequest = ...; // Trigger the request from gameplay logic damageRequest.Invoke(targetCharacter); // Somewhere in a system that processes damage if (damageRequest.TryGet(out Character target)) { Debug.Log($"Applying damage is required to {target.Name}"); } if (damageRequest.Consume(out target)) { Debug.Log("Damage request handled and consumed."); } ``` -------------------------------- ### Implement and Control UpTimer in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Time/UpTimer.md Demonstrates the lifecycle management of an UpTimer instance, including event subscription, manual ticking, and state control methods like pause, resume, and stop. This example shows how to initialize a timer with a specific duration and handle its progression through events. ```csharp // Create a timer of 30 seconds UpTimer timer = 30f; // Subscribe to events timer.OnStarted += () => Console.WriteLine("Timer started!"); timer.OnTimeChanged += t => Console.WriteLine($"Time remaining: {t:F1}s"); timer.OnProgressChanged += p => Console.WriteLine($"Progress: {p:P0}"); timer.OnCompleted += () => Console.WriteLine("Timer completed!"); // 1. Start the timer timer.Start(); // must call Start before ticking // 2. Tick the timer (simulate time passing, e.g., 1 second per tick) float deltaTime = 1f; while (!timer.IsCompleted()) { timer.Tick(deltaTime); System.Threading.Thread.Sleep(1000); // wait 1 second (simulation) } // 3. After completion, you can restart the timer if (timer.IsCompleted()) { Console.WriteLine("Restarting timer..."); timer.Start(); } // 4. Pause and resume (optional) timer.Pause(); Console.WriteLine("Timer paused..."); timer.Resume(); // 5. Stop the timer (optional) timer.Stop(); Console.WriteLine("Timer stopped!"); // 6. Reset or manually set time/progress (optional) timer.SetTime(15f); // set remaining time to 15 seconds timer.SetProgress(0.5f); // set progress to 50% ``` -------------------------------- ### InlineExpression Example: SUM Expression (C#) Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Expressions/InlineExpression.md Demonstrates how to create and use an InlineExpression to calculate the sum of values returned by a list of functions. It shows adding functions and then invoking the expression to get the final sum. ```csharp var expression = new InlineExpression(enumerator => { int sum = 0; while (enumerator.MoveNext()) sum += enumerator.Current.Invoke(); return sum; }); expression.Add(() => 1); expression.Add(() => 2); expression.Add(() => 3); int sum = expression.Invoke(); // 1 + 2 + 3 = 6 ``` -------------------------------- ### Create Non-Generic Scene Entity Baker Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Baking/Manual.md This example demonstrates how to create a non-generic SceneEntityBaker. It overrides the Install method to add tags, values, and behaviors to the entity. This approach is useful for a unified handling of multiple entity types. ```csharp public class EnemyBaker : SceneEntityBaker { protected override void Install(IEntity entity) { entity.AddTag("Enemy"); entity.AddValue("Health", 100); entity.AddValue("Speed", 5f); entity.AddBehaviour(); } } ``` -------------------------------- ### Weapon Firing Cooldown using C# Source: https://github.com/starkre22/atomic/blob/main/Docs/BestPractices/UsingCooldownInGameMechanics.md This C# example shows how to implement a weapon firing cooldown using Atomic.Entities. The cooldown is managed within an installer and checked before firing to control the weapon's rate of fire. ```csharp public sealed class WeaponInstaller : SceneEntityInstaller { [SerializeField] private Transform _firePoint; [SerializeField] private Cooldown _cooldown = 0.5f; public override void Install(IWeaponEntity weapon) { weapon.AddFireAction(new InlineAction(() => { // Check cooldown before firing if (!_cooldown.IsCompleted()) return; // TODO: weapon shooting logic // Reset cooldown after shot _cooldown.ResetTime(); })); // Tick cooldown each FixedUpdate weapon.WhenFixedTick(_cooldown.Tick); } } ``` -------------------------------- ### Example Usage of EntityViewCatalog Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/UI/EntityViewCatalog.md Demonstrates loading an EntityViewCatalog from Resources and retrieving specific prefabs using both index-based and name-based lookup methods. ```csharp var catalog = Resources.Load("EntityViewCatalog"); // Get prefab by index EntityView prefabEntry = catalog.GetPrefab(0); // Get prefab by name EntityView soldierView = catalog.GetPrefab("SoldierView"); ``` -------------------------------- ### C# Generated Entity Extension Methods Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/EntityAPI/Obsolete_ApiGeneration.md An example of the C# code generated by the API generation process. This static class provides extension methods for adding, checking, deleting, and getting entity tags and values, with aggressive inlining enabled. ```csharp /** * Code generation. Don't modify! **/ public static class EntityAPI { ///Tags public static readonly int Player; public static readonly int NPC; ///Values public static readonly int Health; //int public static readonly int Speed; //float static EntityAPI() { // Values Health = NameToId(nameof(Health)); Speed = NameToId(nameof(Speed)); } ///Tag Extensions #region Player [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasPlayerTag(this IEntity entity) => entity.HasTag(Player); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AddPlayerTag(this IEntity entity) => entity.AddTag(Player); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool DelPlayerTag(this IEntity entity) => entity.DelTag(Player); #endregion #region NPC [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasNPCTag(this IEntity entity) => entity.HasTag(NPC); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AddNPCTag(this IEntity entity) => entity.AddTag(NPC); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool DelNPCTag(this IEntity entity) => entity.DelTag(NPC); #endregion ///Value Extensions #region Health [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IVariable GetHealth(this IEntity entity) => entity.GetValue>(Health); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryGetHealth(this IEntity entity, out IVariable value) => entity.TryGetValue(Health, out value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AddHealth(this IEntity entity, IVariable value) => entity.AddValue(Health, value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasHealth(this IEntity entity) => entity.HasValue(Health); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool DelHealth(this IEntity entity) => entity.DelValue(Health); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SetHealth(this IEntity entity, IVariable value) => entity.SetValue(Health, value); #endregion #region Speed [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IVariable GetSpeed(this IEntity entity) => entity.GetValue>(Speed); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryGetSpeed(this IEntity entity, out IVariable value) => entity.TryGetValue(Speed, out value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AddSpeed(this IEntity entity, IVariable value) => entity.AddValue(Speed, value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasSpeed(this IEntity entity) => entity.HasValue(Speed); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool DelSpeed(this IEntity entity) => entity.DelValue(Speed); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SetSpeed(this IEntity entity, IVariable value) => entity.SetValue(Speed, value); #endregion } ``` -------------------------------- ### Float Mul Expression Example in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Expressions/Manual.md Demonstrates using FloatMulExpression to multiply float values from multiple functions, simulating a scenario like calculating total profit with various multipliers. It includes creating the expression with factors and invoking it to get the final result. ```csharp float baseProfit = 1000f; float seasonalBonus = 1.2f; float marketingBoost = 1.5f; float loyaltyMultiplier = 1.1f; var profitMultiplier = new FloatMulExpression( () => baseProfit, () => seasonalBonus, () => marketingBoost, () => loyaltyMultiplier ); float totalProfit = profitMultiplier.Invoke(); Console.WriteLine($"Total Profit: {totalProfit}"); // Output: 1980 ``` -------------------------------- ### Usage Example for IExpression Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Expressions/IExpression`1.md Demonstrates how to instantiate an IExpression, add function delegates to it, and invoke the combined logic against a target object. ```csharp IExpression attackExpression = ... // Assume we have a group of preconditions for attack Func isEnemy, isAlive = ... // Add some functions attackExpression.Add(isEnemy); attackExpression.Add(isAlive); // Evaluate the combined expression using Value int result = attackExpression.Invoke(); ``` -------------------------------- ### Example Usage of MultiEntityPool in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Pooling/MultiEntityPool.md Demonstrates how to use the MultiEntityPool to manage different types of entities using string keys. It covers initialization, renting, and returning entities. ```csharp // Assume we have string keys for entity types const string Goblin = "Goblin"; const string Orc = "Orc"; ``` ```csharp // Assume we have an instance of IMultiEntityFactory IMultiEntityFactory entityFactory = ...; // Create a non-generic multi-entity pool var entityPool = new MultiEntityPool(entityFactory); // Initialize pools for each enemy type entityPool.Init(Goblin, 5); entityPool.Init(Orc, 3); // Rent entities from pools IEnemyEntity goblin = entityPool.Rent(Goblin); IEnemyEntity orc = entityPool.Rent(Orc); // Return entities to the pool when done entityPool.Return(goblin); entityPool.Return(orc); ``` -------------------------------- ### Stopwatch Usage Example in C# Source: https://github.com/starkre22/atomic/blob/main/Docs/Elements/Time/Stopwatch.md Demonstrates how to create, configure, and control a Stopwatch instance. It includes subscribing to various events like OnStarted, OnTimeChanged, OnPaused, OnResumed, and OnStopped, as well as calling methods like Start, Tick, Pause, Resume, Stop, and ResetTime. ```csharp var stopwatch = new Stopwatch(); stopwatch.OnStarted += () => Console.WriteLine("Stopwatch started!"); stopwatch.OnTimeChanged += t => Console.WriteLine($"Elapsed: {t:F1}s"); stopwatch.OnPaused += () => Console.WriteLine("Stopwatch paused."); stopwatch.OnResumed += () => Console.WriteLine("Stopwatch resumed."); stopwatch.OnStopped += () => Console.WriteLine("Stopwatch stopped."); stopwatch.Start(); float deltaTime = 1f; for (int i = 0; i < 5; i++) { stopwatch.Tick(deltaTime); System.Threading.Thread.Sleep(1000); } stopwatch.Pause(); stopwatch.Resume(); stopwatch.Stop(); stopwatch.ResetTime(); ``` -------------------------------- ### Implement IEntityInit for custom logic Source: https://github.com/starkre22/atomic/blob/main/Docs/Entities/Behaviours/IEntityInit`1.md Demonstrates how to implement the IEntityInit interface to apply specific component values, such as renderer colors, to a concrete entity type during initialization. ```csharp public class InitColorBehaviour : IEntityInit { public void Init(UnitEntity entity) { var renderer = entity.GetValue("Renderer"); var color = entity.GetValue("Color"); renderer.material.color = color; } } ``` -------------------------------- ### C# Example: Managing Event Subscriptions with DisposableComposite Source: https://github.com/starkre22/atomic/blob/main/Docs/BestPractices/UsingSubscriptionsWithDisposeComposite.md Demonstrates using DisposableComposite to manage multiple event subscriptions within a WeaponViewInstaller. The AddTo extension method is used to automatically add each subscription to the composite, ensuring all are disposed when the installer is uninstalled, thus preventing memory leaks. ```csharp public sealed class WeaponViewInstaller : SceneEntityInstaller { [SerializeField] private ParticleSystem _fireVFX; [SerializeField] private AudioSource _fireSFX; [SerializeField] private Animator _animator; private readonly DisposableComposite _disposables = new(); public override void Install(IEntity entity) { ISignal fireEvent = entity.GetFireEvent(); // Subscribe to the "Fire" event and automatically add to the composite fireEvent.Subscribe(_fireVFX.Play).AddTo(_disposables); fireEvent.Subscribe(_fireSFX.Play).AddTo(_disposables); fireEvent.Subscribe(() => _animator.SetTrigger("Fire")).AddTo(_disposables); } public override void Uninstall() { // Dispose all subscriptions and resources when the installer is removed _disposables.Dispose(); } } ```