private void OnDisable() { if (null != _mappedFile) { _mappedFile.Dispose(); _mappedFile = null; _mappedFileDataStart = -1; _mappedFileDataEnd = -1; } if (null != _tmpFile) { System.IO.File.Delete(_tmpFile); _tmpFile = null; } if (null != text) { text.text = string.Empty; } }
private IEnumerator MemoryMapFile() { string path = System.IO.Path.Combine(Application.streamingAssetsPath, file); Debug.LogFormat("MemoryMapTest: {0}", path); if (path.Contains("://")) { // StreamingAssets on Android is packed in the compressed jar so we can't mmap it directly... // Use UnityWebRequest to copy to a tmp file first. UnityWebRequest req = UnityWebRequest.Get(path); // We can't use System.IO.Path.GetTempFileName() on Android either... path = System.IO.Path.Combine(Application.temporaryCachePath, System.IO.Path.GetRandomFileName()); Debug.LogFormat("MemoryMapTest: {0}", path); // Kick off the async operation saving the file directly to disk. req.downloadHandler = new DownloadHandlerFile(path); yield return(req.SendWebRequest()); if (req.result == UnityWebRequest.Result.ConnectionError || req.result == UnityWebRequest.Result.ProtocolError || req.result == UnityWebRequest.Result.DataProcessingError) { throw new System.IO.IOException(req.error); } } _mappedFile = Memory.MappedFile.CreateFromFile(path); if (null != _mappedFile && System.IntPtr.Zero != _mappedFile.data) { _mappedFileDataStart = _mappedFile.data.ToInt64(); _mappedFileDataEnd = _mappedFileDataStart + _mappedFile.size; _mappedFileDataOffset = 0; Redraw(); } yield return(null); }