2020-12-20 10:56:15 +00:00
|
|
|
|
using OWML.Utils;
|
2020-08-13 19:25:12 +02:00
|
|
|
|
using QSB.WorldSync;
|
2020-08-12 21:58:29 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2020-12-31 12:10:55 +00:00
|
|
|
|
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;
|
2020-08-12 21:58:29 +02:00
|
|
|
|
|
2020-12-23 22:43:05 +00:00
|
|
|
|
public override void Init(Elevator elevator, int id)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2020-12-23 23:08:55 +00:00
|
|
|
|
AttachedObject = elevator;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
ObjectId = id;
|
2021-03-13 10:17:52 +00:00
|
|
|
|
QSBCore.UnityEvents.RunWhen(() => AttachedObject.GetValue<SingleInteractionVolume>("_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()
|
|
|
|
|
{
|
2020-12-23 23:08:55 +00:00
|
|
|
|
_startLocalPos = AttachedObject.GetValue<Vector3>("_startLocalPos");
|
|
|
|
|
_endLocalPos = AttachedObject.GetValue<Vector3>("_endLocalPos");
|
|
|
|
|
_interactVolume = AttachedObject.GetValue<SingleInteractionVolume>("_interactVolume");
|
|
|
|
|
_owAudioSourceOneShot = AttachedObject.GetValue<OWAudioSource>("_owAudioSourceOneShot");
|
|
|
|
|
_owAudioSourceLP = AttachedObject.GetValue<OWAudioSource>("_owAudioSourceLP");
|
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)
|
|
|
|
|
{
|
|
|
|
|
SetDirection(isGoingUp);
|
|
|
|
|
RemoteStartLift();
|
|
|
|
|
}
|
2020-08-12 21:58:29 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void SetDirection(bool isGoingUp)
|
|
|
|
|
{
|
|
|
|
|
var targetPos = isGoingUp ? _endLocalPos : _startLocalPos;
|
2020-12-23 23:08:55 +00:00
|
|
|
|
AttachedObject.SetValue("_goingToTheEnd", isGoingUp);
|
|
|
|
|
AttachedObject.SetValue("_targetLocalPos", targetPos);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
_interactVolume.transform.Rotate(0f, 180f, 0f);
|
|
|
|
|
}
|
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;
|
|
|
|
|
AttachedObject.SetValue("_initLocalPos", AttachedObject.transform.localPosition);
|
|
|
|
|
AttachedObject.SetValue("_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
|
|
|
|
}
|