using System.Collections.Generic; using System.Threading; using Cysharp.Threading.Tasks; using Game.Pathfinding; using Game.Room; using UnityEngine; namespace Game.Player; public interface IPlayer { string playerName { get; } GameObject self { get; } PlayerData playerData { get; } IRoom room { get; } void SetGameObject(GameObject gameObject, string name, float jinbei); UniTask MoveAsync(List wayPoint, IRoom roo, CancellationToken token); void Dispose(); } internal class Player : IPlayer { private GameObject _self; private PlayerData _playerData; private IRoom _room; PlayerInfo playerInfo; public string playerName => this._playerData.playerName; public GameObject self => this._self; public PlayerData playerData => this._playerData; public IRoom room => this._room; public void SetGameObject(GameObject gameObject, string name, float jinbei) { this._self = gameObject; playerInfo = this._self.GetComponent(); playerInfo.SetPlayer(this); this._playerData = new PlayerData(name, jinbei, 100); } public async UniTask MoveAsync(List wayPoint, IRoom roo, CancellationToken token) { this._room = roo; var endPos = roo.roomInfo.GetJoinPosition(); await playerInfo.MoveAsync(wayPoint, endPos, token); return true; } public void Dispose() { GameObject.DestroyImmediate(this.self); } }