Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PrimitiveSettings + 3 overloads to Primitive::Create method #2107

Merged
merged 7 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
29 changes: 28 additions & 1 deletion Exiled.API/Features/Toys/Light.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Exiled.API.Features.Toys
{
using System;
using System.Linq;

using AdminToys;
Expand Down Expand Up @@ -80,9 +81,10 @@ public bool ShadowEmission
/// <param name="scale">The scale of the <see cref="Light"/>.</param>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <returns>The new <see cref="Light"/>.</returns>
[Obsolete("Use Create(Vector3, Vector3, Vector3, bool, Color) instead.", true)]
Thundermaker300 marked this conversation as resolved.
Show resolved Hide resolved
public static Light Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true)
{
Light light = new(Object.Instantiate(ToysHelper.LightBaseObject));
Light light = new(UnityEngine.Object.Instantiate(ToysHelper.LightBaseObject));

light.AdminToyBase.transform.position = position ?? Vector3.zero;
light.AdminToyBase.transform.eulerAngles = rotation ?? Vector3.zero;
Expand All @@ -94,6 +96,31 @@ public static Light Create(Vector3? position = null, Vector3? rotation = null, V
return light;
}

/// <summary>
/// Creates a new <see cref="Light"/>.
/// </summary>
/// <param name="position">The position of the <see cref="Light"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Light"/>.</param>
/// <param name="scale">The scale of the <see cref="Light"/>.</param>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <param name="color">The color of the <see cref="Light"/>.</param>
/// <returns>The new <see cref="Light"/>.</returns>
public static Light Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true, Color? color = null)
{
Light light = new(UnityEngine.Object.Instantiate(ToysHelper.LightBaseObject));

light.AdminToyBase.transform.position = position ?? Vector3.zero;
light.AdminToyBase.transform.eulerAngles = rotation ?? Vector3.zero;
light.AdminToyBase.transform.localScale = scale ?? Vector3.one;

if (spawn)
light.Spawn();

light.Color = color ?? Color.white;
NaoUnderscore marked this conversation as resolved.
Show resolved Hide resolved

return light;
}

/// <summary>
/// Gets the <see cref="Light"/> belonging to the <see cref="LightSourceToy"/>.
/// </summary>
Expand Down
89 changes: 84 additions & 5 deletions Exiled.API/Features/Toys/Primitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Exiled.API.Features.Toys

using Enums;
using Exiled.API.Interfaces;

using Exiled.API.Structs;
using UnityEngine;

using Object = UnityEngine.Object;
Expand Down Expand Up @@ -75,15 +75,68 @@ public bool Collidable
}
}

/// <summary>
/// Creates a new <see cref="Primitive"/>.
/// </summary>
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Primitive"/>.</param>
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
[Obsolete("Use Create(Vector3, Vector3, Vector3, bool, Color) instead.", true)]
Thundermaker300 marked this conversation as resolved.
Show resolved Hide resolved
public static Primitive Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true)
{
Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject));

primitive.AdminToyBase.transform.position = position ?? Vector3.zero;
primitive.AdminToyBase.transform.eulerAngles = rotation ?? Vector3.zero;
primitive.AdminToyBase.transform.localScale = scale ?? Vector3.one;

if (spawn)
primitive.Spawn();

primitive.AdminToyBase.NetworkScale = primitive.AdminToyBase.transform.localScale;

return primitive;
}

/// <summary>
/// Creates a new <see cref="Primitive"/>.
/// </summary>
/// <param name="primitiveType">The type of primitive to spawn.</param>
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Primitive"/>.</param>
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
[Obsolete("Use Create(PrimitiveType, Vector3, Vector3, Vector3, bool, Color) instead.", true)]
Thundermaker300 marked this conversation as resolved.
Show resolved Hide resolved
public static Primitive Create(PrimitiveType primitiveType = PrimitiveType.Sphere, Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true)
{
Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject));

primitive.AdminToyBase.transform.position = position ?? Vector3.zero;
primitive.AdminToyBase.transform.eulerAngles = rotation ?? Vector3.zero;
primitive.AdminToyBase.transform.localScale = scale ?? Vector3.one;

if (spawn)
primitive.Spawn();

