void OnDisable() { if (_current == this) { _current = null; } }
/// <summary> /// 在Android平台上,从(apk包中的) Assets目录复制文件至指定目录 /// 注意:只能在子线程中调用 /// </summary> /// <param name="sourceDir">源目录,是以 assets 为根目录的相对路径</param> /// <param name="destDir">目标目录</param> /// <param name="title">进度对话框标题</param> /// <returns></returns> public static void CopyAssetDirectoryInThread(String sourceDir, String destDir, Action <bool> callback) { StreamingAssetHelper.sourceDir = sourceDir; StreamingAssetHelper.destDir = assetPath != null?Path.Combine(assetPath, destDir) : null; StreamingAssetHelper.callback = callback; if (StreamingAssetHelper.destDir != null) { ColaLoom.RunAsync(CopyAssetDirectory); } }
/// <summary> /// 初始化ColaLoom多线程工具,只在游戏开始调用一次就好 /// </summary> public static void Initialize() { if (!initialized) { if (!Application.isPlaying) { return; } initialized = true; var g = new GameObject("ColaLoom"); DontDestroyOnLoad(g); _current = g.AddComponent <ColaLoom>(); } }
/// <summary> /// 在Android平台上,从(apk包中的) Assets目录复制文件至指定目录 /// 注意:只能在主线程中调用 /// </summary> /// <param name="sourceDir">源目录,是以 assets 为根目录的相对路径</param> /// <param name="destDir">目标目录</param> /// <param name="title">进度对话框标题</param> /// <returns></returns> public static void CopyAssetDirectory() { ColaLoom.QueueOnMainThread(() => { Debug.Log("CopyAssetDirectory, sourceDir = " + sourceDir + ", destDir = " + destDir); AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActitivy = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity"); Debug.Log("CopyAssetDirectory before execute"); bool ret = currentActitivy.Call <bool>("copyAssets", sourceDir, destDir); callback(ret); Debug.Log("CopyAssetDirectory finished"); }); }
void Awake() { _current = this; initialized = true; }