1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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();
- }
- }
|