Class EditorUtils
Utility methods for use in the Editor
Namespace: Unity.XRTools.Utils
Syntax
public static class EditorUtils
Methods
ConsumeMouseInput()
Consumes mouse input events. Call this at the end of a GUI window draw function to block clicking on controls behind the window.
Declaration
public static void ConsumeMouseInput()
GetActiveSceneAsset()
Get the SceneAsset representing the active scene
Declaration
public static SceneAsset GetActiveSceneAsset()
Returns
Type | Description |
---|---|
SceneAsset | The active SceneAsset |
GetAssetPreview(Object, Action<Texture>)
Tries to get an asset preview. If one is not available, waits until IsLoadingAssetPreview is false, and if preview is still not loaded, returns the result of AssetPreview.GetMiniThumbnail
Declaration
public static IEnumerator GetAssetPreview(Object asset, Action<Texture> callback)
Parameters
Type | Name | Description |
---|---|---|
Object | asset | The asset for which to get a preview |
Action<Texture> | callback | Called with the preview texture as an argument, when it is available |
Returns
Type | Description |
---|---|
IEnumerator | An enumerator used to tick the corutine |
GetFieldInfoFromProperty(SerializedProperty)
Get the FieldInfo which backs a property
Declaration
public static FieldInfo GetFieldInfoFromProperty(SerializedProperty property)
Parameters
Type | Name | Description |
---|---|---|
SerializedProperty | property | The property from which to get FieldInfo |
Returns
Type | Description |
---|---|
FieldInfo | The FieldInfo which backs the property |
GetMemberAttributes(SerializedProperty)
Get attributes from the field which represents a property
Declaration
public static Attribute[] GetMemberAttributes(SerializedProperty property)
Parameters
Type | Name | Description |
---|---|---|
SerializedProperty | property | The property from which to get attributes |
Returns
Type | Description |
---|---|
Attribute[] | Array of attributes from property |
GetMemberInfoFromPropertyPath(Type, String, out Type)
Get MemberInfo for a property by path
Declaration
public static MemberInfo GetMemberInfoFromPropertyPath(Type host, string path, out Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | host | The type of the container object |
String | path | The property path to search for |
Type | type | The type of the property at path |
Returns
Type | Description |
---|---|
MemberInfo | The MemberInfo found on the host type at the given path |
GetTooltip(SerializedProperty)
Gets the tooltip of the property. This is a workaround for a bug where SerializedProperty.tooltip always returns an empty string: https://issuetracker.unity3d.com/issues/when-using-custom-propertydrawers-the-tooltip-field-of-the-serializedproperty-is-always-empty
Declaration
public static string GetTooltip(this SerializedProperty property)
Parameters
Type | Name | Description |
---|---|---|
SerializedProperty | property | The property from which to get a tooltip |
Returns
Type | Description |
---|---|
String | Tooltip specified in the property's TooltipAttribute, if it has one. Otherwise returns an empty string. |
MaskField(Rect, GUIContent, Int32, String[], Type)
Special version of EditorGUI.MaskField which ensures that only the chosen bits are set. We need this version of the function to check explicitly whether only a single bit was set.
Declaration
public static int MaskField(Rect position, GUIContent label, int mask, string[] displayedOptions, Type propertyType)
Parameters
Type | Name | Description |
---|---|---|
Rect | position | Rectangle on the screen to use for this control. |
GUIContent | label | Label for the field. |
Int32 | mask | The current mask to display. |
String[] | displayedOptions | A string array containing the labels for each flag. |
Type | propertyType | The type of the property |
Returns
Type | Description |
---|---|
Int32 | The value modified by the user. |
NicifySerializedPropertyType(String)
Strip PPtr<> and $ from a string for getting a System.Type from SerializedProperty.type
Declaration
public static string NicifySerializedPropertyType(string type)
Parameters
Type | Name | Description |
---|---|---|
String | type | Type string |
Returns
Type | Description |
---|---|
String | Nicified type string |
SerializedPropertyToField(SerializedProperty)
Get the FieldInfo for a given property
Declaration
public static FieldInfo SerializedPropertyToField(SerializedProperty property)
Parameters
Type | Name | Description |
---|---|---|
SerializedProperty | property | The property for which to get the FieldInfo |
Returns
Type | Description |
---|---|
FieldInfo | The FieldInfo for the property |
SerializedPropertyToType(SerializedProperty)
Guess the type of a SerializedProperty
and return a System.Type
, if one exists.
The guess is done by checking the type of the target object and iterating through its fields looking for
one that matches the property name. This may return null if you give it a SerializedProperty
that
represents a native type with no managed equivalent
Declaration
public static Type SerializedPropertyToType(SerializedProperty property)
Parameters
Type | Name | Description |
---|---|---|
SerializedProperty | property | The |
Returns
Type | Description |
---|---|
Type | The best guess type |
ToggleClassIcons(Dictionary<Int32, KeyValuePair<String, Boolean>>)
Enable / disable class icons by class id and script class name
Declaration
public static void ToggleClassIcons(Dictionary<int, KeyValuePair<string, bool>> enabledStates)
Parameters
Type | Name | Description |
---|---|---|
Dictionary<Int32, KeyValuePair<String, Boolean>> | enabledStates | A mapping of class to and script class name to desired enabled state |
ToggleCommonIcons(Boolean, Dictionary<Int32, KeyValuePair<String, Boolean>>)
Enable / disable a number of common class icons in Scene Views
Declaration
public static void ToggleCommonIcons(bool enabled, Dictionary<int, KeyValuePair<string, bool>> classIconEnabledStates)
Parameters
Type | Name | Description |
---|---|---|
Boolean | enabled | whether to enable or disable the icons |
Dictionary<Int32, KeyValuePair<String, Boolean>> | classIconEnabledStates | An empty dictionary to store the previous state of the icons |
TypeNameToType(String)
Search through all assemblies in the current AppDomain for a class that is assignable to UnityObject and matches the given weak name TODO: expose internal SerializedProperty.ValidateObjectReferenceValue to remove his hack
Declaration
public static Type TypeNameToType(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | Weak type name |
Returns
Type | Description |
---|---|
Type | Best guess System.Type |