align steles puzzle
This commit is contained in:
20
Assets/Station46/Modules/Steles/Scripts/AlignStele.cs
Normal file
20
Assets/Station46/Modules/Steles/Scripts/AlignStele.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Station46.Modules.Steles.Scripts
|
||||
{
|
||||
public class AlignStele : MonoBehaviour
|
||||
{
|
||||
public float speed;
|
||||
|
||||
[ShowNativeProperty] public float Displacement { get; set; }
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var t = transform;
|
||||
var position = t.localPosition;
|
||||
var delta = position.y - Displacement;
|
||||
t.localPosition = new Vector3(0, position.y - delta * speed, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a920c663eb740c084fc8e87fbe72cb7
|
||||
timeCreated: 1683754591
|
||||
91
Assets/Station46/Modules/Steles/Scripts/AlignSteles.cs
Normal file
91
Assets/Station46/Modules/Steles/Scripts/AlignSteles.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using Station46.Modules.Dispenser.Scripts;
|
||||
using Station46.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
namespace Station46.Modules.Steles.Scripts
|
||||
{
|
||||
public class AlignSteles : StatePuzzle
|
||||
{
|
||||
private static readonly int SlotIn = Animator.StringToHash("Slot In");
|
||||
|
||||
public float accuracy = 0.1f;
|
||||
public float sensitivity = 0.001f;
|
||||
public Vector3 movementScaling = Vector3.one;
|
||||
[BoxGroup("Internal")] [SerializeField] private Transform target;
|
||||
[BoxGroup("Internal")] [SerializeField] private AlignStele steleX, steleY, steleZ;
|
||||
[BoxGroup("Internal")] [SerializeField] private Animator animator;
|
||||
|
||||
private DispenserOrb _orb;
|
||||
private Vector3 _previousPosition;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
PuzzleEvent += (_, type) =>
|
||||
{
|
||||
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
|
||||
switch (type)
|
||||
{
|
||||
case PuzzleEventType.Restarted:
|
||||
_orb.GetComponent<XRGrabInteractable>().enabled = true;
|
||||
_orb.Color = EscapeRoomEngine.Engine.Runtime.Engine.Theme.puzzleColor.hdr;
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
_orb.transform.position = target.position;
|
||||
steleX.Displacement = 0;
|
||||
steleY.Displacement = 0;
|
||||
steleZ.Displacement = 0;
|
||||
_orb.Color = EscapeRoomEngine.Engine.Runtime.Engine.Theme.solvedColor.hdr;
|
||||
_orb.GetComponent<XRGrabInteractable>().enabled = false;
|
||||
animator.SetTrigger(SlotIn);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!Solved)
|
||||
{
|
||||
var position = _orb.transform.position - target.position;
|
||||
steleX.Displacement = position.x * movementScaling.x;
|
||||
steleY.Displacement = position.y * movementScaling.y;
|
||||
steleZ.Displacement = position.z * movementScaling.z;
|
||||
|
||||
SetState(0, Mathf.RoundToInt(steleX.Displacement / accuracy), false);
|
||||
SetState(1, Mathf.RoundToInt(steleY.Displacement / accuracy), false);
|
||||
SetState(2, Mathf.RoundToInt(steleZ.Displacement / accuracy), true);
|
||||
|
||||
if (_orb.Color != EscapeRoomEngine.Engine.Runtime.Engine.Theme.solvedColor.hdr)
|
||||
{
|
||||
_orb.Color = (position - _previousPosition).magnitude < sensitivity
|
||||
? EscapeRoomEngine.Engine.Runtime.Engine.Theme.puzzleColor.hdr
|
||||
: EscapeRoomEngine.Engine.Runtime.Engine.Theme.activeColor.hdr;
|
||||
_previousPosition = position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetModule(Module module)
|
||||
{
|
||||
base.SetModule(module);
|
||||
|
||||
// The holes require a related dispenser module
|
||||
var firstRelatedModule = Module.relatedModules[0];
|
||||
if (firstRelatedModule.State is DispenserOrbGroup orbGroup)
|
||||
{
|
||||
_orb = orbGroup.GetComponentInChildren<DispenserOrb>();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new EngineException("Align steles was not assigned a related dispenser orb.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c3022c62a3d4d92be9a4e42a558270c
|
||||
timeCreated: 1683750812
|
||||
Reference in New Issue
Block a user