using AppGame; using AppGame.Sync; using Cinemachine; using DG.Tweening; using Game.JNGState.Logic.Data; using JNGame.Sync.System; using JNGame.Sync.View; using UnityEngine; namespace Game.JNGFrame.View.Entity { public class VDPlayers : ViewData { public GameObject VWorld => App.Resource.VWorld; public GameObject Player => App.Resource.Player; public CinemachineFreeLook FreeLook => App.Resource.FreeLook; public VDPlayers(SViewSystem root) : base(root) { } public override void ViewUpdate(EDPlayerData data, GameObject view) { view.name = $"Player_{data.Id}"; //更新位置 if (data.Value.Position != null) { view.transform.DOKill(); view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f); } //权限操作 if (App.IsClient() && data.Value.Auth == App.ClientID) { //绑定相机 FreeLook.LookAt = view.transform; FreeLook.Follow = view.transform; //更新玩家位置 if (data.Value.Position != null) App.Game.GetClient()?.SetPlayerPosition(data.Value.Position.ToLVector3()); } } public override GameObject NewView(EDPlayerData data) { var gameObject = Object.Instantiate(Player, VWorld.transform); // gameObject.transform.DOMove(gameObject.transform.position + new Vector3(0,0,1000), 100); return gameObject; } public override EDPlayerData[] GetData() { return GetService().Datas; } public override void ViewRemove(GameObject view) { Object.Destroy(view); } } }