using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using XFramework; //抓取物体同步逻辑 public class VRGrabedSyncHandler : AbsSyncHandler { VRGrabInterractableBase grabGO; protected override void Awake() { base.Awake(); grabGO = this.GetComponent(); JoinHandList(); } public override void HandleSyncData(object msg, string msgType = null) { switch (msgType) { case "ActionSync"://操作行为同步 NetActionType action = (NetActionType)msg; HnadleSyncAction(action); break; case "Trans"://位置同步 TransGesture trans = (TransGesture)msg; this.transform.position = trans.GetPos(); this.transform.rotation = Quaternion.Euler(trans.GetRotAnlgle()); break; default: break; } } private void HnadleSyncAction(NetActionType action) { if ((action & NetActionType.yeildCtrl) == NetActionType.yeildCtrl)//放弃抓取同步 { grabGO.SetGrabInteractable(true);//启用抓取功能 if ((action & NetActionType.unGrabbedOnFixed) == NetActionType.unGrabbedOnFixed)//放弃抓取时 在允许安装区域 { grabGO.Ungrabbbed(true); } else /*if ((action & NetActionType.unGrabbedOnFree) == NetActionType.unGrabbedOnFree)//放弃抓取时 在自由位置*/ { grabGO.Ungrabbbed(false); } } else { switch (action) { case NetActionType.getCtrl://其它学员抓取时 关闭抓取功能 grabGO.SetGrabInteractable(false); break; case NetActionType.openAnima: case NetActionType.closeAnima: case NetActionType.OnUseable: case NetActionType.UnUseable: Debug.Log("未实现的行为,无法同步"); break; } } } }