Skip to content
Merged
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
114 changes: 107 additions & 7 deletions EXILED/Exiled.API/Features/Toys/CameraToy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@

namespace Exiled.API.Features.Toys
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using AdminToys;

using Exiled.API.Enums;
using Exiled.API.Interfaces;

using UnityEngine;

using CameraType = Enums.CameraType;

/// <summary>
/// A wrapper class for <see cref="AdminToys.AdminToyBase"/>.
/// </summary>
Expand All @@ -30,6 +28,31 @@ public class CameraToy : AdminToy, IWrapper<Scp079CameraToy>
internal CameraToy(Scp079CameraToy scp079CameraToy)
: base(scp079CameraToy, AdminToyType.CameraToy) => Base = scp079CameraToy;

/// <summary>
/// Gets the prefab for EzArm Camera prefab.
/// </summary>
public static Scp079CameraToy EzArmCameraPrefab { get; } = PrefabHelper.GetPrefab<Scp079CameraToy>(PrefabType.EzArmCameraToy);

/// <summary>
/// Gets the prefab for Ez Camera prefab.
/// </summary>
public static Scp079CameraToy EzCameraPrefab { get; } = PrefabHelper.GetPrefab<Scp079CameraToy>(PrefabType.EzCameraToy);

/// <summary>
/// Gets the prefab for Hcz Camera prefab.
/// </summary>
public static Scp079CameraToy HczCameraPrefab { get; } = PrefabHelper.GetPrefab<Scp079CameraToy>(PrefabType.HczCameraToy);

/// <summary>
/// Gets the prefab for Lcz Camera prefab.
/// </summary>
public static Scp079CameraToy LczCameraPrefab { get; } = PrefabHelper.GetPrefab<Scp079CameraToy>(PrefabType.LczCameraToy);

/// <summary>
/// Gets the prefab for Sz Camera prefab.
/// </summary>
public static Scp079CameraToy SzCameraPrefab { get; } = PrefabHelper.GetPrefab<Scp079CameraToy>(PrefabType.SzCameraToy);

/// <summary>
/// Gets the base <see cref="Scp079CameraToy"/>.
/// </summary>
Expand Down Expand Up @@ -79,5 +102,82 @@ public string Name
get => Base.NetworkLabel;
set => Base.NetworkLabel = value;
}

/// <summary>
/// Creates a new <see cref="CameraToy"/> with a specified type.
/// </summary>
/// <param name="type">The <see cref="CameraType"/> of the camera.</param>
/// <param name="position">The local position of the camera.</param>
/// <returns>The new <see cref="CameraToy"/>.</returns>
public static CameraToy Create(CameraType type, Vector3 position) => Create(type: type, position: position, spawn: true);

/// <summary>
/// Creates a new <see cref="CameraToy"/> with a specified type and name.
/// </summary>
/// <param name="type">The <see cref="CameraType"/> of the camera.</param>
/// <param name="position">The local position of the camera.</param>
/// <param name="name">The name (label) of the camera.</param>
/// <returns>The new <see cref="CameraToy"/>.</returns>
public static CameraToy Create(CameraType type, Vector3 position, string name) => Create(type: type, position: position, name: name, spawn: true);

