diff --git a/EXILED/Exiled.API/Features/Camera.cs b/EXILED/Exiled.API/Features/Camera.cs index bfa38b528..5774fcd51 100644 --- a/EXILED/Exiled.API/Features/Camera.cs +++ b/EXILED/Exiled.API/Features/Camera.cs @@ -362,6 +362,14 @@ public static Camera Get(Scp079Camera camera079) /// if is not , or if is . public static bool TryGet(Scp079Camera camera, out Camera result) => (result = Get(camera)) != null; + /// + /// Gets the belonging to the , if any. + /// + /// The of the camera. + /// The instance of which base. + /// if is not , or if is . + public static bool TryGet(GameObject gameObject, out Camera result) => (result = Get(gameObject)) != null; + /// /// Gets a given the specified . /// diff --git a/EXILED/Exiled.API/Features/PrefabHelper.cs b/EXILED/Exiled.API/Features/PrefabHelper.cs index e5c3bf1c7..afbadb37e 100644 --- a/EXILED/Exiled.API/Features/PrefabHelper.cs +++ b/EXILED/Exiled.API/Features/PrefabHelper.cs @@ -100,7 +100,18 @@ public static T GetPrefab(PrefabType prefabType) /// The position where the will spawn. /// The rotation of the . /// Returns the instantied. - public static GameObject Spawn(PrefabType prefabType, Vector3 position = default, Quaternion? rotation = null) + [Obsolete("This method will be removed in Exiled 10 in favour of overload with more parameters")] + public static GameObject Spawn(PrefabType prefabType, Vector3 position, Quaternion? rotation) => Spawn(prefabType, position, rotation, true); + + /// + /// Spawns the of the specified . + /// + /// The . + /// The position where the will spawn. + /// The rotation of the . + /// Whether the should be initially spawned. + /// Returns the instantied. + public static GameObject Spawn(PrefabType prefabType, Vector3 position = default, Quaternion? rotation = null, bool spawn = true) { if (!TryGetPrefab(prefabType, out GameObject gameObject)) return null; @@ -112,7 +123,7 @@ public static GameObject Spawn(PrefabType prefabType, Vector3 position = default if (newGameObject.TryGetComponent(out StructurePositionSync positionSync)) { positionSync.Network_position = position; - positionSync.Network_rotationY = (sbyte)Mathf.RoundToInt(rotation.Value.eulerAngles.y / 5.625F); + positionSync.Network_rotationY = (sbyte)Mathf.RoundToInt(rotation.Value.eulerAngles.y / StructurePositionSync.ConversionRate); } #pragma warning disable CS0618 // Type or member is obsolete @@ -128,7 +139,8 @@ public static GameObject Spawn(PrefabType prefabType, Vector3 position = default } #pragma warning restore CS0618 // Type or member is obsolete - NetworkServer.Spawn(newGameObject); + if (spawn) + NetworkServer.Spawn(newGameObject); return newGameObject; } @@ -141,11 +153,22 @@ public static GameObject Spawn(PrefabType prefabType, Vector3 position = default /// The rotation of the . /// The type. /// Returns the of the . - public static T Spawn(PrefabType prefabType, Vector3 position = default, Quaternion? rotation = null) + [Obsolete("This method will be removed in Exiled 10 in favour of overload with more parameters")] + public static T Spawn(PrefabType prefabType, Vector3 position, Quaternion? rotation) where T : Component - { - GameObject gameObject = Spawn(prefabType, position, rotation); - return gameObject?.GetComponent(); - } + => Spawn(prefabType, position, rotation, true); + + /// + /// Spawns the of the specified . + /// + /// The . + /// The position where the will spawn. + /// The rotation of the . + /// Whether the should be initially spawned. + /// The type. + /// Returns the of the . + public static T Spawn(PrefabType prefabType, Vector3 position = default, Quaternion? rotation = null, bool spawn = true) + where T : Component + => Spawn(prefabType, position, rotation, spawn)?.GetComponent(); } } \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Toys/AdminToy.cs b/EXILED/Exiled.API/Features/Toys/AdminToy.cs index c93cee110..99fa27e4e 100644 --- a/EXILED/Exiled.API/Features/Toys/AdminToy.cs +++ b/EXILED/Exiled.API/Features/Toys/AdminToy.cs @@ -176,12 +176,22 @@ public static AdminToy Get(AdminToyBase adminToyBase) /// /// Gets the by . /// - /// The to convert into an admintoy. + /// The to convert into an AdminToy. /// The specified type. - /// The admintoy wrapper for the given . + /// The AdminToy wrapper for the given . public static T Get(AdminToyBase adminToyBase) where T : AdminToy => Get(adminToyBase) as T; + /// + /// Gets the by . + /// + /// The to convert into AdminToy. + /// The specified type. + /// The AdminToy wrapper for the given . + public static T Get(GameObject gameObject) + where T : AdminToy + => Get(gameObject.GetComponent()) as T; + /// /// Spawns the toy into the game. Use to remove it. ///