// MIT License - Copyright (c) 2025 wallstop
// Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE
// ReSharper disable once CheckNamespace
namespace WallstopStudios.UnityHelpers.Core.Extension
{
using System;
using UnityEngine;
///
/// General-purpose helpers such as JSON formatting, input filtering, and scene membership checks.
///
public static partial class UnityExtensions
{
///
/// Converts a Vector3 to a JSON-formatted string representation.
///
public static string ToJsonString(this Vector3 vector)
{
return FormattableString.Invariant($"{{{vector.x}, {vector.y}, {vector.z}}}");
}
///
/// Converts a Vector2 to a JSON-formatted string representation.
///
public static string ToJsonString(this Vector2 vector)
{
return FormattableString.Invariant($"{{{vector.x}, {vector.y}}}");
}
///
/// Determines if a Vector2 represents insignificant input (noise) below a threshold.
///
public static bool IsNoise(this Vector2 inputVector, float threshold = 0.2f)
{
float limit = Mathf.Abs(threshold);
return Mathf.Abs(inputVector.x) <= limit && Mathf.Abs(inputVector.y) <= limit;
}
///
/// Determines if a GameObject is in the DontDestroyOnLoad scene.
///
public static bool IsDontDestroyOnLoad(this GameObject gameObjectToCheck)
{
if (gameObjectToCheck == null)
{
return false;
}
return string.Equals(
gameObjectToCheck.scene.name,
"DontDestroyOnLoad",
StringComparison.Ordinal
);
}
}
}