Default Yoo Folder Name 可配空
pull/418/head
何冠峰 2024-12-17 15:27:36 +08:00
parent 906e0e3554
commit 1f07411dde
11 changed files with 146 additions and 69 deletions

View File

@ -22,7 +22,7 @@ namespace YooAsset.Editor
/// </summary>
public static string GetStreamingAssetsRoot()
{
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettingsData.Setting.DefaultYooFolderName}/";
return YooAssetSettingsData.GetYooEditorBuildinRoot();
}
}
}

View File

@ -1,25 +0,0 @@
using System;
using System.IO;
namespace YooAsset
{
internal class CacheHelper
{
/// <summary>
/// 获取默认的缓存根目录
/// </summary>
public static string GetDefaultCacheRoot()
{
#if UNITY_EDITOR
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
projectPath = PathUtility.RegularPath(projectPath);
return PathUtility.Combine(projectPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#elif UNITY_STANDALONE
return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#else
return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#endif
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: cbc12d398555ced46b201626eec6825e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -181,7 +181,7 @@ namespace YooAsset
PackageName = packageName;
if (string.IsNullOrEmpty(rootDirectory))
rootDirectory = GetDefaultRoot();
rootDirectory = GetDefaultBuildinRoot();
_packageRoot = PathUtility.Combine(rootDirectory, packageName);
@ -292,9 +292,9 @@ namespace YooAsset
}
#region 内部方法
protected string GetDefaultRoot()
protected string GetDefaultBuildinRoot()
{
return PathUtility.Combine(Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
return YooAssetSettingsData.GetYooMobileBuildinRoot();
}
public string GetBuildinFileLoadPath(PackageBundle bundle)
{
@ -305,30 +305,25 @@ namespace YooAsset
}
return filePath;
}
public string GetBuildinCatalogFileLoadPath()
{
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
return PathUtility.Combine(YooAssetSettingsData.Setting.DefaultYooFolderName, PackageName, fileName);
}
public string GetBuildinPackageVersionFilePath()
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
return PathUtility.Combine(FileRoot, fileName);
return PathUtility.Combine(_packageRoot, fileName);
}
public string GetBuildinPackageHashFilePath(string packageVersion)
{
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName);
return PathUtility.Combine(_packageRoot, fileName);
}
public string GetBuildinPackageManifestFilePath(string packageVersion)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName);
return PathUtility.Combine(_packageRoot, fileName);
}
public string GetStreamingAssetsPackageRoot()
public string GetCatalogFileLoadPath()
{
string rootPath = PathUtility.Combine(Application.dataPath, "StreamingAssets", YooAssetSettingsData.Setting.DefaultYooFolderName);
return PathUtility.Combine(rootPath, PackageName);
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
}
/// <summary>

View File

@ -17,12 +17,12 @@ namespace YooAsset
{
YooLogger.Log("Begin to create catalog file !");
string savePath = $"Assets/Resources/{YooAssetSettingsData.Setting.DefaultYooFolderName}";
string savePath = YooAssetSettingsData.GetYooResourcesFullPath();
DirectoryInfo saveDirectory = new DirectoryInfo(savePath);
if (saveDirectory.Exists)
saveDirectory.Delete(true);
string rootPath = $"{Application.dataPath}/StreamingAssets/{YooAssetSettingsData.Setting.DefaultYooFolderName}";
string rootPath = YooAssetSettingsData.GetYooEditorBuildinRoot();
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists == false)
{
@ -105,7 +105,8 @@ namespace YooAsset
}
}
string saveFilePath = $"Assets/Resources/{YooAssetSettingsData.Setting.DefaultYooFolderName}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
string fullPath = YooAssetSettingsData.GetYooResourcesFullPath();
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
FileUtility.CreateFileDirectory(saveFilePath);
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath);

View File

@ -65,7 +65,8 @@ namespace YooAsset
#if UNITY_EDITOR
// 兼容性初始化
// 说明:内置文件系统在编辑器下运行时需要动态生成
string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot();
string buildinRoot = YooAssetSettingsData.GetYooEditorBuildinRoot();
string packageRoot = PathUtility.Combine(buildinRoot, _fileSystem.PackageName);
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot);
#endif

View File

