Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Features/Enums/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public enum BlockType
/// Represents a locker.
/// </summary>
Locker = 7,

/// <summary>
/// Represents a Interactable.
/// </summary>
Interactable = 8,
}
7 changes: 4 additions & 3 deletions Features/Enums/ToolGunObjectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum ToolGunObjectType
PlayerSpawnpoint = 6,
Capybara = 7,
Text = 8,
Scp079Camera = 9,
ShootingTarget = 10,
Teleport = 11,
Interactable = 9,
Scp079Camera = 10,
ShootingTarget = 11,
Teleport = 12,
}
6 changes: 6 additions & 0 deletions Features/ObjectSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public static PrimitiveObjectToy SpawnPrimitive(SerializablePrimitive serializab
return gameObject.GetComponent<PrimitiveObjectToy>();
}

public static InvisibleInteractableToy SpawnInteractable(SerializableInteractable serializableInteractable)
{
GameObject gameObject = serializableInteractable.SpawnOrUpdateObject();
return gameObject.GetComponent<InvisibleInteractableToy>();
}

public static SchematicObject SpawnSchematic(SerializableSchematic serializableSchematic)
{
GameObject? gameObject = serializableSchematic.SpawnOrUpdateObject();
Expand Down
8 changes: 8 additions & 0 deletions Features/PrefabManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static class PrefabManager
public static PrimitiveObjectToy PrimitiveObjectPrefab { get; private set; }

public static LightSourceToy LightSourcePrefab { get; private set; }

public static InvisibleInteractableToy InvisibleInteractableToy { get; private set; }

public static DoorVariant LczDoorPrefab { get; private set; }
public static DoorVariant HczDoorPrefab { get; private set; }
Expand Down Expand Up @@ -48,6 +50,12 @@ public static void RegisterPrefabs()
LightSourcePrefab = lightSourceToy;
continue;
}

if (gameObject.TryGetComponent(out InvisibleInteractableToy invisibleInteractableToy))
{
InvisibleInteractableToy = invisibleInteractableToy;
continue;
}

if (gameObject.TryGetComponent(out DoorVariant doorVariant))
{
Expand Down
4 changes: 4 additions & 0 deletions Features/Serializable/MapSchematic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public MapSchematic(string mapName)
public Dictionary<string, SerializablePrimitive> Primitives { get; set; } = [];

public Dictionary<string, SerializableLight> Lights { get; set; } = [];

public Dictionary<string, SerializableInteractable> Interactables { get; set; } = [];

public Dictionary<string, SerializableDoor> Doors { get; set; } = [];

Expand Down Expand Up @@ -51,6 +53,7 @@ public MapSchematic Merge(MapSchematic other)
{
Primitives.AddRange(other.Primitives);
Lights.AddRange(other.Lights);
Interactables.AddRange(other.Interactables);
Doors.AddRange(other.Doors);
Workstations.AddRange(other.Workstations);
ItemSpawnpoints.AddRange(other.ItemSpawnpoints);
Expand All @@ -74,6 +77,7 @@ public void Reload()

Primitives.ForEach(kVP => SpawnObject(kVP.Key, kVP.Value));
Lights.ForEach(kVP => SpawnObject(kVP.Key, kVP.Value));
Interactables.ForEach(kVP => SpawnObject(kVP.Key, kVP.Value));
Doors.ForEach(kVP =>
{
Door? vanillaDoor = Door.Get(kVP.Key);
Expand Down
13 changes: 13 additions & 0 deletions Features/Serializable/Schematics/SchematicBlockData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public GameObject Create(SchematicObject schematicObject, Transform parentTransf
BlockType.Light => CreateLight(),
BlockType.Pickup => CreatePickup(schematicObject),
BlockType.Workstation => CreateWorkstation(),
BlockType.Interactable => CreateInteractable(),
_ => CreateEmpty(true)
};

Expand Down Expand Up @@ -138,4 +139,16 @@ private GameObject CreateWorkstation()

return workstation.gameObject;
}

private GameObject CreateInteractable()
{
InvisibleInteractableToy interactableToy = GameObject.Instantiate(PrefabManager.InvisibleInteractableToy);
interactableToy.NetworkMovementSmoothing = 60;

interactableToy.NetworkShape = (InvisibleInteractableToy.ColliderShape)Convert.ToInt32(Properties["Shape"]);
interactableToy.NetworkInteractionDuration = float.Parse(Properties["InteractionDuration"].ToString());
interactableToy.NetworkIsLocked = bool.Parse(Properties["IsLocked"].ToString());

return interactableToy.gameObject;
}
}
36 changes: 36 additions & 0 deletions Features/Serializable/SerializableInteractable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using AdminToys;
using Room = LabApi.Features.Wrappers.Room;
using Mirror;
using ProjectMER.Features.Extensions;
using ProjectMER.Features.Interfaces;
using UnityEngine;

namespace ProjectMER.Features.Serializable;

public class SerializableInteractable : SerializableObject
{
public InvisibleInteractableToy.ColliderShape Shape { get; set; } = InvisibleInteractableToy.ColliderShape.Box;
public float InteractionDuration { get; set; } = 5f;
public bool Locked { get; set; } = false;

public override GameObject SpawnOrUpdateObject(Room? room = null, GameObject? instance = null)
{
InvisibleInteractableToy interactableToy = instance == null ? UnityEngine.Object.Instantiate(PrefabManager.InvisibleInteractableToy) : instance.GetComponent<InvisibleInteractableToy>();
Vector3 position = room.GetAbsolutePosition(Position);
Quaternion rotation = room.GetAbsoluteRotation(Rotation);
_prevIndex = Index;

interactableToy.transform.SetPositionAndRotation(position, rotation);
interactableToy.transform.localScale = Scale;
interactableToy.NetworkMovementSmoothing = 60;

interactableToy.NetworkShape = Shape;
interactableToy.NetworkInteractionDuration = InteractionDuration;
interactableToy.NetworkIsLocked = Locked;

if (instance == null)
NetworkServer.Spawn(interactableToy.gameObject);

return interactableToy.gameObject;
}
}
1 change: 1 addition & 0 deletions Features/ToolGun/ToolGunItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ToolGunItem
{
{ ToolGunObjectType.Primitive, typeof(SerializablePrimitive) },
{ ToolGunObjectType.Light, typeof(SerializableLight) },
{ ToolGunObjectType.Interactable, typeof(SerializableInteractable) },
{ ToolGunObjectType.Door, typeof(SerializableDoor) },
{ ToolGunObjectType.Workstation, typeof(SerializableWorkstation) },
{ ToolGunObjectType.ItemSpawnpoint, typeof(SerializableItemSpawnpoint)},
Expand Down