// 因为List<T>里获得T类型有一个数组分配所以建议游戏运行时,不要用这个函数
        // 只用在测试中
        public static Dictionary <K, V> TestToWrap <K, V>(byte[] buffer,
                                                          out bool isJson, bool isLoadAll          = false,
                                                          UnityEngine.MonoBehaviour loadAllCortine = null) where V : class, new()
        {
            isJson = false;
            if (buffer == null || buffer.Length <= 0)
            {
                return(null);
            }

            Dictionary <K, V> ret = ConfigWrap.TestCommonToObject <K, V>(buffer, isLoadAll, loadAllCortine);

            if (ret == null)
            {
                try {
                    string text = System.Text.Encoding.UTF8.GetString(buffer);
                    ret    = JsonMapper.ToObject <Dictionary <K, V> >(text);
                    isJson = true;
                } catch {
                    ret = null;
                }
            }

            return(ret);
        }
        public static Dictionary <K1, Dictionary <K2, V> > ToWrapMap <K1, K2, V>(byte[] buffer,
                                                                                 out bool isJson,
                                                                                 bool isLoadAll = false) where V : ConfigBase <K2>, new()
        {
            isJson = false;
            if (buffer == null || buffer.Length <= 0)
            {
                return(null);
            }

            Dictionary <K1, Dictionary <K2, V> > ret = ConfigWrap.ToObjectMap <K1, K2, V>(buffer, isLoadAll);

            if (ret == null)
            {
                try {
                    string text = System.Text.Encoding.UTF8.GetString(buffer);
                    ret    = JsonMapper.ToObject <Dictionary <K1, Dictionary <K2, V> > >(text);
                    isJson = true;
                } catch {
                    ret = null;
                }
            }

            return(ret);
        }
        public static void PreloadWrap <K, V>(Dictionary <K, V> maps, byte[] buffer,
                                              MonoBehaviour mono,
                                              Action <IDictionary> onEnd, Action <float> onProcess) where V : ConfigBase <K>, new()
        {
            if (maps == null || buffer == null || buffer.Length <= 0 || mono == null)
            {
                if (onEnd != null)
                {
                    onEnd(null);
                }
                return;
            }

            maps.Clear();

            MemoryStream stream = new MemoryStream(buffer);


            Coroutine cor = ConfigWrap.ToObjectAsync <K, V>(stream, maps, mono, true, onEnd, onProcess);

            if (cor == null)
            {
                stream.Close();
                stream.Dispose();

                if (onEnd != null)
                {
                    onEnd(null);
                }
            }
        }
        // LitJson转换成自定义格式
        public static void ConvertToBinaryFile(string fileName, string configName, string json)
        {
            if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(json))
            {
                return;
            }

            ConvertClassInfo info = GetConvertClass(configName);

            if (info == null || info.DictionaryType == null)
            {
                return;
            }

            //  System.Type dictType = info.DictionaryType;
            System.Collections.IDictionary values = LitJsonHelper.ToTypeObject(json, info.DictionaryType) as System.Collections.IDictionary;
            if (values == null)
            {
                return;
            }
            string     newFileName = string.Format("{0}/{1}.bytes", Path.GetDirectoryName(fileName), info.convertName);
            FileStream stream      = new FileStream(newFileName, FileMode.Create, FileAccess.Write);

            try {
                try {
                    ConfigWrap.ToStream(stream, values);
                } catch (Exception e) {
                    UnityEngine.Debug.LogErrorFormat("【转换异常】{0}=>{1}", fileName, e.ToString());
                }
            } finally {
                stream.Flush();
                stream.Close();
                stream.Dispose();
            }
        }
        public static Dictionary <K, V> ToWrap <K, V>(byte[] buffer, bool isLoadAll = false) where V : ConfigBase <K>, new()
        {
            if (buffer == null || buffer.Length <= 0)
            {
                return(null);
            }

            Dictionary <K, V> ret = ConfigWrap.ToObject <K, V>(buffer, isLoadAll);

            return(ret);
        }
