using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 继承Mono的同步处理抽象类 /// public abstract class AbsSyncHandler : MonoBehaviour, ISyncHand { protected string soleName; float interval;//帧同步数据正常情况下应该进入的时间间隔 bool lerpTrans;//是否开启lerp同步 bool lerping = false;//当前数据是否需要执行Lerp float lerpTimer;//开启Lerp时的计时器 用于计算每帧的位置 // Start is called before the first frame update protected virtual void Awake() { soleName = this.gameObject.name; } public void ExitHandList() { SyncGOManager.Instance.RemoHandler(this); } public string GetSoleName() { return soleName; } public abstract void HandleSyncData(object msg, string msgType = null); public virtual void InitInterval(float time) { interval = time; if (interval > 0.04f) lerpTrans = true; } /// /// 加入消息分发队列 开始接收同步消息 由子类确定调用时机 /// public void JoinHandList() { SyncGOManager.Instance.AddHandler(this); } protected virtual void FixedUpdate() { if (lerpTrans && lerping) { if (lerpTimer <= interval) { lerpTimer += Time.fixedUnscaledDeltaTime; LerpSyncData(lerpTimer / interval); } else//Lerp完成了 { lerping = false; } } } //Lerp同步位置 protected virtual void LerpSyncData(float progress) { //LerpOneTrans(headTrans, currentHead, personSyncData.head, progress); //LerpOneTrans(leftHandTrans, currentLH, personSyncData.LH, progress); //LerpOneTrans(rightHandTrans, currentRH, personSyncData.RH, progress); } }