mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-27 03:35:20 +00:00
Merge pull request #363 from misternebula/improved-elevators
Improved elevators
This commit is contained in:
commit
c24e7f4c0d
@ -1,5 +1,4 @@
|
||||
using OWML.Utils;
|
||||
using QSB.WorldSync;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.ElevatorSync.WorldObjects
|
||||
@ -12,42 +11,65 @@ namespace QSB.ElevatorSync.WorldObjects
|
||||
private SingleInteractionVolume _interactVolume;
|
||||
private OWAudioSource _owAudioSourceOneShot;
|
||||
private OWAudioSource _owAudioSourceLP;
|
||||
private OWTriggerVolume _elevatorTrigger;
|
||||
|
||||
public override void Init(Elevator elevator, int id)
|
||||
{
|
||||
AttachedObject = elevator;
|
||||
ObjectId = id;
|
||||
QSBCore.UnityEvents.RunWhen(() => AttachedObject.GetValue<SingleInteractionVolume>("_interactVolume") != null, InitValues);
|
||||
QSBCore.UnityEvents.RunWhen(() => AttachedObject._interactVolume != null, InitValues);
|
||||
}
|
||||
|
||||
private void InitValues()
|
||||
{
|
||||
_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");
|
||||
_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>();
|
||||
}
|
||||
|
||||
public void RemoteCall(bool isGoingUp)
|
||||
{
|
||||
SetDirection(isGoingUp);
|
||||
RemoteStartLift();
|
||||
if (_elevatorTrigger.IsTrackingObject(Locator.GetPlayerDetector()))
|
||||
{
|
||||
SetDirection(isGoingUp);
|
||||
|
||||
AttachedObject._attachPoint.AttachPlayer();
|
||||
|
||||
if (Locator.GetPlayerSuit().IsWearingSuit(true) && Locator.GetPlayerSuit().IsTrainingSuit())
|
||||
{
|
||||
Locator.GetPlayerSuit().RemoveSuit(false);
|
||||
}
|
||||
|
||||
RemoteStartLift();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDirection(isGoingUp);
|
||||
RemoteStartLift();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetDirection(bool isGoingUp)
|
||||
{
|
||||
var targetPos = isGoingUp ? _endLocalPos : _startLocalPos;
|
||||
AttachedObject.SetValue("_goingToTheEnd", isGoingUp);
|
||||
AttachedObject.SetValue("_targetLocalPos", targetPos);
|
||||
_interactVolume.transform.Rotate(0f, 180f, 0f);
|
||||
var targetPos = isGoingUp ? _endLocalPos : _startLocalPos;
|
||||
AttachedObject._targetLocalPos = targetPos;
|
||||
AttachedObject._goingToTheEnd = isGoingUp;
|
||||
}
|
||||
|
||||
private void RemoteStartLift()
|
||||
{
|
||||
AttachedObject.enabled = true;
|
||||
AttachedObject.SetValue("_initLocalPos", AttachedObject.transform.localPosition);
|
||||
AttachedObject.SetValue("_initLiftTime", Time.time);
|
||||
AttachedObject._initLocalPos = AttachedObject.transform.localPosition;
|
||||
AttachedObject._initLiftTime = Time.time;
|
||||
_owAudioSourceOneShot.PlayOneShot(AudioType.TH_LiftActivate);
|
||||
_owAudioSourceLP.FadeIn(0.5f);
|
||||
_interactVolume.DisableInteraction();
|
||||
|
Loading…
x
Reference in New Issue
Block a user