using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using DG.Tweening; namespace MapUnit { /// /// 消融控制 /// public class LoopClip : MonoBehaviour { new public Renderer renderer = null; public float from; public float to; public float speed = 1.0f; private float t; private Material m; private Vector3 startPos; private void Start() { startPos = this.transform.localPosition; t = 0.0f; if (renderer == null) { return; } m = renderer.material; } // Update is called once per frame void Update() { } private void OnEnable() { if (renderer == null) { return; } m = renderer.material; m.SetFloat("_Clip", 1.5f); } private void OnDisable() { m.SetFloat("_Clip", -0.5f); } /// /// 显示 /// /// public IEnumerator OnShow(Action finishHandel = null) { yield return new WaitForEndOfFrame(); while (true) { yield return new WaitForEndOfFrame(); if (speed < 0.0f) { speed = 0.0f; } t += Time.deltaTime * speed; if (t > 1.0f) { t = 0.0f; break; } float _lerpVal = Mathf.Lerp(from, to, t); m.SetFloat("_Clip", _lerpVal); } finishHandel?.Invoke(); } /// /// 隐藏 /// /// public IEnumerator OnHide(Action finishHandel = null) { yield return new WaitForEndOfFrame(); while (true) { yield return new WaitForEndOfFrame(); if (speed < 0.0f) { speed = 0.0f; } t += Time.deltaTime * (speed+0.5f) ; if (t > 1.0f) { t = 0.0f; break; } m.SetFloat("_Clip", Mathf.Lerp(to, from, t)); } finishHandel?.Invoke(); } } }