using UnityEngine; namespace BrewMonster { /// /// Straight-line projectile movement. /// Mirrors C++ CGfxLinearMove exactly (A3DSkillGfxEvent2.cpp:22-52). /// 直线弹道移动,完全镜像C++ CGfxLinearMove。 /// public class CGfxLinearMove : CGfxMoveBase { protected float m_fSpeed; private const float _fly_speed = 20.0f / 1000.0f; // units per ms, same as C++ public CGfxLinearMove(GfxMoveMode mode) : base(mode) { } /// /// Initialize movement from host to target. /// 初始化从施法者到目标的移动。 /// public override void StartMove(Vector3 vHost, Vector3 vTarget) { if (m_bArea) { CalcRange((vTarget - vHost).normalized); m_vPos = vHost + GetRandOff(); } else { m_vPos = vHost; } m_vMoveDir = vTarget - m_vPos; float fDist = Normalize(ref m_vMoveDir); float fMax = _fly_speed * m_dwMaxFlyTime; if (fMax >= fDist) { m_fSpeed = _fly_speed; } else { m_fSpeed = fDist / m_dwMaxFlyTime; } } /// /// Tick movement. Returns true when target is hit. /// 更新移动。当命中目标时返回true。 /// public override bool TickMove(uint dwDeltaTime, Vector3 vHostPos, Vector3 vTargetPos) { Vector3 oldPos = m_vPos; Vector3 vFlyDir = vTargetPos - m_vPos; float fDist = Normalize(ref vFlyDir); float fFlyDist = m_fSpeed * dwDeltaTime; if (fFlyDist >= fDist) { return true; // target hit / 命中目标 } m_vPos += vFlyDir * fFlyDist; m_vMoveDir = vFlyDir; return false; } } }