Esempio n. 1
0
        public static PlannerTask Create(BehaviorNode node, Agent pAgent)
        {
            if (ms_factory == null)
            {
                ms_factory = new Dictionary <Type, TaskCreator>();
                Register <Action>((n, a) => new PlannerTaskAction(n, a));
                Register <Task>((n, a) => new PlannerTaskTask(n, a));
                Register <Method>((n, a) => new PlannerTaskMethod(n, a));
                Register <Sequence>((n, a) => new PlannerTaskSequence(n, a));
                Register <Selector>((n, a) => new PlannerTaskSelector(n, a));
                Register <Parallel>((n, a) => new PlannerTaskParallel(n, a));
                Register <ReferencedBehavior>((n, a) => new PlannerTaskReference(n, a));
                Register <DecoratorLoop>((n, a) => new PlannerTaskLoop(n, a));
                Register <DecoratorIterator>((n, a) => new PlannerTaskIterator(n, a));
            }

            Type type = node.GetType();

            while (!ms_factory.ContainsKey(type))
            {
                type = type.BaseType;
                Debug.Check(type != null);
            }

            if (ms_factory.ContainsKey(type))
            {
                TaskCreator c = ms_factory[type];

                PlannerTask task = c(node, pAgent);

                return(task);
            }

            return(null);
        }