private static float CalculateAudioNoiseZ(float _positionY, float _positionX, Hayate hayate) { positionRemapedY = (int)(_positionY % hayate.amountOfSamples); positionRemapedX = (int)(_positionX % hayate.amountOfSamples); indexTurb = ((positionRemapedX) * hayate.amountOfSamples + (positionRemapedY)); indexTurb = Mathf.Abs(indexTurb); turbulenceValue = hayate.hayateSamples[indexTurb] * hayate.Amplitude.z * hayate.deltaTime; return(turbulenceValue); }
public static void CalculateAudioTurbulence( Hayate hayate ) { if (!hayate.audioClip) { return; } hayate.hayateSamples = new float[hayate.amountOfSamples * hayate.amountOfSamples]; float[] audioTurbX = new float[hayate.amountOfSamples * 2]; float[] audioTurbY = new float[hayate.amountOfSamples * 2]; hayate.audioClip.GetData(audioTurbX, hayate.atSample); hayate.audioClip.GetData(audioTurbY, hayate.atSample + hayate.amountOfSamples * 2); for (int x = 0; x < hayate.amountOfSamples; x++) { for (int y = 0; y < hayate.amountOfSamples; y++) { hayate.hayateSamples[y * hayate.amountOfSamples + x] = audioTurbY[x * 2] + audioTurbX[y * 2] / 2f; } } }
public static void CalculateAudioTurbulence(Hayate hayate) { if (!hayate.audioClip) { return; } hayate.hayateSamples = new float[hayate.amountOfSamples * hayate.amountOfSamples]; float[] audioTurbX = new float[hayate.amountOfSamples * 2]; float[] audioTurbY = new float[hayate.amountOfSamples * 2]; hayate.audioClip.GetData(audioTurbX, hayate.atSample); hayate.audioClip.GetData(audioTurbY, hayate.atSample + hayate.amountOfSamples * 2); for (int x = 0; x < hayate.amountOfSamples; x++) { for (int y = 0; y < hayate.amountOfSamples; y++) { hayate.hayateSamples[y * hayate.amountOfSamples + x] = audioTurbY[x * 2] + audioTurbX[y * 2] / 2f; } } }
void functionKeys(int windowID) { GUILayout.Space(5f); GUILayout.BeginHorizontal(); GUILayout.Label("Emitter: ", GUILayout.MaxWidth(80)); if (GUILayout.Button("Plane", GUILayout.MaxWidth(80))) { HayateHolder.SetActive(true); HayateHolder3.SetActive(false); HayateHolder2.SetActive(false); hayate = HayateHolder.GetComponent <Hayate>(); } if (GUILayout.Button("Sphere", GUILayout.MaxWidth(80))) { HayateHolder.SetActive(false); HayateHolder3.SetActive(false); HayateHolder2.SetActive(true); hayate = HayateHolder2.GetComponent <Hayate>(); } if (GUILayout.Button("Line", GUILayout.MaxWidth(80))) { HayateHolder.SetActive(false); HayateHolder3.SetActive(true); HayateHolder2.SetActive(false); hayate = HayateHolder3.GetComponent <Hayate>(); } if (GUILayout.Button("Velocity relative", GUILayout.MaxWidth(120))) { hayate.UseRelativeOrAbsoluteValues = Hayate.TurbulenceType.relative; hayate.AssignTurbulenceTo = Hayate.AssignTo.velocity; } if (GUILayout.Button("Velocity absolute", GUILayout.MaxWidth(120))) { hayate.UseRelativeOrAbsoluteValues = Hayate.TurbulenceType.absolute; hayate.AssignTurbulenceTo = Hayate.AssignTo.velocity; } if (GUILayout.Button("Position relative", GUILayout.MaxWidth(120))) { hayate.UseRelativeOrAbsoluteValues = Hayate.TurbulenceType.relative; hayate.AssignTurbulenceTo = Hayate.AssignTo.position; } GUILayout.EndHorizontal(); GUILayout.Space(5f); GUILayout.BeginHorizontal(); GUILayout.Label("X-Axis: ", GUILayout.MaxWidth(80)); if (GUILayout.Button("None", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodX = Hayate.CalculationMethod.none; } if (GUILayout.Button("Sine", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodX = Hayate.CalculationMethod.sine; } if (GUILayout.Button("Cosine", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodX = Hayate.CalculationMethod.cosine; } if (GUILayout.Button("Perlin", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodX = Hayate.CalculationMethod.perlin; } if (GUILayout.Button("Texture", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodX = Hayate.CalculationMethod.precalculatedTexture; } if (GUILayout.Button("Audio", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodX = Hayate.CalculationMethod.Audio; } GUILayout.Label("Amplitude: ", GUILayout.MaxWidth(80)); hayate.Amplitude.x = float.Parse(GUILayout.TextField(hayate.Amplitude.x.ToString(), GUILayout.MaxWidth(50))); GUILayout.Label("Frequency: ", GUILayout.MaxWidth(80)); hayate.Frequency.x = float.Parse(GUILayout.TextField(hayate.Frequency.x.ToString(), GUILayout.MaxWidth(50))); GUILayout.Label("Offset: ", GUILayout.MaxWidth(80)); hayate.Offset.x = float.Parse(GUILayout.TextField(hayate.Offset.x.ToString(), GUILayout.MaxWidth(50))); GUILayout.Label("OffsetSpeed: ", GUILayout.MaxWidth(80)); hayate.OffsetSpeed.x = float.Parse(GUILayout.TextField(hayate.OffsetSpeed.x.ToString(), GUILayout.MaxWidth(50))); GUILayout.EndHorizontal(); GUILayout.Space(5f); GUILayout.BeginHorizontal(); GUILayout.Label("Y-Axis: ", GUILayout.MaxWidth(80)); if (GUILayout.Button("None", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodY = Hayate.CalculationMethod.none; } if (GUILayout.Button("Sine", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodY = Hayate.CalculationMethod.sine; } if (GUILayout.Button("Cosine", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodY = Hayate.CalculationMethod.cosine; } if (GUILayout.Button("Perlin", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodY = Hayate.CalculationMethod.perlin; } if (GUILayout.Button("Texture", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodY = Hayate.CalculationMethod.precalculatedTexture; } if (GUILayout.Button("Audio", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodY = Hayate.CalculationMethod.Audio; } GUILayout.Label("Amplitude: ", GUILayout.MaxWidth(80)); hayate.Amplitude.y = float.Parse(GUILayout.TextField(hayate.Amplitude.y.ToString(), GUILayout.MaxWidth(50))); GUILayout.Label("Frequency: ", GUILayout.MaxWidth(80)); hayate.Frequency.y = float.Parse(GUILayout.TextField(hayate.Frequency.y.ToString(), GUILayout.MaxWidth(50))); GUILayout.Label("Offset: ", GUILayout.MaxWidth(80)); hayate.Offset.y = float.Parse(GUILayout.TextField(hayate.Offset.y.ToString(), GUILayout.MaxWidth(50))); GUILayout.Label("OffsetSpeed: ", GUILayout.MaxWidth(80)); hayate.OffsetSpeed.y = float.Parse(GUILayout.TextField(hayate.OffsetSpeed.y.ToString(), GUILayout.MaxWidth(50))); GUILayout.EndHorizontal(); GUILayout.Space(5f); GUILayout.BeginHorizontal(); GUILayout.Label("Z-Axis: ", GUILayout.MaxWidth(80)); if (GUILayout.Button("None", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodZ = Hayate.CalculationMethod.none; } if (GUILayout.Button("Sine", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodZ = Hayate.CalculationMethod.sine; } if (GUILayout.Button("Cosine", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodZ = Hayate.CalculationMethod.cosine; } if (GUILayout.Button("Perlin", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodZ = Hayate.CalculationMethod.perlin; } if (GUILayout.Button("Texture", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodZ = Hayate.CalculationMethod.precalculatedTexture; } if (GUILayout.Button("Audio", GUILayout.MaxWidth(80))) { hayate.UseCalculationMethodZ = Hayate.CalculationMethod.Audio; } GUILayout.Label("Amplitude: ", GUILayout.MaxWidth(80)); hayate.Amplitude.z = float.Parse(GUILayout.TextField(hayate.Amplitude.z.ToString(), GUILayout.MaxWidth(50))); GUILayout.Label("Frequency: ", GUILayout.MaxWidth(80)); hayate.Frequency.z = float.Parse(GUILayout.TextField(hayate.Frequency.z.ToString(), GUILayout.MaxWidth(50))); GUILayout.Label("Offset: ", GUILayout.MaxWidth(80)); hayate.Offset.z = float.Parse(GUILayout.TextField(hayate.Offset.z.ToString(), GUILayout.MaxWidth(50))); GUILayout.Label("OffsetSpeed: ", GUILayout.MaxWidth(80)); hayate.OffsetSpeed.z = float.Parse(GUILayout.TextField(hayate.OffsetSpeed.z.ToString(), GUILayout.MaxWidth(50))); GUILayout.EndHorizontal(); //hayate.Amplitude.y = GUILayout.HorizontalSlider(hayate.Amplitude.y, -500f, 500f); //hayate.Amplitude.z = GUILayout.HorizontalSlider(hayate.Amplitude.z, -500f, 500f); }
void Start() { window = new Rect(0, Screen.height - 150, Screen.width, 150); hayate = HayateHolder.GetComponent <Hayate>(); }
public static Vector3 GetTurbulence(Vector3 _position, Hayate hayate) { float turbX = 0f; float turbY = 0f; float turbZ = 0f; if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.sine) { turbX = (Mathf.Sin(_position.z / hayate.Frequency.x - hayate.Offset.x) * hayate.Amplitude.x + hayate.GlobalForce.x) * hayate.deltaTime; } else if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.cosine) { turbX = (Mathf.Cos(_position.z / hayate.Frequency.x - hayate.Offset.x) * hayate.Amplitude.x + hayate.GlobalForce.x) * hayate.deltaTime; } else if(hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.animationCurve) { turbX = (hayate.turbulenceCurveX.Evaluate( _position.y / hayate.Frequency.x - hayate.Offset.x ) * hayate.Amplitude.x + hayate.GlobalForce.x) * hayate.deltaTime; } else if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.perlin) { turbX = ((Mathf.PerlinNoise(_position.z / hayate.Frequency.z - hayate.Offset.z, _position.y / hayate.Frequency.y - hayate.Offset.y) * 2 - 1) * hayate.Amplitude.x + hayate.GlobalForce.x) * hayate.deltaTime; } else if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.precalculatedTexture) { if (hayate.turbulence != null && hayate.turbulence.Length != 0) turbX = (CalculateTextureNoiseOnXAxis(_position.z / hayate.Frequency.z * 100f - hayate.Offset.z, _position.y / hayate.Frequency.y * 100f - hayate.Offset.y, hayate) + hayate.GlobalForce.x) * hayate.deltaTime; } else if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.Audio) { if (hayate.hayateSamples != null && hayate.hayateSamples.Length != 0) turbX = (CalculateAudioNoiseX(_position.z / hayate.Frequency.z * 100f - hayate.Offset.z, _position.y / hayate.Frequency.y * 100f - hayate.Offset.y, hayate) + hayate.GlobalForce.x) * hayate.deltaTime; } if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.sine) { turbY = (Mathf.Sin(_position.z / hayate.Frequency.y - hayate.Offset.y) * hayate.Amplitude.y + hayate.GlobalForce.y) * hayate.deltaTime; } else if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.cosine) { turbY = (Mathf.Cos(_position.z / hayate.Frequency.y - hayate.Offset.y) * hayate.Amplitude.y + hayate.GlobalForce.y) * hayate.deltaTime; } else if(hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.animationCurve) { turbY = (hayate.turbulenceCurveY.Evaluate( _position.x / hayate.Frequency.y - hayate.Offset.y ) * hayate.Amplitude.y + hayate.GlobalForce.y) * hayate.deltaTime; } else if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.perlin) { turbY = ((Mathf.PerlinNoise(_position.x / hayate.Frequency.x - hayate.Offset.x, _position.z / hayate.Frequency.z - hayate.Offset.z) * 2 - 1) * hayate.Amplitude.y + hayate.GlobalForce.y) * hayate.deltaTime; } else if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.precalculatedTexture) { if (hayate.turbulence != null && hayate.turbulence.Length != 0) turbY = (CalculateTextureNoiseOnYAxis(_position.x / hayate.Frequency.x * 100f - hayate.Offset.x, _position.z / hayate.Frequency.z * 100f - hayate.Offset.z, hayate) + hayate.GlobalForce.y) * hayate.deltaTime; } else if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.Audio) { if (hayate.hayateSamples != null && hayate.hayateSamples.Length != 0) turbY = (CalculateAudioNoiseY(_position.x / hayate.Frequency.x * 100f - hayate.Offset.x, _position.z / hayate.Frequency.z * 100f - hayate.Offset.z, hayate) + hayate.GlobalForce.y) * hayate.deltaTime; } if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.sine) { turbZ = (Mathf.Sin(_position.x / hayate.Frequency.z - hayate.Offset.z) * hayate.Amplitude.z + hayate.GlobalForce.z) * hayate.deltaTime; } else if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.cosine) { turbZ = (Mathf.Cos(_position.x / hayate.Frequency.z - hayate.Offset.z) * hayate.Amplitude.z + hayate.GlobalForce.z) * hayate.deltaTime; } else if(hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.animationCurve) { turbZ = (hayate.turbulenceCurveZ.Evaluate( _position.y / hayate.Frequency.z - hayate.Offset.z ) * hayate.Amplitude.z + hayate.GlobalForce.z) * hayate.deltaTime; } else if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.perlin) { turbZ = ((Mathf.PerlinNoise(_position.y / hayate.Frequency.y - hayate.Offset.y, _position.x / hayate.Frequency.x - hayate.Offset.x) * 2 - 1) * hayate.Amplitude.z + hayate.GlobalForce.z) * hayate.deltaTime; } else if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.precalculatedTexture) { if (hayate.turbulence != null && hayate.turbulence.Length != 0) turbZ = (CalculateTextureNoiseOnZAxis(_position.y / hayate.Frequency.y * 100f - hayate.Offset.y, _position.x / hayate.Frequency.x * 100f - hayate.Offset.x, hayate) + hayate.GlobalForce.z) * hayate.deltaTime; } else if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.Audio) { if (hayate.hayateSamples != null && hayate.hayateSamples.Length != 0) turbZ = (CalculateAudioNoiseZ(_position.y / hayate.Frequency.y * 100f - hayate.Offset.y, _position.x / hayate.Frequency.x * 100f - hayate.Offset.x, hayate) + hayate.GlobalForce.z) * hayate.deltaTime; } calculatedTurbulence = new Vector3(turbX, turbY, turbZ); return calculatedTurbulence; }
private static float CalculateTextureNoiseOnZAxis(float _positionY, float _positionX, Hayate hayate) { positionRemapedY = (int)(_positionY % hayate.Turbulence.width); positionRemapedX = (int)(_positionX % hayate.Turbulence.height); indexTurb = ((positionRemapedX) * hayate.Turbulence.width + (positionRemapedY)); indexTurb = Mathf.Abs(indexTurb); if (hayate.useAlphaMask && hayate.turbulence[indexTurb].a == 0) hayate.removeCurrentParticle = true; turbulenceValue = ((hayate.turbulence[indexTurb].b / 256f) * 2 - 1) * hayate.Amplitude.z * hayate.deltaTime; return (turbulenceValue); }
private static float CalculateAudioNoiseZ(float _positionY, float _positionX, Hayate hayate) { positionRemapedY = (int)(_positionY % hayate.amountOfSamples); positionRemapedX = (int)(_positionX % hayate.amountOfSamples); indexTurb = ((positionRemapedX) * hayate.amountOfSamples + (positionRemapedY)); indexTurb = Mathf.Abs(indexTurb); turbulenceValue = hayate.hayateSamples[indexTurb] * hayate.Amplitude.z * hayate.deltaTime; return (turbulenceValue); }
public static ParticleSystem.Particle[] CreateParticlesDynamically( Hayate hayate, Vector3 _Position, float _Width, float _Height, float _Depth, float _TargetParticleSize, float _UiScale, HayateEnums.BuildOrder _buildOrder) { int NumX = Mathf.CeilToInt (_Width / _TargetParticleSize ); int NumY = Mathf.CeilToInt (_Height / _TargetParticleSize ); int NumZ = Mathf.CeilToInt (_Depth / _TargetParticleSize ); int MaxParticles = NumX * NumY * NumZ; hayate.GetComponent<ParticleSystem>().startSize = _TargetParticleSize * _UiScale; hayate.GetComponent<ParticleSystem>().emissionRate = 0f; #if UNITY_4_5 || UNITY_4_6 || UNITY_5_0 hayate.particleSystem.maxParticles = MaxParticles; #endif hayate.GetComponent<ParticleSystem>().Emit( MaxParticles ); ParticleSystem.Particle[] Particles = new ParticleSystem.Particle[MaxParticles]; hayate.GetComponent<ParticleSystem>().GetParticles(Particles); int index = 0; int zIndex = 1; switch (_buildOrder) { case HayateEnums.BuildOrder.TopBottom: for(int z = 0; z < NumZ; z++) { int yIndex = 1; for(int y = NumY; y > 0; y--) { int xIndex = 1; for(int x = 0; x < NumX; x++) { Particles[index].position = new Vector3( ((_Position.x - ( _Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale )), ((_Position.y - ( _Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (y * _TargetParticleSize * _UiScale )), ((_Position.z - ( _Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale )) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * ((NumX/2f) * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.TopRightBottomLeft: for(int z = 0; z < NumZ; z++) { int yIndex = 1; for(int y = NumY; y > 0; y--) { int xIndex = 1; for(int x = NumX; x > 0 ; x--) { Particles[index].position = new Vector3( ((_Position.x - ( _Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (x * _TargetParticleSize * _UiScale )), ((_Position.y - ( _Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (y * _TargetParticleSize * _UiScale )), ((_Position.z - ( _Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale )) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.RightLeft: for(int z = 0; z < NumZ; z++) { int xIndex = 1; for(int x = NumX; x > 0; x--) { int yIndex = 1; for(int y = 0; y < NumY; y++) { Particles[index].position = new Vector3( ((_Position.x - ( _Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (x * _TargetParticleSize * _UiScale )), ((_Position.y - ( _Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale )), ((_Position.z - ( _Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale )) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.BottomRightTopLeft: for(int z = 0; z < NumZ; z++) { int yIndex = 1; for(int y = 0; y < NumY; y++) { int xIndex = 1; for(int x = NumX; x > 0 ; x--) { Particles[index].position = new Vector3( ((_Position.x - ( _Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (x * _TargetParticleSize * _UiScale )), ((_Position.y - ( _Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale )), ((_Position.z - ( _Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale )) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.BottomTop: for(int z = 0; z < NumZ; z++) { int yIndex = 1; for(int y = 0; y < NumY; y++) { int xIndex = 1; for(int x = 0; x < NumX; x++) { Particles[index].position = new Vector3( ((_Position.x - ( _Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale )), ((_Position.y - ( _Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale )), ((_Position.z - ( _Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale )) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * ((NumX/2f) * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.BottomLeftTopRight: for(int z = 0; z < NumZ; z++) { int yIndex = 1; for(int y = 0; y < NumY; y++) { int xIndex = 1; for(int x = 0; x < NumX; x++) { Particles[index].position = new Vector3( ((_Position.x - ( _Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale )), ((_Position.y - ( _Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale )), ((_Position.z - ( _Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale ))); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.LeftRight: for(int z = 0; z < NumZ; z++) { int xIndex = 1; for(int x = 0; x < NumX; x++) { int yIndex = 1; for(int y = 0; y < NumY; y++) { Particles[index].position = new Vector3( ((_Position.x - ( _Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale )), ((_Position.y - ( _Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale )), ((_Position.z - ( _Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale )) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.TopLeftBottomRight: for(int z = 0; z < NumZ; z++) { int yIndex = 1; for(int y = NumY; y > 0; y--) { int xIndex = 1; for(int x = 0; x < NumX; x++) { Particles[index].position = new Vector3( ((_Position.x - ( _Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale )), ((_Position.y - ( _Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (y * _TargetParticleSize * _UiScale )), ((_Position.z - ( _Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale )) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; } return Particles; }
public static ParticleSystem.Particle[] CreateParticlesDynamically(Hayate hayate, Vector3 _Position, float _Width, float _Height, float _Depth, float _TargetParticleSize, float _UiScale, HayateEnums.BuildOrder _buildOrder) { int NumX = Mathf.CeilToInt(_Width / _TargetParticleSize); int NumY = Mathf.CeilToInt(_Height / _TargetParticleSize); int NumZ = Mathf.CeilToInt(_Depth / _TargetParticleSize); int MaxParticles = NumX * NumY * NumZ; hayate.particleSystem.startSize = _TargetParticleSize * _UiScale; hayate.particleSystem.emissionRate = 0f; #if UNITY_4_5 || UNITY_4_6 || UNITY_5_0 hayate.particleSystem.maxParticles = MaxParticles; #endif hayate.particleSystem.Emit(MaxParticles); ParticleSystem.Particle[] Particles = new ParticleSystem.Particle[MaxParticles]; hayate.particleSystem.GetParticles(Particles); int index = 0; int zIndex = 1; switch (_buildOrder) { case HayateEnums.BuildOrder.TopBottom: for (int z = 0; z < NumZ; z++) { int yIndex = 1; for (int y = NumY; y > 0; y--) { int xIndex = 1; for (int x = 0; x < NumX; x++) { Particles[index].position = new Vector3( ((_Position.x - (_Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale)), ((_Position.y - (_Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (y * _TargetParticleSize * _UiScale)), ((_Position.z - (_Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale)) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * ((NumX / 2f) * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.TopRightBottomLeft: for (int z = 0; z < NumZ; z++) { int yIndex = 1; for (int y = NumY; y > 0; y--) { int xIndex = 1; for (int x = NumX; x > 0; x--) { Particles[index].position = new Vector3( ((_Position.x - (_Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (x * _TargetParticleSize * _UiScale)), ((_Position.y - (_Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (y * _TargetParticleSize * _UiScale)), ((_Position.z - (_Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale)) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.RightLeft: for (int z = 0; z < NumZ; z++) { int xIndex = 1; for (int x = NumX; x > 0; x--) { int yIndex = 1; for (int y = 0; y < NumY; y++) { Particles[index].position = new Vector3( ((_Position.x - (_Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (x * _TargetParticleSize * _UiScale)), ((_Position.y - (_Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale)), ((_Position.z - (_Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale)) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.BottomRightTopLeft: for (int z = 0; z < NumZ; z++) { int yIndex = 1; for (int y = 0; y < NumY; y++) { int xIndex = 1; for (int x = NumX; x > 0; x--) { Particles[index].position = new Vector3( ((_Position.x - (_Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (x * _TargetParticleSize * _UiScale)), ((_Position.y - (_Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale)), ((_Position.z - (_Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale)) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.BottomTop: for (int z = 0; z < NumZ; z++) { int yIndex = 1; for (int y = 0; y < NumY; y++) { int xIndex = 1; for (int x = 0; x < NumX; x++) { Particles[index].position = new Vector3( ((_Position.x - (_Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale)), ((_Position.y - (_Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale)), ((_Position.z - (_Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale)) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * ((NumX / 2f) * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.BottomLeftTopRight: for (int z = 0; z < NumZ; z++) { int yIndex = 1; for (int y = 0; y < NumY; y++) { int xIndex = 1; for (int x = 0; x < NumX; x++) { Particles[index].position = new Vector3( ((_Position.x - (_Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale)), ((_Position.y - (_Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale)), ((_Position.z - (_Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale))); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.LeftRight: for (int z = 0; z < NumZ; z++) { int xIndex = 1; for (int x = 0; x < NumX; x++) { int yIndex = 1; for (int y = 0; y < NumY; y++) { Particles[index].position = new Vector3( ((_Position.x - (_Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale)), ((_Position.y - (_Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (y * _TargetParticleSize * _UiScale)), ((_Position.z - (_Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale)) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; case HayateEnums.BuildOrder.TopLeftBottomRight: for (int z = 0; z < NumZ; z++) { int yIndex = 1; for (int y = NumY; y > 0; y--) { int xIndex = 1; for (int x = 0; x < NumX; x++) { Particles[index].position = new Vector3( ((_Position.x - (_Width * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (x * _TargetParticleSize * _UiScale)), ((_Position.y - (_Height * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) - (_TargetParticleSize * _UiScale) + (y * _TargetParticleSize * _UiScale)), ((_Position.z - (_Depth * _UiScale / 2f) + _TargetParticleSize * _UiScale / 2f) + (z * _TargetParticleSize * _UiScale)) ); Particles[index].lifetime += (Particles[index].startLifetime / MaxParticles) * (xIndex * yIndex * zIndex); Particles[index].startLifetime = Particles[index].lifetime; index++; xIndex++; } yIndex++; } zIndex++; } break; } return(Particles); }
private static float CalculateTextureNoiseOnZAxis(float _positionY, float _positionX, Hayate hayate) { positionRemapedY = (int)(_positionY % hayate.Turbulence.width); positionRemapedX = (int)(_positionX % hayate.Turbulence.height); indexTurb = ((positionRemapedX) * hayate.Turbulence.width + (positionRemapedY)); indexTurb = Mathf.Abs(indexTurb); if (hayate.useAlphaMask && hayate.turbulence[indexTurb].a == 0) { hayate.removeCurrentParticle = true; } turbulenceValue = ((hayate.turbulence[indexTurb].b / 256f) * 2 - 1) * hayate.Amplitude.z * hayate.deltaTime; return(turbulenceValue); }
public static Vector3 GetTurbulence(Vector3 _position, Hayate hayate) { float turbX = 0f; float turbY = 0f; float turbZ = 0f; if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.sine) { turbX = (Mathf.Sin(_position.z / hayate.Frequency.x - hayate.Offset.x) * hayate.Amplitude.x + hayate.GlobalForce.x) * hayate.deltaTime; } else if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.cosine) { turbX = (Mathf.Cos(_position.z / hayate.Frequency.x - hayate.Offset.x) * hayate.Amplitude.x + hayate.GlobalForce.x) * hayate.deltaTime; } else if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.animationCurve) { turbX = (hayate.turbulenceCurveX.Evaluate(_position.y / hayate.Frequency.x - hayate.Offset.x) * hayate.Amplitude.x + hayate.GlobalForce.x) * hayate.deltaTime; } else if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.perlin) { turbX = ((Mathf.PerlinNoise(_position.z / hayate.Frequency.z - hayate.Offset.z, _position.y / hayate.Frequency.y - hayate.Offset.y) * 2 - 1) * hayate.Amplitude.x + hayate.GlobalForce.x) * hayate.deltaTime; } else if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.precalculatedTexture) { if (hayate.turbulence != null && hayate.turbulence.Length != 0) { turbX = (CalculateTextureNoiseOnXAxis(_position.z / hayate.Frequency.z * 100f - hayate.Offset.z, _position.y / hayate.Frequency.y * 100f - hayate.Offset.y, hayate) + hayate.GlobalForce.x) * hayate.deltaTime; } } else if (hayate.UseCalculationMethodX == HayateEnums.CalculationMethod.Audio) { if (hayate.hayateSamples != null && hayate.hayateSamples.Length != 0) { turbX = (CalculateAudioNoiseX(_position.z / hayate.Frequency.z * 100f - hayate.Offset.z, _position.y / hayate.Frequency.y * 100f - hayate.Offset.y, hayate) + hayate.GlobalForce.x) * hayate.deltaTime; } } if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.sine) { turbY = (Mathf.Sin(_position.z / hayate.Frequency.y - hayate.Offset.y) * hayate.Amplitude.y + hayate.GlobalForce.y) * hayate.deltaTime; } else if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.cosine) { turbY = (Mathf.Cos(_position.z / hayate.Frequency.y - hayate.Offset.y) * hayate.Amplitude.y + hayate.GlobalForce.y) * hayate.deltaTime; } else if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.animationCurve) { turbY = (hayate.turbulenceCurveY.Evaluate(_position.x / hayate.Frequency.y - hayate.Offset.y) * hayate.Amplitude.y + hayate.GlobalForce.y) * hayate.deltaTime; } else if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.perlin) { turbY = ((Mathf.PerlinNoise(_position.x / hayate.Frequency.x - hayate.Offset.x, _position.z / hayate.Frequency.z - hayate.Offset.z) * 2 - 1) * hayate.Amplitude.y + hayate.GlobalForce.y) * hayate.deltaTime; } else if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.precalculatedTexture) { if (hayate.turbulence != null && hayate.turbulence.Length != 0) { turbY = (CalculateTextureNoiseOnYAxis(_position.x / hayate.Frequency.x * 100f - hayate.Offset.x, _position.z / hayate.Frequency.z * 100f - hayate.Offset.z, hayate) + hayate.GlobalForce.y) * hayate.deltaTime; } } else if (hayate.UseCalculationMethodY == HayateEnums.CalculationMethod.Audio) { if (hayate.hayateSamples != null && hayate.hayateSamples.Length != 0) { turbY = (CalculateAudioNoiseY(_position.x / hayate.Frequency.x * 100f - hayate.Offset.x, _position.z / hayate.Frequency.z * 100f - hayate.Offset.z, hayate) + hayate.GlobalForce.y) * hayate.deltaTime; } } if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.sine) { turbZ = (Mathf.Sin(_position.x / hayate.Frequency.z - hayate.Offset.z) * hayate.Amplitude.z + hayate.GlobalForce.z) * hayate.deltaTime; } else if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.cosine) { turbZ = (Mathf.Cos(_position.x / hayate.Frequency.z - hayate.Offset.z) * hayate.Amplitude.z + hayate.GlobalForce.z) * hayate.deltaTime; } else if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.animationCurve) { turbZ = (hayate.turbulenceCurveZ.Evaluate(_position.y / hayate.Frequency.z - hayate.Offset.z) * hayate.Amplitude.z + hayate.GlobalForce.z) * hayate.deltaTime; } else if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.perlin) { turbZ = ((Mathf.PerlinNoise(_position.y / hayate.Frequency.y - hayate.Offset.y, _position.x / hayate.Frequency.x - hayate.Offset.x) * 2 - 1) * hayate.Amplitude.z + hayate.GlobalForce.z) * hayate.deltaTime; } else if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.precalculatedTexture) { if (hayate.turbulence != null && hayate.turbulence.Length != 0) { turbZ = (CalculateTextureNoiseOnZAxis(_position.y / hayate.Frequency.y * 100f - hayate.Offset.y, _position.x / hayate.Frequency.x * 100f - hayate.Offset.x, hayate) + hayate.GlobalForce.z) * hayate.deltaTime; } } else if (hayate.UseCalculationMethodZ == HayateEnums.CalculationMethod.Audio) { if (hayate.hayateSamples != null && hayate.hayateSamples.Length != 0) { turbZ = (CalculateAudioNoiseZ(_position.y / hayate.Frequency.y * 100f - hayate.Offset.y, _position.x / hayate.Frequency.x * 100f - hayate.Offset.x, hayate) + hayate.GlobalForce.z) * hayate.deltaTime; } } calculatedTurbulence = new Vector3(turbX, turbY, turbZ); return(calculatedTurbulence); }