using ImpactCFX;
using Unity.Mathematics;

//Holds data for the effect that is suitable for use in burst-compiled jobs.
public struct ExampleEffectData : IPooledEffectData<ExampleEffectResult>
{
    //Properties used internally by Impact CFX
    public int EffectID { get; set; }
    public ImpactTagMaskFilter IncludeTags { get; set; }
    public ImpactTagMaskFilter ExcludeTags { get; set; }
    public int TemplateID { get; set; }

    //Fields and properties for parameters specific to the effect.
    public float ValueRoundingIncrement;

    //Takes the given collision data to produce a result.
    public ExampleEffectResult GetResult(CollisionInputData collisionData, MaterialCompositionData materialCompositionData, ImpactVelocityData velocityData, ref Unity.Mathematics.Random random)
    {
        //Initialize result
        ExampleEffectResult result = new ExampleEffectResult();

        //Get the velocity magnitude and compare it to the velocity threshold to determine which message to display.
        float velocityMagnitude = math.length(velocityData.ImpactVelocity);

        //Round the value as defined by the rounding increment.
        result.ValueResult = math.round(velocityMagnitude / ValueRoundingIncrement) * ValueRoundingIncrement;

        //Make sure to set the template ID of the result.
        result.TemplateID = TemplateID;
        //Priority is used for object pool stealing.
        result.Priority = collisionData.Priority;

        //Populate these if you plan on using your effect for sliding and rolling.
        result.ContactPointID = ContactPointIDGenerator.CalculateContactPointID(collisionData.TriggerObjectID,
            collisionData.HitObjectID,
            collisionData.CollisionType,
            materialCompositionData.MaterialData.MaterialTags.Value,
            EffectID);
        result.CheckContactPointID = collisionData.CollisionType.RequiresContactPointID();

        //Can optionally add checks for validity. Invalid results will be discarded.
        //Note how both IsEffectValid and IsObjectPoolRequestValid are being set.
        result.IsEffectValid = result.IsObjectPoolRequestValid = true;

        return result;
    }
}
