You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
2.6 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using DG.Tweening;
namespace MapUnit
{
/// <summary>
/// 消融控制
/// </summary>
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);
}
/// <summary>
/// 显示
/// </summary>
/// <returns></returns>
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();
}
/// <summary>
/// 隐藏
/// </summary>
/// <returns></returns>
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();
}
}
}