public void Save(OnlineMapsCache cache)
        {
#if ALLOW_FILECACHE
            StringBuilder builder = cache.GetFileCacheFolder();
            builder.Append("/").Append(atlasFilename);
            string filename = builder.ToString();

            FileInfo fileInfo = new FileInfo(filename);
            if (!Directory.Exists(fileInfo.DirectoryName))
            {
                Directory.CreateDirectory(fileInfo.DirectoryName);
            }

            FileStream   stream = new FileStream(filename, FileMode.Create);
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write((byte)'T');
            writer.Write((byte)'C');
            writer.Write(ATLAS_VERSION);

            writer.Write(_size);

            for (int i = 0; i < count; i++)
            {
                FileCacheItem item = items[i];
                writer.Write(item.filename);
                writer.Write(item.size);
                writer.Write(item.time);
            }

            (writer as IDisposable).Dispose();
#endif
        }
Exemplo n.º 2
0
        public string GetFullPath(OnlineMapsCache cache)
        {
#if ALLOW_FILECACHE
            StringBuilder stringBuilder = cache.GetFileCacheFolder();
            stringBuilder.Append("/CustomCache/").Append(hash).Append(".dat");
            return stringBuilder.ToString();
#else
            return null;
#endif
        }
Exemplo n.º 3
0
        public string GetFullPath(OnlineMapsCache cache, string shortFilename)
        {
#if ALLOW_FILECACHE
            StringBuilder stringBuilder = cache.GetFileCacheFolder();
            stringBuilder.Append("/").Append(shortFilename).Append(".png");
            return stringBuilder.ToString();
#else
            return null;
#endif
        }
        public void Load(OnlineMapsCache cache)
        {
#if ALLOW_FILECACHE
            StringBuilder builder = cache.GetFileCacheFolder();
            builder.Append("/").Append(atlasFilename);
            string filename = builder.ToString();

            if (!File.Exists(filename))
            {
                return;
            }

            FileStream   stream = new FileStream(filename, FileMode.Open);
            BinaryReader reader = new BinaryReader(stream);

            byte c1 = reader.ReadByte();
            byte c2 = reader.ReadByte();

            int cacheVersion = 0;

            if (c1 == 'T' && c2 == 'C')
            {
                cacheVersion = reader.ReadInt16();
                if (cacheVersion > 0)
                {
                }
            }
            else
            {
                stream.Position = 0;
            }

            _size = reader.ReadInt32();

            long l = stream.Length;
            while (stream.Position < l)
            {
                filename = reader.ReadString();
                int           s    = reader.ReadInt32();
                long          time = reader.ReadInt64();
                FileCacheItem item = new FileCacheItem(filename, s, time);
                if (capacity <= count)
                {
                    capacity += 100;
                    Array.Resize(ref items, capacity);
                }
                items[count++] = item;
            }

            (reader as IDisposable).Dispose();
#endif
        }
Exemplo n.º 5
0
        public void Save(OnlineMapsCache cache)
        {
#if ALLOW_FILECACHE
            StringBuilder builder = cache.GetFileCacheFolder();
            builder.Append("/").Append(atlasName);
            string filename = builder.ToString();

            FileInfo fileInfo = new FileInfo(filename);
            if (!Directory.Exists(fileInfo.DirectoryName)) Directory.CreateDirectory(fileInfo.DirectoryName);

            T[] itemsCopy = new T[items.Length];
            items.CopyTo(itemsCopy, 0);

#if !UNITY_WEBGL
            OnlineMapsThreadManager.AddThreadAction(() =>
            {
#endif
                FileStream stream = new FileStream(filename, FileMode.Create);
                BinaryWriter writer = new BinaryWriter(stream);

                writer.Write((byte)'T');
                writer.Write((byte)'C');
                writer.Write(ATLAS_VERSION);

                writer.Write(size);

                for (int i = 0; i < count; i++)
                {
                    T item = itemsCopy[i];
                    writer.Write(item.key);
                    writer.Write(item.size);
                    writer.Write(item.time);
                }

                writer.Close();
#if !UNITY_WEBGL
        });
#endif
#endif
        }
Exemplo n.º 6
0
    private void OnFileCacheGUI()
    {
        bool fileCache = pUseFileCache.boolValue;

        if (fileCache)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
        }
        EditorGUILayout.PropertyField(pUseFileCache, new GUIContent("File Cache"));

        if (pUseFileCache.boolValue)
        {
#if UNITY_WEBPLAYER || UNITY_WEBGL
            EditorGUILayout.HelpBox("File Cache is not supported for Webplayer and WebGL.", MessageType.Warning);
#endif
            CheckFileCacheSize();


            EditorGUILayout.PropertyField(pMaxFileCacheSize, new GUIContent("Size (mb)"));
            pFileCacheUnloadRate.floatValue = EditorGUILayout.Slider("Unload (%)", Mathf.RoundToInt(pFileCacheUnloadRate.floatValue * 100), 1, 50) / 100;
            EditorGUILayout.PropertyField(pFileCacheLocation, new GUIContent("Cache Location"));
            if (pFileCacheLocation.enumValueIndex == (int)OnlineMapsCache.CacheLocation.custom)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PropertyField(pFileCacheCustomPath, new GUIContent("Cache Folder"));
                if (GUILayout.Button("...", GUILayout.ExpandWidth(false)))
                {
                    string folder = EditorUtility.OpenFolderPanel("Cache folder", pFileCacheCustomPath.stringValue, "");
                    if (!string.IsNullOrEmpty(folder))
                    {
                        pFileCacheCustomPath.stringValue = folder;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(pFileCacheTilePath, new GUIContent("Tile Path"));
            if (GUILayout.Button("Open", GUILayout.ExpandWidth(false)))
            {
                Process.Start(cache.GetFileCacheFolder().ToString());
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginVertical(GUI.skin.box);
            showPathTokens = OnlineMapsEditor.Foldout(showPathTokens, "Available Tokens");
            if (showPathTokens)
            {
                GUILayout.Label("{pid} - Provider ID");
                GUILayout.Label("{mid} - MapType ID");
                GUILayout.Label("{zoom}, {z} - Tile Zoom");
                GUILayout.Label("{x} - Tile X");
                GUILayout.Label("{y} - Tile Y");
                GUILayout.Label("{quad} - Tile Quad Key");
                GUILayout.Label("{lng} - Language code");
                GUILayout.Label("{lbs} - Labels");
                GUILayout.Space(10);
            }
            EditorGUILayout.EndVertical();

            if (Application.isPlaying || !fileCacheSize.HasValue)
            {
                fileCacheSize = cache.GetFileCacheSizeFast();
            }

            float  fileCacheSizeMb  = fileCacheSize.Value / 1000000f;
            string fileCacheSizeStr = fileCacheSizeMb.ToString("F2");
            EditorGUILayout.LabelField("Current Size (mb)", fileCacheSizeStr);
            if (GUILayout.Button("Clear"))
            {
                cache.ClearFileCache();
                fileCacheSize = null;
            }
        }

        if (fileCache)
        {
            EditorGUILayout.EndVertical();
        }
    }