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.
44 lines
1.2 KiB
44 lines
1.2 KiB
using UnityEngine;
|
|
|
|
public class IVMateIdle : State<IVMate>
|
|
{
|
|
IVCharacter player;
|
|
|
|
IVMateChasePlayer chasePlayerState;
|
|
|
|
float pow2MaxDistToPlayer;
|
|
|
|
public void Setup(IVCharacter player)
|
|
{
|
|
this.player = player;
|
|
pow2MaxDistToPlayer = GameProperty.Instance.DistRangeMateToPlayer.y * GameProperty.Instance.DistRangeMateToPlayer.y;
|
|
}
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
Owner.TryGetState(out chasePlayerState);
|
|
|
|
Debug.Assert(chasePlayerState != null, "chasePlayerState is null");
|
|
}
|
|
|
|
public override void Enter()
|
|
{
|
|
Debug.Assert(Owner.Excutor.SkeletonAnimation != null && Owner.Excutor.SkeletonAnimation.TryGetAnimation("idle", out Spine.Animation _), "SkeletonAnimation is null or idle animation not exist");
|
|
Owner.Excutor.SkeletonAnimation.AnimationState.SetAnimation(0, "idle", true);
|
|
}
|
|
|
|
public override void Excute()
|
|
{
|
|
if (IsPlayerTooFar())
|
|
{
|
|
chasePlayerState.Setup(player);
|
|
Owner.ChangeState<IVMateChasePlayer>();
|
|
}
|
|
}
|
|
|
|
bool IsPlayerTooFar()
|
|
{
|
|
float sqrtDist = Vector2.SqrMagnitude(Owner.Excutor.transform.position - player.transform.position);
|
|
return sqrtDist > pow2MaxDistToPlayer;
|
|
}
|
|
}
|