Exemplo n.º 1
0
        // EVALUATE //
        //
        public float Evaluate(AmpsEmitter ownerEmitter, int particleIndex)
        {
            float returnValue = 0;

            // If a particle related curve input was chosen but particle data is not available
            // then we just return 0 like a champ. (index == -1, typically when the owner
            // property is in an emitter property stack where particle data and index is meaningless.)
            //
            // TODO: We might need a mechanic to show warnings.
            if (AmpsHelpers.isParticleRelatedInput(curveInput) && particleIndex < 0)
            {
                return(0);
            }

            float finalCurveInput = GetCurveInput(ownerEmitter.blueprint, particleIndex);

            // Remap output.
            returnValue = Mathf.Lerp(outputRangeMin, outputRangeMax, curve.Evaluate(finalCurveInput));

            return(returnValue);
        }
Exemplo n.º 2
0
        // EVALUATE //
        //
        public Vector4 Evaluate(AmpsEmitter ownerEmitter, int particleIndex)
        {
            Vector4 returnValue = Vector4.zero;

            // If a particle related curve input was chosen but particle data is not available
            // then we just return 0. (index == -1, typically when the owner property is in an
            // emitter property stack where particle data and index is meaningless.)
            //
            // TODO: We might need a mechanic to show warnings.
            if (AmpsHelpers.isParticleRelatedInput(curveInput) && particleIndex < 0)
            {
                return(Vector4.zero);
            }

            float finalCurveInput = GetCurveInput(ownerEmitter.blueprint, particleIndex);

            // Remap output.
            returnValue.x = Mathf.Lerp(outputRangeXMin, outputRangeXMax, curveX.Evaluate(finalCurveInput));
            returnValue.y = Mathf.Lerp(outputRangeYMin, outputRangeYMax, curveY.Evaluate(finalCurveInput));
            returnValue.z = Mathf.Lerp(outputRangeZMin, outputRangeZMax, curveZ.Evaluate(finalCurveInput));
            returnValue.w = Mathf.Lerp(outputRangeWMin, outputRangeWMax, curveW.Evaluate(finalCurveInput));

            return(returnValue);
        }
Exemplo n.º 3
0
 // EVALUATE //
 //
 public Vector4 Evaluate(AmpsEmitter ownerEmitter)
 {
     return(Evaluate(ownerEmitter, -1));
 }
Exemplo n.º 4
0
        // MANAGE SAMPLING //
        //
        // Does the actual sampling.
        override public void ManageSampling(int particleIndex)
        {
            int finalParticleIndex = (particleIndex < 0 ? 0 : particleIndex);

            AmpsHelpers.eCurveInputs wantedProperty = (AmpsHelpers.eCurveInputs)property.GetValue();
            bool isWantedPropertyParticleRelated    = AmpsHelpers.isParticleRelatedInput(wantedProperty);
            bool shouldIndeedSample = (particleIndex < 0 && ShouldSample()) || (particleIndex >= 0 && ShouldSample(particleIndex));

            if (wasParentChecked == false)
            {
                if (ownerBlueprint.ownerEmitter.transform.parent != null)
                {
                    parentEmitter = ownerBlueprint.ownerEmitter.transform.parent.GetComponent <AmpsEmitter>();
                }
                wasParentChecked = true;
            }

            if (sampleFromParent.GetValue())
            {
                // Leave if it's not time yet to sample.
                if (shouldIndeedSample == false)
                {
                    return;
                }

                // INVALID SAMPLE: Parent doesn't exist or has no emitter component or no blueprint.
                if (parentEmitter == null ||
                    parentEmitter.blueprint == null)
                {
                    isValidSample[finalParticleIndex] = false;
                    return;
                }

                // Try to get valid parent particle index.
                if (parentParticleIndices[finalParticleIndex] < 0)
                {
                    parentParticleIndices[finalParticleIndex] = parentEmitter.GetRandomParticleIndex(ownerBlueprint.ownerEmitter.particleIds[finalParticleIndex]);
                }

                // TODO: Invalid sample case: particle id at current particle index is different, ie we did lose
                // original particle index as it got replaced by another.

                // INVALID SAMPLE: Invalid parent particle index.
                //
                // TODO: We might have an invalid parent particle index but we might not need it anymore since
                // we already got a valid sample from it before and we don't need a new one for the time being.
                if (parentParticleIndices[finalParticleIndex] < 0)
                {
                    isValidSample[finalParticleIndex] = false;
                    return;
                }

                // INVALID SAMPLE: Parent particle is dead.
                if (parentParticleIndices[finalParticleIndex] >= 0 &&
                    parentEmitter.particleMarkers.IsActive(parentParticleIndices[finalParticleIndex]) == false)
                {
                    parentParticleIndices[finalParticleIndex] = -1;
                    isValidSample[finalParticleIndex]         = false;
                    return;
                }

                // INVALID SAMPLE: Asking for particle specific data but have no valid particle index.
                if (isWantedPropertyParticleRelated && parentParticleIndices[finalParticleIndex] < 0)
                {
                    return;
                }

                samples[finalParticleIndex] = AmpsHelpers.GetSystemProperty(parentEmitter.blueprint,
                                                                            parentParticleIndices[finalParticleIndex],
                                                                            wantedProperty);
                isValidSample[finalParticleIndex] = true;
            }
            else
            {
                // Leave if it's not time yet to sample.
                if (shouldIndeedSample == false)
                {
                    return;
                }

                // INVALID SAMPLE: Asking for particle specific data but have no valid particle index.
                if (isWantedPropertyParticleRelated && finalParticleIndex < 0)
                {
                    return;
                }

                samples[finalParticleIndex] = AmpsHelpers.GetSystemProperty(ownerBlueprint,
                                                                            finalParticleIndex,
                                                                            wantedProperty);
                isValidSample[finalParticleIndex] = true;
            }
        }
Exemplo n.º 5
0
 // EVALUATE //
 //
 public float Evaluate(AmpsEmitter ownerEmitter)
 {
     return(Evaluate(ownerEmitter, -1));
 }