forked from zxl/Frame
1
0
Fork 0
Frame/Assets/Scripts/Player/Player.cs

58 lines
1.5 KiB
C#
Raw Normal View History

2024-04-06 11:59:18 +08:00
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<bool> MoveAsync(List<WayPoint> 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>();
playerInfo.SetPlayer(this);
this._playerData = new PlayerData(name, jinbei, 100);
}
public async UniTask<bool> MoveAsync(List<WayPoint> 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);
}
}