mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
86 lines
2.4 KiB
C#
86 lines
2.4 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 : VDEntityBasis<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)
|
|
{
|
|
|
|
Register((int)GDataValueCode.Position, OnUpdatePosition);
|
|
Register((int)EDPlayerValueCode.Auth, OnUpdateAuth);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新坐标
|
|
/// </summary>
|
|
/// <param name="tuple"></param>
|
|
private void OnUpdatePosition((GameObject View, EDPlayerData Data) tuple)
|
|
{
|
|
var (view, data) = tuple;
|
|
|
|
//更新位置
|
|
if (data.Value.Position != null)
|
|
{
|
|
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
|
|
}
|
|
|
|
if (data.Value.Auth == App.ClientID)
|
|
{
|
|
//更新本地玩家位置
|
|
if (data.Value.Position != null) App.Game.GetClient<JNGTileClientSystem>()?.SetPlayerPosition(data.Value.Position.ToLVector3());
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新权限
|
|
/// </summary>
|
|
private void OnUpdateAuth((GameObject View, EDPlayerData Data) tuple)
|
|
{
|
|
|
|
var (view, data) = tuple;
|
|
|
|
//权限操作
|
|
if (App.IsClient() && data.Value.Auth == App.ClientID)
|
|
{
|
|
|
|
//绑定相机
|
|
FreeLook.LookAt = view.transform;
|
|
FreeLook.Follow = view.transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public override GameObject NewView(EDPlayerData data)
|
|
{
|
|
var gameObject = Object.Instantiate(Player, VWorld.transform);
|
|
gameObject.name = $"Player_{data.Id}";
|
|
return gameObject;
|
|
}
|
|
|
|
public override EDPlayerData[] GetData()
|
|
{
|
|
return GetService<EDPlayerDataSystem>().Datas;
|
|
}
|
|
|
|
public override void ViewRemove(GameObject view)
|
|
{
|
|
view.transform.DOKill();
|
|
Object.Destroy(view);
|
|
}
|
|
}
|
|
} |