make dispenser available to all puzzles
This commit is contained in:
96
Assets/Desert/Runtime/Dispenser/Dispenser.cs
Normal file
96
Assets/Desert/Runtime/Dispenser/Dispenser.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Dispenser
|
||||
{
|
||||
[SelectionBase]
|
||||
[RequireComponent(typeof(Animator), typeof(Emission))]
|
||||
public class Dispenser : ModuleState
|
||||
{
|
||||
private static readonly int Open = Animator.StringToHash("Open");
|
||||
|
||||
public Transform dispensable;
|
||||
[SerializeField] [Min(0)]
|
||||
private float cooldown;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private Transform dispenseOrigin;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private Button dispenseButton;
|
||||
|
||||
public bool Solved
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
CloseHatch();
|
||||
dispenseButton.Disable();
|
||||
_light.color = Engine.Runtime.Engine.DefaultEngine.theme.solvedColor.hdr;
|
||||
}
|
||||
else
|
||||
{
|
||||
dispenseButton.Enable();
|
||||
_light.color = Engine.Runtime.Engine.DefaultEngine.theme.puzzleColor.hdr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float _previousDispense = -1;
|
||||
private Animator _animator;
|
||||
private Emission _light;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_animator = GetComponent<Animator>();
|
||||
_light = GetComponent<Emission>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
dispenseButton.ButtonEvent += (_, type) =>
|
||||
{
|
||||
if (type == ButtonEventType.Pressed)
|
||||
{
|
||||
Dispense();
|
||||
}
|
||||
};
|
||||
|
||||
_light.active = true;
|
||||
}
|
||||
|
||||
#region Debug Buttons
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void Dispense()
|
||||
{
|
||||
if (_previousDispense + cooldown <= Time.time)
|
||||
{
|
||||
Logger.Log($"{this} dispensing {dispensable.gameObject}", LogType.PuzzleDetail);
|
||||
|
||||
_animator.SetBool(Open, true);
|
||||
Instantiate(dispensable, dispenseOrigin.position, dispenseOrigin.rotation);
|
||||
|
||||
_previousDispense = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void CloseHatch()
|
||||
{
|
||||
_animator.SetBool(Open, false);
|
||||
}
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void Solve() => Solved = true;
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void Reset() => Solved = false;
|
||||
|
||||
#endregion
|
||||
|
||||
public override void SetModule(Module module) {}
|
||||
}
|
||||
}
|
||||
3
Assets/Desert/Runtime/Dispenser/Dispenser.cs.meta
Normal file
3
Assets/Desert/Runtime/Dispenser/Dispenser.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ca2acc9138242c59fbba68a62435318
|
||||
timeCreated: 1669991155
|
||||
39
Assets/Desert/Runtime/Dispenser/DispenserLights.cs
Normal file
39
Assets/Desert/Runtime/Dispenser/DispenserLights.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Dispenser
|
||||
{
|
||||
[Serializable]
|
||||
public struct DispenserLightRow
|
||||
{
|
||||
public bool[] lights;
|
||||
}
|
||||
|
||||
public class DispenserLights : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private DispenserLightRow[] lights;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private GameObject lightPrefab;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private Vector2Int gridDimensions;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private Vector2 lightOffset;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var position = transform.localPosition;
|
||||
for (var y = 0; y < gridDimensions.y; y++)
|
||||
{
|
||||
var row = lights[y].lights;
|
||||
for (var x = 0; x < gridDimensions.x; x++)
|
||||
{
|
||||
var instance = Instantiate(lightPrefab, transform, false);
|
||||
instance.transform.localPosition = new Vector3(-x * lightOffset.x, 0, y * lightOffset.y);
|
||||
instance.GetComponent<Emission>().active = row[x];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Desert/Runtime/Dispenser/DispenserLights.cs.meta
Normal file
3
Assets/Desert/Runtime/Dispenser/DispenserLights.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b796efe5676490b81fe24366d556b18
|
||||
timeCreated: 1670273719
|
||||
25
Assets/Desert/Runtime/Dispenser/DispenserOrb.cs
Normal file
25
Assets/Desert/Runtime/Dispenser/DispenserOrb.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Dispenser
|
||||
{
|
||||
[RequireComponent(typeof(Rigidbody), typeof(Collider), typeof(Emission))]
|
||||
public class DispenserOrb : MonoBehaviour
|
||||
{
|
||||
public Color Color
|
||||
{
|
||||
set => _emission.color = value;
|
||||
}
|
||||
|
||||
private Emission _emission;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_emission = GetComponent<Emission>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_emission.active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Desert/Runtime/Dispenser/DispenserOrb.cs.meta
Normal file
3
Assets/Desert/Runtime/Dispenser/DispenserOrb.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 461335b38aec4817a787dae9c5a63f0b
|
||||
timeCreated: 1669815545
|
||||
Reference in New Issue
Block a user