using System; using UnityEngine; public class UI_ParticleRange : UI_ScreenFitBase { protected override void Start() { this.m_MyParticle = base.GetComponent(); this.m_FirstLifeTime = this.m_MyParticle.main.startLifetimeMultiplier; this.m_FirstSpeed = this.m_MyParticle.main.startSpeedMultiplier; this.m_FirstCircleRange = this.m_MyParticle.shape.radius; this.m_FirstBoxRange = this.m_MyParticle.shape.box; this.m_FirstSize = this.m_MyParticle.main.startSizeMultiplier; this.m_FirstSize3D.x = this.m_MyParticle.main.startSizeXMultiplier; this.m_FirstSize3D.y = this.m_MyParticle.main.startSizeYMultiplier; this.m_FirstSize3D.z = this.m_MyParticle.main.startSizeZMultiplier; if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.Circle) { base.transform.localScale = base.ScreenRate(0f, 1f, 1f) * Vector3.one; } base.Start(); } protected override void Update() { base.Update(); } protected override void FitAction() { this.m_MyParticle.shape.box = this.m_FirstBoxRange; UI_ParticleRange.ParticleRangeType rangeType = this.m_RangeType; switch (rangeType) { case UI_ParticleRange.ParticleRangeType.Circle: case UI_ParticleRange.ParticleRangeType.CircleHorizontal: case UI_ParticleRange.ParticleRangeType.CircleVirtical: this.FitShapeCircle(); break; case UI_ParticleRange.ParticleRangeType.Cone: this.FitShapeCone(); break; default: if (rangeType != UI_ParticleRange.ParticleRangeType.None) { this.FitShapeBox(); } break; case UI_ParticleRange.ParticleRangeType.EdgeHorizontal: case UI_ParticleRange.ParticleRangeType.EdgeVertical: this.FitShapeEdge(); break; } } private void FitShapeBox() { ParticleSystem.ShapeModule shape = this.m_MyParticle.shape; ParticleSystem.MainModule main = this.m_MyParticle.main; Vector3 zero = Vector3.zero; UI_ParticleRange.ParticleRangeType rangeType = this.m_RangeType; if (rangeType != UI_ParticleRange.ParticleRangeType.ScreenHorizontal) { if (rangeType != UI_ParticleRange.ParticleRangeType.ScreenVertical) { if (rangeType == UI_ParticleRange.ParticleRangeType.ScreenAll) { zero.x = (float)Screen.width; zero.y = (float)Screen.height; } } else { zero.y = (float)Screen.height; } } else { zero.x = (float)Screen.width; } if (UI_ScreenFitBase.m_NGUICamera) { Vector3 vector = UI_ScreenFitBase.m_NGUICamera.ScreenToWorldPoint(zero) - UI_ScreenFitBase.m_NGUICamera.transform.position; Vector3 zero2 = Vector3.zero; UI_ParticleRange.ParticleRangeType rangeType2 = this.m_RangeType; if (rangeType2 != UI_ParticleRange.ParticleRangeType.ScreenHorizontal) { if (rangeType2 != UI_ParticleRange.ParticleRangeType.ScreenVertical) { if (rangeType2 == UI_ParticleRange.ParticleRangeType.ScreenAll) { zero2.x = vector.x * 2f; zero2.y = vector.y * 2f; } } else { zero2.y = vector.y * 2f; if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f) { zero2.x = this.m_AsspectRatio.x / this.m_AsspectRatio.y * zero2.y; } else if (!this.m_IsSizeAdjust) { zero2.x = base.ScreenRate(0f, this.m_FirstBoxRange.x, this.m_FirstBoxRange.x); } else { zero2.x = base.ScreenRate(0f, this.m_FirstSize3D.x, this.m_FirstSize3D.x); } } } else { zero2.x = vector.x * 2f; if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f) { zero2.y = this.m_AsspectRatio.y / this.m_AsspectRatio.x * zero2.x; } else if (!this.m_IsSizeAdjust) { zero2.y = base.ScreenRate(0f, this.m_FirstBoxRange.y, this.m_FirstBoxRange.y); } else { zero2.y = base.ScreenRate(0f, this.m_FirstSize3D.y, this.m_FirstSize3D.y); } } if (this.m_IsSizeAdjust) { shape.box = this.m_FirstBoxRange; if (main.startSize3D) { main.startSizeX = zero2.x; main.startSizeY = zero2.y; } else if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.ScreenHorizontal) { main.startSize = zero2.x; } else if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.ScreenVertical) { main.startSize = zero2.y; } } else { shape.box = zero2; } } } private void FitShapeCircle() { ParticleSystem.ShapeModule shape = this.m_MyParticle.shape; ParticleSystem.MainModule main = this.m_MyParticle.main; if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.Circle) { main.startSpeedMultiplier = base.ScreenRate(this.m_MinSpeed, this.m_FirstSpeed, this.m_FirstSpeed); main.simulationSpeed = main.startSpeedMultiplier / this.m_FirstSpeed; base.transform.localScale = base.ScreenRate(0f, 1f, 1f) * Vector3.one; } else { Vector3 position = Vector3.zero; if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.CircleHorizontal) { position = Vector3.right * (float)Screen.width; } else { position = Vector3.up * (float)Screen.height; } Vector3 vector = UI_ScreenFitBase.m_NGUICamera.ScreenToWorldPoint(position) - UI_ScreenFitBase.m_NGUICamera.transform.position; if (this.m_IsSizeAdjust) { if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.CircleHorizontal) { main.startSizeMultiplier = vector.x; } else { main.startSizeMultiplier = vector.y; } } else if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.CircleHorizontal) { shape.radius = vector.x; } else { shape.radius = vector.y; } } } private void FitShapeCone() { ParticleSystem.MainModule main = this.m_MyParticle.main; main.startLifetimeMultiplier = base.ScreenRate(this.m_MinLifeTime, this.m_FirstLifeTime, this.m_FirstLifeTime); main.startSpeedMultiplier = base.ScreenRate(this.m_MinSpeed, this.m_FirstSpeed, this.m_FirstSpeed); main.simulationSpeed = main.startSpeedMultiplier / this.m_FirstSpeed; } private void FitShapeEdge() { ParticleSystem.MainModule main = this.m_MyParticle.main; Vector3 position = Vector3.zero; if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.EdgeHorizontal) { position = Vector3.right * (float)Screen.width; } else { position = Vector3.up * (float)Screen.height; } Vector3 vector = UI_ScreenFitBase.m_NGUICamera.ScreenToWorldPoint(position) - UI_ScreenFitBase.m_NGUICamera.transform.position; if (!this.m_IsAdjustSpeed) { if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.EdgeHorizontal) { main.startLifetimeMultiplier = vector.x * 3f / this.m_FirstSpeed; } else { main.startLifetimeMultiplier = vector.y * 3f / this.m_FirstSpeed; } if (this.m_STSync) { float b = this.m_FirstSpeed * (main.startLifetimeMultiplier / this.m_FirstLifeTime); main.startSpeedMultiplier = Mathf.Max(this.m_FirstSpeed, b); } else { main.startSpeedMultiplier = this.m_FirstSpeed; } } else { if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.EdgeHorizontal) { main.startSpeedMultiplier = vector.x * 3f / this.m_FirstLifeTime; } else { main.startSpeedMultiplier = vector.y * 3f / this.m_FirstLifeTime; } if (this.m_STSync) { float b2 = this.m_FirstLifeTime * (main.startSpeedMultiplier / this.m_FirstSpeed); main.startLifetimeMultiplier = Mathf.Max(this.m_FirstLifeTime, b2); } else { main.startLifetimeMultiplier = this.m_FirstLifeTime; } } if (this.m_MyParticle.noise.enabled && this.m_IsNoiseAdjust) { Vector3 localScale = base.transform.localScale; localScale.z = (float)Screen.height / (float)Screen.width; base.transform.localScale = localScale; } } [SerializeField] private UI_ParticleRange.ParticleRangeType m_RangeType = UI_ParticleRange.ParticleRangeType.None; [SerializeField] [Header("Shapeの大きさではなくStartSizeを直接変えるか")] private bool m_IsSizeAdjust; [SerializeField] [Header("Horizontal・Vertical時の画像の比率((0, 0)で比率固定されない)")] private Vector2 m_AsspectRatio = Vector2.zero; [SerializeField] [Header("パーティクルの最小速度(Circle・Coneで使用)")] private float m_MinSpeed = 0.15f; [SerializeField] [Header("パーティクル最小生存時間(Coneで使用)")] private float m_MinLifeTime = 0.01f; [SerializeField] [Header("ノイズも調整するか")] private bool m_IsNoiseAdjust; [SerializeField] [Header("(Edgeで使用)スピードで範囲調整するか")] private bool m_IsAdjustSpeed; [SerializeField] [Header("(Edgeで使用)速度と生存時間を同期させるか")] private bool m_STSync; private ParticleSystem m_MyParticle; private float m_FirstSize; private Vector3 m_FirstSize3D; private Vector3 m_FirstBoxRange; private float m_FirstCircleRange; private float m_FirstSpeed; private float m_FirstLifeTime; private enum ParticleRangeType { ScreenHorizontal, ScreenVertical, Circle = 4, Cone, ScreenAll, EdgeHorizontal, EdgeVertical, CircleHorizontal, CircleVirtical, None = 100 } }