RuntimeObjectUtility¶
Namespace:
SideXP.Core
Miscellaneous functions for working with Objects and assets at runtime.
Methods¶
GetTransform(Object)¶
Gets the Transform component of an object that can be placed in a scene.
Parameters
obj: The object from which you want to get theTransformcomponent.
Returns
Returns the found Transform component.
GetTransform(Object, Transform)¶
Gets the Transform component of an object that can be placed in a scene.
Parameters
transform: Outputs the foundTransformcomponent.obj: The object from which you want to get theTransformcomponent.
Returns
Returns true if the given object has a Transform component.
GetGameObject(Object)¶
Gets the GameObject to which the given object is attached.
Parameters
obj: The object of which you want to get the attachedGameObject.
Returns
Returns the found attached GameObject.
GetGameObject(Object, GameObject)¶
Gets the GameObject to which the given object is attached.
Parameters
gameObject: Outputs the found attachedGameObject.obj: The object of which you want to get the attachedGameObject.
Returns
Returns true if the given object is attached to a GameObject.
IsPrefab(GameObject)¶
Checks if a GameObject is a prefab at runtime.
Parameters
gameObject: TheGameObjectto check.
Returns
Returns true if the given object is a prefab.
FindObjectFrom(object, Type, string, FFindObjectStrategy)¶
public static Object FindObjectFrom(object origin, Type type, string name = null, FFindObjectStrategy strategy = None)
Finds an Object.
Parameters
origin: The object from which the expected one is queried.type: The type of the expected object.name: If provided, this function will consider only the objects with that exact name.strategy: The strategy to use to find the expected object.
Returns
Returns the found object.
Remarks
By default the strategy None is used. This means the reference is queried using the following rules. If this attribute is used inside a MonoBehaviour script: - If the decorated property is of type GameObject or Component, the reference will be queried in the following order: this game object, its direct children, its direct parent, or the whole scene. - Else, in any other case, the reference will be queried from the whole scene. If this attribute is used inside a ScriptableObject script, the reference will be queried from subassets, or the loaded resources. This default behavior is equivalent as using the value DirectHierarchy|Scene. Special case: if type is GameObject or Component and this function tries to find the object in the scene (using Scene, the name is in fact the expected tag name of the objects. This is counter-intuitive, but using tags in Unity is the expected way to "group" game objects, instead of naming them the same.
FindObjectFrom(object, Type, Object, string, FFindObjectStrategy)¶
public static bool FindObjectFrom(object origin, Type type, out Object obj, string name = null, FFindObjectStrategy strategy = None)
Finds an Object.
Parameters
obj: Outputs the found object.origin: The object from which the expected one is queried.type: The type of the expected object.name: If provided, this function will consider only the objects with that exact name.strategy: The strategy to use to find the expected object.
Returns
Returns true if an object has been found.
Remarks
By default the strategy None is used. This means the reference is queried using the following rules. If this attribute is used inside a MonoBehaviour script: - If the decorated property is of type GameObject or Component, the reference will be queried in the following order: this game object, its direct children, its direct parent, or the whole scene. - Else, in any other case, the reference will be queried from the whole scene. If this attribute is used inside a ScriptableObject script, the reference will be queried from subassets, or the loaded resources. This default behavior is equivalent as using the value DirectHierarchy|Scene. Special case: if type is GameObject or Component and this function tries to find the object in the scene (using Scene, the name is in fact the expected tag name of the objects. This is counter-intuitive, but using tags in Unity is the expected way to "group" game objects, instead of naming them the same.
FindObjectFrom<T>(object, string, FFindObjectStrategy)¶
public static T FindObjectFrom<T>(object origin, string name = null, FFindObjectStrategy strategy = None)
Finds an Object.
Type parameters
T: The type of the expected object.
Parameters
origin: The object from which the expected one is queried.name: If provided, this function will consider only the objects with that exact name.strategy: The strategy to use to find the expected object.
Returns
Returns the found object.
Remarks
By default the strategy None is used. This means the reference is queried using the following rules. If this attribute is used inside a MonoBehaviour script: - If the decorated property is of type GameObject or Component, the reference will be queried in the following order: this game object, its direct children, its direct parent, or the whole scene. - Else, in any other case, the reference will be queried from the whole scene. If this attribute is used inside a ScriptableObject script, the reference will be queried from subassets, or the loaded resources. This default behavior is equivalent as using the value DirectHierarchy|Scene. Special case: if type is GameObject or Component and this function tries to find the object in the scene (using Scene, the name is in fact the expected tag name of the objects. This is counter-intuitive, but using tags in Unity is the expected way to "group" game objects, instead of naming them the same.
FindObjectFrom<T>(object, T, string, FFindObjectStrategy)¶
public static bool FindObjectFrom<T>(object origin, out T obj, string name = null, FFindObjectStrategy strategy = None)
Parameters
obj: Outputs the found object.
Returns
Returns true if an object has been found.
TryOpenAsset(int, int)¶
Invokes registered OpenAssetDelegate handlers to check if one of them can open the asset. WARNING: Since this function resolves the asset by using InstanceIDToObject, it won't do anything outside the editor context.
Parameters
instanceId: The instance id of the asset being opened.line: The target line in the file being opened.
Returns
Returns true if the asset can be opened.
Remarks
This is mostly meant to use OnOpenAssetAttribute without having to implement editor code in your assets, and allowing the custom editors to handle this event easily.
AddOpenAssetHandler(OpenAssetDelegate)¶
Registers a handler for an "open asset" operation.
Parameters
handler: The handler of this operation.