//============================================================================// #region GUI // SHOW PROPERTIES // // override public void ShowProperties(ref bool shouldRepaint) { moduleName.ShowProperty(ref selectedProperty, false); useCurrentStack.ShowProperty(ref selectedProperty, false); if (useCurrentStack.GetValue() == false) { if (property.displayData == null) { property.displayData = () => AmpsHelpers.curveInputDisplayData; // We have to do this here because delegates are not serialized. } property.ShowProperty(ref selectedProperty, false); } if ((useCurrentStack.GetValue() == false && AmpsHelpers.isFloatInput((AmpsHelpers.eCurveInputs)property.GetValue()) == false) || (useCurrentStack.GetValue() && AmpsHelpers.isFloatStack(ownerStack.stackFunction) == false)) { if (propertyVectorComponent.displayData == null) { propertyVectorComponent.displayData = () => AmpsHelpers.vectorComponentsDisplayData; // We have to do this here because delegates are not serialized. } propertyVectorComponent.ShowProperty(ref selectedProperty, false); } if (condition.displayData == null) { condition.displayData = () => conditionsDisplayData; // We have to do this here because delegates are not serialized. } condition.ShowProperty(ref selectedProperty, false); value.ShowProperty(ref selectedProperty, false); if (action.displayData == null) { action.displayData = () => actionsDisplayData; // We have to do this here because delegates are not serialized. } action.ShowProperty(ref selectedProperty, false); PropertyGroup("Constraints"); if (maxEventCount == null) // HACK { maxEventCount = ScriptableObject.CreateInstance <ScalarProperty>(); maxEventCount.Initialize("Max event count per loop", 1f, ownerBlueprint); maxEventCount.SetDataModes(true, false, false, false, false, false); maxEventCount.isInteger = true; AddProperty(maxEventCount, false); } maxEventCount.ShowProperty(ref selectedProperty, false); minEventDelay.ShowProperty(ref selectedProperty, false); shouldRepaint = true; }
public int randomSeed = 0; // A curve specific random seed; // GET CURVE INPUT // // public float GetCurveInput(AmpsBlueprint ownerBlueprint, int particleIndex) { float returnValue = 0; Vector3 v3 = Vector3.zero; Vector4 v4 = Vector4.zero; //Matrix4x4 toMatrix = AmpsHelpers.identityMatrix; // Slightly faster than Matrix4x4.identity; v4 = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, curveInput); // The only need to work with conversion to emitter space as everything // is world relative by default. if (curveInputCoordSystem == AmpsHelpers.eCoordSystems.Emitter) { //toMatrix = ownerBlueprint.ownerEmitter.emitterMatrixFull; if (AmpsHelpers.isPositionInput(curveInput)) { v3 = AmpsHelpers.ConvertVector4Vector3(v4); v3 -= ownerBlueprint.ownerEmitter.transform.position; v3 = AmpsHelpers.RotateAroundPoint(v3, ownerBlueprint.ownerEmitter.emitterPosition, ownerBlueprint.ownerEmitter.transform.rotation); v4 = AmpsHelpers.ConvertVector3Vector4(v3, 0); } else if (AmpsHelpers.isRotationInput(curveInput)) { v3 = AmpsHelpers.ConvertVector4Vector3(v4); v3 += ownerBlueprint.ownerEmitter.transform.rotation.eulerAngles; v4 = AmpsHelpers.ConvertVector3Vector4(v3, 0); } else if (AmpsHelpers.isVelocityInput(curveInput)) { v3 = AmpsHelpers.ConvertVector4Vector3(v4); v3 += ownerBlueprint.ownerEmitter.emitterMatrixPositionZero.MultiplyPoint3x4(v3); v4 = AmpsHelpers.ConvertVector3Vector4(v3, 0); } else if (AmpsHelpers.isScaleInput(curveInput)) { v3 = AmpsHelpers.ConvertVector4Vector3(v4); v3.x *= ownerBlueprint.ownerEmitter.transform.lossyScale.x; v3.y *= ownerBlueprint.ownerEmitter.transform.lossyScale.y; v3.z *= ownerBlueprint.ownerEmitter.transform.lossyScale.z; v4 = AmpsHelpers.ConvertVector3Vector4(v3, 0); } } if (AmpsHelpers.isFloatInput(curveInput)) { returnValue = v4.x; } else { //if (AmpsHelpers.isPositionInput(curveInput)) v = toMatrix.MultiplyPoint3x4(v); //else v = toMatrix.MultiplyVector(v); switch (curveInputVectorComponent) { case AmpsHelpers.eVectorComponents.X: returnValue = v4.x; break; case AmpsHelpers.eVectorComponents.Y: returnValue = v4.y; break; case AmpsHelpers.eVectorComponents.Z: returnValue = v4.z; break; case AmpsHelpers.eVectorComponents.W: returnValue = v4.w; break; case AmpsHelpers.eVectorComponents.Mag: returnValue = new Vector3(v4.x, v4.y, v4.z).magnitude; break; } // TODO: Handle Color. } // Normalize input. float finalInputRangeMin = inputRangeMin; float finalInputRangeMax = inputRangeMax; if (isInputRangeRandom) { System.Random theRandom = new System.Random(ownerBlueprint.ownerEmitter.randomSeed + randomSeed + ownerBlueprint.ownerEmitter.particleIds[particleIndex]); finalInputRangeMin = Mathf.Lerp(inputRangeMin, inputRangeRandomMin, (float)theRandom.NextDouble()); finalInputRangeMax = Mathf.Lerp(inputRangeMax, inputRangeRandomMax, (float)theRandom.NextDouble()); } if (finalInputRangeMax - finalInputRangeMin == 0) { returnValue = 0; } else { returnValue = (returnValue - finalInputRangeMin) / (finalInputRangeMax - finalInputRangeMin); } return(returnValue); }
// CURVE PICKER INPUT // // // HACK: It's exactly the same as the previous one, except the passed param type. public void CurvePickerInput(VectorCurve theCurve) { GUILayout.BeginHorizontal(); GUILayout.Label("Input"); GUILayout.FlexibleSpace(); theCurve.curveInput = (AmpsHelpers.eCurveInputs)SortedPopup((int)theCurve.curveInput, AmpsHelpers.curveInputDisplayData, GUILayout.Width(120)); if (AmpsHelpers.isFloatInput(theCurve.curveInput) == false) { theCurve.curveInputVectorComponent = (AmpsHelpers.eVectorComponents)SortedPopup((int)theCurve.curveInputVectorComponent, AmpsHelpers.vectorComponentsDisplayData, GUILayout.Width(40)); } else { GUILayout.Space(40); } GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (theCurve.curveInput == AmpsHelpers.eCurveInputs.Acceleration || theCurve.curveInput == AmpsHelpers.eCurveInputs.Position || theCurve.curveInput == AmpsHelpers.eCurveInputs.Rotation || theCurve.curveInput == AmpsHelpers.eCurveInputs.RotationRate || theCurve.curveInput == AmpsHelpers.eCurveInputs.Velocity) { theCurve.curveInputCoordSystem = coordSystemPopup(theCurve.curveInputCoordSystem); } GUILayout.BeginHorizontal(); GUILayout.Label("Random range?"); GUILayout.FlexibleSpace(); theCurve.isInputRangeRandom = GUILayout.Toggle(theCurve.isInputRangeRandom, "", "toggle"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUIUtility.labelWidth = 30; EditorGUIUtility.fieldWidth = 40; theCurve.inputRangeMin = MyFloatField(" ", theCurve.inputRangeMin, GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace(); theCurve.inputRangeMax = MyFloatField(" ", theCurve.inputRangeMax, GUILayout.ExpandWidth(false)); EditorGUIUtility.labelWidth = 0; EditorGUIUtility.fieldWidth = 0; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (theCurve.isInputRangeRandom) { EditorGUIUtility.labelWidth = 30; EditorGUIUtility.fieldWidth = 40; theCurve.inputRangeRandomMin = MyFloatField(" ", theCurve.inputRangeRandomMin, GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace(); theCurve.inputRangeRandomMax = MyFloatField(" ", theCurve.inputRangeRandomMax, GUILayout.ExpandWidth(false)); EditorGUIUtility.labelWidth = 0; EditorGUIUtility.fieldWidth = 0; } GUILayout.EndHorizontal(); }
// 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; } }
//============================================================================// #region GUI // SHOW PROPERTIES // // override public void ShowProperties(ref bool shouldRepaint) { moduleName.ShowProperty(ref selectedProperty, false); eventName.ShowProperty(ref selectedProperty, false); useCurrentStack.ShowProperty(ref selectedProperty, false); if (useCurrentStack.GetValue() == false) { if (property.displayData == null) { property.displayData = () => AmpsHelpers.curveInputDisplayData; // We have to do this here because delegates are not serialized. } property.ShowProperty(ref selectedProperty, false); } if ((useCurrentStack.GetValue() == false && AmpsHelpers.isFloatInput((AmpsHelpers.eCurveInputs)property.GetValue()) == false) || (useCurrentStack.GetValue() && AmpsHelpers.isFloatStack(ownerStack.stackFunction) == false)) { if (propertyVectorComponent.displayData == null) { propertyVectorComponent.displayData = () => AmpsHelpers.vectorComponentsDisplayData; // We have to do this here because delegates are not serialized. } propertyVectorComponent.ShowProperty(ref selectedProperty, false); } if (condition.displayData == null) { condition.displayData = () => conditionsDisplayData; // We have to do this here because delegates are not serialized. } condition.ShowProperty(ref selectedProperty, false); value.ShowProperty(ref selectedProperty, false); PropertyGroup("Constraints"); maxEventCount.ShowProperty(ref selectedProperty, false); minEventDelay.ShowProperty(ref selectedProperty, false); PropertyGroup("Extra data"); if (sentProperty1.displayData == null) { sentProperty1.displayData = () => AmpsHelpers.curveInputDisplayData; // We have to do this here because delegates are not serialized. } sentProperty1.ShowProperty(ref selectedProperty, false); if (sentProperty2.displayData == null) { sentProperty2.displayData = () => AmpsHelpers.curveInputDisplayData; // We have to do this here because delegates are not serialized. } sentProperty2.ShowProperty(ref selectedProperty, false); if (sentProperty3.displayData == null) { sentProperty3.displayData = () => AmpsHelpers.curveInputDisplayData; // We have to do this here because delegates are not serialized. } sentProperty3.ShowProperty(ref selectedProperty, false); if (sentProperty4.displayData == null) { sentProperty4.displayData = () => AmpsHelpers.curveInputDisplayData; // We have to do this here because delegates are not serialized. } sentProperty4.ShowProperty(ref selectedProperty, false); shouldRepaint = true; }
// 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; } }