Beispiel #1
0
        public static AbstractNavPath Create(NavPathType pathType, NavPathData pathData, Vector3 offset, bool pathFlipOn, IPathTrigger triggerHandler)
        {
            AbstractNavPath navPath = null;

            if (pathData.WayPoints.Count == 2 && pathType != NavPathType.LinePosLineDir)
            {
                pathType = NavPathType.LinePosLineDir;
                DebugUtils.Warning("AbstractNavPath", "Create LineType, Not ", EnumUtils.EnumToString(pathType));
            }
            switch (pathType)
            {
            case NavPathType.CurvePosCurveDir:
                navPath = new NavCurvePosCurveDir(pathData, offset, pathFlipOn, triggerHandler);
                break;

            case NavPathType.LinePosLineDir:
                navPath = new NavCurvePosCurveDir(pathData, offset, pathFlipOn, triggerHandler);
                break;

            case NavPathType.LinePosLineAngle:
                navPath = new NavCurvePosCurveDir(pathData, offset, pathFlipOn, triggerHandler);
                break;

            case NavPathType.LinePosCurveDir:
                navPath = new NavCurvePosCurveDir(pathData, offset, pathFlipOn, triggerHandler);
                break;

            default:
                DebugUtils.Error("AbstractNavPath", "Create Not Supported ", EnumUtils.EnumToString(pathType));
                break;
            }
            return(navPath);
        }
Beispiel #2
0
        public static Properties Create(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                DebugUtils.Info("Create", "Attempting to create a Properties object from an empty URL!");
                return(null);
            }
            // Calculate the file and full namespace path from the specified url.
            string        urlString     = url;
            string        fileString    = null;
            List <string> namespacePath = new List <string>();

            CalculateNamespacePath(ref urlString, ref fileString, namespacePath);
            using (NullMemoryStream stream = NullMemoryStream.ReadTextFromFile(fileString))
            {
                Properties properties = new Properties(stream);
                properties.ResolveInheritance();
                // Get the specified properties object.
                Properties p = GetPropertiesFromNamespacePath(properties, namespacePath);
                if (p == null)
                {
                    DebugUtils.Warning("Create", "Failed to load properties from url '%s'.", url);
                    return(null);
                }
                if (p != properties)
                {
                    p = p.Clone();
                }
                p.SetDirectoryPath(Path.GetDirectoryName(fileString));
                p.Rewind();
                return(p);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 将字符串转成 Lua table 可识别的格式。
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 private static string EncodeString(string value)
 {
     if (value.Length > 999)
     {
         DebugUtils.Warning("PackLuaTable", "EncodeString overflow: " + value);
     }
     return(string.Concat('s', Encoding.UTF8.GetBytes(value).Length.ToString("000"), value));
 }
Beispiel #4
0
        public object FormatXMLData(string fileName, Type dicType, Type type, string fileContent = null)
        {
            object result = null;

            if (string.IsNullOrEmpty(fileName))
            {
                DebugUtils.Warning("FormatXMLData", "fileName IsNullOrEmpty");
                return(result);
            }
            try
            {
                result = dicType.GetConstructor(Type.EmptyTypes).Invoke(null);
                Dictionary <Int32, Dictionary <String, String> > map;//Int32 为 mId, string 为 属性名, string 为 属性值
                if (fileContent != null && XmlFileUtils.LoadIntMap(fileContent, out map))
                {
                    var props = type.GetProperties();//获取实体属性
                    foreach (var item in map)
                    {
                        var t = type.GetConstructor(Type.EmptyTypes).Invoke(null);//构造实体实例
                        foreach (var prop in props)
                        {
                            if (prop.Name == XmlData.mKeyFieldName)
                            {
                                prop.SetValue(t, item.Key, null);
                            }
                            else
                            {
                                if (item.Value.ContainsKey(prop.Name))
                                {
                                    var value = XmlFileUtils.GetValue(item.Value[prop.Name], prop.PropertyType);
                                    prop.SetValue(t, value, null);
                                }
                            }
                        }
                        dicType.GetMethod("Add").Invoke(result, new object[] { item.Key, t });
                    }
                    DebugUtils.Info(fileName + " Loaded ", map.Count);
                }
                else
                {
                    result = null;
                    DebugUtils.Warning(fileName + " Not Founded ", "Please Check Timestamps right");
                }
            }
            catch (Exception ex)
            {
                DebugUtils.Error("XmlData", ex.Message);
            }
            return(result);
        }
Beispiel #5
0
 public static Properties GetPropertiesFromNamespacePath(Properties properties, List <string> namespacePath)
 {
     if (namespacePath.Count > 0)
     {
         int size = namespacePath.Count;
         properties.Rewind();
         Properties iter = properties.GetNextNamespace();
         for (int i = 0; i < size;)
         {
             while (true)
             {
                 if (iter == null)
                 {
                     DebugUtils.Warning("getPropertiesFromNamespacePath", "Failed to load properties object from url.");
                     return(null);
                 }
                 if (namespacePath[i].Equals(iter.GetId())) // id, not namespace
                 {
                     if (i != size - 1)
                     {
                         properties = iter.GetNextNamespace();
                         iter.Rewind();
                         iter = properties;
                     }
                     else
                     {
                         properties = iter;
                     }
                     i++;
                     break;
                 }
                 iter = properties.GetNextNamespace();
             }
         }
         properties.Rewind();
         return(properties);
     }
     return(properties);
 }