generic doors
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
{
|
||||
@@ -7,14 +8,15 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
Entrance = ModuleType.DoorEntrance, Exit = ModuleType.DoorExit
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class DoorModule : Module
|
||||
{
|
||||
public bool IsEntrance => IsType((ModuleType)DoorType.Entrance);
|
||||
public bool IsExit => IsType((ModuleType)DoorType.Exit);
|
||||
|
||||
internal DoorModule(DoorType type, Space space) : base(space)
|
||||
internal DoorModule(Space space, DoorModuleDescription description) : base(space, description)
|
||||
{
|
||||
types.Add((ModuleType)type);
|
||||
_description.types.Add((ModuleType)description.doorType);
|
||||
srDimensions.Size = Vector2Int.one; // door always has size 1x1
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Door Module")]
|
||||
public class DoorModuleDescription : ModuleDescription
|
||||
{
|
||||
public DoorType doorType;
|
||||
/// <summary>
|
||||
/// The description for the door that should be connected with this one.
|
||||
/// <example>If this is a teleporter entrance, the connected door should be a teleporter exit.</example>
|
||||
/// </summary>
|
||||
public DoorModuleDescription connectedDoorDescription;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5c1202346c34ebc9c3f701a98b50877
|
||||
timeCreated: 1667833660
|
||||
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||
using UnityEngine;
|
||||
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
|
||||
using LogType = Escape_Room_Engine.Engine.Scripts.Utilities.LogType;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
{
|
||||
@@ -16,43 +17,43 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
/// <summary>
|
||||
/// Get the room relative (<i>RR</i>) position of this module.
|
||||
/// </summary>
|
||||
internal Vector2Int RrPosition => space.ToRoomRelative(SrPosition);
|
||||
internal Vector2Int RrPosition => _space.ToRoomRelative(SrPosition);
|
||||
|
||||
internal readonly Space space;
|
||||
|
||||
internal readonly ModuleDescription _description;
|
||||
protected GameObject _moduleObject;
|
||||
protected readonly List<ModuleType> types = new();
|
||||
/// <summary>
|
||||
/// The space relative (<i>SR</i>) dimensions of this module.
|
||||
/// </summary>
|
||||
protected Dimensions srDimensions;
|
||||
|
||||
internal Module(Space space)
|
||||
private readonly Space _space;
|
||||
|
||||
internal Module(Space space, ModuleDescription description)
|
||||
{
|
||||
this.space = space;
|
||||
_space = space;
|
||||
_description = description;
|
||||
}
|
||||
|
||||
internal bool IsType(ModuleType type)
|
||||
{
|
||||
return types.Contains(type);
|
||||
return _description.types.Contains(type);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Place this module with a position relative to the room.
|
||||
/// </summary>
|
||||
/// <param name="rrPosition">The room relative (<i>RR</i>) position of this module. Must be inside the space dimensions.</param>
|
||||
/// <exception cref="Exception">If the position is not inside the space dimensions.</exception>
|
||||
internal void PlaceRoomRelative(Vector2Int rrPosition) => Place(space.ToSpaceRelative(rrPosition));
|
||||
internal void PlaceRoomRelative(Vector2Int rrPosition) => Place(_space.ToSpaceRelative(rrPosition));
|
||||
/// <summary>
|
||||
/// Place this module with a position relative to the space it is in.
|
||||
/// </summary>
|
||||
/// <param name="srPosition">The space relative (<i>SR</i>) position of this module. Must be inside the space dimensions.</param>
|
||||
/// <exception cref="Exception">If the position is not inside the space dimensions.</exception>
|
||||
internal void Place(Vector2Int srPosition) {
|
||||
if (space != null && !srPosition.IsInsideRelative(space.rrDimensions))
|
||||
if (_space != null && !srPosition.IsInsideRelative(_space.rrDimensions))
|
||||
{
|
||||
throw new Exception($"Trying to place {this} at {srPosition}, which is outside space dimensions {space.rrDimensions}.");
|
||||
throw new Exception($"Trying to place {this} at {srPosition}, which is outside space dimensions {_space.rrDimensions}.");
|
||||
}
|
||||
|
||||
srDimensions.Position = srPosition;
|
||||
@@ -60,9 +61,18 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
Logger.Log($"{this} has been placed at {srPosition} (SR)", LogType.ModulePlacement);
|
||||
}
|
||||
|
||||
internal void InstantiateModule(Transform parent)
|
||||
{
|
||||
_moduleObject = new GameObject(ToString());
|
||||
_moduleObject.transform.SetParent(parent, false);
|
||||
_moduleObject.transform.localPosition = new Vector3(srDimensions.x, 0, srDimensions.z);
|
||||
|
||||
Object.Instantiate(_description.modulePrefab, _moduleObject.transform, false);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Module ({string.Join(',', types.ConvertAll(type => type.ToString()))})";
|
||||
return $"Module ({string.Join(',', _description.types.ToList().ConvertAll(type => type.ToString()))})";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Generic Module")]
|
||||
public class ModuleDescription : ScriptableObject
|
||||
{
|
||||
public readonly HashSet<ModuleType> types = new();
|
||||
public GameObject modulePrefab;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: abf4a405f6c64073995bded39977563e
|
||||
timeCreated: 1667831630
|
||||
Reference in New Issue
Block a user