Class Utils
Editor utilities and helper functions.
Inheritance
Namespace: FlaxEditor.Utilities
Assembly: FlaxEngine.CSharp.dll
Syntax
public static class Utils : Object
Fields
FlaxEngineAssemblyName
The name of the Flax Engine C# assembly name.
Declaration
public static readonly string FlaxEngineAssemblyName
Field Value
System.String
|
Methods
ByteArrayToStructure(Byte[], Type)
Converts the raw bytes into the structure. Supported only for structures with simple types and no GC objects.
Declaration
public static object ByteArrayToStructure(byte[] bytes, Type type)
Parameters
System.Byte[]
bytes
The data bytes. |
System.Type
type
The structure type. |
Returns
System.Object
The structure. |
ByteArrayToStructure<T>(Byte[])
Converts the raw bytes into the structure. Supported only for structures with simple types and no GC objects.
Declaration
public static T ByteArrayToStructure<T>(byte[] bytes)
where T : struct, ValueType
Parameters
System.Byte[]
bytes
The data bytes. |
Returns
T
The structure. |
Type Parameters
T
The structure type. |
ByteArrayToStructure<T>(Byte[], out T)
Converts the raw bytes into the structure. Supported only for structures with simple types and no GC objects.
Declaration
public static void ByteArrayToStructure<T>(byte[] bytes, out T result)
where T : struct, ValueType
Parameters
System.Byte[]
bytes
The data bytes. |
T
result
The result. |
Type Parameters
T
The structure type. |
CreateSearchPopup(out TextBox, out Tree, Single, Boolean)
Creates the search popup with a tree.
Declaration
public static ContextMenuBase CreateSearchPopup(out TextBox searchBox, out Tree tree, float headerHeight = 0F, bool autoSearch = false)
Parameters
TextBox
searchBox
The search box. |
FlaxEditor.GUI.Tree.Tree
tree
The tree control. |
System.Single
headerHeight
Amount of additional space above the search box to put custom UI. |
System.Boolean
autoSearch
Plug automatic tree search delegate. |
Returns
FlaxEditor.GUI.ContextMenu.ContextMenuBase
The created menu to setup and show. |
DirectoryCopy(String, String, Boolean, Boolean)
Copies the directory. Supports subdirectories copy with files override option.
Declaration
public static void DirectoryCopy(string srcDirectoryPath, string dstDirectoryPath, bool copySubDirs = true, bool overrideFiles = false)
Parameters
System.String
srcDirectoryPath
The source directory path. |
System.String
dstDirectoryPath
The destination directory path. |
System.Boolean
copySubDirs
If set to |
System.Boolean
overrideFiles
if set to |
FormatBytesCount(Int32)
Formats the amount of bytes to get a human-readable data size in bytes with abbreviation. Eg. 32 kB [Deprecated in v1.9]
Declaration
public static string FormatBytesCount(int bytes)
Parameters
System.Int32
bytes
The bytes. |
Returns
System.String
The formatted amount of bytes. |
FormatBytesCount(UInt64)
Formats the amount of bytes to get a human-readable data size in bytes with abbreviation. Eg. 32 kB
Declaration
public static string FormatBytesCount(ulong bytes)
Parameters
System.UInt64
bytes
The bytes. |
Returns
System.String
The formatted amount of bytes. |
FormatFloat(Double)
Formats the floating point value (single precision) into the readable text representation.
Declaration
public static string FormatFloat(double value)
Parameters
System.Double
value
The value. |
Returns
System.String
The text representation. |
FormatFloat(Double, Utils.ValueCategory)
Format a double value either as-is, with a distance unit or with a degree sign
Declaration
public static string FormatFloat(double value, Utils.ValueCategory category)
Parameters
System.Double
value
The value to format. |
Utils.ValueCategory
category
The value type: none means just a number, distance will format in cm/m/km, angle with an appended degree sign. |
Returns
System.String
The formatted string. |
FormatFloat(Single)
Formats the floating point value (double precision) into the readable text representation.
Declaration
public static string FormatFloat(float value)
Parameters
System.Single
value
The value. |
Returns
System.String
The text representation. |
FormatFloat(Single, Utils.ValueCategory)
Format a float value either as-is, with a distance unit or with a degree sign.
Declaration
public static string FormatFloat(float value, Utils.ValueCategory category)
Parameters
System.Single
value
The value to format. |
Utils.ValueCategory
category
The value type: none means just a number, distance will format in cm/m/km, angle with an appended degree sign. |
Returns
System.String
The formatted string. |
GetAssetNamePath(String)
Gets the asset name relative to the project root folder (without asset file extension)
Declaration
public static string GetAssetNamePath(string path)
Parameters
System.String
path
The asset path. |
Returns
System.String
The processed name path. |
GetAssetNamePathWithExt(String)
Gets the asset name relative to the project root folder (with asset file extension)
Declaration
public static string GetAssetNamePathWithExt(string path)
Parameters
System.String
path
The asset path. |
Returns
System.String
The processed name path. |
GetPropertyNameUI(String)
Gets the property name for UI. Removes unnecessary characters and filters text. Makes it more user-friendly.
Declaration
public static string GetPropertyNameUI(string name)
Parameters
System.String
name
The name. |
Returns
System.String
The result. |
HasInvalidPathChar(String)
Determines whether the specified path string contains any invalid character.
Declaration
public static bool HasInvalidPathChar(string path)
Parameters
System.String
path
The path. |
Returns
System.Boolean
|
IncrementNameNumber(String, Func<String, Boolean>)
Tries to parse number in the name brackets at the end of the value and then increment it to create a new name. Supports numbers at the end without brackets.
Declaration
public static string IncrementNameNumber(string name, Func<string, bool> isValid)
Parameters
System.String
name
The input name. |
System.Func<System.String, System.Boolean>
isValid
Custom function to validate the created name. |
Returns
System.String
The new name. |
InitDefaultValues(Object)
Initializes the object fields and properties with their default values based on System.ComponentModel.DefaultValueAttribute.
Declaration
public static void InitDefaultValues(object obj)
Parameters
System.Object
obj
The object. |
RayCastWire(ref OrientedBoundingBox, ref Ray, out Single, ref Vector3)
Checks if given ray intersects with the oriented bounding wire box.
Declaration
public static bool RayCastWire(ref OrientedBoundingBox box, ref Ray ray, out float distance, ref Vector3 viewPosition)
Parameters
OrientedBoundingBox
box
The box. |
Ray
ray
The ray. |
System.Single
distance
The result intersection distance. |
Vector3
viewPosition
The view position used to scale the wires thickness depending on the wire distance from the view. |
Returns
System.Boolean
True ray hits bounds, otherwise false. |
RemoveFileIfExists(String)
Removes the file if it exists.
Declaration
public static void RemoveFileIfExists(string file)
Parameters
System.String
file
The file path. |
SetupCommonInputActions(EditorWindow)
Binds global input actions for the window.
Declaration
public static void SetupCommonInputActions(EditorWindow window)
Parameters
EditorWindow
window
The editor window. |
ShowSourceCodeWindow(String, String, Window)
Shows the source code window.
Declaration
public static void ShowSourceCodeWindow(string source, string title, Window parentWindow = null)
Parameters
System.String
source
The source code. |
System.String
title
The window title. |
Window
parentWindow
The optional parent window. |
StructureToByteArray(Object, Type)
Converts the structure to the raw bytes. Supported only for structures with simple types and no GC objects.
Declaration
public static byte[] StructureToByteArray(object value, Type type)
Parameters
System.Object
value
The structure value. |
System.Type
type
The structure type. |
Returns
System.Byte[]
The bytes array that contains a structure data. |
StructureToByteArray<T>(ref T)
Converts the structure to the raw bytes. Supported only for structures with simple types and no GC objects.
Declaration
public static byte[] StructureToByteArray<T>(ref T value)
where T : struct, ValueType
Parameters
T
value
The structure value. |
Returns
System.Byte[]
The bytes array that contains a structure data. |
Type Parameters
T
The structure type. |
UpdateSearchPopupFilter(Tree, String)
Updates (recursively) search popup tree structures based on the filter text.
Declaration
public static void UpdateSearchPopupFilter(Tree tree, string filterText)
Parameters
FlaxEditor.GUI.Tree.Tree
tree
|
System.String
filterText
|
UpdateSearchPopupFilter(TreeNode, String)
Updates (recursively) search popup tree structures based on the filter text.
Declaration
public static void UpdateSearchPopupFilter(TreeNode node, string filterText)
Parameters
FlaxEditor.GUI.Tree.TreeNode
node
|
System.String
filterText
|