Infohazard.Core 1.4.1
Infohazard Core Utility Library
Loading...
Searching...
No Matches
Infohazard.Core.Editor.CoreEditorUtility Class Reference

Contains several editor-only utilities. More...

Static Public Member Functions

static object GetValue (this SerializedProperty property)
 Get the value of a SerializedProperty of any type. Does not work for serializable objects or gradients. Enum values are returned as ints. More...
 
static object FindValue (this SerializedProperty prop)
 Find the value of a given property using reflection and reading the field directly. More...
 
static T FindValue< T > (this SerializedProperty prop)
 Find the value of a given property using Reflection and reading the field directly. More...
 
static FieldInfo FindFieldInfo (this SerializedProperty prop)
 Find the FieldInfo of a given property using Reflection and reading the field directly. If the property is an array element, return null. More...
 
static List< string > GetDefinesList (BuildTargetGroup group)
 Get the Unity PlayerSettings list of #define symbols for the given build target. More...
 
static void SetSymbolDefined (string symbol, bool value, BuildTargetGroup group)
 Sets whether the given symbol is defined in the PlayerSettings for the given build target. More...
 
static string GetResourcePath (Object obj)
 Get the path an object lives in relative to a resource folder. More...
 
static string GetResourcePath (string path)
 Get the given path relative to a resource folder. More...
 
static string GetPathRelativeToAssetsFolder (string path)
 Convert the given path to be relative to the Assets folder. More...
 
static void DoLazyDropdown< T > (Rect position, GUIContent content, Func< T[]> optionsFunc, Func< T, string > stringifier, Action< T > setter)
 Create a dropdown button in the IMGUI, whose options will not be calculated until it is clicked. More...
 
static IEnumerable< T > GetAssetsOfType< T > (string folder=null)
 Find all the assets of the given type in the project. More...
 
static IEnumerable< Object > GetAssetsOfType (string type)
 Find all the assets of the given type in the project. More...
 
static string GetTypeName (this SerializedProperty property)
 Get the type full name (including assembly) of the type of the underlying field for the given property. More...
 
static void CopyFrom (this SerializedProperty destination, SerializedObject source)
 Perform a recursive copy of the values from a SerializedObject to a struct-type SerializedProperty. More...
 
static void CopyFrom (this SerializedProperty destination, SerializedProperty source)
 Perform a recursive copy of the values from one SerializedProperty to another. For compound types, values in one of the properties but not the other are ignored. More...
 
static Type GetFieldType (this PropertyDrawer drawer)
 Get the type of the field the property drawer is drawing. If the type is an array or list, returns the element type. More...
 
static void EnsureDataFolderExists ()
 Ensure that the DataFolder directory exists in your project, and contains an assembly definition. More...
 
static bool ExecuteProcess (string command, string args, bool showMessages)
 Launch an external process using the given command and arguments, and wait for it to complete. More...
 
static GameObject InstantiatePrefabInScene (string path, string name)
 Instantiate the given prefab in the scene, as a child of the selected GameObject if there is one. More...
 
static GameObject CreateGameObjectInScene (string name)
 Create an empty GameObject in the scene, as a child of the selected GameObject if there is one. More...
 
static T CreateGameObjectInSceneWithComponent< T > (string name)
 Create a GameObject in the scene with a given component, as a child of the selected GameObject if there is one. More...
 
static Object CreateAndSaveNewAsset (string name, Type type, string defaultSavePath, Object copyObject=null, Object parentObject=null, Action< Object, string > saveAction=null)
 Prompts the user to browse for a path to save a new asset at. Upon confirmation, a new asset is created and saved. More...
 

Static Public Attributes

const string DataFolder = "Assets/Infohazard.Core.Data/"
 Folder where all generated files used by the Infohazard libraries should live. More...
 

Detailed Description

Contains several editor-only utilities.

Member Function Documentation

◆ CopyFrom() [1/2]

static void Infohazard.Core.Editor.CoreEditorUtility.CopyFrom ( this SerializedProperty  destination,
SerializedObject  source 
)
static

Perform a recursive copy of the values from a SerializedObject to a struct-type SerializedProperty.

Parameters
destinationDestination property to update. Must by a serializable class or struct.
sourceSource object to read.

◆ CopyFrom() [2/2]

