private static BehaviorNodeConfig CreateNodeConfig(this BehaviorTreeConfig treeConfig, string name)
        {
            NodeMeta   proto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(name);
            GameObject go    = new GameObject()
            {
                name = name
            };

            go.transform.parent = treeConfig.gameObject.transform;
            BehaviorNodeConfig node = go.AddComponent <BehaviorNodeConfig>();

            node.name     = name;
            node.describe = proto.describe;

            foreach (NodeFieldDesc args in proto.new_args_desc)
            {
                Type type = BTTypeManager.GetBTType(args.type);
                UnityEngine.Component comp = go.AddComponent(type);
                FieldInfo             info = type.GetField("fieldName");
                info.SetValue(comp, args.name);
                FieldInfo info1 = type.GetField("fieldValue");
                info1.SetValue(comp, args.value);
            }
            return(node);
        }
Exemplo n.º 2
0
        public static BehaviorNodeConfig ProtoToConfig(NodeProto nodeData)
        {
            GameObject         go         = new GameObject();
            BehaviorNodeConfig nodeConfig = go.AddComponent <BehaviorNodeConfig>();

            nodeConfig.id       = nodeData.Id;
            nodeConfig.name     = nodeData.Name;
            go.name             = nodeData.Name;
            nodeConfig.describe = nodeData.Desc;
            foreach (KeyValuePair <string, object> args in nodeData.Args.Dict())
            {
                Type originType = NodeMetaHelper.GetFieldType(nodeData.Name, args.Key);
                try
                {
                    string fieldName                    = args.Key;
                    object fieldValue                   = args.Value;
                    Type   type                         = BTTypeManager.GetBTType(originType);
                    UnityEngine.Component comp          = go.AddComponent(type);
                    FieldInfo             fieldNameInfo = type.GetField("fieldName");
                    fieldNameInfo.SetValue(comp, fieldName);
                    FieldInfo fieldValueinfo = type.GetField("fieldValue");
                    if (TypeHelper.IsEnumType(originType))
                    {
                        fieldValue = fieldValue.ToString();
                    }
                    fieldValueinfo.SetValue(comp, fieldValue);
                }
                catch (Exception e)
                {
                    throw new Exception($"transform failed,nodeName:{nodeData.Name}  fieldName:{args.Key} fieldType:{originType} {e}");
                }
            }
            foreach (NodeProto child in nodeData.children)
            {
                BehaviorNodeConfig childConfig = ProtoToConfig(child);
                childConfig.gameObject.transform.parent = nodeConfig.gameObject.transform;
            }
            return(nodeConfig);
        }
Exemplo n.º 3
0
        public static BehaviorNodeConfig ProtoToConfig(NodeProto nodeData)
        {
            GameObject         go         = new GameObject();
            BehaviorNodeConfig nodeConfig = go.AddComponent <BehaviorNodeConfig>();

            nodeConfig.id = nodeData.nodeId;
            ((UnityEngine.Object)nodeConfig).name = nodeData.name;
            go.name             = nodeData.name;
            nodeConfig.describe = nodeData.describe;
            foreach (var args in nodeData.args_dict)
            {
                Type originType = ExportNodeTypeConfig.GetFieldType(nodeData.name, args.Key);
                try
                {
                    string fieldName                    = args.Key;
                    object fieldValue                   = args.Value.GetValueByType(originType);
                    Type   type                         = BTTypeManager.GetBTType(originType);
                    UnityEngine.Component comp          = go.AddComponent(type);
                    FieldInfo             fieldNameInfo = type.GetField("fieldName");
                    fieldNameInfo.SetValue(comp, fieldName);
                    FieldInfo fieldValueinfo = type.GetField("fieldValue");
                    if (BehaviorTreeArgsDict.IsEnumType(originType))
                    {
                        fieldValue = fieldValue.ToString();
                    }
                    fieldValueinfo.SetValue(comp, fieldValue);
                }
                catch (Exception ex)
                {
                    throw new GameException($"transform failed,nodeName:{nodeData.name}  fieldName:{args.Key} fieldType:{originType}");
                }
            }
            foreach (var child in nodeData.children)
            {
                BehaviorNodeConfig childConfig = ProtoToConfig(child);
                childConfig.gameObject.transform.parent = nodeConfig.gameObject.transform;
            }
            return(nodeConfig);
        }
        private static BehaviorNodeConfig CreateNodeConfig(this BehaviorTreeConfig treeConfig, string name)
        {
            ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name);
            GameObject          go    = new GameObject();

            go.name             = name;
            go.transform.parent = treeConfig.gameObject.transform;
            BehaviorNodeConfig node = go.AddComponent <BehaviorNodeConfig>();

            node.name     = name;
            node.describe = proto.describe;

            foreach (var args in proto.new_args_desc)
            {
                Type type = BTTypeManager.GetBTType(args.type);
                UnityEngine.Component comp = go.AddComponent(type);
                FieldInfo             info = type.GetField("fieldName");
                info.SetValue(comp, args.name);
                FieldInfo info1 = type.GetField("fieldValue");
                info1.SetValue(comp, args.value);
            }
            return(node);
        }