Ejemplo n.º 1
0
        public static BehaviorNode RemoveChildByName(this BehaviorNode root, string name)
        {
            var child = root.FindChildByName(name, out var parent);

            // didn't find child or child was root
            if (parent == null)
            {
                var rootName = root.GetName();
                Main.HBSLog?.Log($"Could not find child to remove named: {name} in tree with root {rootName}");
                return(null);
            }

            var parentName = parent.GetName();

            Main.HBSLog?.Log($"Deleting child named: {name} from parent named: {parentName}");
            switch (parent)
            {
            case CompositeBehaviorNode composite:
                composite.Children.Remove(child);
                break;

            case DecoratorBehaviorNode decorator:
                decorator.ChildNode = null;
                break;
            }

            return(child);
        }
Ejemplo n.º 2
0
 public static void Postfix(BehaviorNode __instance, ref BehaviorTreeResults __result)
 {
     if (__instance is LeafBehaviorNode && __result.orderInfo != null)
     {
         AIPause.PausePopup.AppendText(__instance.GetName());
     }
 }
Ejemplo n.º 3
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);
        }