예제 #1
0
        public static BehaviorNodeDef FromNode(BehaviorNode node)
        {
            var rep = new BehaviorNodeDef();

            rep.Name     = node.GetName();
            rep.TypeName = node.GetType().ToString();

            switch (node)
            {
            case CompositeBehaviorNode composite:
                rep.Children = new List <BehaviorNodeDef>();
                foreach (var child in composite.Children)
                {
                    rep.Children.Add(FromNode(child));
                }
                break;

            case DecoratorBehaviorNode decorator:
                rep.Children = new List <BehaviorNodeDef> {
                    FromNode(decorator.ChildNode)
                };
                break;

            default:
                rep.Children = null;
                break;
            }

            var extraParameterInfo = NodeUtil.GetConstructorExtraParameterInfo(node.GetType());

            if (extraParameterInfo == null || extraParameterInfo.Length == 0)
            {
                return(rep);
            }

            rep.ExtraParameters = new Dictionary <string, object>();
            foreach (var parameterInfo in extraParameterInfo)
            {
                var value = NodeUtil.GetParameterValueByType(node, parameterInfo.ParameterType);
                rep.ExtraParameters.Add(parameterInfo.Name, value);
            }

            return(rep);
        }