添加缺失插件
This commit is contained in:
54
Assets/FileLoad.cs
Normal file
54
Assets/FileLoad.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FileLoad
|
||||
{
|
||||
public static string GetMoviesFolder()
|
||||
{
|
||||
string[] temp = null;
|
||||
#if UNITY_EDITOR
|
||||
temp = new string[1];
|
||||
// 获取项目根目录的AssetBundle文件夹路径
|
||||
string projectPath = Application.dataPath.Replace("/Assets", "");
|
||||
temp[0] = System.IO.Path.Combine(projectPath, "AssetBundle").Replace("\\", "/");
|
||||
#else
|
||||
temp = new string[1];
|
||||
temp[0] = GetObbPath();
|
||||
#endif
|
||||
return temp[0];
|
||||
}
|
||||
|
||||
public static string GetObbPath()
|
||||
{
|
||||
string obbPath = "";
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
// 在Android设备上运行时
|
||||
if (Application.platform == RuntimePlatform.Android)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取OBB路径
|
||||
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
||||
using (AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
|
||||
using (AndroidJavaObject packageManager = currentActivity.Call<AndroidJavaObject>("getPackageManager"))
|
||||
{
|
||||
string packageName = currentActivity.Call<string>("getPackageName");
|
||||
|
||||
// 获取OBB路径
|
||||
AndroidJavaObject packageInfo = packageManager.Call<AndroidJavaObject>("getPackageInfo", packageName, 0);
|
||||
int versionCode = packageInfo.Get<int>("versionCode");
|
||||
string mainOBBPath = string.Format("/storage/emulated/0/Android/obb/{0}/", packageName);
|
||||
|
||||
obbPath = mainOBBPath;
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError("获取OBB路径出错: " + e.Message);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return obbPath;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user