static void Infohazard.Core.Editor.CoreEditorUtility.CopyFrom ( this SerializedProperty  destination,
SerializedProperty  source 
)
static

Perform a recursive copy of the values from one SerializedProperty to another. For compound types, values in one of the properties but not the other are ignored.

Parameters
destinationDestination property to update.
sourceSource property to read.

◆ CreateAndSaveNewAsset()

static Object Infohazard.Core.Editor.CoreEditorUtility.CreateAndSaveNewAsset ( string  name,
Type  type,
string  defaultSavePath,
Object  copyObject = null,
Object  parentObject = null,
Action< Object, string >  saveAction = null 
)
static

Prompts the user to browse for a path to save a new asset at. Upon confirmation, a new asset is created and saved.

By using a custom save action, you can, for example, add the created object to another asset rather than saving to the project directly. If a custom save action is used, the file browser will not be shown.

Parameters
nameThe default filename of the created object.
typeType of object to create.
defaultSavePathDefault path to save the asset.
parentObjectThe object containing the created object (can be null).
saveActionAction to take to save the asset. Can be null for regular asset save.
copyObjectCopy this object to create the new asset (can be null).

◆ CreateGameObjectInScene()

static GameObject Infohazard.Core.Editor.CoreEditorUtility.CreateGameObjectInScene ( string  name)
static

Create an empty GameObject in the scene, as a child of the selected GameObject if there is one.

Parameters
nameName to assign to the object.
Returns
The created GameObject.

◆ CreateGameObjectInSceneWithComponent< T >()

static T Infohazard.Core.Editor.CoreEditorUtility.CreateGameObjectInSceneWithComponent< T > ( string  name)
static

Create a GameObject in the scene with a given component, as a child of the selected GameObject if there is one.

Parameters
nameName to assign to the object.
Template Parameters
TThe type of component to add.
Returns
The created component.
Type Constraints
T :Component 

◆ DoLazyDropdown< T >()

static void Infohazard.Core.Editor.CoreEditorUtility.DoLazyDropdown< T > ( Rect  position,
GUIContent  content,
Func< T[]>  optionsFunc,
Func< T, string >  stringifier,
Action< T >  setter 
)
static

Create a dropdown button in the IMGUI, whose options will not be calculated until it is clicked.

For a normal dropdown, you'd need to know all of the options before the button was clicked. With lazy dropdown, they are not evaluated until needed. They are also re-evaluated every time the dropdown is opened, preventing the need for cache invalidation.

Parameters
positionPosition to draw the dropdown button.
contentCurrent value to show in the dropdown button (when not selected).
optionsFuncFunction that will calculate and return the options.
stringifierFunction that converts options to strings for display.
setterFunction that sets the value when an option is chosen.
Template Parameters
TType of the options before they are converted to strings.

◆ EnsureDataFolderExists()

static void Infohazard.Core.Editor.CoreEditorUtility.EnsureDataFolderExists ( )
static

Ensure that the DataFolder directory exists in your project, and contains an assembly definition.

◆ ExecuteProcess()

static bool Infohazard.Core.Editor.CoreEditorUtility.ExecuteProcess ( string  command,
string  args,
bool  showMessages 
)
static

Launch an external process using the given command and arguments, and wait for it to complete.

Parameters
commandThe command (executable file) to run.
argsThe argument string to pass to the command.
showMessagesWhether to display a dialog box if the command fails.
Returns
Whether the command succeeded.

◆ FindFieldInfo()

static FieldInfo Infohazard.Core.Editor.CoreEditorUtility.FindFieldInfo ( this SerializedProperty  prop)
static

Find the FieldInfo of a given property using Reflection and reading the field directly. If the property is an array element, return null.

Parameters
propThe property to read
Returns
The FieldInfo of the property.

◆ FindValue()

static object Infohazard.Core.Editor.CoreEditorUtility.FindValue ( this SerializedProperty  prop)
static

Find the value of a given property using reflection and reading the field directly.

Parameters
propThe property to read.
Returns
The value of the property.

◆ FindValue< T >()

static T Infohazard.Core.Editor.CoreEditorUtility.FindValue< T > ( this SerializedProperty  prop)
static

Find the value of a given property using Reflection and reading the field directly.

Template Parameters
TThe type to cast the value to.
Parameters
propThe property to read
Returns
The value of the property.

