Skip to main content

SpatialBundle

Struct SpatialBundle 

Source
pub struct SpatialBundle {
    pub name: Name,
    pub transform: Transform,
    pub global_transform: GlobalTransform,
    pub visibility: Visibility,
    pub layer: Layer,
}
Expand description

空间实体 Bundle

包含空间变换和可见性信息,适用于需要位置和渲染的实体。

§包含组件

  • Name: 实体名称
  • Transform: 本地变换
  • GlobalTransform: 全局变换
  • Visibility: 可见性
  • Layer: 渲染层级

§示例

use anvilkit_ecs::prelude::*;
 
let mut world = World::new();
 
// 直接创建
let entity = world.spawn(SpatialBundle {
    name: Name::new("空间实体"),
    transform: Transform::from_translation(Vec3::new(1.0, 2.0, 3.0)),
    global_transform: GlobalTransform::default(),
    visibility: Visibility::Visible,
    layer: Layer::new(1),
}).id();
 
// 使用构建器
let entity2 = world.spawn(
    SpatialBundle::new("移动实体")
        .with_position(Vec3::new(5.0, 0.0, 0.0))
        .with_layer(2)
).id();

Fields§

§name: Name

实体名称

§transform: Transform

本地变换

§global_transform: GlobalTransform

全局变换

§visibility: Visibility

可见性

§layer: Layer

渲染层级

Implementations§

Source§

impl SpatialBundle

Source

pub fn new(name: impl Into<String>) -> SpatialBundle

创建新的空间实体 Bundle

§参数
  • name: 实体名称
§示例
use anvilkit_ecs::bundle::SpatialBundle;
 
let bundle = SpatialBundle::new("空间实体");
Source

pub fn with_position(self, position: Vec3) -> SpatialBundle

设置位置

§参数
  • position: 世界坐标位置
§示例
use anvilkit_ecs::prelude::*;
 
let bundle = SpatialBundle::new("实体")
    .with_position(Vec3::new(1.0, 2.0, 3.0));
Source

pub fn with_rotation(self, rotation: Quat) -> SpatialBundle

设置旋转

§参数
  • rotation: 四元数旋转
§示例
use anvilkit_ecs::prelude::*;
 
let bundle = SpatialBundle::new("实体")
    .with_rotation(Quat::from_rotation_y(std::f32::consts::PI));
Source

pub fn with_scale(self, scale: Vec3) -> SpatialBundle

设置缩放

§参数
  • scale: 缩放向量
§示例
use anvilkit_ecs::prelude::*;
 
let bundle = SpatialBundle::new("实体")
    .with_scale(Vec3::splat(2.0));
Source

pub fn with_transform(self, transform: Transform) -> SpatialBundle

设置变换

§参数
  • transform: 完整的变换
§示例
use anvilkit_ecs::prelude::*;
 
let transform = Transform::from_translation(Vec3::new(1.0, 0.0, 0.0));
let bundle = SpatialBundle::new("实体")
    .with_transform(transform);
Source

pub fn with_visibility(self, visibility: Visibility) -> SpatialBundle

设置可见性

§参数
  • visibility: 可见性状态
§示例
use anvilkit_ecs::prelude::*;
 
let bundle = SpatialBundle::new("实体")
    .with_visibility(Visibility::Hidden);
Source

pub fn with_layer(self, layer: i32) -> SpatialBundle

设置渲染层级

§参数
  • layer: 层级数值
§示例
use anvilkit_ecs::prelude::*;
 
let bundle = SpatialBundle::new("实体")
    .with_layer(5);

Trait Implementations§

Source§

impl Bundle for SpatialBundle

Source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

Gets this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl Clone for SpatialBundle

Source§

fn clone(&self) -> SpatialBundle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpatialBundle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for SpatialBundle

Source§

fn default() -> SpatialBundle

Returns the “default value” for a type. Read more
Source§

impl DynamicBundle for SpatialBundle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given World.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,