最近整理出一个Unity平台路径的工具类,使用的时候直接调用该类的方法就好,不需要在你的代码中加各种判断了,也不需要根据平台加”file:///”了,总之根据自己的需求扩展吧。

/** 
 *FileName:   AppPlatform.cs
 *Author:       Sorpcboy   
 *Description: 获取平台路径
 *USE: 游戏开始时调用Initialize()进行初始化。平台判断:AppPlatform.PlatformCurrent == Platform.Android 获得该平台AB包路径直接调用GetRuntimeAssetBundleUrl()方法即可
*/
using UnityEngine;
using System.Collections;

public enum Platform
{
    OSXEditor = 0,
    OSXPlayer,
    WindowsPlayer,
    WindowsEditor,
    IPhonePlayer,
    Android,
    Unkown,
}

public static class AppPlatform 
{
    public static string[] PlatformPathPrefixs = 
    {
        "file:///",         //OSXEditor
        "file:///",         //OSXPlayer
        "file:///",         //WindowsPlayer
        "file:///",         //WindowsEditor
        "file://",          //IphonePlayer
        "file:///",         //Android
    };

    public static string[] PlatformNames = 
    {
        "Windows",
        "OSX",
        "Windows",
        "Windows",
        "IOS",
        "Android"
    };

    public static bool[] PlatformIsEditor = 
    {
        true,
        false,
        false,
        true,
        false,
        false
    };

    public static Platform PlatformCurrent { set; get; }

    //运行时资源路径,解包后
    public static string RuntimeAssetsPath
    {
        get
        {
            //移动平台走沙盒
            if (Application.isMobilePlatform)
            {
                return Application.persistentDataPath + "/";
            }

            if (Global.IsSandboxMode)
            {
				return Application.dataPath + "/../";

            }
            return Application.streamingAssetsPath + "/";
        }
    }

    public static string GetRuntimePackagePath()
    {
        return RuntimeAssetsPath + GetPackageName() + "/";
    }

    /// <summary>
    /// 运行平台
    /// </summary>
    /// <returns></returns>
    public static string GetRuntimeModelPackgePath() 
    {
        return RuntimeAssetsPath + GetModelPackageName() + "/";
    }

    public static string GetPackagePath()
    {
        return Application.streamingAssetsPath + "/" + GetPackageName() + "/";
    }

    public static string GetPackageName()
    {
        int index = (int)AppPlatform.PlatformCurrent;     
        return "Package_" + AppPlatform.PlatformNames[index];
    }

    /// <summary>
    /// 运行平台
    /// </summary>
    /// <returns></returns>
    public static string GetModelPackageName() 
    {
        int index = (int)AppPlatform.PlatformCurrent;
        return AppPlatform.PlatformNames[index];
    }

    public static string PlatformCurrentName
    {
        get { return PlatformNames[(int)AppPlatform.PlatformCurrent]; }
    }

    public static string GetAssetBundleDirName()
    {
        return "AssetBundles";
    }

    public static string GetAssetBundleDirModelName() 
    {
        return "ModelBundles"; //Windows
    }

    public static string GetRuntimeChecklist
    {
        get
        {
            int index = (int)AppPlatform.PlatformCurrent;
            return AppPlatform.PlatformPathPrefixs[index] + GetStreamingAssetsPath;
        }
    }

    public static string GetRuntimeAssetBundleUrl()
    {
        int index = (int)AppPlatform.PlatformCurrent;
        return AppPlatform.PlatformPathPrefixs[index] + RuntimeAssetsPath + GetPackageName() + "/" + GetAssetBundleDirName() + "/";
    }
    
    public static string GetServerAssetBundleUrl()
    {
        int index = (int)AppPlatform.PlatformCurrent;
        return AppPlatform.PlatformNames[index].ToLower() + "/";
    }

    public static void Initialize()
    {
        AppPlatform.PlatformCurrent = RuntimePlatform_To_AppPlaform(Application.platform);
    }

    public static string GetImgAndViedoPath() 
    {
        if (Application.platform == RuntimePlatform.Android) 
        {
            return "/sdcard/DCIM/Camera/";
        }
        else if (Application.platform == RuntimePlatform.IPhonePlayer) 
        {
            return "";
        }

        return Application.streamingAssetsPath + "/";
    }

    private static Platform RuntimePlatform_To_AppPlaform(RuntimePlatform runtimePlatform)
    {
        switch (runtimePlatform)
        {
            case UnityEngine.RuntimePlatform.Android: return Platform.Android;
            case UnityEngine.RuntimePlatform.IPhonePlayer: return Platform.IPhonePlayer;
            case UnityEngine.RuntimePlatform.OSXEditor: return Platform.OSXEditor;
            case UnityEngine.RuntimePlatform.OSXPlayer: return Platform.OSXPlayer;
            case UnityEngine.RuntimePlatform.WindowsEditor: return Platform.WindowsEditor;
            case UnityEngine.RuntimePlatform.WindowsPlayer: return Platform.WindowsPlayer;
            default: return Platform.Unkown;
        }
    }
}