//============================================================================// #if UNITY_EDITOR // INITIALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); samplerCondition = ScriptableObject.CreateInstance <DropdownProperty>(); samplerCondition.Initialize("Sample condition", 0, theOwnerBlueprint); AddProperty(samplerCondition, true); sampleOnSpawn = ScriptableObject.CreateInstance <BoolProperty>(); sampleOnSpawn.Initialize("Sample on spawn?", true, theOwnerBlueprint); AddProperty(sampleOnSpawn, true); interval = ScriptableObject.CreateInstance <ScalarProperty>(); interval.Initialize("Interval", 1, theOwnerBlueprint); interval.SetDataModes(true, false, false, false, true, true); AddProperty(interval, true); intervalOffset = ScriptableObject.CreateInstance <ScalarProperty>(); intervalOffset.Initialize("Initial delay", 0, theOwnerBlueprint); intervalOffset.SetDataModes(true, false, false, false, true, true); AddProperty(intervalOffset, true); directValue = ScriptableObject.CreateInstance <ScalarProperty>(); directValue.Initialize("Direct value", 0, theOwnerBlueprint); directValue.SetDataModes(false, false, true, true, true, true); AddProperty(directValue, true); System.Random theRandom = new System.Random(); randomSeed = theRandom.Next(1, 65536); }
//============================================================================// #if UNITY_EDITOR // INITALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); subMenuName = AmpsHelpers.formatEnumString(eCategories.Basic.ToString()); type = "Scalar condition"; SetDefaultName(); useStackValue = ScriptableObject.CreateInstance <BoolProperty>(); useStackValue.Initialize("Use stack value?", true, theOwnerBlueprint); AddProperty(useStackValue, true); valueA = ScriptableObject.CreateInstance <ScalarProperty>(); valueA.Initialize("Value A", 0f, theOwnerBlueprint); AddProperty(valueA, true); condition = ScriptableObject.CreateInstance <DropdownProperty>(); condition.Initialize("Condition", 0, theOwnerBlueprint); condition.SetDataModes(true, false, false, false, false, false); AddProperty(condition, false); valueB = ScriptableObject.CreateInstance <ScalarProperty>(); valueB.Initialize("Value B", 1f, theOwnerBlueprint); AddProperty(valueB, true); valueFalse = ScriptableObject.CreateInstance <ScalarProperty>(); valueFalse.Initialize("Output for FALSE", 1f, theOwnerBlueprint); AddProperty(valueFalse, true); valueTrue = ScriptableObject.CreateInstance <ScalarProperty>(); valueTrue.Initialize("Output for TRUE", 1f, theOwnerBlueprint); AddProperty(valueTrue, true); }
// 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); }
//============================================================================// #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; }
//============================================================================// #if UNITY_EDITOR // INITALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); subMenuName = AmpsHelpers.formatEnumString(eCategories.Basic.ToString()); type = "Scalar"; SetDefaultName(); value = ScriptableObject.CreateInstance <ScalarProperty>(); value.Initialize("Value", 1f, theOwnerBlueprint); AddProperty(value, true); }
//============================================================================// #if UNITY_EDITOR // INITIALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); weight = ScriptableObject.CreateInstance <ScalarProperty>(); weight.Initialize("Weight", 1, theOwnerBlueprint); weight.SetDataModes(true, true, true, true, false, true); AddProperty(weight, false); blendMode = ScriptableObject.CreateInstance <DropdownProperty>(); blendMode.Initialize("Blend mode", 0, theOwnerBlueprint); blendMode.SetDataModes(true, false, false, false, false, false); AddProperty(blendMode, false); }
//============================================================================// #if UNITY_EDITOR // INITIALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); subMenuName = AmpsHelpers.formatEnumString(eCategories.Misc.ToString()); type = "Event listener"; SetDefaultName(); eventName = ScriptableObject.CreateInstance <StringProperty>(); eventName.Initialize("Event name", theOwnerBlueprint); eventName.value = "event"; eventName.SetDataModes(true, false, false, false, false, false); AddProperty(eventName, false); untriggeredValue = ScriptableObject.CreateInstance <VectorProperty>(); untriggeredValue.Initialize("Untriggered value", theOwnerBlueprint); AddProperty(untriggeredValue, false); triggeredCustomValue = ScriptableObject.CreateInstance <VectorProperty>(); triggeredCustomValue.Initialize("Triggered value", theOwnerBlueprint); triggeredCustomValue.constant = new Vector4(1, 0, 0, 0); AddProperty(triggeredCustomValue, false); triggerDataMode = ScriptableObject.CreateInstance <DropdownProperty>(); triggerDataMode.Initialize("Trigger data mode", 0, theOwnerBlueprint); triggerDataMode.SetDataModes(true, false, false, false, false, false); AddProperty(triggerDataMode, false); infiniteTriggerCount = ScriptableObject.CreateInstance <BoolProperty>(); infiniteTriggerCount.Initialize("Infinite trigger count?", theOwnerBlueprint); infiniteTriggerCount.value = true; infiniteTriggerCount.SetDataModes(true, false, false, false, false, false); AddProperty(infiniteTriggerCount, false); maxTriggerCount = ScriptableObject.CreateInstance <ScalarProperty>(); maxTriggerCount.Initialize("Max trigger count per loop", 1f, theOwnerBlueprint); maxTriggerCount.SetDataModes(true, false, false, false, false, false); maxTriggerCount.isInteger = true; AddProperty(maxTriggerCount, false); triggerToggle = ScriptableObject.CreateInstance <BoolProperty>(); triggerToggle.Initialize("Does an event toggle?", theOwnerBlueprint); triggerToggle.value = true; triggerToggle.SetDataModes(true, false, false, false, false, false); AddProperty(triggerToggle, false); triggerDuration = ScriptableObject.CreateInstance <ScalarProperty>(); triggerDuration.Initialize("Trigger duration", 1f, theOwnerBlueprint); triggerDuration.SetDataModes(true, true, false, false, false, false); AddProperty(triggerDuration, false); }
//============================================================================// #if UNITY_EDITOR // INITIALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); subMenuName = AmpsHelpers.formatEnumString(eCategories.Misc.ToString()); type = "Child control"; SetDefaultName(); value = ScriptableObject.CreateInstance <ScalarProperty>(); value.Initialize("Value", 0f, theOwnerBlueprint); value.SetDataModes(true, false, false, false, false, false); AddProperty(value, false); condition = ScriptableObject.CreateInstance <DropdownProperty>(); condition.Initialize("Condition", 0, theOwnerBlueprint); condition.SetDataModes(true, false, false, false, false, false); AddProperty(condition, false); useCurrentStack = ScriptableObject.CreateInstance <BoolProperty>(); useCurrentStack.Initialize("Current stack?", theOwnerBlueprint); useCurrentStack.value = true; useCurrentStack.SetDataModes(true, false, false, false, false, false); AddProperty(useCurrentStack, false); property = ScriptableObject.CreateInstance <DropdownProperty>(); property.Initialize("Property", 0, theOwnerBlueprint); property.SetDataModes(true, false, false, false, false, false); AddProperty(property, false); propertyVectorComponent = ScriptableObject.CreateInstance <DropdownProperty>(); propertyVectorComponent.Initialize("Component", 0, theOwnerBlueprint); propertyVectorComponent.SetDataModes(true, false, false, false, false, false); AddProperty(propertyVectorComponent, false); action = ScriptableObject.CreateInstance <DropdownProperty>(); action.Initialize("Action", 0, theOwnerBlueprint); action.SetDataModes(true, false, false, false, false, false); AddProperty(action, false); maxEventCount = ScriptableObject.CreateInstance <ScalarProperty>(); maxEventCount.Initialize("Max event count per loop", 1f, theOwnerBlueprint); maxEventCount.SetDataModes(true, false, false, false, false, false); maxEventCount.isInteger = true; AddProperty(maxEventCount, false); minEventDelay = ScriptableObject.CreateInstance <ScalarProperty>(); minEventDelay.Initialize("Min event delay", 0.1f, theOwnerBlueprint); minEventDelay.SetDataModes(true, false, false, false, false, false); AddProperty(minEventDelay, false); }
//============================================================================// #if UNITY_EDITOR // INITALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); subMenuName = AmpsHelpers.formatEnumString(eCategories.Basic.ToString()); type = "Scalar accumulator"; SetDefaultName(); useStackValue = ScriptableObject.CreateInstance <BoolProperty>(); useStackValue.Initialize("Use stack value?", true, theOwnerBlueprint); AddProperty(useStackValue, true); changePerSecond = ScriptableObject.CreateInstance <ScalarProperty>(); changePerSecond.Initialize("Change per second", 1f, theOwnerBlueprint); AddProperty(changePerSecond, true); }
// COPY PROPERTY // // override public void CopyProperty(BaseProperty originalProperty, AmpsBlueprint theOwnerBlueprint) { base.CopyProperty(originalProperty, theOwnerBlueprint); ScalarProperty originalScalarProperty = originalProperty as ScalarProperty; constant = originalScalarProperty.constant; randomMin = originalScalarProperty.randomMin; randomMax = originalScalarProperty.randomMax; curve = ScriptableObject.CreateInstance <ScalarCurve>(); curve.Initialize(originalScalarProperty.curve); curveMin = ScriptableObject.CreateInstance <ScalarCurve>(); curveMin.Initialize(originalScalarProperty.curveMin); curveMax = ScriptableObject.CreateInstance <ScalarCurve>(); curveMax.Initialize(originalScalarProperty.curveMax); isInteger = originalScalarProperty.isInteger; Randomize(); }
//============================================================================// #if UNITY_EDITOR // INITIALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); type = "Basic setup"; emitterDuration = ScriptableObject.CreateInstance <ScalarProperty>(); emitterDuration.Initialize("Emitter duration", 5, theOwnerBlueprint); emitterDuration.SetDataModes(true, false, false, false, false, true); AddProperty(emitterDuration, false); isLooping = ScriptableObject.CreateInstance <BoolProperty>(); isLooping.SetDataModes(true, false, false, false, false, false); isLooping.Initialize("Looping?", true, theOwnerBlueprint); AddProperty(isLooping, false); maxParticles = ScriptableObject.CreateInstance <ScalarProperty>(); maxParticles.Initialize("Particle limit", 10, theOwnerBlueprint); maxParticles.SetDataModes(true, true, false, false, false, false); maxParticles.isInteger = true; AddProperty(maxParticles, false); updateRate = ScriptableObject.CreateInstance <ScalarProperty>(); updateRate.Initialize("Updates per second", 30, theOwnerBlueprint); updateRate.SetDataModes(true, false, false, false, false, false); AddProperty(updateRate, false); timeScale = ScriptableObject.CreateInstance <ScalarProperty>(); timeScale.Initialize("Time scale", 1, theOwnerBlueprint); timeScale.SetDataModes(true, false, false, false, false, false); AddProperty(timeScale, false); accelerationNoiseSmoothing = ScriptableObject.CreateInstance <ScalarProperty>(); accelerationNoiseSmoothing.Initialize("Accel. noise smoothing", 0.5f, theOwnerBlueprint); accelerationNoiseSmoothing.SetDataModes(true, false, false, false, false, false); AddProperty(accelerationNoiseSmoothing, false); playOnAwake = ScriptableObject.CreateInstance <BoolProperty>(); playOnAwake.SetDataModes(true, false, false, false, false, false); playOnAwake.Initialize("Plays on start?", true, theOwnerBlueprint); AddProperty(playOnAwake, false); pauseWhenUnseenDuration = ScriptableObject.CreateInstance <ScalarProperty>(); pauseWhenUnseenDuration.Initialize("Pause when unseen duration", 1, theOwnerBlueprint); pauseWhenUnseenDuration.SetDataModes(true, false, false, false, false, false); AddProperty(pauseWhenUnseenDuration, false); //canParentControlPlayback = ScriptableObject.CreateInstance<BoolProperty>(); //canParentControlPlayback.SetDataModes(true, false, false, false, false, false); //canParentControlPlayback.Initialize("Can parent control playback?", true, theOwnerBlueprint); //AddProperty(canParentControlPlayback, false); }
//============================================================================// #if UNITY_EDITOR // INITIALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); subMenuName = ""; type = "Mesh renderer"; SetDefaultName(); inputMeshCount = ScriptableObject.CreateInstance <ScalarProperty>(); inputMeshCount.Initialize("Mesh count", 1, theOwnerBlueprint); inputMeshCount.SetDataModes(true, false, false, false, false, false); inputMeshCount.isInteger = true; AddProperty(inputMeshCount, false); inputMeshes = new MeshProperty[1]; inputMeshes[0] = ScriptableObject.CreateInstance <MeshProperty>(); inputMeshes[0].Initialize("Mesh 0"); // We don't add mesh[0] to the property array because we will handle // the dynamic array of meshes in our own CopyProperties(). //SoftReset(); // To initialize the private variables. }
//============================================================================// #region Module management // DELETE MODULE FROM ASSET // // public void DeleteModuleFromAsset(BaseModule theModule) { for (int i = 0; i < theModule.properties.Count; i++) { if (theModule.properties[i].GetType() == typeof(ScalarProperty)) { ScalarProperty sp = theModule.properties[i] as ScalarProperty; UnityEngine.Object.DestroyImmediate(sp.curve, true); UnityEngine.Object.DestroyImmediate(sp.curveMin, true); UnityEngine.Object.DestroyImmediate(sp.curveMax, true); } if (theModule.properties[i].GetType() == typeof(VectorProperty)) { VectorProperty vp = theModule.properties[i] as VectorProperty; UnityEngine.Object.DestroyImmediate(vp.curve, true); UnityEngine.Object.DestroyImmediate(vp.curveMin, true); UnityEngine.Object.DestroyImmediate(vp.curveMax, true); } if (theModule.properties[i].GetType() == typeof(ColorProperty)) { ColorProperty cp = theModule.properties[i] as ColorProperty; UnityEngine.Object.DestroyImmediate(cp.curve, true); UnityEngine.Object.DestroyImmediate(cp.curveMin, true); UnityEngine.Object.DestroyImmediate(cp.curveMax, true); } if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(theModule.properties[i].reference)) == false) { UnityEngine.Object.DestroyImmediate(theModule.properties[i].reference, true); } UnityEngine.Object.DestroyImmediate(theModule.properties[i], true); } UnityEngine.Object.DestroyImmediate(theModule, true); AssetDatabase.SaveAssets(); ownerBlueprint.ownerEmitter.SoftReset(); }
//============================================================================// #if UNITY_EDITOR // INITIALIZE // // override public void Initialize(BaseStack theOwnerStack, AmpsBlueprint theOwnerBlueprint) { base.Initialize(theOwnerStack, theOwnerBlueprint); subMenuName = ""; type = "Quick setup"; SetDefaultName(); modifySpawnRate.value = true; modifyDeathCondition.value = true; modifyAcceleration.value = true; modifyVelocity.value = true; modifyPosition.value = true; modifyRotationRate.value = true; modifyRotation.value = true; modifyScale.value = true; modifyColor.value = true; modifyPivotOffset.value = true; spawnRate = ScriptableObject.CreateInstance <ScalarProperty>(); spawnRate.Initialize("Spawn rate", 5, theOwnerBlueprint); spawnRate.allowDataModeReference = false; AddProperty(spawnRate, false); deathCondition = ScriptableObject.CreateInstance <ScalarProperty>(); deathCondition.Initialize("Death condition", 0, theOwnerBlueprint); deathCondition.allowDataModeReference = false; deathCondition.dataMode = BaseProperty.eDataMode.Curve; deathCondition.curve.curveInput = AmpsHelpers.eCurveInputs.ParticleTime; deathCondition.curve.inputRangeMin = 0; deathCondition.curve.inputRangeMax = 2; // Default lifetime. deathCondition.curve.curve.AddKey(0, 0); deathCondition.curve.curve.AddKey(1, 1); deathCondition.curve.outputRangeMin = 0; deathCondition.curve.outputRangeMax = 1; AddProperty(deathCondition, false); acceleration = ScriptableObject.CreateInstance <VectorProperty>(); acceleration.Initialize("Acceleration", new Vector4(0, -0.1f, 0, 0), theOwnerBlueprint); acceleration.allowDataModeReference = false; acceleration.coordSystemConversionMode = BaseProperty.eCoordSystemConversionMode.AsVelocity; acceleration.usePerComponentRandom = true; acceleration.hideW = true; AddProperty(acceleration, false); velocity = ScriptableObject.CreateInstance <VectorProperty>(); velocity.Initialize("Velocity min", new Vector4(0, 0, 0, 0), theOwnerBlueprint); velocity.allowDataModeReference = false; velocity.coordSystemConversionMode = BaseProperty.eCoordSystemConversionMode.AsVelocity; velocity.hideW = true; velocity.usePerComponentRandom = true; velocity.dataMode = BaseProperty.eDataMode.RandomConstant; velocity.randomMin = new Vector4(-1, 1, -1, 0); velocity.randomMax = new Vector4(1, 2, 1, 0); AddProperty(velocity, false); position = ScriptableObject.CreateInstance <VectorProperty>(); position.Initialize("Position", new Vector4(0, 0, 0, 0), theOwnerBlueprint); position.allowDataModeReference = false; position.coordSystemConversionMode = BaseProperty.eCoordSystemConversionMode.AsPosition; position.coordSystem = AmpsHelpers.eCoordSystems.Emitter; position.hideW = true; position.usePerComponentRandom = true; AddProperty(position, false); rotationRate = ScriptableObject.CreateInstance <VectorProperty>(); rotationRate.Initialize("Rotation rate", new Vector4(0, 0, 0, 0), theOwnerBlueprint); rotationRate.allowDataModeReference = false; rotationRate.coordSystemConversionMode = BaseProperty.eCoordSystemConversionMode.AsVelocity; rotationRate.hideW = true; rotationRate.usePerComponentRandom = true; AddProperty(rotationRate, false); rotation = ScriptableObject.CreateInstance <VectorProperty>(); rotation.Initialize("Rotation", new Vector4(0, 0, 0, 0), theOwnerBlueprint); rotation.allowDataModeReference = false; rotation.coordSystemConversionMode = BaseProperty.eCoordSystemConversionMode.AsRotation; rotation.coordSystem = AmpsHelpers.eCoordSystems.Emitter; rotation.hideW = true; rotation.usePerComponentRandom = true; AddProperty(rotation, false); scale = ScriptableObject.CreateInstance <VectorProperty>(); scale.Initialize("Scale", new Vector4(0.2f, 0.2f, 0.2f, 0), theOwnerBlueprint); scale.allowDataModeReference = false; scale.coordSystemConversionMode = BaseProperty.eCoordSystemConversionMode.AsScale; scale.coordSystem = AmpsHelpers.eCoordSystems.Emitter; scale.usePerComponentRandom = false; scale.hideW = true; AddProperty(scale, false); color = ScriptableObject.CreateInstance <ColorProperty>(); color.Initialize("Color", new Vector4(1, 0.5f, 0.25f, 1), theOwnerBlueprint); color.allowDataModeReference = false; color.usePerComponentRandom = false; AddProperty(color, false); pivotOffset = ScriptableObject.CreateInstance <VectorProperty>(); pivotOffset.Initialize("Pivot offset", new Vector4(0, 0, 0, 0), theOwnerBlueprint); pivotOffset.allowDataModeReference = false; pivotOffset.coordSystemConversionMode = BaseProperty.eCoordSystemConversionMode.AsPosition; pivotOffset.hideW = true; pivotOffset.usePerComponentRandom = true; AddProperty(pivotOffset, false); }