GameObject and Component extensions
Gizmos and Icon (GizmosUtility in runtime script)
(It is recommended to use GizmosUtility in editor).
SetGizmosVisibility
Sets GizmosVisibility of the object.
GetGizmosVisibility
Gets GizmosVisibility of the object.
SetIconVisibility
Sets IconVisibility of the object.
GetIconVisibility
Gets IconVisibility of the object.
SetIcon, GetIcon, RemoveIcon
Icon in inspector.
public class TestSetIcon : MonoBehaviour {
void Reset() {
gameObject.SetEditorIcon("GameEntity_DamageableIcon");
}
}
GetIcon
Gets the Object icon in inspector.
GetPreview
Returns preview or thumbnail
var p = AssetPreview.GetAssetPreview(obj);
if (p == null) p = AssetPreview.GetMiniThumbnail(obj);
return p;
RemoveIcon
Removes the Object icon in inspector.
Find
Add a recursive option for Transform.Find
.
transform.Find("MyChild", true);
GetOrCreateChild
Creates a gameObject or gameObjects with a path. "myGO1/myGO2/myGO3"
gameObjectOrComponent.GetOrCreateChild("MyChild");
GetOrAddComponent
Gets or adds a component.
gameObjectOrComponent.GetOrAddComponent<MyComponent>();
RemoveComponent
Remove a component. Destroy or DestroyImmediate in editor mode.
gameObjectOrComponent.RemoveComponent<MyComponent>();
RemoveComponents
Remove a component. Destroy or DestroyImmediate in editor mode.
gameObjectOrComponent.RemoveComponents<MyComponent>();
SafeDestroy
Safe version of Destroy (making it usable in the editor)
gameObjectOrComponent.SafeDestroy([withUndo=false]);
GetComponentInParents
Returns the first component in parents
gameObjectOrComponent.GetComponentInParents<MyComponent>([cond]);
GetComponentsInParents
Returns a list of components in parents
gameObjectOrComponent.GetComponentsInParents<MyComponent>([cond]);
LastComponentInParents
Returns the highest component found in parents
gameObjectOrComponent.LastComponentInParents<MyComponent>([cond]);
SetAllChildrenActive
Enable/Disable children (not recursively)
gameObject.SetAllChildrenActive(false);
SetLayer
Alias of gameObject.layer = LayerMask.NameToLayer("MyLayer")
gameObject.SetLayer("PostProcess"[, recursive = false]);
GetLayerMask
Returns the collidable layermask of this GameObject
gameObject.GetLayerMask();
gameObject.GetLayerMask2D(); // using Physics2D
IsPrefabMode
Prefab mode is opened and this object is in
gameObjectOrComponent.IsPrefabMode();
EditorSetDirty
Force Dirty for component. Works in scene and prefab mode.
- Prefab mode -> prefab scene become dirty;
- Scene mode -> scene become dirty
component.EditorSetDirty();