Specs ECS 를 사용하는 rust 자습서를 따르고 있으며 대신 legion ECS 를 사용하여 구현하려고합니다 . 나는 군단을 사랑하고 문제에 직면 할 때까지 모든 것이 순조롭게 진행되었습니다.
내 질문을 공식화하는 방법을 잘 모르겠습니다. 내가하려는 것은 예를 들어 ComponentA와 ComponentB가있는 모든 엔티티를 반복하는 시스템을 만드는 것입니다.하지만 엔티티에 ComponentC가 있는지 확인하고 그럴 경우 특별한 작업을 수행합니다.
Specs (예제 코드)를 사용하여 그렇게 할 수 있습니다.
// Uses Specs
pub struct SystemA {}
impl<'a> System<'a> for SystemA {
type SystemData = ( Entities<'a>,
WriteStorage<'a, ComponentA>,
ReadStorage<'a, ComponentB>,
ReadStorage<'a, ComponentC>);
fn run(&mut self, data : Self::SystemData) {
let (entities, mut compA, compB, compC) = data;
// Finding all entities with ComponentA and ComponentB
for (ent, compA, compB) in (&entities, &mut compA, &compB).join() {
// Do stuff with compA and compB
// Check if Entity also has ComponentC
let c : Option<&ComponentC> = compC.get(ent);
if let Some(c) = c {
// Do something special with entity if it also has ComponentC
}
}
}
}
나는 이것을 legion (현재 최신 0.4.0 버전 사용) 사용으로 번역하는 데 어려움을 겪습니다. 현재 엔터티에있는 다른 구성 요소를 가져 오는 방법을 모르겠습니다. 내가 가진 코드는 다음과 같습니다.
#[system(for_each)]
pub fn systemA(entity: &Entity, compA: &mut compA, compB: &mut ComponentB) {
// Do stuff with compA and compB
// How do I check if entity has compC here?
}
위 시스템의 엔티티에는 ID 만 포함되어 있습니다. World없이이 엔터티가 가지고있는 구성 요소 목록에 어떻게 액세스합니까? 아니면 군단의 시스템에서 세계에 접근 할 수있는 방법이 있습니까? 아니면 사양 버전과 동일한 결과를 얻을 수있는 다른 방법이 있습니까?
감사!
옵션 구성 요소에 옵션 <...>을 사용할 수 있습니다 .
#[system(for_each)]
pub fn systemA(entity: &Entity, compA: &mut compA, compB: &mut ComponentB, compC: Option<&ComponentC>) {
...
if let Some(compC) = compC {
// this entity has compC
...
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다