puzzle module framework, puzzle a ball module
This commit is contained in:
@@ -13,7 +13,7 @@ MonoBehaviour:
|
||||
m_Name: Generic Door Entrance
|
||||
m_EditorClassIdentifier:
|
||||
types: 00000000
|
||||
modulePrefab: {fileID: 5399176795272327488, guid: da9b7a57e7c37d149827fe17188bdeea,
|
||||
modulePrefab: {fileID: 7146915386488129308, guid: da9b7a57e7c37d149827fe17188bdeea,
|
||||
type: 3}
|
||||
placementRequirements:
|
||||
- {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
|
||||
|
||||
@@ -13,7 +13,7 @@ MonoBehaviour:
|
||||
m_Name: Generic Door Exit
|
||||
m_EditorClassIdentifier:
|
||||
types: 01000000
|
||||
modulePrefab: {fileID: 5399176795272327488, guid: d877ee36ba6ace440aebce2c20cf70d6,
|
||||
modulePrefab: {fileID: 7146915386488129308, guid: d877ee36ba6ace440aebce2c20cf70d6,
|
||||
type: 3}
|
||||
placementRequirements:
|
||||
- {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
|
||||
|
||||
@@ -13,7 +13,7 @@ MonoBehaviour:
|
||||
m_Name: Generic Module
|
||||
m_EditorClassIdentifier:
|
||||
types:
|
||||
modulePrefab: {fileID: 3864228228344123331, guid: ad2655de8289afa40aa520f9fc474681,
|
||||
modulePrefab: {fileID: 4604142456167599783, guid: ad2655de8289afa40aa520f9fc474681,
|
||||
type: 3}
|
||||
placementRequirements:
|
||||
- {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
|
||||
|
||||
@@ -13,7 +13,7 @@ MonoBehaviour:
|
||||
m_Name: Generic Puzzle
|
||||
m_EditorClassIdentifier:
|
||||
types: 02000000
|
||||
modulePrefab: {fileID: 1780958886295268827, guid: e419cb35bd744b24ea973860d8b1405d,
|
||||
modulePrefab: {fileID: 9077423192650498975, guid: e419cb35bd744b24ea973860d8b1405d,
|
||||
type: 3}
|
||||
placementRequirements:
|
||||
- {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
|
||||
|
||||
@@ -13,7 +13,7 @@ MonoBehaviour:
|
||||
m_Name: Spawn
|
||||
m_EditorClassIdentifier:
|
||||
types: 00000000
|
||||
modulePrefab: {fileID: 641449049689494886, guid: db5350cd22f3a0f4f818a5f985342136,
|
||||
modulePrefab: {fileID: 2388501677731357498, guid: db5350cd22f3a0f4f818a5f985342136,
|
||||
type: 3}
|
||||
placementRequirements:
|
||||
- {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
|
||||
|
||||
@@ -77,5 +77,24 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedComponents:
|
||||
- {fileID: 4604142456167599783, guid: ad2655de8289afa40aa520f9fc474681, type: 3}
|
||||
m_SourcePrefab: {fileID: 100100000, guid: ad2655de8289afa40aa520f9fc474681, type: 3}
|
||||
--- !u!1 &913127997918145164 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 3864228228344123331, guid: ad2655de8289afa40aa520f9fc474681,
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 4110777154808243535}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!114 &2697478118666722512
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 913127997918145164}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 696181e3eda449d49d4c1c88b07d7b05, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
|
||||
@@ -92,6 +92,7 @@ GameObject:
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7860513085978939562}
|
||||
- component: {fileID: 4604142456167599783}
|
||||
m_Layer: 0
|
||||
m_Name: Generic Module
|
||||
m_TagString: Untagged
|
||||
@@ -115,6 +116,18 @@ Transform:
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &4604142456167599783
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3864228228344123331}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: efdc32c450f7411385748449459a17b4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &4439105426094897912
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -82,5 +82,25 @@ PrefabInstance:
|
||||
propertyPath: m_Materials.Array.data[0]
|
||||
value:
|
||||
objectReference: {fileID: 2100000, guid: 46455800cc2ce524c92336599f5ec772, type: 2}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedComponents:
|
||||
- {fileID: 4604142456167599783, guid: ad2655de8289afa40aa520f9fc474681, type: 3}
|
||||
m_SourcePrefab: {fileID: 100100000, guid: ad2655de8289afa40aa520f9fc474681, type: 3}
|
||||
--- !u!1 &1780958886295268827 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 3864228228344123331, guid: ad2655de8289afa40aa520f9fc474681,
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 3249140089838199320}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!114 &9077423192650498975
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1780958886295268827}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 265ea1efb38042b282ea67c50ac3e878, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
theme: {fileID: 0}
|
||||
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Engine Config")]
|
||||
[CreateAssetMenu(menuName = "Engine Theme")]
|
||||
public class EngineTheme : ScriptableObject
|
||||
{
|
||||
#region Size
|
||||
@@ -26,6 +26,10 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
[BoxGroup("Theme")]
|
||||
public GameObject environment;
|
||||
|
||||
[BoxGroup("Theme")]
|
||||
[ColorUsage(false, true)]
|
||||
public Color puzzleColor, solvedColor;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Doors
|
||||
|
||||
@@ -13,8 +13,20 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
{
|
||||
public bool IsEntrance => IsType((ModuleType)DoorType.Entrance);
|
||||
public bool IsExit => IsType((ModuleType)DoorType.Exit);
|
||||
internal new DoorState State { get; private set; }
|
||||
|
||||
|
||||
internal DoorState DoorState
|
||||
{
|
||||
get
|
||||
{
|
||||
if (State is DoorState doorState)
|
||||
{
|
||||
return doorState;
|
||||
}
|
||||
|
||||
throw new Exception("DoorModule must contain a DoorState");
|
||||
}
|
||||
}
|
||||
|
||||
internal DoorModule(Space space, DoorModuleDescription description) : base(space, description)
|
||||
{
|
||||
srDimensions.Size = Vector2Int.one; // door always has size 1x1
|
||||
@@ -27,12 +39,6 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
space.room.AddDoor(this);
|
||||
}
|
||||
|
||||
protected override void AddStateComponent()
|
||||
{
|
||||
State = moduleObject.AddComponent<DoorState>();
|
||||
State.SetModule(this);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{(IsEntrance ? "Entrance" : IsExit ? "Exit" : "Unknown")} door";
|
||||
|
||||
@@ -39,9 +39,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
/// </summary>
|
||||
protected Dimensions srDimensions;
|
||||
|
||||
protected GameObject moduleObject;
|
||||
protected readonly Space space;
|
||||
private GameObject _orientationObject;
|
||||
|
||||
internal Module(Space space, ModuleDescription description)
|
||||
{
|
||||
@@ -96,21 +94,12 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
|
||||
internal virtual void InstantiateModule(Transform parent)
|
||||
{
|
||||
moduleObject = new GameObject(ToString());
|
||||
moduleObject.transform.SetParent(parent, false);
|
||||
moduleObject.transform.localPosition = new Vector3(srDimensions.x + .5f, 0, srDimensions.z + .5f);
|
||||
AddStateComponent();
|
||||
|
||||
_orientationObject = new GameObject("Orientation");
|
||||
_orientationObject.transform.SetParent(moduleObject.transform, false);
|
||||
_orientationObject.transform.Rotate(Vector3.up, (float)orientation);
|
||||
|
||||
Object.Instantiate(description.modulePrefab, _orientationObject.transform, false);
|
||||
}
|
||||
|
||||
protected virtual void AddStateComponent()
|
||||
{
|
||||
State = moduleObject.AddComponent<ModuleState>();
|
||||
Logger.Log($"Instantiating {this}", LogType.RoomGeneration);
|
||||
|
||||
State = Object.Instantiate(description.modulePrefab, parent, false);
|
||||
State.transform.localPosition = new Vector3(srDimensions.x + .5f, 0, srDimensions.z + .5f);
|
||||
State.transform.Rotate(Vector3.up, (float)orientation);
|
||||
State.name = ToString();
|
||||
State.SetModule(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
public class ModuleDescription : ScriptableObject
|
||||
{
|
||||
public List<ModuleType> types = new();
|
||||
public GameObject modulePrefab;
|
||||
public ModuleState modulePrefab;
|
||||
public List<PlacementRequirement> placementRequirements = new();
|
||||
public List<OrientationRequirement> orientationRequirements = new();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
{
|
||||
public class PuzzleModule : Module
|
||||
{
|
||||
internal new PuzzleState State { get; private set; }
|
||||
internal PuzzleState PuzzleState
|
||||
{
|
||||
get
|
||||
{
|
||||
if (State is PuzzleState puzzleState)
|
||||
{
|
||||
return puzzleState;
|
||||
}
|
||||
|
||||
throw new Exception("PuzzleModule must contain a PuzzleState");
|
||||
}
|
||||
}
|
||||
|
||||
internal PuzzleModule(Space space, PuzzleModuleDescription description) : base(space, description)
|
||||
{
|
||||
@@ -17,11 +29,5 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
|
||||
space.room.AddPuzzle(this);
|
||||
}
|
||||
|
||||
protected override void AddStateComponent()
|
||||
{
|
||||
State = moduleObject.AddComponent<PuzzleState>();
|
||||
State.SetModule(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,36 @@
|
||||
using System;
|
||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
|
||||
using LogType = Escape_Room_Engine.Engine.Scripts.Utilities.LogType;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
{
|
||||
public enum PuzzleEventType
|
||||
{
|
||||
Restarted, Solved
|
||||
Restarted, Solved, WrongInput
|
||||
}
|
||||
|
||||
|
||||
public static class PuzzleEventExtensions
|
||||
{
|
||||
public static string Description(this PuzzleEventType type, PuzzleModule module)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PuzzleEventType.Restarted => $"{module} has been restarted",
|
||||
PuzzleEventType.Solved => $"{module} has been solved",
|
||||
PuzzleEventType.WrongInput => $"Wrong input for {module}",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void PuzzleEventHandler(PuzzleModule source, PuzzleEventType e);
|
||||
|
||||
public class PuzzleState : ModuleState
|
||||
{
|
||||
public event PuzzleEventHandler PuzzleEvent;
|
||||
public EngineTheme theme;
|
||||
|
||||
private new PuzzleModule Module { get; set; }
|
||||
public bool Solved
|
||||
@@ -34,7 +51,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
|
||||
private void OnPuzzleEvent(PuzzleEventType type)
|
||||
{
|
||||
Logger.Log($"{Module} has been {type}", LogType.PuzzleFlow);
|
||||
Logger.Log(type.Description(Module), LogType.PuzzleFlow);
|
||||
|
||||
PuzzleEvent?.Invoke(Module, type);
|
||||
}
|
||||
@@ -62,5 +79,11 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
{
|
||||
Solved = false;
|
||||
}
|
||||
|
||||
[Button("Trigger Wrong Input", EButtonEnableMode.Playmode)]
|
||||
public void WrongInput()
|
||||
{
|
||||
OnPuzzleEvent(PuzzleEventType.WrongInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
||||
// ReSharper disable once RedundantIfElseBlock
|
||||
else
|
||||
{
|
||||
Utilities.Logger.Log("Could not find suitable placement for module", Utilities.LogType.ModulePlacement);
|
||||
Utilities.Logger.Log($"Could not find suitable placement for {module}", Utilities.LogType.ModulePlacement);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,22 +34,22 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
{
|
||||
Logger.Log($"Skipping {this}...", LogType.PuzzleFlow);
|
||||
|
||||
_puzzles.ForEach(puzzle => puzzle.State.Solve());
|
||||
_puzzles.ForEach(puzzle => puzzle.PuzzleState.Solve());
|
||||
}
|
||||
|
||||
internal void AddPuzzle(PuzzleModule puzzle)
|
||||
{
|
||||
_puzzles.Add(puzzle);
|
||||
puzzle.State.PuzzleEvent += OnPuzzleEvent;
|
||||
puzzle.PuzzleState.PuzzleEvent += OnPuzzleEvent;
|
||||
}
|
||||
|
||||
private void OnPuzzleEvent(PuzzleModule puzzle, PuzzleEventType type)
|
||||
{
|
||||
if (type == PuzzleEventType.Solved)
|
||||
{
|
||||
if (_puzzles.All(p => p.State.Solved))
|
||||
if (_puzzles.All(p => p.PuzzleState.Solved))
|
||||
{
|
||||
exit.fromOut.State.Unlock();
|
||||
exit.fromOut.DoorState.Unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
internal void AddDoor(DoorModule door)
|
||||
{
|
||||
_doors.Add(door);
|
||||
door.State.DoorEvent += OnDoorEvent;
|
||||
door.DoorState.DoorEvent += OnDoorEvent;
|
||||
}
|
||||
|
||||
private void OnDoorEvent(DoorModule door, DoorEventType type)
|
||||
|
||||
Reference in New Issue
Block a user