DESKTOP-5RP3AKU\Jisol ced7fdce74 完美
2024-09-13 04:06:25 +08:00

65 lines
1.9 KiB
C#

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<EDPlayerData>
{
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.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<JNGTileClientSystem>()?.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<EDPlayerDataSystem>().Datas;
}
public override void ViewRemove(GameObject view)
{
view.transform.DOKill();
Object.Destroy(view);
}
}
}