// EVALUATE // // // Evaluate when particle specific data is NOT available. override public void Evaluate(ref float input) { if (ownerBlueprint.ownerEmitter.emitterLoopTime < previousLoopTime) { currentEventCount = 0; } previousLoopTime = ownerBlueprint.ownerEmitter.emitterLoopTime; if (currentEventCount < maxEventCount.GetValue() && ownerBlueprint.ownerEmitter.emitterTime > timeOfLastEvent + minEventDelay.GetValue()) { ManageEvent(new Vector4(input, 0, 0, 0), true, -1); } }
private float[] accumulatedValues; // The accumulator floats for each particle. // EVALUATE // // // Evaluate when particle specific data is NOT available. override public void Evaluate(ref float input) { InitializeNewParticles(); if (useStackValue.GetValue()) { accumulatedValues[0] += input * ownerBlueprint.ownerEmitter.deltaTime; } else { accumulatedValues[0] += changePerSecond.GetValue() * ownerBlueprint.ownerEmitter.deltaTime; } input = Blend(input, accumulatedValues[0], weight.GetValue()); }
// EVALUATE SPAWN RATE// // override public void Evaluate_SpawnRate() { if (modifySpawnRate.GetValue()) { ownerBlueprint.spawnRateStack.value = spawnRate.GetValue(); } }
// GET VALUE // // // GetValue when particle index IS known. public float GetValue(int particleIndex) { float returnValue = 0; System.Random theRandom = new System.Random(ownerBlueprint.ownerEmitter.randomSeed + randomSeed + ownerBlueprint.ownerEmitter.particleIds[particleIndex]); #if UNITY_EDITOR CheckReferences(); #endif switch (dataMode) { case eDataMode.Constant: returnValue = constant; break; case eDataMode.RandomConstant: returnValue = Mathf.Lerp(randomMin, randomMax, (float)theRandom.NextDouble()); break; case eDataMode.Curve: returnValue = curve.Evaluate(ownerBlueprint.ownerEmitter, particleIndex); break; case eDataMode.RandomCurve: returnValue = Mathf.Lerp(curveMin.Evaluate(ownerBlueprint.ownerEmitter, particleIndex), curveMax.Evaluate(ownerBlueprint.ownerEmitter, particleIndex), (float)theRandom.NextDouble()); break; case eDataMode.Reference: if (reference != null) { ScalarProperty theReference = (ScalarProperty)reference.property; returnValue = theReference.GetValue(particleIndex); } break; case eDataMode.Parameter: if (wasParameterQueried == false) { parameter = ownerBlueprint.ownerEmitter.GetParameter(parameterName, AmpsHelpers.eParameterTypes.Scalar); wasParameterQueried = true; } if (parameter != null) { returnValue = parameter.GetScalarValue(); } else { returnValue = constant; } break; } if (isInteger) { returnValue = (int)returnValue; // Round toward zero. } return(returnValue); }
// EVALUATE // // // Evaluate when particle specific data is NOT available. override public void Evaluate(ref float input) { Vector4 finalValue = untriggeredValue.GetValue(); if (ownerBlueprint.ownerEmitter.emitterLoopTime < previousLoopTime) { currentTriggerCount = 0; } previousLoopTime = ownerBlueprint.ownerEmitter.emitterLoopTime; if (triggerToggle.GetValue() == false && ownerBlueprint.ownerEmitter.emitterTime > lastTriggerTime + triggerDuration.GetValue()) { isTriggered = false; } if (isTriggered) { switch ((eTriggerDataModes)triggerDataMode.GetValue()) { case eTriggerDataModes.CustomValue: finalValue = triggeredCustomValue.GetValue(); break; case eTriggerDataModes.EventData1: finalValue = lastEventData.DataSlot1; break; case eTriggerDataModes.EventData2: finalValue = lastEventData.DataSlot2; break; case eTriggerDataModes.EventData3: finalValue = lastEventData.DataSlot3; break; case eTriggerDataModes.EventData4: finalValue = lastEventData.DataSlot4; break; } } input = Blend(input, finalValue, weight.GetValue()); }
// EVALUATE // // // Evaluate when particle specific data is NOT available. override public void Evaluate(ref float input) { float output = 0; float finalValueA = useStackValue.GetValue() ? input : valueA.GetValue(); switch (condition.GetValue()) { case (int)eConditions.Greater: if (finalValueA > valueB.GetValue()) { output = valueTrue.GetValue(); } else { output = valueFalse.GetValue(); } break; case (int)eConditions.Less: if (finalValueA < valueB.GetValue()) { output = valueTrue.GetValue(); } else { output = valueFalse.GetValue(); } break; case (int)eConditions.Equal: if (finalValueA == valueB.GetValue()) { output = valueTrue.GetValue(); } else { output = valueFalse.GetValue(); } break; case (int)eConditions.NotEqual: if (finalValueA != valueB.GetValue()) { output = valueTrue.GetValue(); } else { output = valueFalse.GetValue(); } break; } input = Blend(input, output, weight.GetValue()); }
// EVALUATE DEATH CONDITION// // override public void Evaluate_DeathCondition() { if (modifyDeathCondition.GetValue()) { int particleIndex; for (int i = 0; i < ownerBlueprint.ownerEmitter.activeParticleIndices.Length; i++) { particleIndex = ownerBlueprint.ownerEmitter.activeParticleIndices[i]; ownerBlueprint.deathConditionStack.values[particleIndex] = deathCondition.GetValue(particleIndex); } } }
//============================================================================// #region GUI // SHOW PROPERTIES // // override public void ShowProperties(ref bool shouldRepaint) { base.ShowProperties(ref shouldRepaint); BaseProperty previousSelection = selectedProperty; PropertyGroup(""); inputMeshCount.constant = inputMeshes.Length; inputMeshCount.ShowProperty(ref selectedProperty, false); if (inputMeshCount.GetValue() > 0 && inputMeshCount.GetValue() != inputMeshes.Length) { MeshProperty[] newMeshes = new MeshProperty[(int)inputMeshCount.GetValue()]; for (int i = 0; i < newMeshes.Length; i++) { if (i <= inputMeshes.Length - 1) { newMeshes[i] = inputMeshes[i]; } else { newMeshes[i] = ScriptableObject.CreateInstance <MeshProperty>(); newMeshes[i].Initialize("Mesh " + i); AddProperty(newMeshes[i], false); } } inputMeshes = newMeshes; } foreach (MeshProperty m in inputMeshes) { m.ShowProperty(ref selectedProperty, false); } if (selectedProperty != previousSelection) { shouldRepaint = true; } }
// HANDLE EVENT // // public void HandleEvent(EventData theEventData) { bool isTriggerCountFine = infiniteTriggerCount.GetValue() || (infiniteTriggerCount.GetValue() == false && currentTriggerCount < maxTriggerCount.GetValue()); if (theEventData.eventName == eventName.GetValue() && isTriggerCountFine) { if (triggerToggle.GetValue()) { isTriggered = isTriggered == false; } else { isTriggered = true; } lastEventData = theEventData; lastTriggerTime = ownerBlueprint.ownerEmitter.emitterTime; currentTriggerCount++; } }
// SHOULD SAMPLE // // // Check sampling condition when particle data IS available. public bool ShouldSample(int particleIndex) { bool returnValue = false; float currentTime; // Get "currentTime" from the proper source. if (ownerStack.isParticleStack) { currentTime = ownerBlueprint.ownerEmitter.particleTimes[particleIndex]; } else { currentTime = ownerBlueprint.ownerEmitter.emitterTime; } // Apply time offset if appropriate. if (samplerCondition.GetValue() == (int)eSamplerConditions.ByTime) { currentTime = currentTime - intervalOffset.GetValue(); if (currentTime < 0) { currentTime = 0; } } else if (samplerCondition.GetValue() == (int)eSamplerConditions.OnCreation && lastSampleTimes[particleIndex] < 0 && currentTime >= intervalOffset.GetValue()) { lastSampleTimes[particleIndex] = currentTime; returnValue = true; } // We do a sample if we should on spawn and if the last sample timestamp is -1 i.e. no sample has been taken yet. if (sampleOnSpawn.GetValue() && lastSampleTimes[particleIndex] < 0) { lastSampleTimes[particleIndex] = currentTime; returnValue = true; } switch ((eSamplerConditions)samplerCondition.GetValue()) { // AmpsHelpers.eSamplerConditions.OnCreation was handled above. case eSamplerConditions.ByTime: if (currentTime >= lastSampleTimes[particleIndex] + interval.GetValue()) { returnValue = true; lastSampleTimes[particleIndex] = Mathf.Round(currentTime / interval.GetValue()) * interval.GetValue(); } break; case eSamplerConditions.ByDirectValue: float theDirectValue = 0; if (ownerStack.isParticleStack) { theDirectValue = directValue.GetValue(particleIndex); } else { theDirectValue = directValue.GetValue(); } if (theDirectValue >= 1) { returnValue = true; lastSampleTimes[particleIndex] = currentTime; } break; case eSamplerConditions.OnCollision: // True if collision occured on last update. // TODO: Implement collision. break; } return(returnValue); }
// MANAGE EVENT // // void ManageEvent(Vector4 input, bool isInputFloat, int particleIndex) { bool shouldTriggerEvent = false; Vector4 rawProperty; bool isRawPropertyFloat = isInputFloat; float thePropertyValue = 0; if (useCurrentStack.GetValue() == false) { rawProperty = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)property.GetValue()); isRawPropertyFloat = AmpsHelpers.isFloatInput((AmpsHelpers.eCurveInputs)property.GetValue()); } else { rawProperty = input; } if (isRawPropertyFloat) { thePropertyValue = rawProperty.x; } else { switch (propertyVectorComponent.GetValue()) { case (int)AmpsHelpers.eVectorComponents.X: thePropertyValue = rawProperty.x; break; case (int)AmpsHelpers.eVectorComponents.Y: thePropertyValue = rawProperty.y; break; case (int)AmpsHelpers.eVectorComponents.Z: thePropertyValue = rawProperty.z; break; case (int)AmpsHelpers.eVectorComponents.W: thePropertyValue = rawProperty.w; break; case (int)AmpsHelpers.eVectorComponents.Mag: thePropertyValue = new Vector3(rawProperty.x, rawProperty.y, rawProperty.z).magnitude; break; } } switch (condition.GetValue()) { case (int)eConditions.Greater: shouldTriggerEvent = thePropertyValue > value.GetValue(); break; case (int)eConditions.Less: shouldTriggerEvent = thePropertyValue < value.GetValue(); break; case (int)eConditions.Equal: shouldTriggerEvent = thePropertyValue == value.GetValue(); break; case (int)eConditions.NotEqual: shouldTriggerEvent = thePropertyValue != value.GetValue(); break; } if (shouldTriggerEvent) { AmpsEmitter[] childEmitters = ownerBlueprint.ownerEmitter.transform.GetComponentsInChildren <AmpsEmitter>(); for (int i = 0; i < childEmitters.Length; i++) { switch ((eActions)action.GetValue()) { case eActions.ResetAndPlay: childEmitters[i].Play(); break; case eActions.PlayIfNotPlaying: if (childEmitters[i].isStopped) { childEmitters[i].Play(); } else if (childEmitters[i].isPaused) { childEmitters[i].Unpause(); } break; case eActions.Pause: if (childEmitters[i].isPaused == false) { childEmitters[i].Pause(); } break; default: break; } } timeOfLastEvent = ownerBlueprint.ownerEmitter.emitterTime; } }
// EVALUATE // // // Evaluate when particle specific data is NOT available. override public void Evaluate(ref float input) { input = Blend(input, value.GetValue(), weight.GetValue()); }
// MANAGE EVENT // // void ManageEvent(Vector4 input, bool isInputFloat, int particleIndex) { bool shouldTriggerEvent = false; Vector4 rawProperty; bool isRawPropertyFloat = isInputFloat; float thePropertyValue = 0; if (useCurrentStack.GetValue() == false) { rawProperty = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)property.GetValue()); isRawPropertyFloat = AmpsHelpers.isFloatInput((AmpsHelpers.eCurveInputs)property.GetValue()); } else { rawProperty = input; } if (isRawPropertyFloat) { thePropertyValue = rawProperty.x; } else { switch (propertyVectorComponent.GetValue()) { case (int)AmpsHelpers.eVectorComponents.X: thePropertyValue = rawProperty.x; break; case (int)AmpsHelpers.eVectorComponents.Y: thePropertyValue = rawProperty.y; break; case (int)AmpsHelpers.eVectorComponents.Z: thePropertyValue = rawProperty.z; break; case (int)AmpsHelpers.eVectorComponents.W: thePropertyValue = rawProperty.w; break; case (int)AmpsHelpers.eVectorComponents.Mag: thePropertyValue = new Vector3(rawProperty.x, rawProperty.y, rawProperty.z).magnitude; break; } } switch (condition.GetValue()) { case (int)eConditions.Greater: shouldTriggerEvent = thePropertyValue > value.GetValue(); break; case (int)eConditions.Less: shouldTriggerEvent = thePropertyValue < value.GetValue(); break; case (int)eConditions.Equal: shouldTriggerEvent = thePropertyValue == value.GetValue(); break; case (int)eConditions.NotEqual: shouldTriggerEvent = thePropertyValue != value.GetValue(); break; } if (shouldTriggerEvent) { EventData theEventData = new EventData(); theEventData.eventName = eventName.GetValue(); theEventData.particleIndex = particleIndex; theEventData.DataSlot1 = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)sentProperty1.GetValue()); theEventData.DataSlot2 = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)sentProperty2.GetValue()); theEventData.DataSlot3 = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)sentProperty3.GetValue()); theEventData.DataSlot4 = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)sentProperty4.GetValue()); #if UNITY_EDITOR AmpsEmitter[] selfAndChildEmitters = ownerBlueprint.ownerEmitter.transform.root.GetComponentsInChildren <AmpsEmitter>(); for (int i = 0; i < selfAndChildEmitters.Length; i++) { selfAndChildEmitters[i].AmpsHandleEvent(theEventData); } #else ownerBlueprint.ownerEmitter.BroadcastMessage("AmpsHandleEvent", theEventData, SendMessageOptions.DontRequireReceiver); #endif currentEventCount++; timeOfLastEvent = ownerBlueprint.ownerEmitter.emitterTime; } }