set room size in ui

This commit is contained in:
2023-05-12 02:59:40 +02:00
parent 939c741787
commit 05c952e7c7
12 changed files with 1680 additions and 100 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -63,7 +63,7 @@ namespace EscapeRoomEngine.Engine.Runtime
{
_playSpaceOrigin = new GameObject("Play Space Origin");
_playSpaceOrigin.transform.SetParent(transform);
_playSpaceOrigin.transform.localPosition = new Vector3(-theme.playSpace.x / 2f, 0, -theme.playSpace.y / 2f);
_playSpaceOrigin.transform.localPosition = new Vector3(-GameControl.Instance.RoomSize.x / 2f, 0, -GameControl.Instance.RoomSize.y / 2f);
}
#region Generation

View File

@@ -13,16 +13,6 @@ namespace EscapeRoomEngine.Engine.Runtime
[CreateAssetMenu(menuName = "Engine Theme")]
public class EngineTheme : ScriptableObject
{
#region Size
[BoxGroup("Size")] [Tooltip("The minimum size that should be allowed for rooms.")]
public Vector2Int minRoomSize;
[BoxGroup("Size")] [Tooltip("The size of the physical play space available to the engine.")]
public Vector2Int playSpace;
#endregion
#region Theme
[BoxGroup("Theme")] [Required]

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Modules.Description;
using EscapeRoomEngine.Engine.Runtime.UI;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
@@ -51,10 +52,11 @@ namespace EscapeRoomEngine.Engine.Runtime
internal Space(Room room, Passage entrance)
{
this.room = room;
rrPlacement = GenerateSpaceDimensions(
entrance,
Engine.Theme.minRoomSize.ProjectAtFloor(),
Engine.Theme.playSpace.ProjectAtFloor());
rrPlacement = new Placement
{
position = Vector3Int.zero,
size = new Vector2Int(GameControl.Instance.RoomSize.x, GameControl.Instance.RoomSize.y)
};
// connect the space to its entrance passage
entrance.PlaceEntrance(new DoorModule(this,
@@ -146,62 +148,5 @@ namespace EscapeRoomEngine.Engine.Runtime
/// </summary>
/// <param name="rrPosition">The room relative (<i>RR</i>) position that should be converted to a space relative (<i>SR</i>) position.</param>
internal Vector3Int ToSpaceRelative(Vector3Int rrPosition) => rrPosition - rrPlacement.position;
/// <summary>
/// Generate space dimensions that fit the required size constraints and cover the position of the entrance.
/// </summary>
/// <returns>A room relative (<i>RR</i>) placement with the generated dimensions. Always faces North.</returns>
private static Placement GenerateSpaceDimensions(Passage entrance, Vector3Int minSize, Vector3Int availableSpace)
{
var x = new Range(-1, -1);
var z = new Range(-1, -1);
var door = entrance.fromOut;
var position = door.RrPosition;
var bottomLeft = door.srPlacement.BottomLeft;
var doorSize = door.Size;
// fix the side the door is facing away from
switch (door.Orientation)
{
case Orientation.North:
z.min = position.z;
z.max = Utilities.Utilities.RandomInclusive(z.min + minSize.z, availableSpace.z);
break;
case Orientation.East:
x.min = position.x;
x.max = Utilities.Utilities.RandomInclusive(x.min + minSize.x, availableSpace.x);
break;
case Orientation.South:
z.max = position.z + 1;
z.min = Utilities.Utilities.RandomInclusive(0, z.max - minSize.z);
break;
case Orientation.West:
x.max = position.x + 1;
x.min = Utilities.Utilities.RandomInclusive(0, x.max - minSize.x);
break;
default:
throw new ArgumentOutOfRangeException();
}
// calculate remaining values if they haven't been covered by the switch statement yet
if(x.min == -1)
x.min = Utilities.Utilities.RandomInclusive(0, Math.Min(bottomLeft.x, availableSpace.x - minSize.x));
if(x.max == -1)
x.max = Utilities.Utilities.RandomInclusive(Math.Max(bottomLeft.x + doorSize.x, x.min + minSize.x), availableSpace.x);
if(z.min == -1)
z.min = Utilities.Utilities.RandomInclusive(0, Math.Min(bottomLeft.z, availableSpace.z - minSize.z));
if(z.max == -1)
z.max = Utilities.Utilities.RandomInclusive(Math.Max(bottomLeft.z + doorSize.x, z.min + minSize.z), availableSpace.z);
var dimensions = new Placement
{
position = new Vector3Int(x.min, 0, z.min),
size = new Vector2Int(x.Length, z.Length)
};
Logger.Log($"Generated space dimensions {dimensions} from entrance position {position}", LogType.RoomGeneration);
return dimensions;
}
}
}

View File

@@ -19,6 +19,8 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
/// </summary>
public class GameControl : MonoBehaviour
{
public static readonly Vector2Int DefaultRoomSize = new Vector2Int(2, 4);
/// <summary>
/// The active instance of the game control.
/// </summary>
@@ -33,7 +35,11 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
[BoxGroup("Internal")] [SerializeField]
private Button startButton, stopButton, pauseButton, addTimeButton, removeTimeButton;
[BoxGroup("Internal")] [SerializeField]
private Text timeText, roomTimeText, estimateTimeText, targetTimeText, percentileText;
private Text timeText, roomTimeText, estimateTimeText, targetTimeText, percentileText, widthText, lengthText;
[BoxGroup("Internal")] [SerializeField]
private Slider roomWidth, roomLength;
[BoxGroup("Internal")] [SerializeField]
private Transform roomSizeElement;
[BoxGroup("Internal")] [SerializeField]
private PuzzlePlan puzzlePlan;
@@ -67,12 +73,15 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
/// The estimated total time the player will spend in the experience.
/// </summary>
public float EstimatedTime { get; private set; }
public Vector2Int RoomSize { get; private set; }
private float _previousUIUpdate, _previousPlanUpdate;
private void Awake()
{
Instance = this;
RoomSize = DefaultRoomSize;
}
private void Start()
@@ -114,6 +123,8 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
pauseButton.interactable = gameState is GameState.Running or GameState.Paused;
addTimeButton.interactable = gameState is GameState.Running or GameState.Paused;
removeTimeButton.interactable = gameState is GameState.Running or GameState.Paused && TargetTime >= TimeElapsed + 60;
roomWidth.interactable = gameState == GameState.Stopped;
roomLength.interactable = gameState == GameState.Stopped;
}
#region Time Controls
@@ -124,6 +135,8 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
TimeElapsed = 0;
Destroy(roomSizeElement.gameObject);
// generate the first room if it hasn't been generated yet
Engine.Instance.CurrentRoom.Match(none: () => Engine.Instance.GenerateRoom());
@@ -217,6 +230,13 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
#endregion
public void SetRoomSize()
{
RoomSize = new Vector2Int((int)roomWidth.value, (int)roomLength.value);
widthText.text = RoomSize.x.ToString();
lengthText.text = RoomSize.y.ToString();
}
public void ExitGame()
{
StopGame();

View File

@@ -302,6 +302,46 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2536345795331795879, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2536345795331795879, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2536345795331795879, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2702596707407149509, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2702596707407149509, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6669187003974842087, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6669187003974842087, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6669187003974842087, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6854256364732531324, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_Name
@@ -362,6 +402,16 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7871291356846442061, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7871291356846442061, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []

View File

@@ -102,6 +102,7 @@ MonoBehaviour:
debugShaders:
debugReplacementPS: {fileID: 4800000, guid: cf852408f2e174538bcd9b7fda1c5ae7,
type: 3}
hdrDebugViewPS: {fileID: 4800000, guid: 573620ae32aec764abd4d728906d2587, type: 3}
m_RendererFeatures:
- {fileID: -1381608776974771741}
- {fileID: -7323701910238630107}
@@ -126,6 +127,7 @@ MonoBehaviour:
coreBlitPS: {fileID: 4800000, guid: 93446b5c5339d4f00b85c159e1159b7c, type: 3}
coreBlitColorAndDepthPS: {fileID: 4800000, guid: d104b2fc1ca6445babb8e90b0758136b,
type: 3}
blitHDROverlay: {fileID: 4800000, guid: a89bee29cffa951418fc1e2da94d1959, type: 3}
cameraMotionVector: {fileID: 4800000, guid: c56b7e0d4c7cb484e959caeeedae9bbf,
type: 3}
objectMotionVector: {fileID: 4800000, guid: 7b3ede40266cd49a395def176e1bc486,

View File

@@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 690929a59dc7a42da9030305190d391f, type: 3}
m_Name: XRDeviceSimulatorSettings
m_EditorClassIdentifier:
m_AutomaticallyInstantiateSimulatorPrefab: 0
m_SimulatorPrefab: {fileID: 0}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8dc191dd1ed110442ba3033ce39f67fe
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant: