ring model
This commit is contained in:
95
Assets/Station46/Modules/Rings/Scripts/AlignRings.cs
Normal file
95
Assets/Station46/Modules/Rings/Scripts/AlignRings.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
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.Rings.Scripts
|
||||
{
|
||||
public class AlignRings : 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 Ring ringX, ringY, ringZ;
|
||||
[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;
|
||||
ringX.Displacement = 0;
|
||||
ringY.Displacement = 0;
|
||||
ringZ.Displacement = 0;
|
||||
var color = EscapeRoomEngine.Engine.Runtime.Engine.Theme.solvedColor.hdr;
|
||||
ringX.Emission.color = color;
|
||||
ringY.Emission.color = color;
|
||||
ringZ.Emission.color = color;
|
||||
_orb.Color = color;
|
||||
_orb.GetComponent<XRGrabInteractable>().enabled = false;
|
||||
animator.SetTrigger(SlotIn);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!Solved)
|
||||
{
|
||||
var position = _orb.transform.position - target.position;
|
||||
ringX.Displacement = position.x * movementScaling.x;
|
||||
ringY.Displacement = position.y * movementScaling.y;
|
||||
ringZ.Displacement = position.z * movementScaling.z;
|
||||
|
||||
SetState(0, Mathf.RoundToInt(ringX.Displacement / accuracy), false);
|
||||
SetState(1, Mathf.RoundToInt(ringY.Displacement / accuracy), false);
|
||||
SetState(2, Mathf.RoundToInt(ringZ.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 rings was not assigned a related dispenser orb.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c3022c62a3d4d92be9a4e42a558270c
|
||||
timeCreated: 1683750812
|
||||
29
Assets/Station46/Modules/Rings/Scripts/Ring.cs
Normal file
29
Assets/Station46/Modules/Rings/Scripts/Ring.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using NaughtyAttributes;
|
||||
using Station46.Scripts;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Station46.Modules.Rings.Scripts
|
||||
{
|
||||
[RequireComponent(typeof(Emission))]
|
||||
public class Ring : MonoBehaviour
|
||||
{
|
||||
public float speed;
|
||||
|
||||
[ShowNativeProperty] public float Displacement { get; set; }
|
||||
public Emission Emission { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Emission = GetComponent<Emission>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Station46/Modules/Rings/Scripts/Ring.cs.meta
Normal file
11
Assets/Station46/Modules/Rings/Scripts/Ring.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a920c663eb740c084fc8e87fbe72cb7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user