Esempio n. 1
0
 public void Restart()
 {
     ResetLua();
     CoroutineManager.EndOfFrame(StartLua);
 }
Esempio n. 2
0
 public void Dispose()
 {
     m_WWW.Dispose();
     CoroutineManager.Stop(m_WaitIe);
     m_Disposed = true;
 }
Esempio n. 3
0
        public static void ReadAsync(string path, Action <byte[]> callback)
        {
            if (!IsFileExist(path))
            {
                Debugger.LogError("File is not exist: " + path);
                if (callback != null)
                {
                    callback(null);
                }
                return;
            }
            if (s_ReadDataDict.ContainsKey(path))
            {
                if (callback != null)
                {
                    DataContainer <byte[]> dataContainer = s_ReadDataDict[path];
                    CoroutineManager.Wait(() => dataContainer.IsDone, () => callback(dataContainer.Data));
                }
            }
            else
            {
                Debugger.Log("ReadAsync: " + path);
                DataContainer <byte[]> dataContainer = new DataContainer <byte[]>();
                s_ReadDataDict.Add(path, dataContainer);

#if !UNITY_EDITOR && UNITY_ANDROID
                if (path.StartsWith(ConstValue.STREAMING_DIR_PATH))
                {
                    ThreadPool.QueueUserWorkItem(obj =>
                    {
                        string relativePath = path.Replace(ConstValue.STREAMING_DIR_PATH, "Android");
                        byte[] bytes        = s_StreamingLoader.CallStatic <byte[]>("read", path, ConstValue.BYTE_ARRAY_TEMP_LENGTH);
                        if (callback != null)
                        {
                            CoroutineManager.MainThread(() => callback(bytes));
                        }
                        s_ReadDataDict.Remove(path);
                    });
                    return;
                }
#endif

                FileStream fs = null;
                try
                {
                    FileInfo file = new FileInfo(path);
                    fs = file.OpenRead();
                    byte[] bytesTemp = new byte[ConstValue.BYTE_ARRAY_TEMP_LENGTH];
                    fs.BeginRead(bytesTemp, 0, ConstValue.BYTE_ARRAY_TEMP_LENGTH, ar =>
                    {
                        MemoryStream ms = null;
                        try
                        {
                            ms             = new MemoryStream();
                            int readLength = fs.EndRead(ar);
                            while (readLength > 0)
                            {
                                ms.Write(bytesTemp, 0, readLength);
                                readLength = fs.Read(bytesTemp, 0, ConstValue.BYTE_ARRAY_TEMP_LENGTH);
                            }
                            ms.Flush();
                            dataContainer.Data = ms.ToArray();

                            if (callback != null)
                            {
                                CoroutineManager.MainThread(() => callback(dataContainer.Data));
                            }
                        }
                        catch (Exception e)
                        {
                            Debugger.LogError("ReadAsync [" + path + "] error: " + e);
                        }
                        finally
                        {
                            if (ms != null)
                            {
                                ms.Close();
                            }
                            fs.Close();
                            s_ReadDataDict.Remove(path);
                        }
                    }, null);
                }
                catch (Exception e)
                {
                    Debugger.LogError("ReadAsync [" + path + "] error: " + e);
                    if (fs != null)
                    {
                        fs.Close();
                    }
                    s_ReadDataDict.Remove(path);
                }
            }
        }