Created
March 5, 2017 18:18
-
-
Save zachiPL/fe8be80683e3123a23a664ae652b057d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
using System.Collections; | |
using System.IO; | |
using System; | |
public class PreLoader : MonoBehaviour | |
{ | |
public Slider slider; | |
void Start() | |
{ | |
this.StartCoroutine("CopyFile"); | |
} | |
IEnumerator CopyFile() | |
{ | |
#if UNITY_ANDROID && !UNITY_EDITOR | |
string basename = "glued_converted.mp4_"; | |
string dir = Application.persistentDataPath + "/"; | |
if (!File.Exists(dir + basename)) | |
{ | |
for (int videoFiles = 0; videoFiles < 2; videoFiles++) | |
{ | |
for (int sub = 0; sub < 20; sub++) | |
{ | |
WWW unpackerWWW = new WWW("jar:file://" + Application.dataPath + "!/assets/" + basename + "." + sub.ToString()); | |
//try | |
{ | |
while (!unpackerWWW.isDone) | |
{ | |
} // This will block in the webplayer. | |
if (!string.IsNullOrEmpty(unpackerWWW.error)) | |
{ | |
Debug.Log("Error unpacking 'jar:file://" + Application.dataPath + "!/assets/" + basename + "'"); | |
dir = ""; | |
//break; | |
} | |
else | |
{ | |
Debug.Log(basename + " readed"); | |
} | |
FileMode fMode = FileMode.Create; | |
if (sub > 0) | |
{ | |
fMode = FileMode.Append; | |
} | |
using (FileStream stream = new FileStream(dir + basename, fMode, FileAccess.Write)) | |
{ | |
stream.Write(unpackerWWW.bytes, 0, unpackerWWW.bytes.Length); | |
stream.Close(); | |
} | |
slider.value += 0.025f; | |
yield return null; | |
//File.WriteAllBytes (dir + basename, unpackerWWW.bytes); // 64MB limit on File.WriteAllBytes. | |
} | |
//catch (Exception e) | |
{ | |
//Debug.LogError("Error copying movie: " + e); | |
} | |
} | |
basename = "glued_second.mp4_"; | |
} | |
} | |
#endif | |
yield return null; | |
Application.LoadLevel(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment