You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
using UnityEngine;
|
|
|
|
public class IVMateIdle : IState
|
|
{
|
|
IVMate owner;
|
|
IVCharacter player;
|
|
|
|
StateHandler stateHandler;
|
|
float pow2MaxDistToPlayer;
|
|
|
|
public IVMateIdle(IVMate owner, IVCharacter player)
|
|
{
|
|
this.owner = owner;
|
|
this.player = player;
|
|
pow2MaxDistToPlayer = GameProperty.Instance.DistRangeMateToPlayer.y * GameProperty.Instance.DistRangeMateToPlayer.y;
|
|
}
|
|
|
|
public void Enter(StateHandler excutor)
|
|
{
|
|
stateHandler = excutor;
|
|
#if UNITY_EDITOR
|
|
if (owner.SkeletonAnimation != null && owner.SkeletonAnimation.TryGetAnimation("idle", out Spine.Animation _))
|
|
#endif
|
|
owner.SkeletonAnimation.AnimationState.SetAnimation(0, "idle", true);
|
|
}
|
|
|
|
public void Excute()
|
|
{
|
|
if (IsPlayerTooFar())
|
|
{
|
|
stateHandler.ChangeState(new IVMateChasePlayer(owner, player));
|
|
}
|
|
}
|
|
|
|
public void Exit()
|
|
{
|
|
stateHandler = null;
|
|
}
|
|
|
|
bool IsPlayerTooFar()
|
|
{
|
|
float sqrtDist = Vector2.SqrMagnitude(owner.transform.position - player.transform.position);
|
|
return sqrtDist > pow2MaxDistToPlayer;
|
|
}
|
|
}
|