using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; namespace DisComputer { /// /// 延申指向箭头 /// public class ProgressArrow : MonoBehaviour { //箭头进度延申 private List arrowImgs; [SerializeField] private Color init_color = new Color(67.0f/255.0f,123.0f/255.0f,171.0f/255.0f,1); [SerializeField] private Color shake_color = new Color(245.0f/255.0f,244.0f/255.0f,38.0f/255.0f,1); public bool isInitColor = true; [Header("初始隐藏")] public bool isInitHide = false; private float speed = 1.2f; private void Awake() { arrowImgs = new List(GetComponentsInChildren()); } // Start is called before the first frame update void Start() { if(isInitHide) SetArrowZero(); } public void PlayArrow(bool isShake,Action finish=null) { SetArrowZero(); StartCoroutine(Play(isShake,finish)); } private void OnDisable() { SetArrowZero(); } /// /// 设置箭头归零 /// public void SetArrowZero() { if ( arrowImgs == null||arrowImgs.Count < 0) return; foreach(var item in arrowImgs) { item.fillAmount = 0; if(isInitColor) item.color = init_color; } } /// /// 设置箭头归一 /// void SetArrowOne() { if (arrowImgs == null || arrowImgs.Count < 0) return; foreach (var item in arrowImgs) { item.fillAmount = 1; } } /// /// 播放箭头动效 /// IEnumerator Play(bool isShake,Action finish=null) { int i = 0; float fillamount = .0f; while (true) { yield return new WaitForEndOfFrame(); Image image = arrowImgs[i]; if (isShake) image.color = shake_color; fillamount += Time.deltaTime * speed; image.fillAmount = fillamount; if (fillamount >= 1.0f) { i++; fillamount = .0f; } if (i >= arrowImgs.Count) break; } finish?.Invoke(); } } }