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 = new GameObject("Play Space Origin");
_playSpaceOrigin.transform.SetParent(transform); _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 #region Generation

View File

@@ -13,16 +13,6 @@ namespace EscapeRoomEngine.Engine.Runtime
[CreateAssetMenu(menuName = "Engine Theme")] [CreateAssetMenu(menuName = "Engine Theme")]
public class EngineTheme : ScriptableObject 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 #region Theme
[BoxGroup("Theme")] [Required] [BoxGroup("Theme")] [Required]

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Modules; using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Modules.Description; using EscapeRoomEngine.Engine.Runtime.Modules.Description;
using EscapeRoomEngine.Engine.Runtime.UI;
using EscapeRoomEngine.Engine.Runtime.Utilities; using EscapeRoomEngine.Engine.Runtime.Utilities;
using UnityEngine; using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger; using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
@@ -51,10 +52,11 @@ namespace EscapeRoomEngine.Engine.Runtime
internal Space(Room room, Passage entrance) internal Space(Room room, Passage entrance)
{ {
this.room = room; this.room = room;
rrPlacement = GenerateSpaceDimensions( rrPlacement = new Placement
entrance, {
Engine.Theme.minRoomSize.ProjectAtFloor(), position = Vector3Int.zero,
Engine.Theme.playSpace.ProjectAtFloor()); size = new Vector2Int(GameControl.Instance.RoomSize.x, GameControl.Instance.RoomSize.y)
};
// connect the space to its entrance passage // connect the space to its entrance passage
entrance.PlaceEntrance(new DoorModule(this, entrance.PlaceEntrance(new DoorModule(this,
@@ -146,62 +148,5 @@ namespace EscapeRoomEngine.Engine.Runtime
/// </summary> /// </summary>
/// <param name="rrPosition">The room relative (<i>RR</i>) position that should be converted to a space relative (<i>SR</i>) position.</param> /// <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; 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> /// </summary>
public class GameControl : MonoBehaviour public class GameControl : MonoBehaviour
{ {
public static readonly Vector2Int DefaultRoomSize = new Vector2Int(2, 4);
/// <summary> /// <summary>
/// The active instance of the game control. /// The active instance of the game control.
/// </summary> /// </summary>
@@ -33,7 +35,11 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
[BoxGroup("Internal")] [SerializeField] [BoxGroup("Internal")] [SerializeField]
private Button startButton, stopButton, pauseButton, addTimeButton, removeTimeButton; private Button startButton, stopButton, pauseButton, addTimeButton, removeTimeButton;
[BoxGroup("Internal")] [SerializeField] [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] [BoxGroup("Internal")] [SerializeField]
private PuzzlePlan puzzlePlan; private PuzzlePlan puzzlePlan;
@@ -67,12 +73,15 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
/// The estimated total time the player will spend in the experience. /// The estimated total time the player will spend in the experience.
/// </summary> /// </summary>
public float EstimatedTime { get; private set; } public float EstimatedTime { get; private set; }
public Vector2Int RoomSize { get; private set; }
private float _previousUIUpdate, _previousPlanUpdate; private float _previousUIUpdate, _previousPlanUpdate;
private void Awake() private void Awake()
{ {
Instance = this; Instance = this;
RoomSize = DefaultRoomSize;
} }
private void Start() private void Start()
@@ -114,6 +123,8 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
pauseButton.interactable = gameState is GameState.Running or GameState.Paused; pauseButton.interactable = gameState is GameState.Running or GameState.Paused;
addTimeButton.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; 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 #region Time Controls
@@ -124,6 +135,8 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
TimeElapsed = 0; TimeElapsed = 0;
Destroy(roomSizeElement.gameObject);
// generate the first room if it hasn't been generated yet // generate the first room if it hasn't been generated yet
Engine.Instance.CurrentRoom.Match(none: () => Engine.Instance.GenerateRoom()); Engine.Instance.CurrentRoom.Match(none: () => Engine.Instance.GenerateRoom());
@@ -217,6 +230,13 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
#endregion #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() public void ExitGame()
{ {
StopGame(); StopGame();

View File

@@ -302,6 +302,46 @@ PrefabInstance:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 0} m_TransformParent: {fileID: 0}
m_Modifications: 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, - target: {fileID: 6854256364732531324, guid: ecbf9ce952d5f38458b8237a4483c562,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
@@ -362,6 +402,16 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 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_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []

View File

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

View File

@@ -7,7 +7,7 @@
"com.unity.timeline": "1.7.4", "com.unity.timeline": "1.7.4",
"com.unity.ugui": "1.0.0", "com.unity.ugui": "1.0.0",
"com.unity.visualscripting": "1.8.0", "com.unity.visualscripting": "1.8.0",
"com.unity.xr.interaction.toolkit": "2.2.0", "com.unity.xr.interaction.toolkit": "2.3.1",
"com.unity.xr.mock-hmd": "1.3.1-preview.1", "com.unity.xr.mock-hmd": "1.3.1-preview.1",
"com.unity.xr.openxr": "1.7.0", "com.unity.xr.openxr": "1.7.0",
"io.realm.unity": "10.21.1", "io.realm.unity": "10.21.1",

View File

@@ -65,7 +65,7 @@
"source": "builtin", "source": "builtin",
"dependencies": { "dependencies": {
"com.unity.mathematics": "1.2.1", "com.unity.mathematics": "1.2.1",
"com.unity.burst": "1.8.2", "com.unity.burst": "1.8.4",
"com.unity.render-pipelines.core": "14.0.7", "com.unity.render-pipelines.core": "14.0.7",
"com.unity.shadergraph": "14.0.7" "com.unity.shadergraph": "14.0.7"
} }
@@ -86,15 +86,6 @@
"com.unity.searcher": "4.9.2" "com.unity.searcher": "4.9.2"
} }
}, },
"com.unity.subsystemregistration": {
"version": "1.1.1",
"depth": 2,
"source": "registry",
"dependencies": {
"com.unity.modules.subsystems": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.textmeshpro": { "com.unity.textmeshpro": {
"version": "3.0.6", "version": "3.0.6",
"depth": 0, "depth": 0,
@@ -136,7 +127,7 @@
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.xr.core-utils": { "com.unity.xr.core-utils": {
"version": "2.1.1", "version": "2.2.0",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
@@ -145,14 +136,15 @@
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.xr.interaction.toolkit": { "com.unity.xr.interaction.toolkit": {
"version": "2.2.0", "version": "2.3.1",
"depth": 0, "depth": 0,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.inputsystem": "1.3.0", "com.unity.inputsystem": "1.4.4",
"com.unity.mathematics": "1.2.6",
"com.unity.ugui": "1.0.0", "com.unity.ugui": "1.0.0",
"com.unity.xr.core-utils": "2.0.0", "com.unity.xr.core-utils": "2.2.0",
"com.unity.xr.legacyinputhelpers": "2.1.8", "com.unity.xr.legacyinputhelpers": "2.1.10",
"com.unity.modules.audio": "1.0.0", "com.unity.modules.audio": "1.0.0",
"com.unity.modules.imgui": "1.0.0", "com.unity.modules.imgui": "1.0.0",
"com.unity.modules.physics": "1.0.0" "com.unity.modules.physics": "1.0.0"
@@ -170,15 +162,14 @@
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.xr.management": { "com.unity.xr.management": {
"version": "4.2.0", "version": "4.3.3",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.modules.subsystems": "1.0.0", "com.unity.modules.subsystems": "1.0.0",
"com.unity.modules.vr": "1.0.0", "com.unity.modules.vr": "1.0.0",
"com.unity.modules.xr": "1.0.0", "com.unity.modules.xr": "1.0.0",
"com.unity.xr.legacyinputhelpers": "2.1.7", "com.unity.xr.legacyinputhelpers": "2.1.7"
"com.unity.subsystemregistration": "1.0.6"
}, },
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },

View File

@@ -1,2 +1,2 @@
m_EditorVersion: 2022.2.14f1 m_EditorVersion: 2022.2.19f1
m_EditorVersionWithRevision: 2022.2.14f1 (b2c9b1ac6cc0) m_EditorVersionWithRevision: 2022.2.19f1 (765657fe9343)