Skip to content

VFX

Title: Unity Spawn VFX On Event System Documentation

Overview: The Unity Spawn VFX On Event System is a component designed to spawn visual effects (VFX) in response to specific events within a Unity application. This system is built using the Unity Entities framework and leverages the Rukhanka animation system for event handling. It provides functionalities for pre-instantiating VFX, pooling them for efficient usage, and recycling them after a specified duration. Additionally, it supports dynamic spawning of VFX based on the current zoom level of the application.

Dependencies: - Rukhanka: Animation system for event handling. - Stratkit.Entities: Unity Entities framework for ECS (Entity Component System). - Stratkit.Zoom: Component for managing zoom levels. - Unity.Collections: For managing collections of entities. - Unity.Entities: Core Unity Entities functionality. - Unity.Mathematics: Mathematics library for Unity. - Unity.Transforms: Component for managing entity transforms. - UnityEngine: Core Unity engine functionality. - Unity.Jobs: Unity job system for parallel processing. - System: System namespace for basic functionalities. - System.Threading.Tasks: For asynchronous task handling. - Stillfront.Logging: Logging functionalities.

Namespaces: - Using Rukhanka: Provides access to the Rukhanka animation system. - Using Stratkit.Entities: Access to Unity Entities framework. - Using Stratkit.Zoom: Zoom level management functionalities. - Using Unity.Collections: Collection management in Unity. - Using Unity.Entities: Core Unity Entities functionality. - Using Unity.Mathematics: Mathematical functionalities in Unity. - Using Unity.Transforms: Transform management in Unity. - Using UnityEngine: Core Unity engine functionalities. - Using Unity.Jobs: Job system in Unity. - Using System: Basic system functionalities. - Using System.Threading.Tasks: Asynchronous task handling. - Using Stillfront.Logging: Logging functionalities.

Components: 1. SpawnVFXOnEventSystem: Main system class responsible for spawning VFX on events. - Inherits from SystemBase. - Requires update after RukhankaAnimationSystemGroup. - Defines a constant for the maximum pool size of VFX objects. - Contains an EntityQuery for fetching muzzle transforms. - Initializes a dictionary for mapping VFX root IDs to VFX data. - Initializes a VFX object pool. - Implements methods for spawning and recycling VFX. - Overrides OnCreate, OnStartRunning, and OnUpdate methods for system lifecycle management.

Usage: 1. Attach the SpawnVFXOnEventSystem component to a GameObject in your Unity scene. 2. Ensure that the necessary dependencies are included in your Unity project. 3. Configure VFX data and root IDs using the provided VFXUnitsReferenceConfig. 4. Optionally, adjust the maximum pool size for VFX objects. 5. Define event triggers and associate them with appropriate VFX root IDs. 6. Run the Unity application, and the system will automatically spawn VFX based on defined events.

Example: ```csharp using UnityEngine; using Unity.Entities; using Unity.Transforms; using Stratkit.VFX;

public class ExampleScript : MonoBehaviour { // Reference to the SpawnVFXOnEventSystem public SpawnVFXOnEventSystem vfxSystem;

// Example event trigger function
public void TriggerEvent()
{
    // Fetch muzzle transform and entity information
    Transform muzzleTransform = GetMuzzleTransform();
    Entity parentEntity = GetParentEntity();

    // Spawn VFX based on event
    vfxSystem.SpawnVFX(VFXRootID.SomeRootID, new LocalToWorld { Position = muzzleTransform.position, Rotation = muzzleTransform.rotation }, parentEntity);
}

// Example function to fetch muzzle transform
private Transform GetMuzzleTransform()
{
    // Implement logic to fetch muzzle transform
    return null;
}

// Example function to fetch parent entity
private Entity GetParentEntity()
{
    // Implement logic to fetch parent entity
    return Entity.Null;
}

}