Skip to main content

ComponentType

Trait ComponentType 

Source
pub trait ComponentType: Il2CppValue {
    const ASSEMBLY: &'static str;
    const NAMESPACE: &'static str;
    const NAME: &'static str;

    // Required methods
    fn from_object(object: Object) -> Self;
    fn object(&self) -> Object;

    // Provided methods
    fn game_object(&self) -> Result<GameObject> { ... }
    fn transform(&self) -> Result<Transform> { ... }
    fn get_component<U: ComponentType>(&self) -> Result<Option<U>> { ... }
    fn is_enabled(&self) -> Result<bool> { ... }
    fn set_enabled(&self, enabled: bool) -> Result<()> { ... }
}
Expand description

A component type, for GameObject::add_component.

Every component wrapper in this crate implements it. A mod can wrap its own (or the game’s) MonoBehaviour the same way by naming the class.

Required Associated Constants§

Source

const ASSEMBLY: &'static str

The assembly (.dll name without the extension) that defines the class.

Source

const NAMESPACE: &'static str

The class’s namespace.

Source

const NAME: &'static str

The class’s name, without its namespace.

Required Methods§

Source

fn from_object(object: Object) -> Self

Wraps a managed object known to be of this class.

Source

fn object(&self) -> Object

The untyped managed object.

Provided Methods§

Source

fn game_object(&self) -> Result<GameObject>

Component.gameObject: the game object this component is attached to.

Source

fn transform(&self) -> Result<Transform>

Component.transform: the transform of this component’s game object.

Source

fn get_component<U: ComponentType>(&self) -> Result<Option<U>>

GetComponent<U>() on this component’s game object, or None if absent.

Source

fn is_enabled(&self) -> Result<bool>

Whether the component is enabled. For Behaviour-derived components (MonoBehaviour, Canvas, …); meaningless on a plain Transform.

Source

fn set_enabled(&self, enabled: bool) -> Result<()>

Enables or disables the component (Behaviour.enabled); a disabled MonoBehaviour gets no Update calls.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ComponentType for Camera

Source§

const ASSEMBLY: &'static str = "UnityEngine.CoreModule"

Source§

const NAMESPACE: &'static str = "UnityEngine"

Source§

const NAME: &'static str = "Camera"

Source§

impl ComponentType for Canvas

Source§

const ASSEMBLY: &'static str = "UnityEngine.UIModule"

Source§

const NAMESPACE: &'static str = "UnityEngine"

Source§

const NAME: &'static str = "Canvas"

Source§

impl ComponentType for Component

Source§

const ASSEMBLY: &'static str = "UnityEngine.CoreModule"

Source§

const NAMESPACE: &'static str = "UnityEngine"

Source§

const NAME: &'static str = "Component"

Source§

impl ComponentType for RawImage

Source§

const ASSEMBLY: &'static str = "UnityEngine.UI"

Source§

const NAMESPACE: &'static str = "UnityEngine.UI"

Source§

const NAME: &'static str = "RawImage"

Source§

impl ComponentType for RectTransform

Source§

const ASSEMBLY: &'static str = "UnityEngine.CoreModule"

Source§

const NAMESPACE: &'static str = "UnityEngine"

Source§

const NAME: &'static str = "RectTransform"

Source§

impl ComponentType for TextMeshPro

Source§

const ASSEMBLY: &'static str = "Unity.TextMeshPro"

Source§

const NAMESPACE: &'static str = "TMPro"

Source§

const NAME: &'static str = "TextMeshProUGUI"

Source§

impl ComponentType for Transform

Source§

const ASSEMBLY: &'static str = "UnityEngine.CoreModule"

Source§

const NAMESPACE: &'static str = "UnityEngine"

Source§

const NAME: &'static str = "Transform"