@ -30,7 +30,7 @@ namespace YooAsset
if (_steps == ESteps.LoadCatalog)
{
string catalogFilePath = _fileSystem.GetBuildinCatalogFileLoadPath();
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
if (catalog == null)
{

View File

@ -255,7 +255,7 @@ namespace YooAsset
PackageName = packageName;
if (string.IsNullOrEmpty(rootDirectory))
rootDirectory = CacheHelper.GetDefaultCacheRoot();
rootDirectory = GetDefaultCacheRoot();
_packageRoot = PathUtility.Combine(rootDirectory, packageName);
_cacheFileRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.SaveFilesFolderName);
@ -520,6 +520,16 @@ namespace YooAsset
#endregion
#region 内部方法
public string GetDefaultCacheRoot()
{
#if UNITY_EDITOR
return YooAssetSettingsData.GetYooEditorCacheRoot();
#elif UNITY_STANDALONE
return YooAssetSettingsData.GetYooStandaloneCacheRoot();
#else
return YooAssetSettingsData.GetYooMobileCacheRoot();
#endif
}
public string GetCacheFileLoadPath(PackageBundle bundle)
{
return GetDataFilePath(bundle);

View File

@ -163,8 +163,7 @@ namespace YooAsset
#region 内部方法
protected string GetDefaultWebRoot()
{
string path = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
return path;
return YooAssetSettingsData.GetYooWebBuildinRoot();
}
public string GetWebFileLoadPath(PackageBundle bundle)
{
@ -175,11 +174,6 @@ namespace YooAsset
}
return filePath;
}
public string GetCatalogFileLoadPath()
{
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
return PathUtility.Combine(YooAssetSettingsData.Setting.DefaultYooFolderName, PackageName, fileName);
}
public string GetWebPackageVersionFilePath()
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
@ -195,10 +189,10 @@ namespace YooAsset
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName);
}
public string GetStreamingAssetsPackageRoot()
public string GetCatalogFileLoadPath()
{
string rootPath = PathUtility.Combine(Application.dataPath, "StreamingAssets", YooAssetSettingsData.Setting.DefaultYooFolderName);
return PathUtility.Combine(rootPath, PackageName);
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
}
/// <summary>

View File

@ -35,7 +35,8 @@ namespace YooAsset
#if UNITY_EDITOR
// 兼容性初始化
// 说明:内置文件系统在编辑器下运行时需要动态生成
string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot();
string buildinRoot = YooAssetSettingsData.GetYooEditorBuildinRoot();
string packageRoot = PathUtility.Combine(buildinRoot, _fileSystem.PackageName);
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot);
#endif

View File

@ -1,4 +1,5 @@
using UnityEngine;
using System.IO;
using UnityEngine;
namespace YooAsset
{
@ -71,5 +72,115 @@ namespace YooAsset
{
return $"{Setting.ManifestFileName}_{packageName}.version";
}
#region 路径相关
/// <summary>
/// 获取YOO的Resources目录的加载路径
/// </summary>
public static string GetYooResourcesLoadPath(string packageName, string fileName)
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return PathUtility.Combine(packageName, fileName);
else
return PathUtility.Combine(Setting.DefaultYooFolderName, packageName, fileName);
}
/// <summary>
/// 获取YOO的Resources目录的全路径
/// </summary>
public static string GetYooResourcesFullPath()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return $"Assets/Resources";
else
return $"Assets/Resources/{Setting.DefaultYooFolderName}";
}
/// <summary>
/// 获取YOO的编辑器下内置文件根目录
/// </summary>
public static string GetYooEditorBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return PathUtility.Combine(Application.dataPath, "StreamingAssets");
else
return PathUtility.Combine(Application.dataPath, "StreamingAssets", Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO的PC端内置文件根目录
/// </summary>
public static string GetYooStandaloneBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return Application.streamingAssetsPath;
else
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO的移动端内置文件根目录
/// </summary>
public static string GetYooMobileBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return Application.streamingAssetsPath;
else
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO的Web端内置文件根目录
/// </summary>
public static string GetYooWebBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return Application.streamingAssetsPath;
else
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO的编辑器下缓存文件根目录
/// </summary>
public static string GetYooEditorCacheRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
{
string projectPath = Path.GetDirectoryName(Application.dataPath);
projectPath = PathUtility.RegularPath(projectPath);
return projectPath;
}
else
{
// 注意:为了方便调试查看,编辑器下把存储目录放到项目根目录下。
string projectPath = Path.GetDirectoryName(Application.dataPath);
projectPath = PathUtility.RegularPath(projectPath);
return PathUtility.Combine(projectPath, Setting.DefaultYooFolderName);
}
}
/// <summary>
/// 获取YOO的PC端缓存文件根目录
/// </summary>
public static string GetYooStandaloneCacheRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return Application.dataPath;
else
return PathUtility.Combine(Application.dataPath, Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO的移动端缓存文件根目录
/// </summary>
public static string GetYooMobileCacheRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return Application.persistentDataPath;
else
return PathUtility.Combine(Application.persistentDataPath, Setting.DefaultYooFolderName);
}
#endregion
}
}