laser puzzle platform and elevated platform module
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using JetBrains.Annotations;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Station46.Modules.Elevated_Platform.Scripts
|
||||
{
|
||||
public class ElevatedPlatform : ModuleState
|
||||
{
|
||||
[BoxGroup("Internal")] [SerializeField] private PlatformElevator _elevator;
|
||||
|
||||
public override void SetModule(Module module) {}
|
||||
|
||||
#region Debug Buttons
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
[UsedImplicitly]
|
||||
public void ActivateElevator()
|
||||
{
|
||||
_elevator.Activate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc9f2092e90b48a7bdd5d8dbe8c934e8
|
||||
timeCreated: 1683703386
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using EscapeRoomEngine.VR.Runtime;
|
||||
using NaughtyAttributes;
|
||||
using Station46.Scripts;
|
||||
using UnityEngine;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||
|
||||
namespace Station46.Modules.Elevated_Platform.Scripts
|
||||
{
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class PlatformElevator : MonoBehaviour
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
Bottom, Top, Moving
|
||||
}
|
||||
|
||||
private static readonly int
|
||||
AscendHash = Animator.StringToHash("Ascend"),
|
||||
DescendHash = Animator.StringToHash("Descend");
|
||||
|
||||
[BoxGroup("Internal")] [SerializeField] private Button _button;
|
||||
|
||||
[ShowNativeProperty]
|
||||
internal Status ElevatorStatus
|
||||
{
|
||||
get => _status;
|
||||
set
|
||||
{
|
||||
_status = value;
|
||||
switch (value)
|
||||
{
|
||||
case Status.Bottom:
|
||||
case Status.Top:
|
||||
ReleasePlayer();
|
||||
_button.Enable();
|
||||
break;
|
||||
case Status.Moving:
|
||||
_button.Disable();
|
||||
CapturePlayer();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Status _status = Status.Bottom;
|
||||
private Animator _animator;
|
||||
private Transform _previousPlayerParent;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_button.ButtonEvent += (_, type) =>
|
||||
{
|
||||
if (type == ButtonEventType.Pressed)
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void CapturePlayer()
|
||||
{
|
||||
Logger.Log($"{this} captured player.", LogType.PuzzleDetail);
|
||||
|
||||
_previousPlayerParent = Player.Instance.transform.parent;
|
||||
Player.Instance.transform.SetParent(transform);
|
||||
}
|
||||
|
||||
private void ReleasePlayer()
|
||||
{
|
||||
Logger.Log($"{this} released player.", LogType.PuzzleDetail);
|
||||
|
||||
Player.Instance.transform.SetParent(_previousPlayerParent);
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
switch (ElevatorStatus)
|
||||
{
|
||||
case Status.Bottom:
|
||||
Logger.Log($"{this} ascending.", LogType.PuzzleDetail);
|
||||
|
||||
ElevatorStatus = Status.Moving;
|
||||
_animator.SetTrigger(AscendHash);
|
||||
break;
|
||||
case Status.Top:
|
||||
Logger.Log($"{this} descending.", LogType.PuzzleDetail);
|
||||
|
||||
ElevatorStatus = Status.Moving;
|
||||
_animator.SetTrigger(DescendHash);
|
||||
break;
|
||||
case Status.Moving:
|
||||
Logger.Log($"{this} is already moving.", LogType.PuzzleDetail);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2efb4119000540cca1ccfab69c8abf9c
|
||||
timeCreated: 1683703157
|
||||
Reference in New Issue
Block a user