Beispiel #6
0
        public static Dictionary <K, V> ToWrapSingleType <K, V>(byte[] buffer)
        {
            if (buffer == null || buffer.Length <= 0)
            {
                return(null);
            }
            MemoryStream      stream = new MemoryStream(buffer);
            Dictionary <K, V> ret    = null;

            ConfigWrap.InitDictMap(stream, ref ret);
            ConfigWrap.ToSingleVarType <K, V>(stream, ret);
            return(ret);
        }
 public bool TryGetValue(K1 key, out Dictionary <K2, V> value)
 {
     value = null;
     if (m_Map == null)
     {
         return(false);
     }
     if (!ConfigWrap.ConfigTryGetValue <K1, K2, V>(m_Map, key, out value))
     {
         value = null;
         return(false);
     }
     return(true);
 }
 public bool TryGetValue(K key, out V value)
 {
     value = default(V);
     if (m_Map == null)
     {
         return(false);
     }
     if (!ConfigWrap.ConfigTryGetValue <K, V>(m_Map, key, out value))
     {
         value = default(V);
         return(false);
     }
     return(true);
 }
        public bool TryGetValue(K key, out List <V> value)
        {
            value = null;
            if (m_Map == null)
            {
                return(false);
            }

            if (!ConfigWrap.ConfigTryGetValue <K, V>(m_Map, key, out value))
            {
                value = null;
                return(false);
            }
            return(true);
        }
        public static void ThreadPreloadWrap <K, V>(Dictionary <K, V> maps, byte[] buffer,
                                                    Action <IDictionary> onEnd, Action <float> onProcess) where V : ConfigBase <K>, new()
        {
            if (maps == null || buffer == null || buffer.Length <= 0)
            {
                if (onEnd != null)
                {
                    onEnd(null);
                }
                return;
            }

            maps.Clear();

            MemoryStream stream = new MemoryStream(buffer);

            ConfigWrap.ToObjectThreadAsync <K, V>(stream, maps, true, onEnd, onProcess);
        }
Beispiel #11
0
        public static void PreloadWrapOfSingleType <K, V>(ref Dictionary <K, V> maps, byte[] buffer, MonoBehaviour mono, Action <IDictionary> onEnd, Action <float> onProcess)
        {
            if (buffer == null || buffer.Length <= 0 || mono == null)
            {
                if (onEnd != null)
                {
                    onEnd(null);
                }
                return;
            }
            if (maps != null)
            {
                maps.Clear();
            }
            MemoryStream stream = new MemoryStream(buffer);

            ConfigWrap.InitDictMap(stream, ref maps);
            ConfigWrap.ToSingleVarType <K, V>(stream, maps, mono, onEnd, onProcess);
        }
        public static void PreloadWrap <K, V>(Dictionary <K, V> maps, byte[] buffer,
                                              MonoBehaviour mono, out bool isJson,
                                              Action <IDictionary> onEnd, Action <float> onProcess) where V : ConfigBase <K>, new()
        {
            isJson = false;
            if (maps == null || buffer == null || buffer.Length <= 0 || mono == null)
            {
                if (onEnd != null)
                {
                    onEnd(null);
                }
                return;
            }

            maps.Clear();

            MemoryStream stream = new MemoryStream(buffer);


            Coroutine cor = ConfigWrap.ToObjectAsync <K, V>(stream, maps, mono, true, onEnd, onProcess);

            if (cor == null)
            {
                stream.Close();
                stream.Dispose();

                Dictionary <K, V> ret;
                try {
                    string text = System.Text.Encoding.UTF8.GetString(buffer);
                    maps   = JsonMapper.ToObject <Dictionary <K, V> >(text);
                    ret    = maps;
                    isJson = true;
                } catch {
                    ret = null;
                }

                if (onEnd != null)
                {
                    onEnd(ret);
                }
            }
        }
Beispiel #13
0
        public static void TestReadConfig()
        {
            TextAsset asset = (Selection.activeObject as TextAsset);

            if (asset == null)
            {
                return;
            }
            byte[] buffer = asset.bytes;
            if (buffer == null || buffer.Length <= 0)
            {
                return;
            }

            string fileName = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }

            string configName = Path.GetFileNameWithoutExtension(fileName);

            ConfigConvertManager.BuildConfigConvert();
            var info = ConfigConvertManager.GetTargetConvert(configName);

            if (info == null)
            {
                return;
            }

            IDictionary map = ConfigWrap.TestCommonToObject(buffer, info.type, info.DictionaryType, true);

            if (map != null)
            {
                Debug.Log("二进制配置读取正确");
            }
            else
            {
                Debug.LogError("二进制配置读取错误");
            }
        }
Beispiel #14
0
        public static void ThreadPreloadWrap <K1, K2, V>(ref Dictionary <K1, Dictionary <K2, V> > maps, byte[] buffer,
                                                         Action <IDictionary> onEnd,
                                                         Action <float> onProcess = null) where V : ConfigBase <K2>, new()
        {
            if (buffer == null || buffer.Length <= 0)
            {
                if (onEnd != null)
                {
                    onEnd(null);
                }
                return;
            }

            if (maps != null)
            {
                maps.Clear();
            }

            MemoryStream stream = new MemoryStream(buffer);

            ConfigWrap.InitDictMap(stream, ref maps);
            ConfigWrap.ToObjectMapThreadAsync <K1, K2, V>(stream, maps, true, onEnd, onProcess);
        }