primitive.AdminToyBase.NetworkScale = primitive.AdminToyBase.transform.localScale;
primitive.Base.NetworkPrimitiveType = primitiveType;

return primitive;
}

/// <summary>
/// Creates a new <see cref="Primitive"/>.
/// </summary>
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Primitive"/>.</param>
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <param name="color">The color of the <see cref="Primitive"/>.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true)
public static Primitive Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true, Color? color = null)
{
Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject));

Expand All @@ -95,6 +148,7 @@ public static Primitive Create(Vector3? position = null, Vector3? rotation = nul
primitive.Spawn();

primitive.AdminToyBase.NetworkScale = primitive.AdminToyBase.transform.localScale;
primitive.Color = color ?? Color.white;
NaoUnderscore marked this conversation as resolved.
Show resolved Hide resolved

return primitive;
}
Expand All @@ -103,12 +157,13 @@ public static Primitive Create(Vector3? position = null, Vector3? rotation = nul
/// Creates a new <see cref="Primitive"/>.
/// </summary>
/// <param name="primitiveType">The type of primitive to spawn.</param>
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Primitive"/>.</param>
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <param name="color">The color of the <see cref="Primitive"/>.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(PrimitiveType primitiveType = PrimitiveType.Sphere, Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true)
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(ToysHelper.PrimitiveBaseObject));

Expand All @@ -121,6 +176,30 @@ public static Primitive Create(PrimitiveType primitiveType = PrimitiveType.Spher

primitive.AdminToyBase.NetworkScale = primitive.AdminToyBase.transform.localScale;
primitive.Base.NetworkPrimitiveType = primitiveType;
primitive.Color = color ?? Color.white;
NaoUnderscore marked this conversation as resolved.
Show resolved Hide resolved

return primitive;
}

/// <summary>
/// Creates a new <see cref="Primitive"/>.
/// </summary>
/// <param name="primitiveSettings">The settings of the <see cref="Primitive"/>.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(PrimitiveSettings primitiveSettings)
{
Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject));

primitive.AdminToyBase.transform.position = primitiveSettings.Position;
primitive.AdminToyBase.transform.eulerAngles = primitiveSettings.Rotation;
primitive.AdminToyBase.transform.localScale = primitiveSettings.Scale;

if (primitiveSettings.Spawn)
primitive.Spawn();

primitive.AdminToyBase.NetworkScale = primitive.AdminToyBase.transform.localScale;
primitive.Base.NetworkPrimitiveType = primitiveSettings.PrimitiveType;
primitive.Color = primitiveSettings.Color;

return primitive;
}
Expand Down
66 changes: 66 additions & 0 deletions Exiled.API/Structs/PrimitiveSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// -----------------------------------------------------------------------
// <copyright file="PrimitiveSettings.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Structs
{
using UnityEngine;

/// <summary>
/// Settings for primitives.
/// </summary>
public struct PrimitiveSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="PrimitiveSettings"/> struct.
/// </summary>
/// <param name="primitiveType">The type of the primitive.</param>
/// <param name="color">The color of the primitive.</param>
/// <param name="position">The position of the primitive.</param>
/// <param name="rotation">The rotation of the primitive.</param>
/// <param name="scale">The scale of the primitive.</param>
/// <param name="spawn">Whether or not the primitive should be spawned.</param>
public PrimitiveSettings(PrimitiveType primitiveType, Color color, Vector3 position, Vector3 rotation, Vector3 scale, bool spawn)
{
PrimitiveType = primitiveType;
Color = color;
Position = position;
Rotation = rotation;
Scale = scale;
Spawn = spawn;
}

/// <summary>
/// Gets the primitive type.
/// </summary>
public PrimitiveType PrimitiveType { get; }

/// <summary>
/// Gets the primitive color.
/// </summary>
public Color Color { get; }

/// <summary>
/// Gets the primitive position.
/// </summary>
public Vector3 Position { get; }

/// <summary>
/// Gets the primitive rotation.
/// </summary>
public Vector3 Rotation { get; }

/// <summary>
/// Gets the primitive scale.
/// </summary>
public Vector3 Scale { get; }

/// <summary>
/// Gets a value indicating whether or not the primitive should be spawned.
/// </summary>
public bool Spawn { get; }
}
}
Loading