AssetBundle框架之辅助类PathTools

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PathTools
{

    //需要打包的资源路径常量
    public const string AB_RESOURCES = "AB_Res";

    //获取需要打包的资源路径
    public static string GetABResourcesPath()
    {
        return Application.dataPath + "/" + AB_RESOURCES;
    }

    //Application.streamingAssetsPath
    /// <summary>
    /// 获取AB包输出路径
    /// 算法
    ///     1:平台(PC/移动端)路径
    ///     2:平台的名称
    /// </summary>
    /// <returns></returns>
    public static string GetABOutPath()
    {
        return GetPlatformPath() + "/" + GetPlatformName();
    }

    /// <summary>
    /// 获取平台路径 资源解压路径
    /// </summary>
    /// <returns></returns>
    private static string GetPlatformPath()
    {
        string strReturnPlaformPath = string.Empty;

        switch (Application.platform)
        {
            case RuntimePlatform.WindowsEditor:
            case RuntimePlatform.WindowsPlayer:
                strReturnPlaformPath = Application.streamingAssetsPath;
                break;
            case RuntimePlatform.IPhonePlayer:
            case RuntimePlatform.Android:
                strReturnPlaformPath = Application.persistentDataPath;
                break;
            default:
                break;
        }

        return strReturnPlaformPath;
    }


    /// <summary>
    /// 获取平台的名称
    /// </summary>
    /// <returns></returns>
    public static string GetPlatformName()
    {
        string strReturnPlaformName = string.Empty;

        switch (Application.platform)
        {
            case RuntimePlatform.WindowsEditor:
            case RuntimePlatform.WindowsPlayer:
                strReturnPlaformName = "Windows";
                break;
            case RuntimePlatform.IPhonePlayer:
                strReturnPlaformName = "IPhone";
                break;
            case RuntimePlatform.Android:
                strReturnPlaformName = "Android";
                break;
            default:
                break;
        }

        return strReturnPlaformName;
    }


    /// <summary>
    /// 获取下载Ab包资源路径
    /// </summary>
    /// <returns></returns>
    public static string GetABPath()
    {
        string strReturnPath = string.Empty;
        switch (Application.platform)
        {
            case RuntimePlatform.Android:
                strReturnPath = "jar:file://" + GetABOutPath();
                break;
            case RuntimePlatform.WindowsPlayer:
            case RuntimePlatform.WindowsEditor:
                strReturnPath = "file://" + GetABOutPath();
                break;
            case RuntimePlatform.IPhonePlayer:
                strReturnPath = GetABOutPath() + "/Raw/";
                break;
            default:
                break;
        }
        return strReturnPath;
    }

}

--若是对您有所帮助,世界便多了一份你我的温暖
--您的支持将是我的动力,手有余粮的话,一点点赞赏我将开心不已(一毛钱也是极好的) 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章