87 lines
2.4 KiB
C#
87 lines
2.4 KiB
C#
using Obvious.Soap;
|
|
using UFS3.Management;
|
|
using UnityEngine;
|
|
|
|
public class GameBoatManager : Singleton<GameBoatManager>
|
|
{
|
|
public GameObjectVariable BoatParking;
|
|
|
|
[SerializeField]
|
|
private Transform _Boat;
|
|
|
|
[SerializeField]
|
|
private Transform _Input;
|
|
|
|
[SerializeField]
|
|
private BoatController _AdvancedShip;
|
|
|
|
[SerializeField]
|
|
private LayerMask collisionDetectLayer;
|
|
|
|
[SerializeField]
|
|
private ScriptableEventNoParam onParkingOccupied;
|
|
|
|
public void ResetBoat(bool reset)
|
|
{
|
|
if (!reset)
|
|
{
|
|
_AdvancedShip.InputThrottle(0f);
|
|
_AdvancedShip.InputSterring(0f);
|
|
_AdvancedShip.BowThrusters(0f);
|
|
_AdvancedShip.AutoSetInput(enable: false);
|
|
}
|
|
else
|
|
{
|
|
_AdvancedShip.AutoSetInput(enable: true);
|
|
}
|
|
}
|
|
|
|
public void ActivateBoat()
|
|
{
|
|
}
|
|
|
|
public void SpawnBoat()
|
|
{
|
|
_Boat.position = BoatParking.Value.transform.position;
|
|
_Boat.rotation = BoatParking.Value.transform.rotation;
|
|
_Boat.gameObject.SetActive(value: true);
|
|
_AdvancedShip.InputThrottle(0f);
|
|
_AdvancedShip.InputSterring(0f);
|
|
_AdvancedShip.BowThrusters(0f);
|
|
Rigidbody component = _Boat.GetComponent<Rigidbody>();
|
|
component.MoveRotation(BoatParking.Value.transform.rotation);
|
|
component.MovePosition(BoatParking.Value.transform.position);
|
|
component.linearVelocity = Vector3.zero;
|
|
component.angularVelocity = Vector3.zero;
|
|
}
|
|
|
|
public void SpawnBoat(GameObject boatSpawnPlace)
|
|
{
|
|
BoxCollider component = boatSpawnPlace.GetComponent<BoxCollider>();
|
|
if (component != null && IsColliderOverlapping(component))
|
|
{
|
|
onParkingOccupied.Raise();
|
|
return;
|
|
}
|
|
_Boat.position = boatSpawnPlace.transform.position;
|
|
_Boat.rotation = boatSpawnPlace.transform.rotation;
|
|
_Boat.gameObject.SetActive(value: true);
|
|
_AdvancedShip.InputThrottle(0f);
|
|
_AdvancedShip.InputSterring(0f);
|
|
_AdvancedShip.BowThrusters(0f);
|
|
Rigidbody component2 = _Boat.GetComponent<Rigidbody>();
|
|
component2.MoveRotation(boatSpawnPlace.transform.rotation);
|
|
component2.MovePosition(boatSpawnPlace.transform.position);
|
|
component2.linearVelocity = Vector3.zero;
|
|
component2.angularVelocity = Vector3.zero;
|
|
}
|
|
|
|
private bool IsColliderOverlapping(BoxCollider overlapCollider)
|
|
{
|
|
Vector3 center = overlapCollider.transform.position + overlapCollider.center;
|
|
Vector3 halfExtents = overlapCollider.size * 0.5f;
|
|
Quaternion rotation = overlapCollider.transform.rotation;
|
|
return Physics.OverlapBox(center, halfExtents, rotation, collisionDetectLayer, QueryTriggerInteraction.Ignore).Length != 0;
|
|
}
|
|
}
|