Files
Ultimate-Fishing-Simulator-…/Assets/Scripts/Assembly-CSharp/ECM2/Examples/FirstPersonFly/FlyAbility.cs
2026-03-04 09:37:33 +08:00

67 lines
1.3 KiB
C#

using UnityEngine;
namespace ECM2.Examples.FirstPersonFly
{
public class FlyAbility : MonoBehaviour
{
public bool canEverFly = true;
private Character _character;
private bool IsFlyAllowed()
{
if (canEverFly)
{
return _character.IsFalling();
}
return false;
}
protected virtual bool CanFly()
{
bool flag = IsFlyAllowed();
if (flag)
{
Vector3 rhs = -_character.GetGravityDirection();
flag = Vector3.Dot(_character.GetVelocity(), rhs) < 0f;
}
return flag;
}
private void OnCollided(ref CollisionResult collisionResult)
{
if (_character.IsFlying() && collisionResult.isWalkable)
{
_character.SetMovementMode(Character.MovementMode.Falling);
}
}
private void OnBeforeSimulationUpdated(float deltaTime)
{
bool num = _character.IsFlying();
bool jumpInputPressed = _character.jumpInputPressed;
if (!num && jumpInputPressed && CanFly())
{
_character.SetMovementMode(Character.MovementMode.Flying);
}
}
private void Awake()
{
_character = GetComponent<Character>();
}
private void OnEnable()
{
_character.Collided += OnCollided;
_character.BeforeSimulationUpdated += OnBeforeSimulationUpdated;
}
private void OnDisable()
{
_character.Collided -= OnCollided;
_character.BeforeSimulationUpdated -= OnBeforeSimulationUpdated;
}
}
}