Utils
A helper function for Unity
Utils is an important part in library. A short brief is Helper function.
Platform
providing platform infomation
var platform = ALib.Platform;
string name = platform.CurrentPlatform
bool result = platform.IsPlaying
bool result = platform.IsEditor
// Mobile
bool result = platform.IsMobile
bool result = platform.IsAndroid
bool result = platform.IsIphone
// Destop
bool result = platform.IsDesktop
bool result = platform.IsPC
bool result = platform.IsMac
bool result = platform.IsLinux
// WebGL
bool result = platform.IsWebGL
// Server
bool result = platform.IsServer
bool result = platform.IsWinServer
bool result = platform.IsOSXServer
bool result = platform.IsLinuxServer
// Console
bool result = platform.IsConsole
bool result = platform.IsPS
bool result = platform.IsPS4
bool result = platform.IsPS5
bool result = platform.IsSwitch
bool result = platform.IsXboxOne
// Apple TV
bool result = platform.IsAppleTV
// Windows Store App
bool result = platform.IsWindowsStoreApp
bool result = platform.IsWSA_Arm
bool result = platform.IsWSA_x86
bool result = platform.IsWSA_x64BinaryFormatter
// get Binary Formatter with supported Surrogate in library
IFormatter formatter = ALib.Helper.GetBinaryFormatter();Color
// create a random color
Color result = ALib.Helper.RandomColor();
// create a random color with given alpha
Color result = ALib.Helper.RandomColor(0.5f);float
// smooth damp
float dampValue = ALib.Helper.SmoothDamp(current, target,
ref velocity, smoothTime, maxSpeed, deltaTime);
// inverse lerp result
float result - ALib.Helper.InverseLerp(a, b, value)GameObject
// create a gameobject with given name
GameObject result = ALib.Helper.CreateEmptyInHierarchy("My GameObject");
// create a gameobject with given name and parent
GameObject result = ALib.Helper.CreateEmptyInHierarchy("My GameObject", parentTransform);Mathmatics.float2
// check is all close
bool result = ALib.Helper.AllClose(a, b, epsilon)
// remap a float2 value from range to range
float2 value = ALib.Helper.Remap(value, from1, to1, from2, to2);
// calculate new position after move towards
float2 position = ALib.Helper.MoveTowards(current, target, maxDistanceDeta);
// clamp to given length
float2 result = ALib.Helper.ClampLength(value, maxLength);
// smooth damp
float2 dampValue = ALib.Helper.SmoothDamp(current, target,
ref velocity, smoothTime, maxSpeed, deltaTime);Mathmatics.float3
// check is all close
bool result = ALib.Helper.AllClose(a, b, epsilon)
// remap a float2 value from range to range
float3 value = ALib.Helper.Remap(value, from1, to1, from2, to2);
// calculate new position after move towards
float3 position = ALib.Helper.MoveTowards(current, target, maxDistanceDeta);
// clamp to given length
float3 result = ALib.Helper.ClampLength(value, maxLength);
// smooth damp
float3 dampValue = ALib.Helper.SmoothDamp(current, target,
ref velocity, smoothTime, maxSpeed, deltaTime);string
public enum CharacterType
{
FullCharacters,
Characters,
Letters,
Digits,
}
// create a random string
string result = ALib.Helper.GetRandomString(length, CharacterType.Letters);
// encode and decode string in Base64
string encode = ALib.Helper.Base64Encode(text, Encoding.Default);
string decode = ALib.Helper.Base64Decode(encode, Encoding.Default);
// spilt path and filename
ALib.Helper.SplitPathAndFilename(fullPath, out var path, out var filename);UI
// check a screen position is over an UI element
bool result = ALib.Helper.IsOverUIElement(screenPosition);
// check a screen position is over an UI element with displayIndex
bool result = ALib.Helper.IsOverUIElement(screenPosition, displayIndex);Vector3
public enum TransformDirection
{
Left, Right, Up, Down, Forward, Back,
}
// change TransformDirection to Vector3 value in world space
Vector3 result = ALib.Helper.GetRotateAxis(transformDirection.Left);
// get a smooth direction when hit on object
Vector3 result = ALib.Helper.SmoothDirection(normal, inDirection)WebCam
// get total number of webcam
int result = ALib.Helper.WebCamCount;
// check device has webcam
bool result = ALib.Helper.HasWebCam;
// try get webcam
bool result = ALib.Helper.TryGetWebCam(camId, width, height, fps,
out var webCamDevice, out var webCamTexture);
// try get front webcam (camId = 0)
bool result = ALib.Helper.TryGetFrontCam(width, height, fps,
out var webCamDevice, out var webCamTexture);Last updated