diff --git a/EXILED/Exiled.API/Features/Toys/AdminToy.cs b/EXILED/Exiled.API/Features/Toys/AdminToy.cs index 84983ae55..9c58b1df8 100644 --- a/EXILED/Exiled.API/Features/Toys/AdminToy.cs +++ b/EXILED/Exiled.API/Features/Toys/AdminToy.cs @@ -161,7 +161,7 @@ public Vector3 Scale /// public byte MovementSmoothing { - get => AdminToyBase.MovementSmoothing; + get => AdminToyBase.NetworkMovementSmoothing; set => AdminToyBase.NetworkMovementSmoothing = value; } @@ -170,7 +170,7 @@ public byte MovementSmoothing /// public bool IsStatic { - get => AdminToyBase.IsStatic; + get => AdminToyBase.NetworkIsStatic; set => AdminToyBase.NetworkIsStatic = value; } diff --git a/EXILED/Exiled.API/Features/Toys/CameraToy.cs b/EXILED/Exiled.API/Features/Toys/CameraToy.cs index 85727a176..70718892a 100644 --- a/EXILED/Exiled.API/Features/Toys/CameraToy.cs +++ b/EXILED/Exiled.API/Features/Toys/CameraToy.cs @@ -124,10 +124,10 @@ public string Name /// 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 of the camera. /// The name (label) of the camera. /// The room associated with this camera. /// The vertical limits. Leave null to use prefab default. @@ -135,7 +135,7 @@ public string Name /// 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) + public static CameraToy Create(Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, CameraType type = CameraType.EzArmCameraToy, string name = "New Camera", Room room = null, Vector2? verticalConstraint = null, Vector2? horizontalConstraint = null, Vector2? zoomConstraint = null, bool spawn = true) { Scp079CameraToy prefab = type switch { @@ -156,12 +156,11 @@ public static CameraToy Create(Transform parent = null, CameraType type = Camera CameraToy toy = new(Object.Instantiate(prefab, parent)) { Name = name, + LocalPosition = position ?? Vector3.zero, + LocalRotation = rotation ?? Quaternion.identity, + Scale = scale ?? Vector3.one, }; - 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; diff --git a/EXILED/Exiled.API/Features/Toys/Capybara.cs b/EXILED/Exiled.API/Features/Toys/Capybara.cs index d615b25a1..664282901 100644 --- a/EXILED/Exiled.API/Features/Toys/Capybara.cs +++ b/EXILED/Exiled.API/Features/Toys/Capybara.cs @@ -83,12 +83,11 @@ public static Capybara Create(Transform parent = null, Vector3? position = null, Capybara toy = new(Object.Instantiate(Prefab, parent)) { Collidable = collidable, + LocalPosition = position ?? Vector3.zero, + LocalRotation = rotation ?? Quaternion.identity, + Scale = scale ?? Vector3.one, }; - toy.Transform.localPosition = position ?? Vector3.zero; - toy.Transform.localRotation = rotation ?? Quaternion.identity; - toy.Transform.localScale = scale ?? Vector3.one; - if (spawn) toy.Spawn(); diff --git a/EXILED/Exiled.API/Features/Toys/InteractableToy.cs b/EXILED/Exiled.API/Features/Toys/InteractableToy.cs index 1653e69b7..c89fea9c7 100644 --- a/EXILED/Exiled.API/Features/Toys/InteractableToy.cs +++ b/EXILED/Exiled.API/Features/Toys/InteractableToy.cs @@ -66,22 +66,7 @@ public bool IsLocked } /// - /// 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. + /// Creates a new . /// /// The local position of the . /// The shape of the collider. @@ -90,16 +75,16 @@ public bool IsLocked 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. + /// Creates a new . /// - /// The transform to create this on. + /// The local position 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 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); + public static InteractableToy Create(Vector3 position, ColliderShape shape = ColliderShape.Sphere, float interactionDuration = 1f, bool isLocked = false, bool spawn = true) + => Create(position: position, shape: shape, interactionDuration: interactionDuration, isLocked: isLocked, spawn: spawn); /// /// Creates a new . @@ -120,12 +105,11 @@ public static InteractableToy Create(Transform parent = null, Vector3? position Shape = shape, IsLocked = isLocked, InteractionDuration = interactionDuration, + LocalPosition = position ?? Vector3.zero, + LocalRotation = rotation ?? Quaternion.identity, + Scale = scale ?? Vector3.one, }; - toy.Transform.localPosition = position ?? Vector3.zero; - toy.Transform.localRotation = rotation ?? Quaternion.identity; - toy.Transform.localScale = scale ?? Vector3.one; - if (spawn) toy.Spawn(); diff --git a/EXILED/Exiled.API/Features/Toys/Light.cs b/EXILED/Exiled.API/Features/Toys/Light.cs index 6bf193b62..d8b1f0041 100644 --- a/EXILED/Exiled.API/Features/Toys/Light.cs +++ b/EXILED/Exiled.API/Features/Toys/Light.cs @@ -18,6 +18,8 @@ namespace Exiled.API.Features.Toys using UnityEngine; + using Object = UnityEngine.Object; + /// /// A wrapper class for . /// @@ -129,36 +131,62 @@ public LightShadows ShadowType /// Creates a new . /// /// The position of the . - /// The rotation of the . - /// The scale of the . - /// Whether the should be initially spawned. + /// The color of the . /// The new . - public static Light Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) - => Create(position, rotation, scale, spawn, null); + public static Light Create(Vector3 position, Color color) => Create(position: position, color: color, spawn: true); /// /// Creates a new . /// - /// The position of the . - /// The rotation of the . + /// The transform to create this on. + /// The local position of the . + /// The local rotation of the . /// The scale of the . - /// Whether the should be initially spawned. /// The color of the . + /// The intensity of the light. + /// The range of the light. + /// The angle of the light. + /// The inner angle of the light. + /// The shadow strength of the light. + /// The type of light the Light emits. + /// The type of shadows the light casts. + /// Whether the should be initially spawned. /// The new . - public static Light Create(Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/) + public static Light Create(Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, Color? color = null, float? intensity = null, float? range = null, float? spotAngle = null, float? innerSpotAngle = null, float? shadowStrength = null, LightType? lightType = null, LightShadows? shadowType = null, bool spawn = true) { - Light light = new(UnityEngine.Object.Instantiate(Prefab)) + Light toy = new(Object.Instantiate(Prefab, parent)) { - Position = position ?? Vector3.zero, - Rotation = Quaternion.Euler(rotation ?? Vector3.zero), + LocalPosition = position ?? Vector3.zero, + LocalRotation = rotation ?? Quaternion.identity, Scale = scale ?? Vector3.one, - Color = color ?? Color.gray, + Color = color ?? Color.white, }; + if (intensity.HasValue) + toy.Intensity = intensity.Value; + + if (range.HasValue) + toy.Range = range.Value; + + if (spotAngle.HasValue) + toy.SpotAngle = spotAngle.Value; + + if (innerSpotAngle.HasValue) + toy.InnerSpotAngle = innerSpotAngle.Value; + + if (shadowStrength.HasValue) + toy.ShadowStrength = shadowStrength.Value; + + if (lightType.HasValue) + toy.LightType = lightType.Value; + + if (shadowType.HasValue) + toy.ShadowType = shadowType.Value; + if (spawn) - light.Spawn(); + toy.Spawn(); - return light; + return toy; } /// diff --git a/EXILED/Exiled.API/Features/Toys/Primitive.cs b/EXILED/Exiled.API/Features/Toys/Primitive.cs index ad00b21f5..fe22f7a81 100644 --- a/EXILED/Exiled.API/Features/Toys/Primitive.cs +++ b/EXILED/Exiled.API/Features/Toys/Primitive.cs @@ -90,132 +90,63 @@ public PrimitiveFlags Flags /// /// Creates a new . /// + /// The type of primitive to spawn. /// The position of the . - /// The rotation of the . - /// The scale of the . - /// Whether the should be initially spawned. /// The new . - public static Primitive Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) - => Create(position, rotation, scale, spawn, null); + public static Primitive Create(PrimitiveType type, Vector3 position) => Create(type: type, position: position, spawn: true); /// /// Creates a new . /// - /// The type of primitive to spawn. - /// The position of the . - /// The rotation of the . - /// The scale of the . - /// Whether the should be initially spawned. - /// The new . - public static Primitive Create(PrimitiveType primitiveType = PrimitiveType.Sphere, Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) - => Create(primitiveType, position, rotation, scale, spawn, null); - - /// - /// Creates a new . - /// - /// The position of the . - /// The rotation of the . - /// The scale of the . - /// Whether the should be initially spawned. - /// The color of the . - /// The new . - public static Primitive Create(Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/) - { - Primitive primitive = new(Object.Instantiate(Prefab)) - { - Position = position ?? Vector3.zero, - Rotation = Quaternion.Euler(rotation ?? Vector3.zero), - Scale = scale ?? Vector3.one, - Color = color ?? Color.gray, - }; - - if (spawn) - primitive.Spawn(); - - return primitive; - } - - /// - /// Creates a new . - /// - /// The type of primitive to spawn. - /// The position of the . - /// The rotation of the . + /// The transform to create this on. + /// The local position of the . + /// The local rotation of the . /// The scale of the . - /// Whether the should be initially spawned. - /// The color of the . - /// The new . - public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sphere*/, Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/) - { - Primitive primitive = new(Object.Instantiate(Prefab)) - { - Position = position ?? Vector3.zero, - Rotation = Quaternion.Euler(rotation ?? Vector3.zero), - Scale = scale ?? Vector3.one, - }; - - primitive.Base.NetworkPrimitiveType = primitiveType; - primitive.Color = color ?? Color.gray; - - if (spawn) - primitive.Spawn(); - - return primitive; - } - - /// - /// Creates a new . - /// - /// The type of primitive to spawn. + /// The type of primitive to spawn. /// The primitive flags. - /// The position of the . - /// The rotation of the . - /// The scale of the . - /// Whether the should be initially spawned. /// The color of the . + /// Whether the should be initially spawned. /// The new . - public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sphere*/, PrimitiveFlags flags, Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/) + public static Primitive Create(Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, PrimitiveType type = PrimitiveType.Sphere, PrimitiveFlags flags = PrimitiveFlags.Visible | PrimitiveFlags.Collidable, Color? color = null, bool spawn = true) { - Primitive primitive = new(Object.Instantiate(Prefab)) + Primitive toy = new(Object.Instantiate(Prefab, parent)) { - Position = position ?? Vector3.zero, - Rotation = Quaternion.Euler(rotation ?? Vector3.zero), - Scale = scale ?? Vector3.one, + Type = type, Flags = flags, + LocalPosition = position ?? Vector3.zero, + LocalRotation = rotation ?? Quaternion.identity, + Scale = scale ?? Vector3.one, + Color = color ?? Color.gray, }; - primitive.Base.NetworkPrimitiveType = primitiveType; - primitive.Color = color ?? Color.gray; - if (spawn) - primitive.Spawn(); + toy.Spawn(); - return primitive; + return toy; } /// - /// Creates a new . + /// Creates a new with using . /// /// The settings of the . /// The new . public static Primitive Create(PrimitiveSettings primitiveSettings) { - Primitive primitive = new(Object.Instantiate(Prefab)) + Primitive toy = new(Object.Instantiate(Prefab)) { - Position = primitiveSettings.Position, - Rotation = Quaternion.Euler(primitiveSettings.Rotation), - Scale = primitiveSettings.Scale, + Type = primitiveSettings.PrimitiveType, Flags = primitiveSettings.Flags, + LocalPosition = primitiveSettings.Position, + LocalRotation = Quaternion.Euler(primitiveSettings.Rotation), + Scale = primitiveSettings.Scale, + Color = primitiveSettings.Color, + IsStatic = primitiveSettings.IsStatic, }; - primitive.Base.NetworkPrimitiveType = primitiveSettings.PrimitiveType; - primitive.Color = primitiveSettings.Color; - primitive.IsStatic = primitiveSettings.IsStatic; - if (primitiveSettings.Spawn) - primitive.Spawn(); + toy.Spawn(); - return primitive; + return toy; } /// diff --git a/EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs b/EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs index fd3ed8eba..87a82c706 100644 --- a/EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs +++ b/EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs @@ -15,8 +15,6 @@ namespace Exiled.API.Features.Toys using Exiled.API.Interfaces; - using Mirror; - using PlayerStatsSystem; using UnityEngine; @@ -134,20 +132,6 @@ public int AutoResetTime } } - /// - /// Gets or sets the size scale of the target. - /// - public new Vector3 Scale - { - get => GameObject.transform.localScale; - set - { - NetworkServer.UnSpawn(GameObject); - GameObject.transform.localScale = value; - NetworkServer.Spawn(GameObject); - } - } - /// /// Gets or sets a value indicating whether the target is in sync mode. /// @@ -167,43 +151,39 @@ public bool IsSynced /// /// The of the . /// The position of the . + /// The new . + public static ShootingTargetToy Create(ShootingTargetType type, Vector3 position) => Create(type: type, position: position, spawn: true); + + /// + /// Creates a new . + /// + /// The transform to create this on. + /// The position of the . /// The rotation of the . /// The scale of the . + /// The of the . /// Whether the should be initially spawned. /// The new . - public static ShootingTargetToy Create(ShootingTargetType type, Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) + public static ShootingTargetToy Create(Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, ShootingTargetType type = ShootingTargetType.Sport, bool spawn = true) { - ShootingTargetToy shootingTargetToy; - - switch (type) + ShootingTarget prefab = type switch { - case ShootingTargetType.ClassD: - { - shootingTargetToy = new(Object.Instantiate(DboyShootingTargetPrefab)); - break; - } - - case ShootingTargetType.Binary: - { - shootingTargetToy = new(Object.Instantiate(BinaryShootingTargetPrefab)); - break; - } - - default: - { - shootingTargetToy = new(Object.Instantiate(SportShootingTargetPrefab)); - break; - } - } + ShootingTargetType.ClassD => DboyShootingTargetPrefab, + ShootingTargetType.Binary => BinaryShootingTargetPrefab, + _ => SportShootingTargetPrefab, + }; - shootingTargetToy.Position = position ?? Vector3.zero; - shootingTargetToy.Rotation = Quaternion.Euler(rotation ?? Vector3.zero); - shootingTargetToy.Scale = scale ?? Vector3.one; + ShootingTargetToy toy = new(Object.Instantiate(prefab, parent)) + { + LocalPosition = position ?? Vector3.zero, + LocalRotation = rotation ?? Quaternion.identity, + Scale = scale ?? Vector3.one, + }; if (spawn) - shootingTargetToy.Spawn(); + toy.Spawn(); - return shootingTargetToy; + return toy; } /// diff --git a/EXILED/Exiled.API/Features/Toys/Text.cs b/EXILED/Exiled.API/Features/Toys/Text.cs index 5a5980c4c..1dd8ce417 100644 --- a/EXILED/Exiled.API/Features/Toys/Text.cs +++ b/EXILED/Exiled.API/Features/Toys/Text.cs @@ -55,7 +55,7 @@ public Vector2 DisplaySize } /// - /// Creates a new at the specified position. + /// Creates a new . /// /// The local position of the . /// The text content to display. @@ -63,7 +63,7 @@ public Vector2 DisplaySize 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. + /// Creates a new . /// /// The local position of the . /// The text content to display. @@ -71,50 +71,32 @@ public Vector2 DisplaySize /// 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 transform to create this on. /// 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) + public static Text Create(Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, string text = "Hello World!", Vector2? displaySize = null, bool spawn = true) { - Text textToy = new(Object.Instantiate(Prefab, parent)) + Text toy = new(Object.Instantiate(Prefab, parent)) { + DisplaySize = displaySize ?? new Vector2(50, 50), + LocalPosition = position ?? Vector3.zero, + LocalRotation = rotation ?? Quaternion.identity, + Scale = scale ?? Vector3.one, 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(); + toy.Spawn(); - return textToy; + return toy; } } } \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Toys/Waypoint.cs b/EXILED/Exiled.API/Features/Toys/Waypoint.cs index 881188834..0c7c5697a 100644 --- a/EXILED/Exiled.API/Features/Toys/Waypoint.cs +++ b/EXILED/Exiled.API/Features/Toys/Waypoint.cs @@ -60,7 +60,11 @@ public bool VisualizeBounds public Bounds Bounds { get => new(Position, Base.NetworkBoundsSize); - set => Base.NetworkBoundsSize = value.size; + set + { + Position = value.center; + Base.NetworkBoundsSize = value.size; + } } /// @@ -78,7 +82,7 @@ public Vector3 BoundsSize public byte WaypointId => Base._waypointId; /// - /// Creates a new with a specific position and size (bounds). + /// Creates a new . /// /// The position of the . /// The size of the bounds (Applied to NetworkBoundsSize). @@ -86,7 +90,7 @@ public Vector3 BoundsSize public static Waypoint Create(Vector3 position, Vector3 size) => Create(position: position, scale: size, spawn: true); /// - /// Creates a new based on a Transform. + /// Creates a new . /// /// The transform to spawn at (LocalScale is applied to Bounds). /// The size of the bounds (Applied to NetworkBoundsSize). @@ -109,13 +113,12 @@ public static Waypoint Create(Transform parent = null, Vector3? position = null, Waypoint toy = new(Object.Instantiate(Prefab, parent)) { Priority = priority, - BoundsSize = scale ?? (Vector3.one * 255.9961f), VisualizeBounds = visualizeBounds, + BoundsSize = scale ?? (Vector3.one * WaypointToy.MaxBounds), + LocalPosition = position ?? Vector3.zero, + LocalRotation = rotation ?? Quaternion.identity, }; - toy.Transform.localPosition = position ?? Vector3.zero; - toy.Transform.localRotation = rotation ?? Quaternion.identity; - if (spawn) toy.Spawn();