fyrox_impl/utils/behavior/
leaf.rsuse crate::{
core::{pool::Handle, visitor::prelude::*},
utils::behavior::{BehaviorNode, BehaviorTree},
};
use std::cell::RefCell;
#[derive(Debug, PartialEq, Visit, Eq, Clone)]
pub struct LeafNode<B>
where
B: Clone,
{
pub behavior: Option<RefCell<B>>,
}
impl<B> Default for LeafNode<B>
where
B: Clone,
{
fn default() -> Self {
Self { behavior: None }
}
}
impl<B> LeafNode<B>
where
B: Clone + 'static,
{
pub fn new(behavior: B) -> Self {
Self {
behavior: Some(RefCell::new(behavior)),
}
}
pub fn add_to(self, tree: &mut BehaviorTree<B>) -> Handle<BehaviorNode<B>> {
tree.add_node(BehaviorNode::Leaf(self))
}
}