84 lines
2.2 KiB
C#
84 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using Game.Pathfinding;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace Game.Boss;
|
|
|
|
public class BossInfo : MonoBehaviour
|
|
{
|
|
[SerializeField] [ReadOnly] private IBoss _boss;
|
|
[SerializeField] private float speed = 1f;
|
|
private Animator _animator;
|
|
private static readonly int _kill = Animator.StringToHash("Kill");
|
|
|
|
private void Awake()
|
|
{
|
|
this._animator = this.GetComponent<Animator>();
|
|
this._animator.enabled = false;
|
|
}
|
|
|
|
public void SetPlayer(IBoss boss)
|
|
{
|
|
this._boss = boss;
|
|
this.gameObject.name = this._boss.name;
|
|
}
|
|
|
|
public async UniTask<bool> MoveAsync(List<WayPoint> wayPoint, Vector2 endPos, CancellationToken token)
|
|
{
|
|
// enter this room
|
|
foreach (var point in wayPoint)
|
|
{
|
|
await this.MoveAsync(point.position, token);
|
|
}
|
|
|
|
// enter room a point
|
|
await this.MoveAsync(endPos, token);
|
|
|
|
return true;
|
|
}
|
|
|
|
public async UniTask<bool> MoveAsync(List<WayPoint> wayPoint, CancellationToken token)
|
|
{
|
|
// enter this room
|
|
foreach (var point in wayPoint)
|
|
{
|
|
await this.MoveAsync(point.position, token);
|
|
}
|
|
|
|
// enter room a point
|
|
// await this.MoveAsync(endPos, token);
|
|
|
|
return true;
|
|
}
|
|
|
|
async UniTask MoveAsync(Vector2 endPos, CancellationToken token)
|
|
{
|
|
var distance = Vector3.Distance(this.transform.position, endPos);
|
|
var time = distance / this.speed;
|
|
|
|
this.transform.DOMove(endPos, time).SetEase(Ease.Linear);
|
|
float delayTimeSpan = time * 1000;
|
|
await UniTask.Delay((int)delayTimeSpan); // (int)delayTimeSpan
|
|
|
|
Debug.Log($"time is {time}, await time is {delayTimeSpan}");
|
|
}
|
|
|
|
public async UniTask Kill(CancellationToken token)
|
|
{
|
|
if (this._animator != null)
|
|
this._animator.SetTrigger(_kill);
|
|
await UniTask.Delay(500);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
this._animator = null;
|
|
this._boss = null;
|
|
GameObject.DestroyImmediate(this.gameObject);
|
|
}
|
|
} |