Exemple #1
0
        private static void SerializeToXML(string path, Dictionary <string, List <MethodInfo> > data)
        {
            MyAIBehaviorData objectBuilder = MyObjectBuilderSerializer.CreateNewObject <MyAIBehaviorData>();

            objectBuilder.Entries = new MyAIBehaviorData.CategorizedData[data.Count];
            int index = 0;

            foreach (KeyValuePair <string, List <MethodInfo> > pair in data)
            {
                MyAIBehaviorData.CategorizedData data3 = new MyAIBehaviorData.CategorizedData {
                    Category    = pair.Key,
                    Descriptors = new MyAIBehaviorData.ActionData[pair.Value.Count]
                };
                int num2 = 0;
                foreach (MethodInfo local1 in pair.Value)
                {
                    MyAIBehaviorData.ActionData   data4           = new MyAIBehaviorData.ActionData();
                    MyBehaviorTreeActionAttribute customAttribute = local1.GetCustomAttribute <MyBehaviorTreeActionAttribute>();
                    data4.ActionName     = customAttribute.ActionName;
                    data4.ReturnsRunning = customAttribute.ReturnsRunning;
                    ParameterInfo[] parameters = local1.GetParameters();
                    data4.Parameters = new MyAIBehaviorData.ParameterData[parameters.Length];
                    int             num3       = 0;
                    ParameterInfo[] infoArray2 = parameters;
                    int             num4       = 0;
                    while (true)
                    {
                        if (num4 >= infoArray2.Length)
                        {
                            data3.Descriptors[num2] = data4;
                            num2++;
                            break;
                        }
                        ParameterInfo                  element    = infoArray2[num4];
                        BTMemParamAttribute            attribute2 = element.GetCustomAttribute <BTMemParamAttribute>();
                        BTParamAttribute               attribute3 = element.GetCustomAttribute <BTParamAttribute>();
                        MyAIBehaviorData.ParameterData data5      = new MyAIBehaviorData.ParameterData {
                            Name         = element.Name,
                            TypeFullName = element.ParameterType.FullName
                        };
                        if (attribute2 != null)
                        {
                            data5.MemType = attribute2.MemoryType;
                        }
                        else if (attribute3 != null)
                        {
                            data5.MemType = MyMemoryParameterType.PARAMETER;
                        }
                        data4.Parameters[num3] = data5;
                        num3++;
                        num4++;
                    }
                }
                objectBuilder.Entries[index] = data3;
                index++;
            }
            MyObjectBuilderSerializer.SerializeXML(path, false, objectBuilder, null);
        }
Exemple #2
0
        private static void SerializeToXML(string path, Dictionary <string, List <MethodInfo> > data)
        {
            var aiData = MyObjectBuilderSerializer.CreateNewObject <MyAIBehaviorData>();

            aiData.Entries = new MyAIBehaviorData.CategorizedData[data.Count];

            int entryIdx = 0;

            foreach (var categoryPair in data)
            {
                var categoryData = new MyAIBehaviorData.CategorizedData();
                categoryData.Category    = categoryPair.Key;
                categoryData.Descriptors = new MyAIBehaviorData.ActionData[categoryPair.Value.Count];

                int actionDataIdx = 0;
                foreach (var methodInfo in categoryPair.Value)
                {
                    var actionData   = new MyAIBehaviorData.ActionData();
                    var btActionAttr = methodInfo.GetCustomAttribute <MyBehaviorTreeActionAttribute>();
                    actionData.ActionName     = btActionAttr.ActionName;
                    actionData.ReturnsRunning = btActionAttr.ReturnsRunning;

                    var methodParams = methodInfo.GetParameters();
                    actionData.Parameters = new MyAIBehaviorData.ParameterData[methodParams.Length];

                    int paramIdx = 0;
                    foreach (var param in methodParams)
                    {
                        var memParamAttr = param.GetCustomAttribute <BTMemParamAttribute>();
                        var paramAttr    = param.GetCustomAttribute <BTParamAttribute>();
                        var actionParam  = new MyAIBehaviorData.ParameterData();

                        actionParam.Name         = param.Name;
                        actionParam.TypeFullName = param.ParameterType.FullName;

                        if (memParamAttr != null)
                        {
                            actionParam.MemType = memParamAttr.MemoryType;
                        }
                        else if (paramAttr != null)
                        {
                            actionParam.MemType = MyMemoryParameterType.PARAMETER;
                        }
                        else
                        {
                            Debug.Assert(false, "No behavior attribute on parameter. Category: " + categoryPair.Key + ", method name: " + methodInfo.Name);
                        }

                        actionData.Parameters[paramIdx] = actionParam;
                        paramIdx++;
                    }

                    categoryData.Descriptors[actionDataIdx] = actionData;
                    actionDataIdx++;
                }

                aiData.Entries[entryIdx] = categoryData;
                entryIdx++;
            }

            MyObjectBuilderSerializer.SerializeXML(path, false, aiData);
        }