using System.Collections; using System.Collections.Generic; using UnityEngine; using ChivaXR; using System; using Sirenix.OdinInspector; public class AniDriver_JDAnimation : AnimationDriverBase { public TimeType AniTimeType = TimeType.aniFrame; [ShowIf("AniTimeType", Value = TimeType.aniFrame)] [LabelWidth(50)] [HorizontalGroup("frame")] [LabelText("起始帧")] public int startFrame; [ShowIf("AniTimeType", Value = TimeType.aniFrame)] [LabelWidth(50)] [HorizontalGroup("frame")] [LabelText("结束帧")] public int endFrame; [LabelWidth(100)] [ShowIf("AniTimeType", Value = TimeType.aniFrame)] [LabelText("动画FPS")] public float aniFPS = 30; [ShowIf("AniTimeType", Value = TimeType.time)] [LabelText("动画开始时间")] [LabelWidth(100)] [HorizontalGroup("time")] public float startTime = 0; [ShowIf("AniTimeType", Value = TimeType.time)] [LabelText("动画结束时间")] [LabelWidth(100)] [HorizontalGroup("time")] public float endTime = 0; [LabelWidth(100)] public float startValue; [LabelWidth(100)] public float endValue; [LabelText("胶带延长线类型")] public JDLineType jdLineType = JDLineType.lineon_NoJDJuan; public ChivaVR_JD_ShaderController target; public override void FinishedState() { target.SetJDValue(endValue); } public override void InitState() { target.SetJDValue(startValue); target.SetJDLineType(jdLineType); } public override void OnDrawGizmos() { throw new NotImplementedException(); } public override void StartPlay(Action finishedCallBack = null) { StartAniCoroutine(PlayJDAnimation(finishedCallBack)); } private IEnumerator PlayJDAnimation(Action finishedCallBack = null) { float allRunningTime = 0; float currentRunningTime = 0; switch (AniTimeType) { case TimeType.time: yield return new WaitForSeconds(startTime); allRunningTime = endTime - startTime; break; case TimeType.aniFrame: yield return new WaitForSeconds(startFrame / aniFPS); allRunningTime = (endFrame - startFrame) / aniFPS; break; } while (currentRunningTime < allRunningTime) { currentRunningTime += Time.deltaTime; target.SetJDValue(Mathf.Lerp(startValue, endValue, currentRunningTime / allRunningTime)); yield return new WaitForEndOfFrame(); } target.SetJDValue(Mathf.Lerp(startValue, endValue, 1)); finishedCallBack?.Invoke(); } }