ObjectExtensions¶
Namespace:
SideXP.Core.EditorOnly
Miscellaneous extension functions for Object and assets.
Methods¶
GetGUID(Object)¶
Gets the GUID string of the given Object. Note that GUIDs are assigned only to assets, not to scene objects. So if this Object is a scene object or an object loaded only in memory, this function will return null.
Parameters
obj: TheObjectwhose GUID you want to get.
Returns
Returns the GUID string of this Object, or null if this Object is not an asset (meaning it's a scene object or an object loaded only in memory).
IsAsset(Object)¶
Checks if the given Object is an asset (and not a scene object).
Parameters
obj: TheObjectyou want to check.
Returns
Returns true if the given Object is an asset.
GetUniqueAssetName(Object, string)¶
Gets the unique name of an asset to create in the same directory than the given one.
Parameters
asset: The asset you want to process.expectedName: The name you want to set on the asset.
Returns
Returns the processed unique asset name.
GetAssetPath(Object)¶
Gets the relative path to the given asset from the root directory of the current Unity project.
Parameters
asset: The asset of which you want to get the path.
Returns
Returns the found relative asset path, or null if the given asset is not an asset.
GetAbsoluteAssetPath(Object)¶
Gets the absolute path to the given asset.
Returns
Returns the found absolute asset path, or null if the asset is not an asset.
FindSubassetOfType(Object, Type, bool)¶
Gets the first subasset of the given type in the given main asset.
Parameters
asset: The main asset of which you want to get the subasset.type: The expected type of the subasset.includeMainAsset: If enabled, if the main asset has the expected type, it's the one being returned.
Returns
Returns the found subasset with the expected type.
FindSubassetOfType<T>(Object, bool)¶
Type parameters
T: The expected type of the subasset.
FindAllSubassetsOfType(Object, Type, bool)¶
public static Object[] FindAllSubassetsOfType(Object asset, Type type, bool includeMainAsset = false)
Gets the subassets of the given type in the given main asset.
Parameters
asset: The main asset of which you want to get the subassets.type: The expected type of the subassets.includeMainAsset: If enabled, if the main asset has the expected type, it's included in the returned array.
Returns
Returns the found subassets with the expected type.
FindAllSubassetsOfType<T>(Object, bool)¶
Type parameters
T: The expected type of the subassets.
GetMainAsset(Object)¶
Gets the main asset of a given one.
Parameters
asset: The asset from which you want to get the main assset.
Returns
Returns the found main asset, or the given asset itself if it's not a subasset.
FindAssetInHierarchy(Object, Type)¶
Finds an asset of a given type in the hierarchy of a given asset, whether it's the main asset or a subasset.
Parameters
asset: The asset of which you want to inspect the hierarchy.assetType: The type of the asset to find.
Returns
Returns the found asset.
FindAssetInHierarchy(Object, Type, Object)¶
Parameters
foundAsset: Outputs the found asset.
Returns
Returns true if an asset has been found.
FindAssetInHierarchy<T>(Object)¶
Type parameters
T: The type of the asset to find.
FindAssetInHierarchy<T>(Object, T)¶
Inherited documentation.
AttachObject(Object, Object, bool)¶
Attaches an object to an existing asset, and perform the appropriate operations to avoid inconsistent states and refresh views accordingly.
Parameters
asset: The asset to which you want to attach the object.objectToAttach: The object to attach to the asset. Note that this object must not be an asset of the project, only an instance yet not serialized.skipReimport: By default, the modified asset is reimported to save changes on disk. If disabled, you must save and reimport the asset by yourself.
Returns
Returns true if the object has been attached successfully to the asset.
CreateSubasset(Object, Type, string)¶
Creates and attaches a subasset to an existing asset.
Parameters
subAssetType: The type of the subasset to create.asset: The asset to which the created subasset will be attached.name: The name of the subasset to create. If undefined, uses New[subasset type name].
Returns
Returns the created subasset.
CreateSubasset(Object, Type, ScriptableObject, string)¶
public static bool CreateSubasset(Object asset, Type subAssetType, out ScriptableObject subAsset, string name = null)
Parameters
subAsset: Outputs the created subasset.
Returns
Returns true if the subasset has been created and attached successfully.
CreateSubasset<TSubasset>(Object, string)¶
Type parameters
TSubasset: The type of the subasset to create.
CreateSubasset<TSubasset>(Object, TSubasset, string)¶
public static bool CreateSubasset<TSubasset>(Object asset, out TSubasset subAsset, string name = null)
Inherited documentation.
IsSubasset(Object)¶
Checks if a given object is a sub-asset.
Parameters
obj: The object you want to check.
Returns
Returns true if the given object is a sub-asset.
IsSubassetOf(Object, Object)¶
Checks if a given object is a sub-asset of a given asset.
Parameters
container: The expected main asset.
Returns
Returns true if the given object is a sub-asset of the given container.
SaveAndReimport(Object)¶
Reimports the given asset. You should call this function after adding, updating or removing a subasset.
Parameters
asset: The asset you want to save and reimport.
Returns
Returns true if the given object is truly an asset in the project.
Rename(Object, string, bool)¶
Renames a given asset.
Parameters
obj: The asset to rename. If the given object is not an asset saved on disk, this function still renames it but it won't save it on disk.name: The new name of the asset.
Remarks
This function also works fine with subassets, unlike RenameAsset, which only works with main assets.