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;
    }

}

--若是對您有所幫助,世界便多了一份你我的溫暖
--您的支持將是我的動力,手有餘糧的話,一點點讚賞我將開心不已(一毛錢也是極好的) 

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