◆ GetAssetsOfType()

static IEnumerable< Object > Infohazard.Core.Editor.CoreEditorUtility.GetAssetsOfType ( string  type)
static

Find all the assets of the given type in the project.

Only assets whose root object is the given type are included.

Parameters
typeThe type name of assets to find. Use the class name only, without namespace.
Returns
A sequence of all the found assets.

◆ GetAssetsOfType< T >()

static IEnumerable< T > Infohazard.Core.Editor.CoreEditorUtility.GetAssetsOfType< T > ( string  folder = null)
static

Find all the assets of the given type in the project.

Only assets whose root object is the given type are included.

Parameters
folderThe folder to search in, or null for the entire project.
Template Parameters
TThe type of asset to find.
Returns
A sequence of all the found assets.
Type Constraints
T :Object 

◆ GetDefinesList()

static List< string > Infohazard.Core.Editor.CoreEditorUtility.GetDefinesList ( BuildTargetGroup  group)
static

Get the Unity PlayerSettings list of #define symbols for the given build target.

Parameters
groupThe build target.
Returns
A list of all defined symbols for that group.

◆ GetFieldType()

static Type Infohazard.Core.Editor.CoreEditorUtility.GetFieldType ( this PropertyDrawer  drawer)
static

Get the type of the field the property drawer is drawing. If the type is an array or list, returns the element type.

Parameters
drawerDrawer to get the type of.
Returns
Type of the drawer's field.

◆ GetPathRelativeToAssetsFolder()

static string Infohazard.Core.Editor.CoreEditorUtility.GetPathRelativeToAssetsFolder ( string  path)
static

Convert the given path to be relative to the Assets folder.

Accepts absolute paths, paths staring with "Assets/", and paths starting with "/"'". </remarks> <param name="path">

Returns

◆ GetResourcePath() [1/2]

static string Infohazard.Core.Editor.CoreEditorUtility.GetResourcePath ( Object  obj)
static

Get the path an object lives in relative to a resource folder.

The result path can be used with Resources.Load.

Parameters
objThe object to get the path for.
Returns
The path relative to a resource folder, or null.

◆ GetResourcePath() [2/2]

static string Infohazard.Core.Editor.CoreEditorUtility.GetResourcePath ( string  path)
static

Get the given path relative to a resource folder.

The result path can be used with Resources.Load.

Parameters
pathThe path to search for.
Returns
The path relative to a resource folder, or null.

◆ GetTypeName()

static string Infohazard.Core.Editor.CoreEditorUtility.GetTypeName ( this SerializedProperty  property)
static

Get the type full name (including assembly) of the type of the underlying field for the given property.

Due to how Unity works, this will not include the namespace. If you need to access the property type from a PropertyDrawer, use PropertyDrawer.fieldInfo.FieldType instead.

Parameters
propertyProperty to get type of.
Returns
Type name of the property's underlying type, without namespace.

◆ GetValue()

static object Infohazard.Core.Editor.CoreEditorUtility.GetValue ( this SerializedProperty  property)
static

Get the value of a SerializedProperty of any type. Does not work for serializable objects or gradients. Enum values are returned as ints.

Parameters
propertyThe property to read.
Returns
The value of the property, or null if not readable.

◆ InstantiatePrefabInScene()

static GameObject Infohazard.Core.Editor.CoreEditorUtility.InstantiatePrefabInScene ( string  path,
string  name 
)
static

Instantiate the given prefab in the scene, as a child of the selected GameObject if there is one.

Parameters
pathPrefab path to load.
nameName to assign to the object, or null.
Returns
The instantiated GameObject.

◆ SetSymbolDefined()

static void Infohazard.Core.Editor.CoreEditorUtility.SetSymbolDefined ( string  symbol,
bool  value,
BuildTargetGroup  group 
)
static

Sets whether the given symbol is defined in the PlayerSettings for the given build target.

Parameters
symbolThe symbol to set.
valueWhether the symbol should be defined.
groupThe build target.

Member Data Documentation

◆ DataFolder

const string Infohazard.Core.Editor.CoreEditorUtility.DataFolder = "Assets/Infohazard.Core.Data/"
static

Folder where all generated files used by the Infohazard libraries should live.

Call EnsureDataFolderExists to make sure this folder exists before using it.


The documentation for this class was generated from the following file: