78 lines
2.1 KiB
C#
Raw Normal View History

2021-11-25 18:55:22 +00:00
using QSB.WorldSync;
2020-08-12 21:58:29 +02:00
using UnityEngine;
namespace QSB.ElevatorSync.WorldObjects
2020-08-12 21:58:29 +02:00
{
2020-12-23 22:43:05 +00:00
public class QSBElevator : WorldObject<Elevator>
2020-12-02 21:23:01 +00:00
{
private Vector3 _startLocalPos;
private Vector3 _endLocalPos;
2020-08-12 21:58:29 +02:00
2020-12-02 21:23:01 +00:00
private SingleInteractionVolume _interactVolume;
private OWAudioSource _owAudioSourceOneShot;
private OWAudioSource _owAudioSourceLP;
2021-11-25 18:55:22 +00:00
private OWTriggerVolume _elevatorTrigger;
2020-08-12 21:58:29 +02:00
public override void Init()
2020-12-02 21:23:01 +00:00
{
StartDelayedReady();
2021-11-25 18:55:22 +00:00
QSBCore.UnityEvents.RunWhen(() => AttachedObject._interactVolume != null, InitValues);
2020-12-02 21:23:01 +00:00
}
2020-08-13 20:43:47 +02:00
2020-12-02 21:23:01 +00:00
private void InitValues()
{
FinishDelayedReady();
2021-11-25 18:55:22 +00:00
_startLocalPos = AttachedObject._startLocalPos;
_endLocalPos = AttachedObject._endLocalPos;
_interactVolume = AttachedObject._interactVolume;
_owAudioSourceOneShot = AttachedObject._owAudioSourceOneShot;
_owAudioSourceLP = AttachedObject._owAudioSourceLP;
var boxShape = AttachedObject.gameObject.AddComponent<BoxShape>();
boxShape.center = new Vector3(0, 1.75f, 0.25f);
boxShape.size = new Vector3(3, 3.5f, 3);
_elevatorTrigger = AttachedObject.gameObject.GetAddComponent<OWTriggerVolume>();
2020-12-02 21:23:01 +00:00
}
2020-08-12 21:58:29 +02:00
2020-12-02 21:23:01 +00:00
public void RemoteCall(bool isGoingUp)
{
2021-11-25 18:55:22 +00:00
if (_elevatorTrigger.IsTrackingObject(Locator.GetPlayerDetector()))
{
SetDirection(isGoingUp);
2021-12-07 15:56:08 +00:00
2021-11-25 18:55:22 +00:00
AttachedObject._attachPoint.AttachPlayer();
if (Locator.GetPlayerSuit().IsWearingSuit(true) && Locator.GetPlayerSuit().IsTrainingSuit())
{
Locator.GetPlayerSuit().RemoveSuit(false);
}
RemoteStartLift();
}
else
{
SetDirection(isGoingUp);
RemoteStartLift();
}
2020-12-02 21:23:01 +00:00
}
2020-08-12 21:58:29 +02:00
2020-12-02 21:23:01 +00:00
private void SetDirection(bool isGoingUp)
{
_interactVolume.transform.Rotate(0f, 180f, 0f);
2021-11-25 18:55:22 +00:00
var targetPos = isGoingUp ? _endLocalPos : _startLocalPos;
AttachedObject._targetLocalPos = targetPos;
AttachedObject._goingToTheEnd = isGoingUp;
2020-12-02 21:23:01 +00:00
}
2020-08-12 21:58:29 +02:00
2020-12-02 21:23:01 +00:00
private void RemoteStartLift()
{
2020-12-23 23:08:55 +00:00
AttachedObject.enabled = true;
2021-11-25 18:55:22 +00:00
AttachedObject._initLocalPos = AttachedObject.transform.localPosition;
AttachedObject._initLiftTime = Time.time;
2020-12-02 21:23:01 +00:00
_owAudioSourceOneShot.PlayOneShot(AudioType.TH_LiftActivate);
_owAudioSourceLP.FadeIn(0.5f);
_interactVolume.DisableInteraction();
}
}
2020-12-03 08:28:05 +00:00
}