using System; using UnityEngine; // using WaveHarmonic.Crest; namespace NBF { public class Boat : MonoBehaviour { private Collider boatCollider; [Tooltip("移动力应施加于质心的垂直偏移量。")] [SerializeField] float _ForceHeightOffset; [Tooltip("推力")] [SerializeField] float _ThrustPower = 10f; [Tooltip("加速推力")] [SerializeField] float _ThrustMaxPower = 10f; [Tooltip("转向速度")] [SerializeField] float _SteerPower = 1f; [Tooltip("转弯时要转动船只。")] [Range(0, 1)] [SerializeField] float _TurningHeel = 0.35f; [Tooltip("对浮力变化应用曲线处理。")] [SerializeField] AnimationCurve _BuoyancyCurveFactor = new(new Keyframe[] { new(0, 0, 0.01267637f, 0.01267637f), new(0.6626424f, 0.1791001f, 0.8680198f, 0.8680198f), new(1, 1, 3.38758f, 3.38758f) }); /// /// 船坐下位置 /// public Transform Place; /// /// 船站立位置 /// public Transform standPlace; // /// // /// 浮力组件 // /// // private FloatingObject _floatingObject; private float _BuoyancyFactor = 1f; private void Awake() { boatCollider = GetComponent(); // if (_floatingObject == null) _floatingObject = GetComponent(); } public void Use(FPlayer player) { boatCollider.enabled = false; } public void UnUse() { boatCollider.enabled = true; } public void BoatInput(Vector2 moveInput, bool isRun = false) { // if (!_floatingObject.InWater) return; // // var input = Vector3.zero; // input.x = moveInput.x; // 水平转向(x轴) // input.z = moveInput.y; // 前后移动(y轴映射到z轴) // // var rb = _floatingObject.RigidBody; // // var power = isRun ? _ThrustMaxPower : _ThrustPower; // // // Thrust // var forcePosition = rb.worldCenterOfMass + _ForceHeightOffset * Vector3.up; // rb.AddForceAtPosition(power * input.z * transform.forward, forcePosition, ForceMode.Acceleration); // // // Steer // var rotation = transform.up + _TurningHeel * transform.forward; // rb.AddTorque(_SteerPower * input.x * rotation, ForceMode.Acceleration); // // if (input.y > 0f) // { // if (_BuoyancyFactor < 1f) // { // _BuoyancyFactor += Time.deltaTime * 0.1f; // _BuoyancyFactor = Mathf.Clamp(_BuoyancyFactor, 0f, 1f); // _floatingObject.BuoyancyForceStrength = _BuoyancyCurveFactor.Evaluate(_BuoyancyFactor); // } // } // else if (input.y < 0f) // { // if (_BuoyancyFactor > 0f) // { // _BuoyancyFactor -= Time.deltaTime * 0.1f; // _BuoyancyFactor = Mathf.Clamp(_BuoyancyFactor, 0f, 1f); // _floatingObject.BuoyancyForceStrength = _BuoyancyCurveFactor.Evaluate(_BuoyancyFactor); // } // } } } }