153 lines
3.6 KiB
C#
153 lines
3.6 KiB
C#
using NWH.DWP2.ShipController;
|
|
using Obvious.Soap;
|
|
using SoapCustomVariable;
|
|
using UnityEngine;
|
|
|
|
public class BoatController : MonoBehaviour
|
|
{
|
|
public FSMVariable playerState;
|
|
|
|
public BoolVariable IsInGameMenuEnabled;
|
|
|
|
public BoolVariable IsFishingOnBoat;
|
|
|
|
public BoolVariable IsFlashLightPress;
|
|
|
|
public IKTarget SteeringWheelLeftHand;
|
|
|
|
public IKTarget SteeringWheelRightHand;
|
|
|
|
public Transform SeatTarget;
|
|
|
|
public Transform FishingTarget;
|
|
|
|
public Transform SteeringWheel;
|
|
|
|
private AdvancedShipController _DWPController;
|
|
|
|
public Material boatEmmisionLight;
|
|
|
|
[SerializeField]
|
|
private GameObject lightsRoot;
|
|
|
|
[SerializeField]
|
|
private GameObject sonarPrefab;
|
|
|
|
[SerializeField]
|
|
private Transform sonarParent;
|
|
|
|
[SerializeField]
|
|
private Transform boatColliderTransform;
|
|
|
|
[SerializeField]
|
|
private Transform coppiedColliderTransform;
|
|
|
|
private GameObject _sonar;
|
|
|
|
private bool _inputLastState;
|
|
|
|
private float _TargetWheelYEuler;
|
|
|
|
public float MaxSteeringWheelRotate = 55f;
|
|
|
|
private void OnEnable()
|
|
{
|
|
IsInGameMenuEnabled.OnValueChanged += IsInGameMenuEnabledOnOnValueChanged;
|
|
IsFlashLightPress.OnValueChanged += IsFlashLightPressOnOnValueChanged;
|
|
coppiedColliderTransform.gameObject.SetActive(value: true);
|
|
_sonar = Object.Instantiate(sonarPrefab, sonarParent);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
IsInGameMenuEnabled.OnValueChanged -= IsInGameMenuEnabledOnOnValueChanged;
|
|
IsFlashLightPress.OnValueChanged -= IsFlashLightPressOnOnValueChanged;
|
|
coppiedColliderTransform.gameObject.SetActive(value: false);
|
|
if ((bool)_sonar)
|
|
{
|
|
Object.Destroy(_sonar);
|
|
}
|
|
}
|
|
|
|
private void IsFlashLightPressOnOnValueChanged(bool obj)
|
|
{
|
|
if (obj && playerState.Value == State.vehicle)
|
|
{
|
|
lightsRoot.SetActive(!lightsRoot.activeSelf);
|
|
if (lightsRoot.activeSelf)
|
|
{
|
|
boatEmmisionLight.EnableKeyword("_EMISSION");
|
|
}
|
|
else
|
|
{
|
|
boatEmmisionLight.DisableKeyword("_EMISSION");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void IsInGameMenuEnabledOnOnValueChanged(bool obj)
|
|
{
|
|
if (obj)
|
|
{
|
|
_inputLastState = _DWPController.input.autoSetInput;
|
|
InputThrottle(0f);
|
|
BowThrusters(0f);
|
|
InputSterring(0f);
|
|
AutoSetInput(enable: false);
|
|
}
|
|
else
|
|
{
|
|
AutoSetInput(_inputLastState);
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
_DWPController = GetComponent<AdvancedShipController>();
|
|
}
|
|
|
|
public void InputThrottle(float throttle)
|
|
{
|
|
_DWPController.input.Throttle = throttle;
|
|
}
|
|
|
|
public void BowThrusters(float throttle)
|
|
{
|
|
_DWPController.input.BowThruster = throttle;
|
|
}
|
|
|
|
public void InputSterring(float sterring)
|
|
{
|
|
_DWPController.input.Steering = sterring;
|
|
}
|
|
|
|
public void AutoSetInput(bool enable)
|
|
{
|
|
_DWPController.input.autoSetInput = enable;
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
coppiedColliderTransform.position = boatColliderTransform.position;
|
|
coppiedColliderTransform.rotation = boatColliderTransform.rotation;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
float steering = _DWPController.input.Steering;
|
|
float target = Mathf.LerpUnclamped(0f, MaxSteeringWheelRotate, steering);
|
|
_TargetWheelYEuler = Mathf.MoveTowards(_TargetWheelYEuler, target, Time.deltaTime * 260f);
|
|
SteeringWheel.localEulerAngles = new Vector3(0f, _TargetWheelYEuler, 0f);
|
|
}
|
|
|
|
public void Teleport(Vector3 position, Vector3 forwardDir)
|
|
{
|
|
_DWPController.vehicleRigidbody.MovePosition(position);
|
|
_DWPController.vehicleRigidbody.linearVelocity = Vector3.zero;
|
|
_DWPController.vehicleRigidbody.angularVelocity = Vector3.zero;
|
|
_DWPController.transform.position = position;
|
|
_DWPController.vehicleRigidbody.MoveRotation(Quaternion.LookRotation(-forwardDir, Vector3.up));
|
|
_DWPController.transform.rotation = Quaternion.LookRotation(-forwardDir, Vector3.up);
|
|
}
|
|
}
|