using UnityEngine;
|
|
public class FoNormal : FlyObject
|
{
|
protected Vector3 m_PrevPosition;
|
private SoFoNormal m_FoNormal;
|
|
public sealed override bool Initialize(InitInfo initInfo)
|
{
|
bool _result = base.Initialize(initInfo);
|
|
m_FoNormal = m_Config as SoFoNormal;
|
|
if (m_Config == null)
|
{
|
return false;
|
}
|
|
m_HSpeed = m_FoNormal.hspeed;
|
m_VSpeed = m_FoNormal.vspeed;
|
|
m_PrevPosition = m_Position;
|
|
return _result;
|
}
|
|
protected sealed override void OnUpdate()
|
{
|
m_PrevPosition = m_Position;
|
|
Vector3 _calculatePos = m_Position;
|
|
// 处理水平方向的位移
|
// 计算此次位移距离
|
Vector3 _currentMovePos = m_HSpeed * m_Direction * Time.deltaTime;
|
|
// 已经移动的位移距离
|
m_MoveDistance += _currentMovePos;
|
|
// 如果此次的位移将超过配置的最远距离
|
if (m_MoveDistance.sqrMagnitude < m_FoNormal.distance * m_FoNormal.distance)
|
{
|
// 设定水平位移位置
|
_calculatePos += _currentMovePos;
|
}
|
else
|
{
|
_calculatePos = m_FoNormal.distance * m_Direction;
|
}
|
|
// 处理垂直方向上的位移
|
_calculatePos.y += m_VSpeed * Time.deltaTime;
|
|
m_Position = _calculatePos;
|
|
if (m_Ammo)
|
{
|
m_Ammo.transform.position = m_Position;
|
}
|
|
if (m_FoNormal.acceleration != 0)
|
{
|
m_HSpeed += m_FoNormal.acceleration;
|
}
|
|
if (m_FoNormal.gravity != 0)
|
{
|
m_VSpeed += m_FoNormal.gravity;
|
}
|
}
|
|
public sealed override bool IsOver()
|
{
|
bool _result = base.IsOver();
|
return _result || (m_MoveDistance.magnitude >= m_FoNormal.distance);
|
}
|
|
protected sealed override void OnDebugDraw()
|
{
|
Gizmos.color = Color.blue;
|
Gizmos.DrawWireSphere(m_PrevPosition, m_Config.radius);
|
Gizmos.DrawWireSphere(m_Position, m_Config.radius);
|
Gizmos.DrawLine(m_PrevPosition, m_Position);
|
}
|
}
|