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

97 lines
2.3 KiB
C#
Raw Normal View History

2024-04-09 13:22:52 +08:00
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using Game.Pathfinding;
using Game.Player;
using Game.Room;
using UnityEngine;
namespace Game.Boss;
public interface IBoss
{
string name { get; }
GameObject self { get; }
BossData data { get; }
BossInfo info { get; }
IRoom room { get; }
bool isMoving { get; }
void SetGameObject(GameObject gameObject, IRoom room);
UniTask<float> WaitMoveRoomAndKillAsync(CancellationToken token);
// UniTask<bool> MoveAsync(List<WayPoint> wayPoint, CancellationToken token);
void Init();
void Dispose();
}
public class BossData
{
}
public class Boss : IBoss
{
private string _name;
private GameObject _self;
private IRoom _room;
private bool _isMoving;
private BossInfo _info;
public string name => this._name;
public GameObject self => this._self;
public BossData data { get; }
public BossInfo info => this._info;
public IRoom room => this._room;
public bool isMoving => this._isMoving;
public void SetGameObject(GameObject gameObject, IRoom room)
{
this._self = gameObject;
this._name = room.roomName;
this._room = room;
this._info = gameObject.GetComponent<BossInfo>();
}
public async UniTask<float> WaitMoveRoomAndKillAsync(CancellationToken token)
{
var wayPoints = Game.bfsManager.FindPath(_room.roomInfo.room_Center);
await this.MoveAsync(wayPoints, token);
Debug.Log("Move finish !!!");
var f = await this.Kill(token);
return f;
}
private async UniTask<bool> MoveAsync(List<WayPoint> wayPoint, CancellationToken token)
{
if (!this._isMoving) return false;
_isMoving = false;
// var endPos = this._room.roomInfo.GetJoinPosition();
// await this._info.MoveAsync(wayPoint, endPos, token);
await this._info.MoveAsync(wayPoint, token);
this._isMoving = true;
return true;
}
private async UniTask<float> Kill(CancellationToken token)
{
await this._info.Kill(token);
var jinbei = this._room.ClearAll();
return jinbei;
}
public virtual void Init()
{
}
public virtual void Dispose()
{
this._info.Dispose();
}
}