123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- using System;
- using UnityEngine;
- public class UI_ParticleImageFit : UI_ScreenFitBase
- {
- protected override void Start()
- {
- this.m_MyParticle = base.GetComponent<ParticleSystem>();
- this.m_FirstSpeed = this.m_MyParticle.main.startSpeedMultiplier;
- this.m_FirstLifeTime = this.m_MyParticle.main.startLifetimeMultiplier;
- base.Start();
- }
- protected override void Update()
- {
- base.Update();
- }
- protected override void FitAction()
- {
- if (!this.FitImage)
- {
- return;
- }
- switch (this.m_ParticleType)
- {
- case UI_ParticleImageFit.ParticleType.Box:
- this.FitBox();
- break;
- case UI_ParticleImageFit.ParticleType.Edge:
- this.FitEdge();
- break;
- }
- }
- private void FitBox()
- {
- ParticleSystem.ShapeModule shape = this.m_MyParticle.shape;
- Vector3 vector = this.NguiToWorldSize();
- Vector3 box = vector;
- if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
- {
- UI_ParticleImageFit.FitType fitType = this.m_FitType;
- if (fitType != UI_ParticleImageFit.FitType.Horizontal)
- {
- if (fitType == UI_ParticleImageFit.FitType.Vertical)
- {
- box.x = vector.y * (this.m_AsspectRatio.x / this.m_AsspectRatio.y);
- }
- }
- else
- {
- box.y = vector.x * (this.m_AsspectRatio.y / this.m_AsspectRatio.x);
- }
- }
- shape.box = box;
- }
- private void FitEdge()
- {
- ParticleSystem.MainModule main = this.m_MyParticle.main;
- Vector3 vector = this.NguiToWorldSize();
- if (this.m_SpeedAdjust)
- {
- if (this.m_FitType == UI_ParticleImageFit.FitType.Horizontal)
- {
- main.startSpeedMultiplier = vector.x / this.m_FirstLifeTime;
- }
- else
- {
- main.startSpeedMultiplier = vector.y / this.m_FirstLifeTime;
- }
- main.startLifetimeMultiplier = this.m_FirstLifeTime;
- }
- else
- {
- if (this.m_FitType == UI_ParticleImageFit.FitType.Horizontal)
- {
- main.startLifetimeMultiplier = vector.x / this.m_FirstSpeed;
- }
- else
- {
- main.startLifetimeMultiplier = vector.y / this.m_FirstSpeed;
- }
- main.startSpeedMultiplier = this.m_FirstSpeed;
- }
- }
- private Vector3 NguiToWorldSize()
- {
- Vector3 zero = Vector3.zero;
- switch (this.m_FitType)
- {
- case UI_ParticleImageFit.FitType.Horizontal:
- zero.x = (float)Screen.width;
- break;
- case UI_ParticleImageFit.FitType.Vertical:
- zero.y = (float)Screen.height;
- break;
- case UI_ParticleImageFit.FitType.All:
- zero.x = (float)Screen.width;
- zero.y = (float)Screen.height;
- break;
- }
- Vector3 vector = UI_ScreenFitBase.PointToScreenPos(zero) * 2f;
- Vector3 zero2 = Vector3.zero;
- switch (this.m_FitType)
- {
- case UI_ParticleImageFit.FitType.Horizontal:
- zero2.x = (float)Screen.width * ((float)this.FitImage.width / vector.x + 0.5f);
- break;
- case UI_ParticleImageFit.FitType.Vertical:
- zero2.y = (float)Screen.height * ((float)this.FitImage.height / vector.y + 0.5f);
- break;
- case UI_ParticleImageFit.FitType.All:
- zero2.x = (float)Screen.width * ((float)this.FitImage.width / vector.x + 0.5f);
- zero2.y = (float)Screen.height * ((float)this.FitImage.height / vector.y + 0.5f);
- break;
- }
- Vector3 vector2 = UI_ScreenFitBase.m_NGUICamera.ScreenToWorldPoint(zero2) - UI_ScreenFitBase.m_NGUICamera.transform.position;
- if (this.m_UseFillAmount)
- {
- if (this.m_FillReverse)
- {
- vector2 *= 1f - this.FitImage.fillAmount;
- }
- else
- {
- vector2 *= this.FitImage.fillAmount;
- }
- }
- else if (this.m_UseSizeRate)
- {
- vector2.x *= this.SizeRateX;
- vector2.y *= this.SizeRateY;
- }
- return vector2;
- }
- public UIBasicSprite FitImage;
- [SerializeField]
- private UI_ParticleImageFit.FitType m_FitType;
- [SerializeField]
- private UI_ParticleImageFit.ParticleType m_ParticleType;
- [SerializeField]
- [Header("スプライトのFillAmountを使うかどうか")]
- private bool m_UseFillAmount;
- [SerializeField]
- private bool m_FillReverse;
- [SerializeField]
- [Header("画像に対して一定の割合を使うか")]
- private bool m_UseSizeRate;
- [Range(0f, 1f)]
- public float SizeRateX = 1f;
- [Range(0f, 1f)]
- public float SizeRateY = 1f;
- [Header("ParticleType->Box時の設定項目")]
- [SerializeField]
- [Header("パーティクルの縦横比率((0, 0)で比率固定されない)")]
- private Vector2 m_AsspectRatio = Vector2.zero;
- [Header("ParticleType->Edge時の設定項目")]
- [SerializeField]
- [Header("速度で調整するか(しない場合は生存時間で調整)")]
- private bool m_SpeedAdjust;
- private float m_FirstSpeed;
- private float m_FirstLifeTime;
- private ParticleSystem m_MyParticle;
- private enum FitType
- {
- Horizontal,
- Vertical,
- All
- }
- private enum ParticleType
- {
- Box,
- Edge,
- Other
- }
- }
|