URL: https://wiki.studiominus.nl/internalReference/Utils.html Title: People Playground Modding - Utils ================================================== public static class Utils Class full of utilites that are widely used throughout the game Nested types Utils.Activations Utils.LaserHit Fields public const float UnitsToMeters Multiply this by an amount of units to get back the amount meters it represents Constant value: Global.MetricMultiplier public const float MetersToUnits Multiply this by an amount of meters to get back the amount units it represents Constant value: 1f / Global.MetricMultiplier public const float E Euler's number Constant value: 2.718281828459045f Methods public static bool HasLayer(this LayerMask mask, int layer) Does the current LayerMask have the given layer enabled? This is an extension method. public static void Fill(this T[] array, T val) No description provided public static Vector2 ClosestPointFix(this Rigidbody2D rb, Vector2 point) I absolutely fucking hate Unity public static float SmoothApproach(float pastPosition, float targetPosition, float speed, float deltaTime) Do magic maths to make a value approach another smoothly over time public static Vector3 FloatArrayToVector(float[] array) Converts a float array to a vector. public static float[] VectorToFloatArray(Vector2 vector) Converts a vector to a float array public static float[] VectorToFloatArray(Vector3 vector) Converts a vector to a float array public static float[] ColorToFloatArray(Color col) Converts a color to a float array public static int[] VectorToIntArray(Vector3 vector) Converts a vector to an integer array (Rounds to lowest value) public static Vector2 SmoothApproach(Vector2 pastPosition, Vector2 targetPosition, float speed, float deltaTime) Do magic maths to make a value approach another smoothly over time public static bool UniverseMatches(this ActionUniverse uni, ActionUniverse other) Does the current ActionUniverse match the given universe? This is an extension method. public static uint ToMD5(this string message) No description provided public static uint ToSHA512(this string message) No description provided public static void AddRange(this HashSet hashset, IEnumerable range) Adds a collection to the HashSet. This is an extension method. public static float DistanceFromPointToLineSegment(Vector2 point, Vector2 lineEnd1, Vector2 lineEnd2) Calculates the smallest distance from a point to the given line segment public static float SqrdDistanceFromPointToLineSegment(Vector2 point, Vector2 lineEnd1, Vector2 lineEnd2) Calculates the smallest distance from a point to the given line segment public static T PickRandom(this IList collection) Pick a random entry from a collection. This is an extension method. public static T PickRandom(this IList collection, int count) Pick a random entry from a collection. This is an extension method. public static float Cosh(float x) oh my cosh public static void LiquidMixProcess( BloodContainer container, Liquid a, Liquid b, Liquid result, float delta = 0.05f) Mix two liquids inside a container. This calls all the proper functions and should always be used if you are mixing liquids inside a container. public static void LiquidMixProcess( BloodContainer container, Liquid a, Liquid b, Liquid c, Liquid result, float delta = 0.05f) Mix three liquids inside a container. This calls all the proper functions and should always be used if you are mixing liquids inside a container. public static void LiquidMixProcess( BloodContainer container, Liquid a, Liquid b, Liquid c, Liquid d, Liquid result, float delta = 0.05f) Mix four liquids inside a container. This calls all the proper functions and should always be used if you are mixing liquids inside a container. public static void LiquidMixProcess(BloodContainer container, Liquid[] a, Liquid result, float delta = 0.05f) Mix n liquids inside a container. This calls all the proper functions and should always be used if you are mixing liquids inside a container. public static void UpdateOutlineMaterial(ref MaterialPropertyBlock propertyBlock, SpriteRenderer outlineSpriteRenderer, Sprite targetSprite) Update the outline material property block based on the given renderer and sprite public static float NaNFallback(this float f, float fallback = 0) Returns the fallback if the given float is NaN. This is an extension method. public static Vector2 NaNFallback(this Vector2 f, float fallback = 0) Returns the fallback if the given float is NaN. This is an extension method. public static float RandomBetween(Vector2 range) Returns a random value between the given vector's components public static Color ChangeRedToOrange(in Color color, float fuzzinessDegrees = 0.03f) Just in case the colour is red (blood), it will be changed to orange public static void SetPointVelocity(this Rigidbody2D body, Vector2 vel, Vector2 position) Set the velocity at the given point in world space. This is an extension method. public static string AppendPunctuation(string input) No description provided public static Bounds GetWorldSpaceBounds(this RectTransform rect) Calculates the world space bounds of the given RectTransform. This is an extension method. public static string EscapeRichText(string v) Escape all rich text from the given string public static void TransferEnergyFixedRate(PhysicalBehaviour a, PhysicalBehaviour b, float rate = 0.89f) Transfer electricity between two physical objects based on a constant rate. This has to be called in a fixed update step. public static void TransferEnergyDeltaTime(PhysicalBehaviour a, PhysicalBehaviour b, float rate, float dt) Transfer electricity between two physical objects based on a constant rate and a given timestep. This has to be called in an update step. public static void AverageTemperature(PhysicalBehaviour a, PhysicalBehaviour b, float transferFactor = 0.01f) Average the temperature between two physical objects based on a constant rate. public static float GetMinHeatTransferSpeed(PhysicalBehaviour a, PhysicalBehaviour b) Get the minumum of both object's heat transfer speed public static string GetHierachyPath(Transform transform) Get the unique hierarchy path for the transform public static IEnumerator DelayCoroutine(float delayInSeconds, Action action) Routine that waits the given amount of seconds and then calls the given function public static IEnumerator NextFrameCoroutine(Action action) Routine that waits a frame and then calls the given function public static float Triangle(float x) Triangle wave with the same frequency as a sine wave public static async Task HttpGet(string uri) Generic HTTP GET function public static async Task HttpPost(string uri, string body) HTTP POST function public static async Task HttpDownload(string uri) Downloads the data at the given endpoint public static float PreferenceToCelsius(float i) Converts the given amount to Celsius assuming it's given in whatever the current user preference is set to public static float CelsiusToPreference(float i) Converts the given amount to whatever the current user preference is set to assuming it's given in Celsius public static float CelsiusToFahrenheit(float i) Degrees Celsius to degrees Fahrenheit public static float CelsiusToKelvin(float i) Degrees Celsius to Kelvin public static float FahrenheitToCelsius(float i) Degrees Fahrenheit to degrees Celsius public static float KelvinToCelsius(float i) Kelvin to degrees Celsius public static string GetTemperatureUnitSuffix(TemperatureUnit unit) Returns the unit suffix for the given TemperatureUnit. public static void DrawCross(Vector3 center, float size, Color color, float duration) Debug draw a cross public static byte[] GetMD5(byte[] bytes) Get the MD5 hash for the given data public static byte[] GetMD5(string input) Get the MD5 hash for the given data public static string GetMD5AsString(string input) Get the MD5 hash as a string for the given data public static byte[] GetMD5ForFile(string filePath) Get the MD5 hash as for the given file public static Vector3 GetPerlin2Mapped(float x, float y) Get 2 axes of perlin noise at the given 2D coordinate, returning value ranging from -1, 1 public static float MapRange(float lower1, float upper1, float lower2, float upper2, float value) Map a value from one range to another public static T GetMin(ICollection collection, Func singleFunc) Return the smallest value in the collection based on the given function's result public static SpriteRenderer GetOutlineSprite(Transform transform) [System.Obsolete] Returns the outline sprite on the given transform. Null if it has none. This method is cringe. Do not use. public static bool IsSerialisableType(Type type) Is the given type serialisable by the contraption serialisation system? public static string GetFormattedByteString(ulong b) Turns a countable amount into a formatted string with a proper suffix.Example: GetFormattedByteString(1000) outputs "1 kB" public static LaserHit MaterialAwareRaycast(Vector2 origin, Vector2 dir, float maxDistance, LayerMask layers, int maxSteps = 8, int depth = 0, float currentDistance = 0) Raycasts through the world considering physical properties. It will go through glass but won't reflect off of mirrors. public static float Snap(float v, float snap) Snap a value to a grid of the given resolution public static Vector3 Snap(Vector3 v, float snap) Snap a value to a grid of the given resolution public static Vector3 Snap(Vector3 v, Vector3 snap) Snap a value to a grid of the given resolution public static Vector3 Rotate(Vector2 point, float degrees, Vector2 pivot = default) Rotate a point around another point public static float NormaliseAngle(float degrees) Puts the given degrees in a range from 0 to 360. public static float Mod(float a, float b) Modulo public static void GetLaserEndPoint(Vector2 origin, Vector2 dir, ref List list, LayerMask layers, float maximumDistance, uint maxIterations = 64) Does a whole laser raycast considering mirrors and glass. It puts all hit points inside the given list. public static bool IsFamilyShared() Returns true if the game is not actually owned by the current account or if either account is invalid.If Steam is not available, this function will return false; public static void OpenURL(string url) Opens the given URL in the browser or Steam / GOG Overlay if applicable public static Sprite LoadSprite(string fullPath, FilterMode mode = FilterMode.Bilinear, float pixelsPerUnit = 35f, bool markNonReadable = true) Loads the sprite at the given file path public static Texture2D LoadTexture(string fullPath, FilterMode mode = FilterMode.Bilinear, bool markNonReadable = true) Loads the texture at the given file path public static AudioClip FileToAudioClip(string path) Loads the sound at the given path public static void GetTopMostLayer(SpriteRenderer a, SpriteRenderer b, out int layerId, out int sortingOrder) Get the topmost layer out of the two given renderers public static void GetTopMostLayer(SpriteRenderer a, SpriteRenderer b, out PhysicalBehaviour phys) Get the topmost layer out of the two given renderers public static byte br(this Color color) Returns the red component of the given colour as a byte public static byte bg(this Color color) Returns the green component of the given colour as a byte public static byte bb(this Color color) Returns the blue component of the given colour as a byte public static void FixColliders(this GameObject instance) Removes all colliders from the object and adds a PolygonCollider2D public static T GetOrAddComponent(this GameObject instance) Gets or adds a component of the given type on the given GameObject public static bool HasComponent(this GameObject instance) Returns true of a component of type exists on the game object public static void SendAllChannelIsolatedActivation(MonoBehaviour other) Sends an isolated activation signal on all channels to the given MonoBehaviour public static void SendAllChannelContinuousIsolatedActivation(MonoBehaviour other) Sends a continuous isolated activation signal on all channels to the given MonoBehaviour public static T LoadAddressableSync(string key) [System.Obsolete] No description provided public static void AssertValidThumbnail(string path) Throws an exception if the thumbnail file at the given location is invalid public static float GetLerpFactorDeltaTime(float lerpFactor, float deltaTime) Calculates the lerp factor for the given timestep public static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles) I'm not sure what this does again. It's apart of the lightmap generation code; some code I wrote a while ago. I've forgotten it's purpose. public static Vector2 CalculateNormal(Vector2 A, Vector2 B) Calculates the normal of two points in a specific direction. Used for vertex generation in the lightmap generator. public static float CalculateBreakForceForCable(AnchoredJoint2D joint, float baseStrength, float referenceMass = 5, float massInfluence = 1) Calculates the break force threshold for the given joint, based on the given parameters public static void SetLayer(this GameObject gm, int layer, bool includeChildren = true) Sets the layer of the given GameObject. This is an extension method. public static float GetMaxImpulse(ContactPoint2D[] buffer, int count) Gets the greatest impulse from the given array public static float GetAverageImpulse(ContactPoint2D[] buffer, int count) Gets the average impulse from the given array public static float GetAverageImpulseRemoveOutliers(ContactPoint2D[] buffer, int count, float outlierThreshold = 1) Gets the average impulse from the given array, removing all outliers outside a range public static float GetMinImpulse(ContactPoint2D[] buffer, int count) Gets the smallest impulse from the given array public static ContactPoint2D GetFirstValidContact(ContactPoint2D[] buffer, int count) Get the first valid contact point. Returns the default contact point if no valid one is found. public static bool IsPointInsideBounds(this Bounds bounds, Vector2 point) Returns true if the given point is inside the bounds. This is an extension method. public static GameObject CreateLightmap(Vector2 pos, Texture2D lightmap, int res) No description provided public static GameObject CreateLightmap(Vector2 pos, Texture2D lightmap, int res, GameObject world, int[] lightPos) No description provided public static bool ContainsExpanded(this Bounds bounds, Vector2 point, float expansion = 0) Returns true if the given point is inside the bounds considering the given bounds expansion. This is an extension method. public static bool AreHdrRenderTexturesSupported() Returns true if HDR RenderTextures are supported. public static void OpenFloatInputDialog(float defaultValue, T callingBehaviour, Action setValueFunction, string text, string placeholder) Open an input dialog box that accepts numbers public static void OpenIntInputDialog(int defaultValue, T callingBehaviour, Action setValueFunction, string text, string placeholder) Open an input dialog box that accepts integers public static void OpenTextInputDialog(string defaultValue, T callingBehaviour, Action setValueFunction, string message, string placeholder) Open an input dialog box that accepts text public static void OpenColourInputDialog(Color initialValue, string title, string description, Action setValueFunction) Open an input dialog box that accepts colour public static void OpenColourInputDialog(Color initialValue, string title, string description, UnityEngine.Events.UnityAction setValueFunction) Opens an input dialog box that accepts colour public static Vector2 CastRayUntilOutside(GameObject targetBody, Vector2 minPoint, Vector2 direction, float distance, Collider2D[] buffer = null) Cast a ray from a point (inside or outside a body) until it comes out the other end of the body, then return that position. You can provide a Collider2D buffer, but it uses an internal one if left to null. public static async Task TaskTimeout(Task task, TimeSpan timeout) No description provided public static int ComputeConvexHull(Vector2[] points, List hull) No description provided