using System; using BF; using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(Image))] public class UIResGhostTweenEffect : MonoBehaviour { private Material mat; private float time; private Vector4[] offsets = new Vector4[3] { new Vector4(-30, -30, 0, 0), new Vector4(30, -30, 0, 0), new Vector4(0, -60, 0, 0), }; public float smooth = .25f; private const float TWEEN_TIME = 1f; public void SetMaterial(Material material) { mat = material; } private void Awake() { time = TWEEN_TIME; var img = GetComponent(); if (mat == null) { mat = new Material(Shader.Find("BF/UI/UIGhost")); } img.material = mat; } private void Update() { if (time > 0) { time -= Time.deltaTime; var lerp = (TWEEN_TIME - time) * smooth; offsets[0] = Vector4.Lerp(offsets[0], Vector4.zero, lerp); offsets[1] = Vector4.Lerp(offsets[1], Vector4.zero, lerp); offsets[2] = Vector4.Lerp(offsets[2], Vector4.zero, lerp); mat.SetVector("_Offset1", offsets[0]); mat.SetVector("_Offset2", offsets[1]); mat.SetVector("_Offset3", offsets[2]); } } private void OnDestroy() { } }