/// <summary>
/// Creates a new <see cref="CameraToy"/>.
/// </summary>
/// <param name="parent">The transform to create this <see cref="CameraToy"/> on.</param>
/// <param name="type">The <see cref="CameraType"/> of the camera.</param>
/// <param name="position">The local position of the camera.</param>
/// <param name="rotation">The local rotation of the camera.</param>
/// <param name="scale">The local scale of the camera.</param>
/// <param name="name">The name (label) of the camera.</param>
/// <param name="room">The room associated with this camera.</param>
/// <param name="verticalConstraint">The vertical limits. Leave null to use prefab default.</param>
/// <param name="horizontalConstraint">The horizontal limits. Leave null to use prefab default.</param>
/// <param name="zoomConstraint">The zoom limits. Leave null to use prefab default.</param>
/// <param name="spawn">Whether the camera should be initially spawned.</param>
/// <returns>The new <see cref="CameraToy"/>.</returns>
public static CameraToy Create(Transform parent = null, CameraType type = CameraType.EzArmCameraToy, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, string name = "New Camera", Room room = null, Vector2? verticalConstraint = null, Vector2? horizontalConstraint = null, Vector2? zoomConstraint = null, bool spawn = true)
{
Scp079CameraToy prefab = type switch
{
CameraType.EzArmCameraToy => EzArmCameraPrefab,
CameraType.EzCameraToy => EzCameraPrefab,
CameraType.HczCameraToy => HczCameraPrefab,
CameraType.LczCameraToy => LczCameraPrefab,
CameraType.SzCameraToy => SzCameraPrefab,
_ => null,
};

if (prefab == null)
{
Log.Warn("Invalid Camera Type for prefab");
return null;
}

CameraToy toy = new(Object.Instantiate(prefab, parent))
{
Name = name,
};

toy.Transform.localPosition = position ?? Vector3.zero;
toy.Transform.localRotation = rotation ?? Quaternion.identity;
toy.Transform.localScale = scale ?? Vector3.one;

if (verticalConstraint.HasValue)
toy.VerticalConstraint = verticalConstraint.Value;

if (horizontalConstraint.HasValue)
toy.HorizontalConstraint = horizontalConstraint.Value;

if (zoomConstraint.HasValue)
toy.ZoomConstraint = zoomConstraint.Value;

if (room != null)
toy.Room = room;

if (spawn)
toy.Spawn();

return toy;
}
}
}
}
57 changes: 55 additions & 2 deletions EXILED/Exiled.API/Features/Toys/Capybara.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
namespace Exiled.API.Features.Toys
{
using AdminToys;

using Enums;

using Exiled.API.Interfaces;

using UnityEngine;

/// <summary>
/// A wrapper class for <see cref="CapybaraToy"/>.
/// </summary>
Expand All @@ -26,7 +30,7 @@ internal Capybara(CapybaraToy capybaraToy)
/// <summary>
/// Gets the prefab.
/// </summary>
public static CapybaraToy Prefab => PrefabHelper.GetPrefab<CapybaraToy>(PrefabType.CapybaraToy);
public static CapybaraToy Prefab { get; } = PrefabHelper.GetPrefab<CapybaraToy>(PrefabType.CapybaraToy);

/// <summary>
/// Gets the base <see cref="CapybaraToy"/>.
Expand All @@ -41,5 +45,54 @@ public bool Collidable
get => Base.NetworkCollisionsEnabled;
set => Base.NetworkCollisionsEnabled = value;
}

/// <summary>
/// Creates a new <see cref="Capybara"/> at the specified position.
/// </summary>
/// <param name="position">The local position of the <see cref="Capybara"/>.</param>
/// <returns>The new <see cref="Capybara"/>.</returns>
public static Capybara Create(Vector3 position) => Create(position: position, spawn: true);

/// <summary>
/// Creates a new <see cref="Capybara"/> with a specific position and rotation.
/// </summary>
/// <param name="position">The local position of the <see cref="Capybara"/>.</param>
/// <param name="rotation">The local rotation of the <see cref="Capybara"/>.</param>
/// <returns>The new <see cref="Capybara"/>.</returns>
public static Capybara Create(Vector3 position, Quaternion rotation) => Create(position: position, rotation: rotation, spawn: true);

/// <summary>
/// Creates a new <see cref="Capybara"/> based on a Transform.
/// </summary>
/// <param name="transform">The transform to spawn at.</param>
/// <returns>The new <see cref="Capybara"/>.</returns>
public static Capybara Create(Transform transform) => Create(parent: transform, spawn: true);

