Class Util
Utility class of AngeliA
Fields
Deg2Rad
Deg angle * Deg2Rad = Rad angle
Declaration
public const float Deg2Rad = 0.017453292
PI
ฯ = 3.14159274f
Declaration
public const float PI = 3.1415927
Rad2Deg
Rad angle * Rad2Deg = Deg angle
Declaration
public const float Rad2Deg = 57.29578
Methods
Abs(int)
Return the absolute value
Declaration
public static int Abs(int value)
Abs(float)
Return the absolute value
Declaration
public static float Abs(float value)
AddAssembly(Assembly)
Add a new assembly into AngeliA. Make sure the assembly is already loaded into .NET. โ Only call this function inside a static constructor โ
Declaration
public static void AddAssembly(Assembly assembly)
AddEnvironmentVariable(string, string)
Add given key and value into system Environment Variable
Declaration
public static void AddEnvironmentVariable(string key, string value)
AllChildClass(Type, bool, bool)
Iterate through all child classes of given type
Declaration
public static IEnumerable<Type> AllChildClass(this Type type, bool includeAbstract = false, bool includeInterface = false)
True if abstract class should be included
True if interface should be included
AllChildClassID(Type, bool, bool)
Iterate through all child class's ID of given type
Declaration
public static IEnumerable<int> AllChildClassID(this Type type, bool includeAbstract = false, bool includeInterface = false)
True if abstract class should be included
True if interface should be included
AllClassImplemented(Type, bool)
Iterate through all class that implement the given interface
Declaration
public static IEnumerable<Type> AllClassImplemented(this Type interfaceType, bool includeAbstract = false)
Parameters
Type | Name | Description |
---|---|---|
Type | interfaceType | Type of the target interface |
bool | includeAbstract | True if abstract class is included |
AllClassImplementedID(Type, bool)
Iterate through all class's ID that implement the given interface
Declaration
public static IEnumerable<int> AllClassImplementedID(this Type interfaceType, bool includeAbstract = false)
Parameters
Type | Name | Description |
---|---|---|
Type | interfaceType | Type of the target interface |
bool | includeAbstract | True if abstract class is included |
AllClassWithAttribute(Type, bool, bool)
Iterate through all classes with given attribute attaching on
Declaration
public static IEnumerable<(Type, Attribute)> AllClassWithAttribute(this Type attribute, bool ignoreAbstract = true, bool ignoreInterface = true)
Parameters
Type | Name | Description |
---|---|---|
Type | attribute | Type of the target attribute |
bool | ignoreAbstract | True if abstract classes should be excluded |
bool | ignoreInterface | True if interfaces should be excluded |
AllClassWithAttribute<A>(bool, bool, bool)
Iterate through all classes with given attribute attaching on
Declaration
public static IEnumerable<(Type, A)> AllClassWithAttribute<A>(bool ignoreAbstract = true, bool ignoreInterface = true, bool inherit = false) where A : Attribute
Parameters
Type | Name | Description |
---|---|---|
bool | ignoreAbstract | True if abstract classes should be excluded |
bool | ignoreInterface | True if interfaces should be excluded |
bool | inherit | Set to true to inspect the ancestors of element |
Type Parameters
Name | Description |
---|---|
A | Type of the target attribute |
AllEnumIdPairs<E>()
Iterate through all value and name AngeHash for the given enum
Declaration
public static IEnumerable<KeyValuePair<E, int>> AllEnumIdPairs<E>() where E : struct, Enum
Type Parameters
Name | Description |
---|---|
E | Type of the enum |
AllStaticMethodWithAttribute<T>()
Iterate through all static method from all classes that with given attribute attached on
Declaration
public static IEnumerable<KeyValuePair<MethodInfo, T>> AllStaticMethodWithAttribute<T>() where T : Attribute
Type Parameters
Name | Description |
---|---|
T | Type of the attribute |
Approximately(float, float)
True if the given two float is almost same
Declaration
public static bool Approximately(float a, float b)
ArgPath_to_Path(string)
Declaration
public static string ArgPath_to_Path(string path)
Atan(float, float)
Return the arctangent of (x,y)
Declaration
public static float Atan(float x, float y)
BabylonianSqrt(int)
Get square root of given value without using too many CPU resources
Declaration
public static int BabylonianSqrt(int n)
ByteToCompressedFile(string, byte[], int)
Save byte array into compressed file
Declaration
public static void ByteToCompressedFile(string path, byte[] rawBytes, int length = -1)
Set to -1 for the full array
BytesToFile(byte[], string, int)
Save byte array into file
Declaration
public static void BytesToFile(byte[] bytes, string path, int length = -1)
Set to -1 to save all byte array
CeilToInt(float)
Get the smallest intager that larger than "value"
Declaration
public static int CeilToInt(float value)
ChangeExtension(string, string)
Change extension of the given path
Declaration
public static string ChangeExtension(string path, string newEx)
Works both with and without the dot
Returns
Type | Description |
---|---|
string | New path with extension changed |
Clamp(int, int, int)
Limit value "a" between "min" and "max"
Declaration
public static int Clamp(int a, int min, int max)
Clamp(float, float, float)
Limit value "a" between "min" and "max"
Declaration
public static float Clamp(float a, float min, float max)
Clamp01(float)
Limit value "a" between 0 and 1
Declaration
public static float Clamp01(float value)
ColorToHtml(Color32, bool)
Get html string from given color value
Declaration
public static string ColorToHtml(Color32 color, bool ignoreAlpha = false)
ColorToInt(Color32)
Convert color value into intager
Declaration
public static int ColorToInt(Color32 color)
CombinePaths(string, string)
Combine strings into a path
Declaration
public static string CombinePaths(string path1, string path2)
Parameters
Type | Name | Description |
---|---|---|
string | path1 | First part to combine |
string | path2 | Second part to combine |
Returns
Type | Description |
---|---|
string | Full path |
CombinePaths(string, string, string)
Combine strings into a path
Declaration
public static string CombinePaths(string path1, string path2, string path3)
Parameters
Type | Name | Description |
---|---|---|
string | path1 | First part to combine |
string | path2 | Second part to combine |
string | path3 | Third part to combine |
Returns
Type | Description |
---|---|
string | Full path |
CombinePaths(string, string, string, string)
Combine strings into a path
Declaration
public static string CombinePaths(string path1, string path2, string path3, string path4)
Parameters
Type | Name | Description |
---|---|---|
string | path1 | First part to combine |
string | path2 | Second part to combine |
string | path3 | Third part to combine |
string | path4 | Fourth part to combine |
Returns
Type | Description |
---|---|
string | Full path |
CombinePaths(params string[])
Combine strings into a path
Declaration
public static string CombinePaths(params string[] paths)
Parameters
Type | Name | Description |
---|---|---|
string[] | paths | Array of parts of path |
Returns
Type | Description |
---|---|
string | Full path |
CompressedFileToByte(string, out int)
Load compressed file into byte array
Declaration
public static byte[] CompressedFileToByte(string path, out int byteLength)
True length of the byte array
Returns
Type | Description |
---|---|
byte[] | The raw byte array |
CopyFile(string, string, bool)
Copy file from one path to other
Declaration
public static bool CopyFile(string from, string to, bool overwrite = true)
True if overwrite existing file at "to"
Returns
Type | Description |
---|---|
bool | True if successfuly copied |
CopyFolder(string, string, bool, bool, bool)
Copy folder from one path to other
Declaration
public static bool CopyFolder(string from, string to, bool copySubDirs, bool ignoreHidden, bool overrideFile = false)
True if copy all folder/files inside root folder
True if hidden files/folders do not get copy
True if overwrite existing files at "to"
Returns
Type | Description |
---|---|
bool | True if successfuly copied |
Cos(float)
Return cos value for given angle in RAD. Use (degAngle * Util.Deg2Rad) to get the Rad angle.
Declaration
public static float Cos(float radAngle)
CreateFolder(string)
Create a folder at given path. Ignore if folder exists.
Declaration
public static void CreateFolder(string path)
CrossVector3(Float3, Float3)
The cross product of two vectors results in a third vector which is perpendicular to the two input vectors.
Declaration
public static Float3 CrossVector3(Float3 lhs, Float3 rhs)
DecompressBytes(byte[])
Make compressed byte array into raw byte array
Declaration
public static byte[] DecompressBytes(byte[] compressedBytes)
DeleteFile(string)
Delete the file at given path. Do nothing when file not exists
Declaration
public static void DeleteFile(string path)
DeleteFolder(string)
Delete folder at given path. Do nothing when folder not exists
Declaration
public static void DeleteFolder(string path)
DistanceFloat(Float2, Float2)
Distance between given two points
Declaration
public static float DistanceFloat(Float2 a, Float2 b)
DistanceFloat(float, float, float, float)
Distance between given two points
Declaration
public static float DistanceFloat(float aX, float aY, float bX, float bY)
DistanceInt(Int2, Int2)
Distance between given two points. (Use BabylonianSqrt internaly)
Declaration
public static int DistanceInt(Int2 a, Int2 b)
DistanceInt(int, int, int, int)
Distance between given two points (Use BabylonianSqrt internaly)
Declaration
public static int DistanceInt(int aX, int aY, int bX, int bY)
DrawFilledEllipse_Patrick(int, int, int, int)
Draw a filled ellipse with Patrick algorithm
Declaration
public static IEnumerable<IRect> DrawFilledEllipse_Patrick(int left, int bottom, int width, int height)
Returns
Type | Description |
---|---|
IEnumerable<IRect> | All rect positions that need to fill with color |
DrawHoloEllipse_Patrick(int, int, int, int)
Draw a holo ellipse with Patrick algorithm
Declaration
public static IEnumerable<Int2> DrawHoloEllipse_Patrick(int left, int bottom, int width, int height)
Returns
Type | Description |
---|---|
IEnumerable<Int2> | All rect positions that need to fill with color |
DrawLineWithRect_DDA(int, int, int, int)
Draw a line between (x0,y0) and (x1,y1) with Digital-Differential-Analyzer algorithm
Declaration
public static IEnumerable<IRect> DrawLineWithRect_DDA(int x0, int y0, int x1, int y1)
Returns
Type | Description |
---|---|
IEnumerable<IRect> | All rect positions that need to fill with color |
DrawLine_DDA(int, int, int, int)
Draw a line between (x0,y0) and (x1,y1) with Digital-Differential-Analyzer algorithm
Declaration
public static IEnumerable<Int2> DrawLine_DDA(int x0, int y0, int x1, int y1)
Returns
Type | Description |
---|---|
IEnumerable<Int2> | All pixel positions |
EnumerateFiles(string, bool, string)
Iterate through path of all files that match given pattern
Declaration
public static IEnumerable<string> EnumerateFiles(string path, bool topOnly, string searchPattern)
Parameters
Type | Name | Description |
---|---|---|
string | path | Root folder path |
bool | topOnly | True if only search top level of the folder |
string | searchPattern | ("" means all files, ".txt" means all txt files) |
EnumerateFiles(string, bool, params string[])
Iterate through path of all files that match any given patterns
Declaration
public static IEnumerable<string> EnumerateFiles(string path, bool topOnly, params string[] searchPatterns)
Parameters
Type | Name | Description |
---|---|---|
string | path | Root folder path |
bool | topOnly | True if only search top level of the folder |
string[] | searchPatterns | ("" means all files, ".txt" means all txt files) |
EnumerateFolders(string, bool, string)
Iterate through path of all folders that match given pattern
Declaration
public static IEnumerable<string> EnumerateFolders(string path, bool topOnly, string searchPattern = "*")
Parameters
Type | Name | Description |
---|---|---|
string | path | Root folder path |
bool | topOnly | True if only search top level of the folder |
string | searchPattern | ("*" means all folders) |
EnumerateFolders(string, bool, params string[])
Iterate through path of all folders that match any given patterns
Declaration
public static IEnumerable<string> EnumerateFolders(string path, bool topOnly, params string[] searchPatterns)
Parameters
Type | Name | Description |
---|---|---|
string | path | Root folder path |
bool | topOnly | True if only search top level of the folder |
string[] | searchPatterns | ("*" means all folders) |
ExecuteCommand(string, string, int, bool)
Perform a command with the terminal
Declaration
public static int ExecuteCommand(string workingDirectory, string arguments, int logID = -1, bool wait = true)
Parameters
Type | Name | Description |
---|---|---|
string | workingDirectory | Path of the working directory |
int | logID | (-1 means ignore log. 0 means log with Debug.Log. >=1 means log with Debug.LogInternal) |
bool | wait | True if wait the terminal process to exit |
Returns
Type | Description |
---|---|
int | Return code |
FileExists(string)
True if the given path refers to an existing file in disk
Declaration
public static bool FileExists(string path)
FileToBytes(string)
Load file as a byte array
Declaration
public static byte[] FileToBytes(string path)
FileToText(string)
Load file into string text
Declaration
public static string FileToText(string path)
FileToText(string, Encoding)
Load file into string text
Declaration
public static string FileToText(string path, Encoding encoding)
FindNextStringStep(string, int, bool)
Get index of the nearby segment of the given string. (eg. for "Test Content String 123" if the start index is 5 which is start of "Content", toRight is true, return value will be 12 which is the end of "Content".)
Declaration
public static int FindNextStringStep(string content, int start, bool toRight)
True if move the cursor to right side
Returns
Type | Description |
---|---|
int | Index of the next step segment |
FixPath(string)
Make given path valid.
- Directory separator will be fixed to the valid one.
- All separators in the start of the path will be removed.
- All separators in the end of the path will be removed.
Declaration
public static string FixPath(string path)
FloorToInt(float)
Get the largest intager that smaller than "value"
Declaration
public static int FloorToInt(float value)
FolderExists(string)
True if the given path refers to an existing folder in disk
Declaration
public static bool FolderExists(string path)
ForAllAssemblyWithAttribute<A>()
Iterate through all given assembly attribute with the inatance of the assembly
Declaration
public static IEnumerable<(Assembly assembly, A attribute)> ForAllAssemblyWithAttribute<A>() where A : Attribute
Type Parameters
Name | Description |
---|---|
A | Type of the attribute |
ForAllLinesInFile(string)
Iterate through every text lines inside given file
Declaration
public static IEnumerable<string> ForAllLinesInFile(string path)
ForAllLinesInFile(string, Encoding)
Iterate through every text lines inside given file
Declaration
public static IEnumerable<string> ForAllLinesInFile(string path, Encoding encoding)
ForAllLinesInString(string)
Iterate through every text lines inside given string
Declaration
public static IEnumerable<string> ForAllLinesInString(string content)
ForAllSystemLanguages()
Iterate through iso of all language AngeliA support
Declaration
public static IEnumerable<string> ForAllSystemLanguages()
GetAllTypeSpan()
Get a ReadOnlySpan for all AngeliA related System.Types
Declaration
public static ReadOnlySpan<Type> GetAllTypeSpan()
GetAngeHashForClassName(string)
Declaration
public static int GetAngeHashForClassName(string className)
GetDirection(int, int)
Get closest direction for vector (deltaX, deltaY)
Declaration
public static Direction8 GetDirection(int deltaX, int deltaY)
GetDisplayName(string)
Make the given string (in English) looks better for user to read.
- If the string start with "m_". Remove the "m_";
- Replace all "_" into " "
- Add space before capital letters that behind a lowercase letter
Declaration
public static string GetDisplayName(string name)
GetDisplayTimeFromTicks(long)
Get time string for display label from given ticks
Declaration
public static string GetDisplayTimeFromTicks(long ticks)
GetExtensionWithDot(string)
Get file extension with the dot at front
Declaration
public static string GetExtensionWithDot(string path)
GetField(Type, string)
Get FieldInfo of the given type and name
Declaration
public static FieldInfo GetField(Type type, string name)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of class that holds the field |
string | name | Name of the field |
Returns
Type | Description |
---|---|
FieldInfo | Instance of the FieldInfo |
GetFieldType(object, string)
Get what type of data the given field holds
Declaration
public static Type GetFieldType(object target, string name)
Parameters
Type | Name | Description |
---|---|---|
object | target | Instance that holds the field |
string | name | Name of the field |
Returns
Type | Description |
---|---|
Type | System.Type that this field holds |
GetFieldValue(object, string)
Get value of the given field
Declaration
public static object GetFieldValue(object target, string fieldName)
Parameters
Type | Name | Description |
---|---|---|
object | target | Instance that holds the field |
string | fieldName | Name of the field |
Returns
Type | Description |
---|---|
object | Value of the field |
GetFileCount(string, string, SearchOption)
Get how many files mathchs the search pattern inside given folder path
Declaration
public static int GetFileCount(string path, string search = "*", SearchOption option = SearchOption.TopDirectoryOnly)
Parameters
Type | Name | Description |
---|---|---|
string | path | Root folder path |
string | search | ("" means all files, ".txt" means all txt files) |
GetFileCreationDate(string)
Declaration
public static long GetFileCreationDate(string path)
GetFileModifyDate(string)
Declaration
public static long GetFileModifyDate(string path)
GetFileSizeInMB(string)
Declaration
public static float GetFileSizeInMB(string path)
GetFolderCount(string, string, SearchOption)
Get how many folders mathchs the search pattern inside given folder path
Declaration
public static int GetFolderCount(string path, string search = "*", SearchOption option = SearchOption.TopDirectoryOnly)
Parameters
Type | Name | Description |
---|---|---|
string | path | Root folder path |
string | search | ("*" means all files) |
GetFolderFullPath(string)
Get the full path of given relative folder path
Declaration
public static string GetFolderFullPath(string path)
GetFolderModifyDate(string)
Declaration
public static long GetFolderModifyDate(string path)
GetFullPath(string)
Get the full path of given relative file path
Declaration
public static string GetFullPath(string path)
GetKeyDisplayName(KeyboardKey)
Get display name in English for given keyboard key
Declaration
public static string GetKeyDisplayName(KeyboardKey key)
GetLanguageDisplayName(string)
Get display name of the given language in it's native language
Declaration
public static string GetLanguageDisplayName(string iso)
Parameters
Type | Name | Description |
---|---|---|
string | iso | ISO of the language (eg. "en" for English, "zht" for Chinese Traditional, "de" for German) |
Returns
Type | Description |
---|---|
string | Result name. Return empty string when iso not valid. |
GetLanguageDisplayNameInEnglish(string)
Get display name of the given language in English
Declaration
public static string GetLanguageDisplayNameInEnglish(string iso)
Parameters
Type | Name | Description |
---|---|---|
string | iso | ISO of the language (eg. "en" for English, "zht" for Chinese Traditional, "de" for German) |
Returns
Type | Description |
---|---|
string | Result name. Return empty string when iso not valid. |
GetLongTime()
Get FileTimeUTC from UtcNow
Declaration
public static long GetLongTime()
GetNameWithExtension(string)
Get file/folder name with extension
Declaration
public static string GetNameWithExtension(string path)
GetNameWithoutExtension(string)
Get file/folder name without extension
Declaration
public static string GetNameWithoutExtension(string path)
GetParentPath(string)
Get the parent full path of the given file/folder
Declaration
public static string GetParentPath(string path)
GetProperty(Type, string)
Get PropertyInfo of the given type and name
Declaration
public static PropertyInfo GetProperty(Type type, string name)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of class that holds the property |
string | name | Name of the property |
Returns
Type | Description |
---|---|
PropertyInfo | Instance of the PropertyInfo |
GetPropertyValue(object, string)
Get current value of a property
Declaration
public static object GetPropertyValue(object target, string name)
Parameters
Type | Name | Description |
---|---|---|
object | target | Instance that holds the property |
string | name | Name of the property |
Returns
Type | Description |
---|---|
object | Value of the property |
GetStaticFieldType(Type, string)
Get what type of data the given static field holds
Declaration
public static Type GetStaticFieldType(Type type, string name)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of class that holds the field |
string | name | Name of the field |
Returns
Type | Description |
---|---|
Type | System.Type that this field holds |
GetStaticFieldValue(Type, string)
Get value of the given static field
Declaration
public static object GetStaticFieldValue(Type type, string name)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of class that holds the field |
string | name | Name of the field |
Returns
Type | Description |
---|---|
object | Value of the field |
GetStaticPropertyValue(Type, string)
Get current value of a static property
Declaration
public static object GetStaticPropertyValue(Type type, string name)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of the class that holds the property |
string | name | Name of the property |
Returns
Type | Description |
---|---|
object | Value of the property |
GetTimeString()
Get a string for current date and time
Declaration
public static string GetTimeString()
GetTrimedPixels(in Color32[], int, int, out int, out int, out int, out int)
Trim the clear pixels for the given pixels and create a new instance for the result
Declaration
public static Color32[] GetTrimedPixels(in Color32[] pixels, int width, int height, out int left, out int right, out int down, out int up)
Parameters
Type | Name | Description |
---|---|---|
Color32[] | pixels | Source pixel data. (will not be changed after this operation) |
int | width | Width in pixel |
int | height | Height in pixel |
int | left | Left position that first found a pixel in whole column |
int | right | Right position that first found a pixel in whole column |
int | down | Bottom position that first found a pixel in whole row |
int | up | Top position that first found a pixel in whole row |
Returns
Type | Description |
---|---|
Color32[] | New instance of pixel data created |
GetUrl(string)
Get the AbsoluteUri of the given path
Declaration
public static string GetUrl(string path)
GreatestCommonFactor(int, int)
Get the Greatest-Common-Factor
Declaration
public static int GreatestCommonFactor(int a, int b)
HasFileIn(string, bool, string)
True if there's any file match the pattern
Declaration
public static bool HasFileIn(string path, bool topOnly, string searchPattern)
Parameters
Type | Name | Description |
---|---|---|
string | path | Root folder path |
bool | topOnly | True if only search top level of the folder |
string | searchPattern | ("" means all files, ".txt" means all txt files) |
HasFileIn(string, bool, params string[])
True if there's any file match any of the patterns
Declaration
public static bool HasFileIn(string path, bool topOnly, params string[] searchPattern)
Parameters
Type | Name | Description |
---|---|---|
string | path | Root folder path |
bool | topOnly | True if only search top level of the folder |
string[] | searchPattern | ("" means all files, ".txt" means all txt files) |
HsvToRgb(float, float, float)
Convert Hue-Saturation-Value into Red-Green-Blue.
Declaration
public static Color32 HsvToRgb(float h, float s, float v)
Parameters
Type | Name | Description |
---|---|---|
float | h | Range: 0-1 |
float | s | Range: 0-1 |
float | v | Range: 0-1 |
HsvToRgbF(float, float, float)
Convert Hue-Saturation-Value into Red-Green-Blue.
Declaration
public static ColorF HsvToRgbF(float h, float s, float v)
Parameters
Type | Name | Description |
---|---|---|
float | h | Range: 0-1 |
float | s | Range: 0-1 |
float | v | Range: 0-1 |
HtmlToColor(string, out Color32)
Get color from given html string. Works both with and without "#" at start
Declaration
public static bool HtmlToColor(string html, out Color32 color)
IntToColor(int)
Convert intager value into color
Declaration
public static Color32 IntToColor(int i)
InverseLerp(float, float, float)
Remap "value" between ("from" and "to") into (0 and 1)
Declaration
public static float InverseLerp(float from, float to, float value)
InverseLerpUnclamped(float, float, float)
Remap "value" between ("from" and "to") into (0 and 1)
Declaration
public static float InverseLerpUnclamped(float from, float to, float value)
InvokeAllStaticMethodWithAttribute<A>()
Invoke all static method from all classes that with given attribute attached on
Declaration
public static void InvokeAllStaticMethodWithAttribute<A>() where A : Attribute
Type Parameters
Name | Description |
---|---|
A | Type of the attribute |
InvokeAllStaticMethodWithAttribute<A>(Comparison<KeyValuePair<MethodInfo, A>>)
Invoke all static method from all classes that with given attribute attached on
Declaration
public static void InvokeAllStaticMethodWithAttribute<A>(Comparison<KeyValuePair<MethodInfo, A>> comparison) where A : Attribute
Parameters
Type | Name | Description |
---|---|---|
Comparison<KeyValuePair<MethodInfo, A>> | comparison | Sort the list with this cmoparison |
Type Parameters
Name | Description |
---|---|
A | Type of the attribute |
InvokeAllStaticMethodWithAttribute<A>(Func<KeyValuePair<MethodInfo, A>, bool>)
Invoke all static method from all classes that with given attribute attached on
Declaration
public static void InvokeAllStaticMethodWithAttribute<A>(Func<KeyValuePair<MethodInfo, A>, bool> predicte) where A : Attribute
Parameters
Type | Name | Description |
---|---|---|
Func<KeyValuePair<MethodInfo, A>, bool> | predicte | Only invoke the method if this function returns true |
Type Parameters
Name | Description |
---|---|
A | Type of the attribute |
InvokeMethod(object, string, params object[])
Invoke a method from given name and type
Declaration
public static object InvokeMethod(object obj, string methodName, params object[] param)
Parameters
Type | Name | Description |
---|---|---|
object | obj | Instance that holds the method |
string | methodName | Name of the method |
object[] | param | Param of the method |
Returns
Type | Description |
---|---|
object | Return value of the method |
InvokeStaticMethod(Type, string, params object[])
Invoke a static method from given name and type
Declaration
public static object InvokeStaticMethod(Type type, string methodName, params object[] param)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of the class that holds the method |
string | methodName | Name of the static method |
object[] | param | Param of the static method |
Returns
Type | Description |
---|---|
object | Return value of the static method |
IsExistingFileEmpty(string)
True if path refers to existing file and the file is not empty.
Declaration
public static bool IsExistingFileEmpty(string path)
IsHidden(string)
True if the file/folder at path is hidden
Declaration
public static bool IsHidden(string path)
IsPathValid(string)
True if the given path can be an qualified path
Declaration
public static bool IsPathValid(string path)
IsPowerOfTwo(int)
True if the given value is power of two
Declaration
public static bool IsPowerOfTwo(int x)
IsSameDay(long, long)
True if two ticks inside same day
Declaration
public static bool IsSameDay(long timeA, long timeB)
IsSamePath(string, string)
True if the two given paths refers to the same location
Declaration
public static bool IsSamePath(string pathA, string pathB)
IsSupportedLanguageISO(string)
True if the given iso is valid
Declaration
public static bool IsSupportedLanguageISO(string iso)
IsValidForFileName(string)
True if the given string can be a file name.
Declaration
public static bool IsValidForFileName(string content)
LeastCommonMultiple(int, int)
Get the Least-Common-Multiple
Declaration
public static int LeastCommonMultiple(int a, int b)
Lerp(float, float, float)
Remap value "t" between (0 and 1) into ("a" and "b")
Declaration
public static float Lerp(float a, float b, float t)
LerpAngle(float, float, float)
Remap angle value "t" between (0 and 1) into ("a" and "b")
Declaration
public static float LerpAngle(float a, float b, float t)
LerpAngleUnclamped(float, float, float)
Remap angle value "t" between (0 and 1) into ("a" and "b")
Declaration
public static float LerpAngleUnclamped(float a, float b, float t)
LerpUnclamped(float, float, float)
Remap value "t" between (0 and 1) into ("a" and "b")
Declaration
public static float LerpUnclamped(float a, float b, float t)
Max(int, int)
Return the bigger value
Declaration
public static int Max(int a, int b)
Max(int, int, int)
Return the biggest value
Declaration
public static int Max(int a, int b, int c)
Max(float, float)
Return the bigger value
Declaration
public static float Max(float a, float b)
MergeColor(Color32, Color32)
Draw color "top" onto "back" with no special blending
Declaration
public static Color32 MergeColor(Color32 top, Color32 back)
MergeColor(ColorF, ColorF)
Draw color "top" onto "back" with no special blending
Declaration
public static ColorF MergeColor(ColorF top, ColorF back)
MergeColor_Editor(Color32, Color32)
Draw color "top" onto "back" with blending for sprite editing
Declaration
public static Color32 MergeColor_Editor(Color32 top, Color32 back)
MergeColor_Lerp(Color32, Color32)
Draw color "top" onto "back" with blending lerp
Declaration
public static Color32 MergeColor_Lerp(Color32 top, Color32 back)
MergeColor_Lerp(ColorF, ColorF)
Draw color "top" onto "back" with blending lerp
Declaration
public static ColorF MergeColor_Lerp(ColorF top, ColorF back)
MergeColor_Overlay(Color32, Color32)
Draw color "top" onto "back" with blending overlay
Declaration
public static Color32 MergeColor_Overlay(Color32 top, Color32 back)
MergeColor_Overlay(ColorF, ColorF)
Draw color "top" onto "back" with blending overlay
Declaration
public static ColorF MergeColor_Overlay(ColorF top, ColorF back)
Min(int, int)
Return the smaller value
Declaration
public static int Min(int a, int b)
Min(int, int, int)
Return the smallest value
Declaration
public static int Min(int a, int b, int c)
Min(float, float)
Return the smaller value
Declaration
public static float Min(float a, float b)
MoveFile(string, string)
Move file from one path to other. Use this function to rename files.
Declaration
public static bool MoveFile(string from, string to)
Returns
Type | Description |
---|---|
bool | True if successfuly moved |
MoveFolder(string, string)
Move folder from one path to other. Use this function to rename folder.
Declaration
public static bool MoveFolder(string from, string to)
Returns
Type | Description |
---|---|
bool | True if successfuly moved |
OverlapRectCircle(int, int, int, int, int, int, int)
True if given rectangle and circle overlaps
Declaration
public static bool OverlapRectCircle(int radius, int circleX, int circleY, int minX, int minY, int maxX, int maxY)
PathIsFolder(string)
True is the given path refers to an exist folder instead of file
Declaration
public static bool PathIsFolder(string path)
Path_to_ArgPath(string)
Declaration
public static string Path_to_ArgPath(string path)
PingPong(float, float)
Make value "t" liner oscillate between 0 and "length"
Declaration
public static float PingPong(float t, float length)
PointInTriangle(Float2, Float2, Float2, Float2)
True if the given point "p" is inside given triangle "a,b,c"
Declaration
public static bool PointInTriangle(Float2 p, Float2 a, Float2 b, Float2 c)
PointInTriangle(float, float, float, float, float, float, float, float)
True if the given point "p" is inside given triangle "a,b,c"
Declaration
public static bool PointInTriangle(float px, float py, float p0x, float p0y, float p1x, float p1y, float p2x, float p2y)
PointLine_Distance(Float2, Float2, Float2, out Float2)
Get distance between given point "pt" and line "p1,p2"
Declaration
public static float PointLine_Distance(Float2 pt, Float2 p1, Float2 p2, out Float2 closest)
Closest point on the line
Pow(float, float)
Return "f" to the power of "p"
Declaration
public static float Pow(float f, float p)
ProjectOnPlaneVector3(Float3, Float3)
Projects a vector onto a plane
Declaration
public static Float3 ProjectOnPlaneVector3(Float3 vector, Float3 planeNormal)
ProjectVector3(Float3, Float3)
Projects a vector onto another vector
Declaration
public static Float3 ProjectVector3(Float3 vector, Float3 onNormal)
QuickRandom()
Get a random int between int.MinValue and int.MaxValue without spending too much CPU resources.
Declaration
public static int QuickRandom()
QuickRandom(int, int)
Get a random int between min and max without spending too much CPU resources. ("min" is Included, "max" is Excluded)
Declaration
public static int QuickRandom(int min, int max)
QuickRandomColor(int, int, int, int, int, int, int, int)
Get a random color without spending too much CPU resources
Declaration
public static Color32 QuickRandomColor(int minH = 0, int maxH = 360, int minS = 0, int maxS = 100, int minV = 0, int maxV = 100, int minA = 0, int maxA = 255)
Parameters
Type | Name | Description |
---|---|---|
int | minH | (from 0 to 360) |
int | maxH | (from 0 to 360) |
int | minS | (from 0 to 100) |
int | maxS | (from 0 to 100) |
int | minV | (from 0 to 100) |
int | maxV | (from 0 to 100) |
int | minA | (from 0 to 255) |
int | maxA | (from 0 to 255) |
QuickRandomSign()
Get a random int which is -1 or 1 without spending too much CPU resources
Declaration
public static int QuickRandomSign()
QuickRandomWithSeed(int)
Get a random int between int.MinValue and int.MaxValue without spending too much CPU resources.
Declaration
public static int QuickRandomWithSeed(int seed)
Parameters
Type | Name | Description |
---|---|---|
int | seed | Same seed always return same result |
QuickRandomWithSeed(int, int, int)
Get a random int between min and max without spending too much CPU resources. ("min" is Included, "max" is Excluded)
Declaration
public static int QuickRandomWithSeed(int seed, int min, int max)
Parameters
Type | Name | Description |
---|---|---|
int | seed | Same seed always return same result |
QuickRandomWithSeed(long)
Get a random int between int.MinValue and int.MaxValue without spending too much CPU resources. ("min" is Included, "max" is Excluded)
Declaration
public static int QuickRandomWithSeed(long seed)
Parameters
Type | Name | Description |
---|---|---|
long | seed | Same seed always return same result |
QuickRandomWithSeed(long, int, int)
Get a random int between min and max without spending too much CPU resources. ("min" is Included, "max" is Excluded)
Declaration
public static int QuickRandomWithSeed(long seed, int min, int max)
Parameters
Type | Name | Description |
---|---|---|
long | seed | Same seed always return same result |
QuickSort<T>(Span<T>, int, int, IComparer<T>)
Sort the given array with QuickSort algorithm.
Declaration
public static void QuickSort<T>(Span<T> array, int min, int max, IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
Span<T> | array | The array data |
int | min | Index range left (included) |
int | max | Index range right (included) |
IComparer<T> | comparer | Comparer instance to comparer the array element |
Type Parameters
Name | Description |
---|---|
T | Type of the array |
QuickSort<T>(T[], int, int, IComparer<T>)
Sort the given array with QuickSort algorithm.
Declaration
public static void QuickSort<T>(T[] array, int min, int max, IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array data |
int | min | Index range left (included) |
int | max | Index range right (included) |
IComparer<T> | comparer | Comparer instance to comparer the array element |
Type Parameters
Name | Description |
---|---|
T | Type of the array |
ReadBool(ref byte*)
Declaration
public static bool ReadBool(ref byte* p)
ReadBool(ref byte*, byte*)
Declaration
public static bool ReadBool(ref byte* p, byte* end)
ReadByte(ref byte*)
Declaration
public static byte ReadByte(ref byte* p)
ReadByte(ref byte*, byte*)
Declaration
public static byte ReadByte(ref byte* p, byte* end)
ReadBytes(ref byte*, int)
Declaration
public static byte[] ReadBytes(ref byte* p, int length)
ReadBytes(ref byte*, int, byte*)
Declaration
public static byte[] ReadBytes(ref byte* p, int length, byte* end)
ReadChar(ref byte*)
Declaration
public static char ReadChar(ref byte* p)
ReadChar(ref byte*, byte*)
Declaration
public static char ReadChar(ref byte* p, byte* end)
ReadDouble(ref byte*)
Declaration
public static double ReadDouble(ref byte* p)
ReadDouble(ref byte*, byte*)
Declaration
public static double ReadDouble(ref byte* p, byte* end)
ReadFloat(ref byte*)
Declaration
public static float ReadFloat(ref byte* p)
ReadFloat(ref byte*, byte*)
Declaration
public static float ReadFloat(ref byte* p, byte* end)
ReadInt(ref byte*)
Declaration
public static int ReadInt(ref byte* p)
ReadInt(ref byte*, byte*)
Declaration
public static int ReadInt(ref byte* p, byte* end)
ReadLong(ref byte*)
Declaration
public static long ReadLong(ref byte* p)
ReadLong(ref byte*, byte*)
Declaration
public static long ReadLong(ref byte* p, byte* end)
ReadSByte(ref byte*)
Declaration
public static sbyte ReadSByte(ref byte* p)
ReadSByte(ref byte*, byte*)
Declaration
public static sbyte ReadSByte(ref byte* p, byte* end)
ReadShort(ref byte*)
Declaration
public static short ReadShort(ref byte* p)
ReadShort(ref byte*, byte*)
Declaration
public static short ReadShort(ref byte* p, byte* end)
ReadUInt(ref byte*)
Declaration
public static uint ReadUInt(ref byte* p)
ReadUInt(ref byte*, byte*)
Declaration
public static uint ReadUInt(ref byte* p, byte* end)
ReadULong(ref byte*)
Declaration
public static ulong ReadULong(ref byte* p)
ReadULong(ref byte*, byte*)
Declaration
public static ulong ReadULong(ref byte* p, byte* end)
ReadUShort(ref byte*)
Declaration
public static ushort ReadUShort(ref byte* p)
ReadUShort(ref byte*, byte*)
Declaration
public static ushort ReadUShort(ref byte* p, byte* end)
ReadXML<T>(string)
Declaration
public static T ReadXML<T>(string path) where T : class
ReflectVector2(Float2, Float2)
Reflects a vector off the surface defined by a normal.
Declaration
public static Float2 ReflectVector2(Float2 inDirection, Float2 inNormal)
ReflectVector3(Float3, Float3)
Reflects a vector off the surface defined by a normal.
Declaration
public static Float3 ReflectVector3(Float3 inDirection, Float3 inNormal)
Remap(int, int, int, int, int)
Value from one range to another, while maintaining it's relative position within the original range. When "t" is "l", return "newL". When "t" is "r", return "newR". When "t" is something in the middle, it find a point between "newL" and "newR".
Declaration
public static int Remap(int l, int r, int newL, int newR, int t)
Parameters
Type | Name | Description |
---|---|---|
int | l | Left range for t |
int | r | Right range for t |
int | newL | Left range for the result |
int | newR | Right range for the result |
int | t | Original value |
Returns
Type | Description |
---|---|
int | Remaped value |
Remap(float, float, float, float, float)
Value from one range to another, while maintaining it's relative position within the original range. When "t" is "l", return "newL". When "t" is "r", return "newR". When "t" is something in the middle, it find a point between "newL" and "newR".
Declaration
public static float Remap(float l, float r, float newL, float newR, float t)
Parameters
Type | Name | Description |
---|---|---|
float | l | Left range for t |
float | r | Right range for t |
float | newL | Left range for the result |
float | newR | Right range for the result |
float | t | Original value |
Returns
Type | Description |
---|---|
float | Remaped value |
RemapUnclamped(int, int, int, int, int)
Value from one range to another, while maintaining it's relative position within the original range. When "t" is "l", return "newL". When "t" is "r", return "newR". When "t" is something in the middle, it find a point between "newL" and "newR".
Declaration
public static int RemapUnclamped(int l, int r, int newL, int newR, int t)
Parameters
Type | Name | Description |
---|---|---|
int | l | Left range for t |
int | r | Right range for t |
int | newL | Left range for the result |
int | newR | Right range for the result |
int | t | Original value |
Returns
Type | Description |
---|---|
int | Remaped value |
RemapUnclamped(float, float, float, float, float)
Value from one range to another, while maintaining it's relative position within the original range. When "t" is "l", return "newL". When "t" is "r", return "newR". When "t" is something in the middle, it find a point between "newL" and "newR".
Declaration
public static float RemapUnclamped(float l, float r, float newL, float newR, float t)
Parameters
Type | Name | Description |
---|---|---|
float | l | Left range for t |
float | r | Right range for t |
float | newL | Left range for the result |
float | newR | Right range for the result |
float | t | Original value |
Returns
Type | Description |
---|---|
float | Remaped value |
Repeat(float, float)
Make value "t" liner loop between 0 and "length"
Declaration
public static float Repeat(float t, float length)
RgbToGrey(Color32)
Get grey scale of given color. (return between 0 and 1)
Declaration
public static float RgbToGrey(Color32 rgbColor)
RgbToGreyF(ColorF)
Get grey scale of given color. (return between 0 and 1)
Declaration
public static float RgbToGreyF(ColorF rgbColor)
RgbToHsv(Color32, out float, out float, out float)
Convert Red-Green-Blue into Hue-Saturation-Value.
Declaration
public static void RgbToHsv(Color32 rgbColor, out float h, out float s, out float v)
Range: 0-1
Range: 0-1
Range: 0-1
RgbToHsvF(ColorF, out float, out float, out float)
Convert Red-Green-Blue into Hue-Saturation-Value.
Declaration
public static void RgbToHsvF(ColorF rgbColor, out float h, out float s, out float v)
Range: 0-1
Range: 0-1
Range: 0-1
RotateAround(int, int, int, int, int)
Rotate given point (x,y) around point (originX, originY) for given rotation
Declaration
public static Int2 RotateAround(int x, int y, int rotation, int originX, int originY)
Returns
Type | Description |
---|---|
Int2 | Point after rotation |
RoundToInt(float)
Round a float to the nearest integer
Declaration
public static int RoundToInt(float value)
SegmentIntersect(Float2, Float2, Float2, Float2)
If given segment "a1,a2" and "b1,b2" intersects
Declaration
public static Float2? SegmentIntersect(Float2 a1, Float2 a2, Float2 b1, Float2 b2)
Returns
Type | Description |
---|---|
Float2? | Null if not intersect. Return intersection point if intersects |
SegmentRectIntersect(Float2, Float2, FRect)
If given segment "a0,a1" intersect with rectangle "rect"
Declaration
public static (Float2? intersect0, Float2? intersect1) SegmentRectIntersect(Float2 a0, Float2 a1, FRect rect)
Returns
Type | Description |
---|---|
(Float2? intersect0, Float2? intersect1) | Null if not intersect. Return intersection points if intersects |
SetFieldValue(object, string, object)
Set value of the given field
Declaration
public static void SetFieldValue(object target, string name, object value)
Parameters
Type | Name | Description |
---|---|---|
object | target | Instance that holds the field |
string | name | Name of the field |
object | value | Value of the field |
SetFileModifyDate(string, long)
Declaration
public static void SetFileModifyDate(string path, long fileTime)
SetFolderModifyDate(string, long)
Declaration
public static void SetFolderModifyDate(string path, long fileTime)
SetPropertyValue(object, string, object)
Set current value of a property
Declaration
public static void SetPropertyValue(object target, string name, object value)
Parameters
Type | Name | Description |
---|---|---|
object | target | Instance that holds the property |
string | name | Name of the property |
object | value | Value of the property |
SetStaticFieldValue(Type, string, object)
Set value of the given static field
Declaration
public static void SetStaticFieldValue(Type type, string name, object value)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of class that holds the field |
string | name | Name of the field |
object | value | Value of the field |
SetStaticPropertyValue(Type, string, object)
Set current value of a static property
Declaration
public static void SetStaticPropertyValue(Type type, string name, object value)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of class that holds the property |
string | name | Name of the property |
object | value | Value of the property |
Sin(float)
Return sin value for given angle in RAD. Use (degAngle * Util.Deg2Rad) to get the Rad angle.
Declaration
public static float Sin(float radAngle)
Sqrt(float)
Return square root of "f"
Declaration
public static float Sqrt(float f)
SquareDistance(Int2, Int2)
Square of the distance between given two points
Declaration
public static int SquareDistance(Int2 a, Int2 b)
SquareDistance(int, int, int, int)
Square of the distance between given two points
Declaration
public static int SquareDistance(int aX, int aY, int bX, int bY)
SquareDistanceF(float, float, float, float)
Square of the distance between given two points
Declaration
public static float SquareDistanceF(float aX, float aY, float bX, float bY)
TextToFile(string, string, bool)
Save string text into file
Declaration
public static void TextToFile(string data, string path, bool append = false)
True if keep the existing content in the file
TextToFile(string, string, Encoding, bool)
Save string text into file
Declaration
public static void TextToFile(string data, string path, Encoding encoding, bool append = false)
True if keep the existing content in the file
TryGetAttributeFromAllAssemblies<A>()
Get first given attribute from all assemblies if found
Declaration
public static bool TryGetAttributeFromAllAssemblies<A>() where A : Attribute
Returns
Type | Description |
---|---|
bool | True if the attribute is found |
Type Parameters
Name | Description |
---|---|
A | Type of the attribute |
TryGetAttributeFromAllAssemblies<A>(out A)
Get first given attribute from all assemblies if found
Declaration
public static bool TryGetAttributeFromAllAssemblies<A>(out A attribute) where A : Attribute
Parameters
Type | Name | Description |
---|---|---|
A | attribute | Instance of the founded attribute |
Returns
Type | Description |
---|---|
bool | True if the attribute is found |
Type Parameters
Name | Description |
---|---|
A | Type of the attribute |
TryGetIntFromString(string, int, out int, out int)
Declaration
public static bool TryGetIntFromString(string str, int startIndex, out int value, out int endIndex)
TryGetLanguageDisplayName(string, out string)
Get display name of the given language in it's native language
Declaration
public static bool TryGetLanguageDisplayName(string iso, out string displayName)
Parameters
Type | Name | Description |
---|---|---|
string | iso | ISO of the language (eg. "en" for English, "zht" for Chinese Traditional, "de" for German) |
string | displayName | Result name |
Returns
Type | Description |
---|---|
bool | True if the iso is valid |
TryGetRelativePath(string, string, out string)
Get relative path from given path and root
Declaration
public static bool TryGetRelativePath(string relativeTo, string path, out string relativePath)
Parameters
Type | Name | Description |
---|---|---|
string | relativeTo | The root folder path |
string | path | The target path inside the root |
string | relativePath | Result relative path |
Returns
Type | Description |
---|---|
bool | True if the path successfuly got |
UpdateFile(string, string, bool)
Copy and override target if the modify date is different
Declaration
public static void UpdateFile(string source, string target, bool skipWhenTargetNotExists = false)
True if only override existing file instead of create new file when target not exists.
Write(ref byte*, bool)
Declaration
public static void Write(ref byte* p, bool value)
Write(ref byte*, bool, byte*)
Declaration
public static void Write(ref byte* p, bool value, byte* end)
Write(ref byte*, byte)
Declaration
public static void Write(ref byte* p, byte value)
Write(ref byte*, byte, byte*)
Declaration
public static void Write(ref byte* p, byte value, byte* end)
Write(ref byte*, byte[], int)
Declaration
public static void Write(ref byte* p, byte[] bytes, int length)
Write(ref byte*, byte[], int, byte*)
Declaration
public static void Write(ref byte* p, byte[] bytes, int length, byte* end)
Write(ref byte*, char)
Declaration
public static void Write(ref byte* p, char value)
Write(ref byte*, char, byte*)
Declaration
public static void Write(ref byte* p, char value, byte* end)
Write(ref byte*, double)
Declaration
public static void Write(ref byte* p, double value)
Write(ref byte*, double, byte*)
Declaration
public static void Write(ref byte* p, double value, byte* end)
Write(ref byte*, short)
Declaration
public static void Write(ref byte* p, short value)
Write(ref byte*, short, byte*)
Declaration
public static void Write(ref byte* p, short value, byte* end)
Write(ref byte*, int)
Declaration
public static void Write(ref byte* p, int value)
Write(ref byte*, int, byte*)
Declaration
public static void Write(ref byte* p, int value, byte* end)
Write(ref byte*, long)
Declaration
public static void Write(ref byte* p, long value)
Write(ref byte*, long, byte*)
Declaration
public static void Write(ref byte* p, long value, byte* end)
Write(ref byte*, sbyte)
Declaration
public static void Write(ref byte* p, sbyte value)
Write(ref byte*, sbyte, byte*)
Declaration
public static void Write(ref byte* p, sbyte value, byte* end)
Write(ref byte*, float)
Declaration
public static void Write(ref byte* p, float value)
Write(ref byte*, float, byte*)
Declaration
public static void Write(ref byte* p, float value, byte* end)
Write(ref byte*, ushort)
Declaration
public static void Write(ref byte* p, ushort value)
Write(ref byte*, ushort, byte*)
Declaration
public static void Write(ref byte* p, ushort value, byte* end)
Write(ref byte*, uint)
Declaration
public static void Write(ref byte* p, uint value)
Write(ref byte*, uint, byte*)
Declaration
public static void Write(ref byte* p, uint value, byte* end)
Write(ref byte*, ulong)
Declaration
public static void Write(ref byte* p, ulong value)
Write(ref byte*, ulong, byte*)
Declaration
public static void Write(ref byte* p, ulong value, byte* end)
WritePixelsToConsole(Color32[], int)
Declaration
public static void WritePixelsToConsole(Color32[] pixels, int width)
WriteXML<T>(T, string)
Declaration
public static void WriteXML<T>(T data, string path) where T : class