Exemplo n.º 1
0
        /************************
         * public methods
         */


        public OTTable GetTable(OTFont fontOwner, DirectoryEntry de)
        {
            // first try getting it from the table cache
            OTTable table = GetTableFromCache(de);

            if (table == null)
            {
                if (de.length != 0 &&
                    de.offset != 0 &&
                    de.offset < m_file.GetFileLength() &&
                    de.offset + de.length <= m_file.GetFileLength())
                {
                    // read the table from the file
                    MBOBuffer buf = m_file.ReadPaddedBuffer(de.offset, de.length);

                    if (buf != null)
                    {
                        // put the buffer into a table object
                        table = CreateTableObject(de.tag, buf);

                        // add the table to the cache
                        CachedTables.Add(table);
                    }
                }
            }

            return(table);
        }
Exemplo n.º 2
0
    private byte[] EngineReadFileProxy(string filePath)
    {
        try
        {
            // Todo: load from bundle
#if LoadDataTableFromCache
            filePath = Path.GetFullPath(filePath).ToLower();
            byte[] bytes;
            if (CachedTables.TryGetValue(filePath, out bytes))
            {
                return(bytes);
            }
            else
            {
                return(null);
            }
#else
            byte[] buffer = null;
            buffer = File.ReadAllBytes(filePath);
            return(buffer);
#endif
        }
        catch (Exception e)
        {
            LogicSystem.LogErrorFromGfx("Exception:{0}\n{1}", e.Message, e.StackTrace);
            return(null);
        }
    }
Exemplo n.º 3
0
    private bool EngineFileExistsProxy(string filePath)
    {
        // TODO: handle bundle
#if LoadDataTableFromCache
        filePath = Path.GetFullPath(filePath).ToLower();
        byte[] bytes;
        return(CachedTables.TryGetValue(filePath, out bytes));
#else
        return(File.Exists(filePath));
#endif
    }
Exemplo n.º 4
0
 private void CleanupCachedTables()
 {
     CachedTables.Clear();
     GC.Collect();
 }
Exemplo n.º 5
0
    private IEnumerator HandleGameLoadingNonEditor()
    {
        LogicSystem.UpdateLoadingTip("加载配置数据");
        string srcPath  = UnityEngine.Application.streamingAssetsPath;
        string destPath = UnityEngine.Application.persistentDataPath + "/Tables";

        Debug.Log(srcPath);
        Debug.Log(destPath);

        if (!srcPath.Contains("://"))
        {
            srcPath = "file://" + srcPath;
        }
        string listPath = srcPath + "/list.txt";
        WWW    listData = new WWW(listPath);

        yield return(listData);

        string listTxt = listData.text;

        if (null != listTxt)
        {
            using (StringReader sr = new StringReader(listTxt))
            {
                string numStr   = sr.ReadLine();
                float  totalNum = 50;
                if (null != numStr)
                {
                    numStr = numStr.Trim();
                    if (numStr.StartsWith(BOMMarkUtf8))
                    {
                        numStr = numStr.Remove(0, BOMMarkUtf8.Length);
                    }
                    totalNum = (float)int.Parse(numStr);
                    if (totalNum <= 0)
                    {
                        totalNum = 50;
                    }
                }
                for (float num = 1; ; num += 1)
                {
                    string path = sr.ReadLine();
                    if (null != path)
                    {
                        path = path.Trim();
                        string url = srcPath + "/" + path;
                        //Debug.Log("extract " + url);
                        string filePath = Path.Combine(destPath, path);
                        string dir      = Path.GetDirectoryName(filePath);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }
                        WWW temp = new WWW(url);
                        yield return(temp);

                        if (null != temp.bytes)
                        {
                            try
                            {
#if LoadDataTableFromCache
                                byte[] newAlloced = new byte[temp.bytes.Length];
                                temp.bytes.CopyTo(newAlloced, 0);
                                CachedTables.Add(Path.GetFullPath(filePath).ToLower(), newAlloced);
#else
                                File.WriteAllBytes(filePath, temp.bytes);
#endif
                            }
                            catch (System.Exception ex)
                            {
                                LogicSystem.LogErrorFromGfx("ExtractDataFileAndStartGame copy config failed. ex:{0} st:{1}",
                                                            ex.Message, ex.StackTrace);
                            }
                        }
                        else
                        {
                            //Debug.Log(path + " can't load");
                        }

                        temp.Dispose();
                        temp = null;
                    }
                    else
                    {
                        break;
                    }

                    LogicSystem.UpdateLoadingProgress(0.8f + 0.2f * num / totalNum);
                }
                sr.Close();
            }
            listData = null;
        }
        else
        {
            Debug.Log("Can't load list.txt");
        }
    }