/// <summary>
/// Creates a new <see cref="Capybara"/>.
/// </summary>
/// <param name="parent">The transform to create this <see cref="Capybara"/> on.</param>
/// <param name="position">The local position of the <see cref="Capybara"/>.</param>
/// <param name="rotation">The local rotation of the <see cref="Capybara"/>.</param>
/// <param name="scale">The local scale of the <see cref="Capybara"/>.</param>
/// <param name="collidable">Whether the capybara has collision enabled.</param>
/// <param name="spawn">Whether the <see cref="Capybara"/> should be initially spawned.</param>
/// <returns>The new <see cref="Capybara"/>.</returns>
public static Capybara Create(Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, bool collidable = true, bool spawn = true)
{
Capybara toy = new(Object.Instantiate(Prefab, parent))
{
Collidable = collidable,
};

toy.Transform.localPosition = position ?? Vector3.zero;
toy.Transform.localRotation = rotation ?? Quaternion.identity;
toy.Transform.localScale = scale ?? Vector3.one;

if (spawn)
toy.Spawn();

return toy;
}
}
}
}
78 changes: 76 additions & 2 deletions EXILED/Exiled.API/Features/Toys/InteractableToy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
namespace Exiled.API.Features.Toys
{
using AdminToys;

using Exiled.API.Enums;
using Exiled.API.Interfaces;

using UnityEngine;

using static AdminToys.InvisibleInteractableToy;

/// <summary>
/// A wrapper class for <see cref="InvisibleInteractableToy"/>.
/// </summary>
internal class InteractableToy : AdminToy, IWrapper<InvisibleInteractableToy>
public class InteractableToy : AdminToy, IWrapper<InvisibleInteractableToy>
{
/// <summary>
/// Initializes a new instance of the <see cref="InteractableToy"/> class.
Expand All @@ -26,6 +28,11 @@ internal class InteractableToy : AdminToy, IWrapper<InvisibleInteractableToy>
internal InteractableToy(InvisibleInteractableToy invisibleInteractableToy)
: base(invisibleInteractableToy, AdminToyType.InvisibleInteractableToy) => Base = invisibleInteractableToy;

/// <summary>
/// Gets the prefab.
/// </summary>
public static InvisibleInteractableToy Prefab { get; } = PrefabHelper.GetPrefab<InvisibleInteractableToy>(PrefabType.InvisibleInteractableToy);

/// <summary>
/// Gets the base <see cref="InvisibleInteractableToy"/>.
/// </summary>
Expand Down Expand Up @@ -57,5 +64,72 @@ public bool IsLocked
get => Base.NetworkIsLocked;
set => Base.NetworkIsLocked = value;
}

/// <summary>
/// Creates a new <see cref="InteractableToy"/> at the specified position.
/// </summary>
/// <param name="position">The local position of the <see cref="InteractableToy"/>.</param>
/// <returns>The new <see cref="InteractableToy"/>.</returns>
public static InteractableToy Create(Vector3 position) => Create(position: position, spawn: true);

/// <summary>
/// Creates a new <see cref="InteractableToy"/> with a specific position and shape.
/// </summary>
/// <param name="position">The local position of the <see cref="InteractableToy"/>.</param>
/// <param name="shape">The shape of the collider.</param>
/// <returns>The new <see cref="InteractableToy"/>.</returns>
public static InteractableToy Create(Vector3 position, ColliderShape shape) => Create(position: position, shape: shape, spawn: true);

/// <summary>
/// Creates a new <see cref="InteractableToy"/> with a specific position, shape, and interaction duration.
/// </summary>
/// <param name="position">The local position of the <see cref="InteractableToy"/>.</param>
/// <param name="shape">The shape of the collider.</param>
/// <param name="duration">How long the interaction takes.</param>
/// <returns>The new <see cref="InteractableToy"/>.</returns>
public static InteractableToy Create(Vector3 position, ColliderShape shape, float duration) => Create(position: position, shape: shape, interactionDuration: duration, spawn: true);

/// <summary>
/// Creates a new <see cref="InteractableToy"/> from a Transform.
/// </summary>
/// <param name="transform">The transform to create this <see cref="InteractableToy"/> on.</param>
/// <param name="shape">The shape of the collider.</param>
/// <param name="interactionDuration">How long the interaction takes.</param>
/// <param name="isLocked">Whether the object is locked.</param>
/// <param name="spawn">Whether the <see cref="InteractableToy"/> should be initially spawned.</param>
/// <returns>The new <see cref="InteractableToy"/>.</returns>
public static InteractableToy Create(Transform transform, ColliderShape shape = ColliderShape.Sphere, float interactionDuration = 1f, bool isLocked = false, bool spawn = true)
=> Create(parent: transform, shape: shape, interactionDuration: interactionDuration, isLocked: isLocked, spawn: spawn);

/// <summary>
/// Creates a new <see cref="InteractableToy"/>.
/// </summary>
/// <param name="parent">The transform to create this <see cref="InteractableToy"/> on.</param>
/// <param name="position">The local position of the <see cref="InteractableToy"/>.</param>
/// <param name="rotation">The local rotation of the <see cref="InteractableToy"/>.</param>
/// <param name="scale">The local scale of the <see cref="InteractableToy"/>.</param>
/// <param name="shape">The shape of the collider.</param>
/// <param name="interactionDuration">How long the interaction takes.</param>
/// <param name="isLocked">Whether the object is locked.</param>
/// <param name="spawn">Whether the <see cref="InteractableToy"/> should be initially spawned.</param>
/// <returns>The new <see cref="InteractableToy"/>.</returns>
public static InteractableToy Create(Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, ColliderShape shape = ColliderShape.Sphere, float interactionDuration = 1f, bool isLocked = false, bool spawn = true)
{
InteractableToy toy = new(Object.Instantiate(Prefab, parent))
{
Shape = shape,
IsLocked = isLocked,
InteractionDuration = interactionDuration,
};

toy.Transform.localPosition = position ?? Vector3.zero;
toy.Transform.localRotation = rotation ?? Quaternion.identity;
toy.Transform.localScale = scale ?? Vector3.one;

if (spawn)
toy.Spawn();

return toy;
}
}
}
}
Loading
Loading