diff --git a/EXILED/Exiled.API/Features/Toys/CameraToy.cs b/EXILED/Exiled.API/Features/Toys/CameraToy.cs index 0e2b856b6..85727a176 100644 --- a/EXILED/Exiled.API/Features/Toys/CameraToy.cs +++ b/EXILED/Exiled.API/Features/Toys/CameraToy.cs @@ -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; + /// /// A wrapper class for . /// @@ -30,6 +28,31 @@ public class CameraToy : AdminToy, IWrapper internal CameraToy(Scp079CameraToy scp079CameraToy) : base(scp079CameraToy, AdminToyType.CameraToy) => Base = scp079CameraToy; + /// + /// Gets the prefab for EzArm Camera prefab. + /// + public static Scp079CameraToy EzArmCameraPrefab { get; } = PrefabHelper.GetPrefab(PrefabType.EzArmCameraToy); + + /// + /// Gets the prefab for Ez Camera prefab. + /// + public static Scp079CameraToy EzCameraPrefab { get; } = PrefabHelper.GetPrefab(PrefabType.EzCameraToy); + + /// + /// Gets the prefab for Hcz Camera prefab. + /// + public static Scp079CameraToy HczCameraPrefab { get; } = PrefabHelper.GetPrefab(PrefabType.HczCameraToy); + + /// + /// Gets the prefab for Lcz Camera prefab. + /// + public static Scp079CameraToy LczCameraPrefab { get; } = PrefabHelper.GetPrefab(PrefabType.LczCameraToy); + + /// + /// Gets the prefab for Sz Camera prefab. + /// + public static Scp079CameraToy SzCameraPrefab { get; } = PrefabHelper.GetPrefab(PrefabType.SzCameraToy); + /// /// Gets the base . /// @@ -79,5 +102,82 @@ public string Name get => Base.NetworkLabel; set => Base.NetworkLabel = value; } + + /// + /// Creates a new with a specified type. + /// + /// The of the camera. + /// The local position of the camera. + /// The new . + public static CameraToy Create(CameraType type, Vector3 position) => Create(type: type, position: position, spawn: true); + + /// + /// Creates a new with a specified type and name. + /// + /// The of the camera. + /// The local position of the camera. + /// The name (label) of the camera. + /// The new . + public static CameraToy Create(CameraType type, Vector3 position, string name) => Create(type: type, position: position, name: name, spawn: true); + + /// + /// Creates a new . + /// + /// The transform to create this on. + /// The of the camera. + /// The local position of the camera. + /// The local rotation of the camera. + /// The local scale of the camera. + /// The name (label) of the camera. + /// The room associated with this camera. + /// The vertical limits. Leave null to use prefab default. + /// The horizontal limits. Leave null to use prefab default. + /// The zoom limits. Leave null to use prefab default. + /// Whether the camera should be initially spawned. + /// The new . + 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; + } } -} +} \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Toys/Capybara.cs b/EXILED/Exiled.API/Features/Toys/Capybara.cs index e15b3600d..d615b25a1 100644 --- a/EXILED/Exiled.API/Features/Toys/Capybara.cs +++ b/EXILED/Exiled.API/Features/Toys/Capybara.cs @@ -8,9 +8,13 @@ namespace Exiled.API.Features.Toys { using AdminToys; + using Enums; + using Exiled.API.Interfaces; + using UnityEngine; + /// /// A wrapper class for . /// @@ -26,7 +30,7 @@ internal Capybara(CapybaraToy capybaraToy) /// /// Gets the prefab. /// - public static CapybaraToy Prefab => PrefabHelper.GetPrefab(PrefabType.CapybaraToy); + public static CapybaraToy Prefab { get; } = PrefabHelper.GetPrefab(PrefabType.CapybaraToy); /// /// Gets the base . @@ -41,5 +45,54 @@ public bool Collidable get => Base.NetworkCollisionsEnabled; set => Base.NetworkCollisionsEnabled = value; } + + /// + /// Creates a new at the specified position. + /// + /// The local position of the . + /// The new . + public static Capybara Create(Vector3 position) => Create(position: position, spawn: true); + + /// + /// Creates a new with a specific position and rotation. + /// + /// The local position of the . + /// The local rotation of the . + /// The new . + public static Capybara Create(Vector3 position, Quaternion rotation) => Create(position: position, rotation: rotation, spawn: true); + + /// + /// Creates a new based on a Transform. + /// + /// The transform to spawn at. + /// The new . + public static Capybara Create(Transform transform) => Create(parent: transform, spawn: true); + + /// + /// Creates a new . + /// + /// The transform to create this on. + /// The local position of the . + /// The local rotation of the . + /// The local scale of the . + /// Whether the capybara has collision enabled. + /// Whether the should be initially spawned. + /// The new . + 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; + } } -} +} \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Toys/InteractableToy.cs b/EXILED/Exiled.API/Features/Toys/InteractableToy.cs index c6c73936c..1653e69b7 100644 --- a/EXILED/Exiled.API/Features/Toys/InteractableToy.cs +++ b/EXILED/Exiled.API/Features/Toys/InteractableToy.cs @@ -8,8 +8,10 @@ namespace Exiled.API.Features.Toys { using AdminToys; + using Exiled.API.Enums; using Exiled.API.Interfaces; + using UnityEngine; using static AdminToys.InvisibleInteractableToy; @@ -17,7 +19,7 @@ namespace Exiled.API.Features.Toys /// /// A wrapper class for . /// - internal class InteractableToy : AdminToy, IWrapper + public class InteractableToy : AdminToy, IWrapper { /// /// Initializes a new instance of the class. @@ -26,6 +28,11 @@ internal class InteractableToy : AdminToy, IWrapper internal InteractableToy(InvisibleInteractableToy invisibleInteractableToy) : base(invisibleInteractableToy, AdminToyType.InvisibleInteractableToy) => Base = invisibleInteractableToy; + /// + /// Gets the prefab. + /// + public static InvisibleInteractableToy Prefab { get; } = PrefabHelper.GetPrefab(PrefabType.InvisibleInteractableToy); + /// /// Gets the base . /// @@ -57,5 +64,72 @@ public bool IsLocked get => Base.NetworkIsLocked; set => Base.NetworkIsLocked = value; } + + /// + /// Creates a new at the specified position. + /// + /// The local position of the . + /// The new . + public static InteractableToy Create(Vector3 position) => Create(position: position, spawn: true); + + /// + /// Creates a new with a specific position and shape. + /// + /// The local position of the . + /// The shape of the collider. + /// The new . + public static InteractableToy Create(Vector3 position, ColliderShape shape) => Create(position: position, shape: shape, spawn: true); + + /// + /// Creates a new with a specific position, shape, and interaction duration. + /// + /// The local position of the . + /// The shape of the collider. + /// How long the interaction takes. + /// The new . + public static InteractableToy Create(Vector3 position, ColliderShape shape, float duration) => Create(position: position, shape: shape, interactionDuration: duration, spawn: true); + + /// + /// Creates a new from a Transform. + /// + /// The transform to create this on. + /// The shape of the collider. + /// How long the interaction takes. + /// Whether the object is locked. + /// Whether the should be initially spawned. + /// The new . + 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); + + /// + /// Creates a new . + /// + /// The transform to create this on. + /// The local position of the . + /// The local rotation of the . + /// The local scale of the . + /// The shape of the collider. + /// How long the interaction takes. + /// Whether the object is locked. + /// Whether the should be initially spawned. + /// The new . + 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; + } } -} +} \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Toys/Text.cs b/EXILED/Exiled.API/Features/Toys/Text.cs index fe2543a42..055993e4a 100644 --- a/EXILED/Exiled.API/Features/Toys/Text.cs +++ b/EXILED/Exiled.API/Features/Toys/Text.cs @@ -8,8 +8,10 @@ namespace Exiled.API.Features.Toys { using AdminToys; - using Enums; + + using Exiled.API.Enums; using Exiled.API.Interfaces; + using UnityEngine; /// @@ -27,7 +29,7 @@ internal Text(TextToy textToy) /// /// Gets the prefab. /// - public static TextToy Prefab => PrefabHelper.GetPrefab(PrefabType.TextToy); + public static TextToy Prefab { get; } = PrefabHelper.GetPrefab(PrefabType.TextToy); /// /// Gets the base . @@ -51,5 +53,68 @@ public Vector2 DisplaySize get => Base.Network_displaySize; set => Base.Network_displaySize = value; } + + /// + /// Creates a new at the specified position. + /// + /// The local position of the . + /// The text content to display. + /// The new . + public static Text Create(Vector3 position, string text) => Create(position: position, text: text, spawn: true); + + /// + /// Creates a new with a specific position, text, and display size. + /// + /// The local position of the . + /// The text content to display. + /// The display size of the text. + /// The new . + public static Text Create(Vector3 position, string text, Vector2 displaySize) => Create(position: position, text: text, displaySize: displaySize, spawn: true); + + /// + /// Creates a new based on a Transform. + /// + /// The transform to spawn at. + /// The text content to display. + /// The new . + public static Text Create(Transform transform, string text) => Create(parent: transform, text: text, spawn: true); + + /// + /// Creates a new based on a Transform with custom size. + /// + /// The transform to spawn at. + /// The text content to display. + /// The display size of the text. + /// The new . + public static Text Create(Transform transform, string text, Vector2 displaySize) => Create(parent: transform, text: text, displaySize: displaySize, spawn: true); + + /// + /// Creates a new . + /// + /// The local position of the . + /// The local rotation of the . + /// The local scale of the . + /// The text content to display. + /// The display size of the text. + /// The transform to create this on. + /// Whether the should be initially spawned. + /// The new . + public static Text Create(Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, string text = "Default Text", Vector2? displaySize = null, Transform parent = null, bool spawn = true) + { + Text textToy = new(Object.Instantiate(Prefab, parent)) + { + TextFormat = text, + DisplaySize = displaySize ?? new Vector3(50, 50), + }; + + textToy.Transform.localPosition = position ?? Vector3.zero; + textToy.Transform.localRotation = rotation ?? Quaternion.identity; + textToy.Transform.localScale = scale ?? Vector3.one; + + if (spawn) + textToy.Spawn(); + + return textToy; + } } } diff --git a/EXILED/Exiled.API/Features/Toys/Waypoint.cs b/EXILED/Exiled.API/Features/Toys/Waypoint.cs index 5f65aec1f..0de33936a 100644 --- a/EXILED/Exiled.API/Features/Toys/Waypoint.cs +++ b/EXILED/Exiled.API/Features/Toys/Waypoint.cs @@ -8,8 +8,10 @@ namespace Exiled.API.Features.Toys { using AdminToys; - using Enums; + + using Exiled.API.Enums; using Exiled.API.Interfaces; + using UnityEngine; /// @@ -27,7 +29,7 @@ internal Waypoint(WaypointToy waypointToy) /// /// Gets the prefab. /// - public static WaypointToy Prefab => PrefabHelper.GetPrefab(PrefabType.WaypointToy); + public static WaypointToy Prefab { get; } = PrefabHelper.GetPrefab(PrefabType.WaypointToy); /// /// Gets the base . @@ -61,9 +63,63 @@ public Bounds Bounds set => Base.NetworkBoundsSize = value.size; } + /// + /// Gets or sets the bounds size this waypoint encapsulates. + /// + public Vector3 BoundsSize + { + get => Base.NetworkBoundsSize; + set => Base.NetworkBoundsSize = value; + } + /// /// Gets the id of the Waypoint used for . /// public byte WaypointId => Base._waypointId; + + /// + /// Creates a new with a specific position and size (bounds). + /// + /// The position of the . + /// The size of the bounds (Applied to NetworkBoundsSize). + /// The new . + public static Waypoint Create(Vector3 position, Vector3 size) => Create(position: position, scale: size, spawn: true); + + /// + /// Creates a new based on a Transform. + /// + /// The transform to spawn at (LocalScale is applied to Bounds). + /// The size of the bounds (Applied to NetworkBoundsSize). + /// The new . + public static Waypoint Create(Transform transform, Vector3 size) => Create(parent: transform, scale: size, spawn: true); + + /// + /// Creates a new . + /// + /// The transform to create this on. + /// The local position of the . + /// The local rotation of the . + /// The size of the bounds (This is NOT localScale, it applies to NetworkBoundsSize). + /// The priority of the waypoint. + /// Whether to visualize the bounds. + /// Whether the should be initially spawned. + /// The new . + public static Waypoint Create(Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, float priority = 0f, bool visualizeBounds = false, bool spawn = true) + { + Waypoint toy = new(Object.Instantiate(Prefab, parent)) + { + Priority = priority, + BoundsSize = scale ?? Vector3.one * 255.9961f, + VisualizeBounds = visualizeBounds, + }; + + toy.Transform.localPosition = position ?? Vector3.zero; + toy.Transform.localRotation = rotation ?? Quaternion.identity; + + if (spawn) + toy.Spawn(); + + return toy; + } } -} +} \ No newline at end of file