shaoxiadiablo/Assets/AGame/Scripts/Game/Stat/Stat_FollowAction.cs

92 lines
2.4 KiB
C#
Raw Permalink Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-09-02
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "Stat_IdleAction" company="Kimch"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections.Generic;
using UnityEngine;
namespace G
{
public class Stat_FollowAction : Stat_BaseAction
{
private float m_moveSpeed;
private float m_totalTime = 5f;
private Vector3 m_targetPos = Vector3.zero;
private Vector3 m_movDir = Vector3.zero;
private float recordDis;
public Stat_FollowAction(Stat_StateManager statMgr)
: base(statMgr)
{
}
public override bool Enter(Dictionary<string, object> param, bool clearDelegates = false)
{
base.Enter(param, clearDelegates);
//string animName = m_char.GetAnimName("run");
//if (m_char.PlayAnimation(animName, true) == -1f)
//{
// return false;
//}
if (param == null || param.Count <= 0 || !param.ContainsKey("follow_pos"))
{
Debug.LogError("param is error");
return false;
}
m_targetPos = (Vector3)param["follow_pos"];
Vector3 value = m_targetPos - m_char.position;
recordDis = value.magnitude;
float num = Vector3.Distance(m_targetPos, m_char.position);
m_movDir = Vector3.Normalize(value);
m_moveSpeed = m_char.GetMoveSpeed();
m_char.ResetRigidBody();
SetTimers();
return true;
}
public override bool UpdateDelegate()
{
m_movDir = Vector3.Normalize(m_targetPos - m_char.position);
float num = Vector3.Distance(m_targetPos, m_char.position);
float num2 = m_char.Move(m_movDir, m_moveSpeed);
if (num < num2 + 0.001f)
{
m_statMgr.ClearTimer();
SetCurActionState(enStat.STAT_ACTION_IDLE);
}
return true;
}
public override bool CanTransition(enStat stat)
{
bool result = false;
if (stat == enStat.STAT_ACTION_HIT || stat == enStat.STAT_ACTION_DEAD || stat == enStat.STAT_ACTION_IDLE)
{
result = true;
}
return result;
}
private void SetTimers()
{
m_statMgr.AddTimer(m_totalTime, TimeIsUp);
}
public bool TimeIsUp(object[] param)
{
m_char.position = (m_targetPos);
return SetCurActionState(enStat.STAT_ACTION_IDLE);
}
}
}