Skip to content

Commit

Permalink
Add Android build to videopak export
Browse files Browse the repository at this point in the history
  • Loading branch information
dromsynt committed Oct 3, 2019
1 parent 195acb1 commit 8ec73a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
4 changes: 4 additions & 0 deletions Assets/Videolab/Videopak/Editor/BuildVideopaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ static void BuildAll()
Directory.CreateDirectory(iosDir);
BuildPipeline.BuildAssetBundles(iosDir, buildMap, BuildAssetBundleOptions.None, BuildTarget.iOS);

string androidDir = pakDir + VideopakManager.GetPlatformString(RuntimePlatform.Android);
Directory.CreateDirectory(androidDir);
BuildPipeline.BuildAssetBundles(androidDir, buildMap, BuildAssetBundleOptions.None, BuildTarget.Android);

string osxDir = pakDir + VideopakManager.GetPlatformString(RuntimePlatform.OSXPlayer);
Directory.CreateDirectory(osxDir);
#if UNITY_2017_3_OR_NEWER
Expand Down
47 changes: 16 additions & 31 deletions Assets/Videolab/Videopak/VideopakManager.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using System.IO;
using System.Collections;

public class VideopakManager : MonoBehaviour
public class VideopakManager
{
AssetBundle _bundle;
string _path;

static VideopakManager _instance;

public static VideopakManager Instance {
get {
if (_instance == null)
{
GameObject go = new GameObject("Videopak Manager");
DontDestroyOnLoad(go);
_instance = go.AddComponent<VideopakManager>();
}
_instance = new VideopakManager();

return _instance;
}
Expand All @@ -28,74 +22,65 @@ public static string GetPlatformString(RuntimePlatform platform)
if (platform == RuntimePlatform.IPhonePlayer)
return "iOS";

if (platform == RuntimePlatform.Android)
return "Android";

if (platform == RuntimePlatform.OSXEditor || platform == RuntimePlatform.OSXPlayer)
return "OSX";

return null;
}

public static IEnumerator LoadPak(string pakRoot)
public static void LoadPak(string pakRoot)
{
if (pakRoot == Instance._path)
yield break;

yield return Instance.StartCoroutine(Unload());
Unload();

string platform = GetPlatformString(Application.platform);
if (platform == null)
{
Debug.Log("[VideopakManager] Unsupported platform");
yield break;
return;
}

string pakName = Path.GetFileName(pakRoot);
string path = pakRoot + "/" + platform + "/" + pakName;
#if !UNITY_ANDROID
if (!File.Exists(path))
{
Debug.Log("[VideopakManager] Missing platform payload " + path);
yield break;
return;
}
#endif

AssetBundle bundle = AssetBundle.LoadFromFile(path);
if (bundle == null)
{
Debug.Log("[VideopakManager] Failed to load videopak " + path);
yield break;
return;
}

var scenePaths = bundle.GetAllScenePaths();
if (scenePaths.Length == 0)
{
Debug.Log("[VideopakManager] No scene to load");
yield break;
return;
}

AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scenePaths[0], LoadSceneMode.Additive);
while (!asyncLoad.isDone)
yield return null;
SceneManager.LoadScene(scenePaths[0], LoadSceneMode.Additive);

Instance._bundle = bundle;
Instance._path = pakRoot;
}

public static IEnumerator Unload()
public static void Unload()
{
AssetBundle bundle = Instance._bundle;

if (bundle != null)
{
var scenePaths = bundle.GetAllScenePaths();
yield return SceneManager.UnloadSceneAsync(scenePaths[0]);
SceneManager.UnloadScene(scenePaths[0]);

bundle.Unload(true);

Instance._bundle = null;
Instance._path = null;
}
}

public static bool IsLoaded()
{
return Instance._bundle;
}
}

0 comments on commit 8ec73a2

Please sign in to comment.