加入编辑器上传资源到oss服务器部署热更资源工具
parent
f0b9cda28e
commit
f680963a73
|
@ -67,7 +67,7 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: No
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_fontAsset: {fileID: 0}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
|
@ -282,8 +282,9 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: Error Tips
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontAsset: {fileID: 11400000, guid: 41512a7f2b107664d9d14634f444209a, type: 2}
|
||||
m_sharedMaterial: {fileID: -3454106745002405512, guid: 41512a7f2b107664d9d14634f444209a,
|
||||
type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
m_fontMaterials: []
|
||||
|
@ -329,7 +330,7 @@ MonoBehaviour:
|
|||
m_linkedTextComponent: {fileID: 0}
|
||||
parentLinkedComponent: {fileID: 0}
|
||||
m_enableKerning: 1
|
||||
m_ActiveFontFeatures: 00000000
|
||||
m_ActiveFontFeatures: 6e72656b
|
||||
m_enableExtraPadding: 0
|
||||
checkPaddingRequired: 0
|
||||
m_isRichText: 1
|
||||
|
@ -806,7 +807,7 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: Download Tips
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_fontAsset: {fileID: 0}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
|
@ -942,7 +943,7 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: Download Tips
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_fontAsset: {fileID: 0}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
|
@ -1078,7 +1079,7 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: Single
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_fontAsset: {fileID: 0}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
|
@ -1508,7 +1509,7 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: Tips
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_fontAsset: {fileID: 0}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
|
@ -1680,7 +1681,7 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: Download Tips
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_fontAsset: {fileID: 0}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
|
@ -2102,7 +2103,7 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: Yes
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_fontAsset: {fileID: 0}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
|
@ -2238,7 +2239,7 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: Quit
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_fontAsset: {fileID: 0}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
|
@ -2707,8 +2708,9 @@ MonoBehaviour:
|
|||
m_Calls: []
|
||||
m_text: Error Tips
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: b62d42a4efb0a374b8d61e0f108b3d4d, type: 2}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontAsset: {fileID: 11400000, guid: 41512a7f2b107664d9d14634f444209a, type: 2}
|
||||
m_sharedMaterial: {fileID: -3454106745002405512, guid: 41512a7f2b107664d9d14634f444209a,
|
||||
type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
m_fontMaterials: []
|
||||
|
@ -2754,7 +2756,7 @@ MonoBehaviour:
|
|||
m_linkedTextComponent: {fileID: 0}
|
||||
parentLinkedComponent: {fileID: 0}
|
||||
m_enableKerning: 1
|
||||
m_ActiveFontFeatures: 00000000
|
||||
m_ActiveFontFeatures: 6e72656b
|
||||
m_enableExtraPadding: 0
|
||||
checkPaddingRequired: 0
|
||||
m_isRichText: 1
|
||||
|
@ -2809,12 +2811,12 @@ RectTransform:
|
|||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 7576580477895193190}
|
||||
- {fileID: 2842693604647789047}
|
||||
- {fileID: 2747978461159930281}
|
||||
- {fileID: 256288714842573992}
|
||||
- {fileID: 123959232355030105}
|
||||
- {fileID: 1686210318258698559}
|
||||
- {fileID: 8786280722722952149}
|
||||
- {fileID: 2842693604647789047}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
|
|
|
@ -5795,7 +5795,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 71b2355dc85b45e2aacc12328451f8d1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
PlayMode: 0
|
||||
PlayMode: 2
|
||||
packageName: DefaultPackage
|
||||
hostServerIP: https://kiosk-assets-bundle.oss-cn-hongkong.aliyuncs.com/Framework/CDN/
|
||||
sceneName:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Aliyun.OSS;
|
||||
using Aliyun.OSS.Common;
|
||||
|
@ -7,6 +8,7 @@ using UnityEngine;
|
|||
|
||||
namespace HK
|
||||
{
|
||||
[System.Serializable]
|
||||
public class OSSConfig
|
||||
{
|
||||
// 阿里云AccessKeyId
|
||||
|
@ -22,10 +24,10 @@ namespace HK
|
|||
public string bucketName = "kiosk-assets-bundle";
|
||||
|
||||
// OSS上的资源根存储目录
|
||||
public string ossRootDirectory = "Framework/"; //
|
||||
public string ossRootDirectory = "Framework"; //
|
||||
|
||||
// OSS上的资源相对存储目录
|
||||
public string ossRelativePath = "GameRes/v1.0/"; //
|
||||
public string ossRelativePath = ""; //
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -201,6 +203,69 @@ namespace HK
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UploadDirectoryAsync(string localDirectory, string ossDirectory, CancellationToken cancellationToken = default,
|
||||
Action<int, int> progressCallback = null)
|
||||
{
|
||||
if (!CheckInitialized()) return false;
|
||||
if (!Directory.Exists(localDirectory))
|
||||
{
|
||||
Debug.LogError($"本地目录不存在: {localDirectory}");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 检查是否已取消
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// 获取所有文件
|
||||
string[] allFiles = Directory.GetFiles(localDirectory, "*.*", SearchOption.AllDirectories);
|
||||
int totalCount = allFiles.Length;
|
||||
int currentCount = 0;
|
||||
|
||||
foreach (string filePath in allFiles)
|
||||
{
|
||||
// 每次循环开始前检查是否取消
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// 计算相对路径
|
||||
string relativePath = Path.GetRelativePath(localDirectory, filePath);
|
||||
// 转换为OSS路径格式(替换反斜杠为正斜杠)
|
||||
relativePath = relativePath.Replace('\\', '/');
|
||||
|
||||
// 构建OSS目标路径
|
||||
string ossTargetPath = string.IsNullOrEmpty(ossDirectory)
|
||||
? relativePath
|
||||
: $"{ossDirectory}/{relativePath}";
|
||||
|
||||
// 上传单个文件(传入取消令牌)
|
||||
bool success = await UploadFileAsync(filePath, ossTargetPath);
|
||||
if (!success)
|
||||
{
|
||||
Debug.LogError($"目录上传中断,文件上传失败: {filePath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 进度回调
|
||||
currentCount++;
|
||||
progressCallback?.Invoke(currentCount, totalCount);
|
||||
}
|
||||
|
||||
Debug.Log($"目录上传完成,共上传 {totalCount} 个文件");
|
||||
return true;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Debug.Log("目录上传已被取消");
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"目录上传异常: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从OSS下载文件到本地(优化版)
|
||||
/// </summary>
|
||||
|
|
|
@ -178,34 +178,29 @@ namespace HK
|
|||
/// </summary>
|
||||
private string GetHostServerURL()
|
||||
{
|
||||
// OSS基础信息(替换为你的Bucket信息)
|
||||
string bucketName = "kiosk-assets-bundle";
|
||||
string endpoint = "oss-cn-hongkong.aliyuncs.com"; // 地域Endpoint
|
||||
string appVersion = "v1.0"; // 资源版本号(需与OSS目录一致)
|
||||
string rootPath = "Framework/CDN"; // OSS上的资源根目录
|
||||
//string hostServerIP = "http://10.0.2.2"; //安卓模拟器地址
|
||||
// string hostServerIP = "http://127.0.0.1";
|
||||
string hostServerIP = "https://kiosk-assets-bundle.oss-cn-hongkong.aliyuncs.com/Framework";
|
||||
string appVersion = "v1.0";
|
||||
|
||||
// 获取平台路径(与OSS的平台目录对应)
|
||||
string platformPath = GetPlatformPath();
|
||||
|
||||
// 拼接OSS完整URL(格式:https://bucket.endpoint/rootPath/platform/version/)
|
||||
// https://kiosk-assets-bundle.oss-cn-hongkong.aliyuncs.com/FUJIFILM/CDN/PC/v1.0/01184a0f7f1c00a9e28a6932cfbe1a4f.bundle
|
||||
return $"https://{bucketName}.{endpoint}/{rootPath}/{platformPath}/{appVersion}/";
|
||||
}
|
||||
|
||||
// 辅助方法:获取平台对应的目录名
|
||||
private string GetPlatformPath()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
|
||||
if (buildTarget == UnityEditor.BuildTarget.Android) return "Android";
|
||||
else if (buildTarget == UnityEditor.BuildTarget.iOS) return "iOS";
|
||||
else if (buildTarget == UnityEditor.BuildTarget.WebGL) return "WebGL";
|
||||
else return "PC";
|
||||
if (UnityEditor.EditorUserBuildSettings.activeBuildTarget == UnityEditor.BuildTarget.Android)
|
||||
return $"{hostServerIP}/CDN/Android/{appVersion}";
|
||||
else if (UnityEditor.EditorUserBuildSettings.activeBuildTarget == UnityEditor.BuildTarget.iOS)
|
||||
return $"{hostServerIP}/CDN/IPhone/{appVersion}";
|
||||
else if (UnityEditor.EditorUserBuildSettings.activeBuildTarget == UnityEditor.BuildTarget.WebGL)
|
||||
return $"{hostServerIP}/CDN/WebGL/{appVersion}";
|
||||
else
|
||||
return $"{hostServerIP}/CDN/PC/{appVersion}";
|
||||
#else
|
||||
if (Application.platform == RuntimePlatform.Android) return "Android";
|
||||
else if (Application.platform == RuntimePlatform.IPhonePlayer) return "iOS";
|
||||
else if (Application.platform == RuntimePlatform.WebGLPlayer) return "WebGL";
|
||||
else return "PC";
|
||||
if (Application.platform == RuntimePlatform.Android)
|
||||
return $"{hostServerIP}/CDN/Android/{appVersion}";
|
||||
else if (Application.platform == RuntimePlatform.IPhonePlayer)
|
||||
return $"{hostServerIP}/CDN/IPhone/{appVersion}";
|
||||
else if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
return $"{hostServerIP}/CDN/WebGL/{appVersion}";
|
||||
else
|
||||
return $"{hostServerIP}/CDN/PC/{appVersion}";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -240,6 +235,7 @@ namespace HK
|
|||
|
||||
private async UniTask UpdatePackageVersion()
|
||||
{
|
||||
Debug.Log("请求资源版本 !");
|
||||
var package = YooAssets.GetPackage(PackageName);
|
||||
var operation = package.RequestPackageVersionAsync();
|
||||
await operation.Task;
|
||||
|
@ -265,6 +261,7 @@ namespace HK
|
|||
|
||||
private async UniTask FsmUpdatePackageManifest()
|
||||
{
|
||||
Debug.Log("更新资源清单!");
|
||||
var package = YooAssets.GetPackage(PackageName);
|
||||
var operation = package.UpdatePackageManifestAsync(packageVersion);
|
||||
await operation.Task;
|
||||
|
@ -288,7 +285,7 @@ namespace HK
|
|||
private async UniTask FsmCreateDownloader()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
Log.Debug("创建资源下载器!");
|
||||
Debug.Log("创建资源下载器!");
|
||||
CreateDownloader();
|
||||
}
|
||||
|
||||
|
@ -326,7 +323,7 @@ namespace HK
|
|||
private async UniTask FsmDownloadPackageFiles()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
Log.Debug("开始下载资源文件!");
|
||||
Debug.Log("开始下载资源文件!");
|
||||
downloader.DownloadErrorCallback = DownloadErrorCallback;
|
||||
downloader.DownloadUpdateCallback = DownloadProgressCallback;
|
||||
downloader.BeginDownload();
|
||||
|
@ -360,7 +357,7 @@ namespace HK
|
|||
private async UniTask FsmDownloadPackageOver()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
Log.Debug("资源文件下载完毕!");
|
||||
Debug.Log("资源文件下载完毕!");
|
||||
await FsmClearCacheBundle();
|
||||
}
|
||||
|
||||
|
@ -371,7 +368,7 @@ namespace HK
|
|||
private async UniTask FsmClearCacheBundle()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
Log.Debug("清理未使用的缓存文件!");
|
||||
Debug.Log("清理未使用的缓存文件!");
|
||||
var package = YooAssets.GetPackage(PackageName);
|
||||
var operation = package.ClearCacheFilesAsync(EFileClearMode.ClearUnusedBundleFiles);
|
||||
operation.Completed += Operation_Completed;
|
||||
|
@ -389,7 +386,7 @@ namespace HK
|
|||
private async UniTask FsmStartGame()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
Log.Debug("开始游戏!");
|
||||
Debug.Log("开始游戏!");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -1,60 +1,46 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace HK.Editor
|
||||
{
|
||||
public class UploadResourcesEditor : OdinEditorWindow
|
||||
[System.Serializable]
|
||||
public class OSSConfig : HK.OSSConfig
|
||||
{
|
||||
[MenuItem("Tool/Upload Resources")]
|
||||
static void GetWindow()
|
||||
[ReadOnly] public BuildTargetPlatform platform;
|
||||
public string appVersion;
|
||||
|
||||
public string GetOssUploadUrl()
|
||||
{
|
||||
// GetWindow<UploadResourcesEditor>().Show();
|
||||
var window = GetWindow<UploadResourcesEditor>();
|
||||
window.projectName = Application.productName;
|
||||
window.version = "v1.0";
|
||||
window.platform = BuildTargetPlatform.StandaloneWindows;
|
||||
window.Show();
|
||||
// https://kiosk-assets-bundle.oss-cn-hongkong.aliyuncs.com/Framework
|
||||
return $"CDN/{GetPlatformName()}/{appVersion}";
|
||||
}
|
||||
|
||||
[FolderPath] public string serverUrl;
|
||||
[FolderPath] public string assetRootFolder;
|
||||
public string projectName;
|
||||
public BuildTargetPlatform platform;
|
||||
public string version;
|
||||
|
||||
|
||||
[Button("上传资源到本地服务器")]
|
||||
public void UploadResources()
|
||||
string GetPlatformName()
|
||||
{
|
||||
Debug.Log("Upload Resources Start");
|
||||
var directories = Directory.GetDirectories(assetRootFolder);
|
||||
var strings = directories.OrderByDescending(a => new DirectoryInfo(a).CreationTime).ToArray();
|
||||
Debug.Log(strings[0]);
|
||||
var paths = Directory.GetFiles(strings[0]);
|
||||
|
||||
string platformPath = "";
|
||||
switch (platform)
|
||||
{
|
||||
case BuildTargetPlatform.StandaloneWindows:
|
||||
platformPath = "PC";
|
||||
return "PC";
|
||||
break;
|
||||
case BuildTargetPlatform.StandaloneWindows64:
|
||||
platformPath = "PC";
|
||||
return "PC";
|
||||
break;
|
||||
case BuildTargetPlatform.Android:
|
||||
platformPath = "Android";
|
||||
return "Android";
|
||||
break;
|
||||
case BuildTargetPlatform.WebGL:
|
||||
platformPath = "WebGL";
|
||||
return "WebGL";
|
||||
break;
|
||||
case BuildTargetPlatform.IOS:
|
||||
platformPath = "IOS";
|
||||
return "iOS";
|
||||
break;
|
||||
case BuildTargetPlatform.StandaloneOSX:
|
||||
break;
|
||||
|
@ -68,21 +54,140 @@ namespace HK.Editor
|
|||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
var serverPath = Path.Combine(serverUrl, projectName, platformPath, version);
|
||||
if (!Directory.Exists(serverPath))
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class ResourceConfig
|
||||
{
|
||||
public string rootFolder = "Bundles";
|
||||
public BuildTargetPlatform platform = BuildTargetPlatform.StandaloneWindows64;
|
||||
public string packageName = "DefaultPackage";
|
||||
[ReadOnly] public string latestVersionPath;
|
||||
|
||||
public string GetPackageFolder()
|
||||
{
|
||||
return Path.Combine(rootFolder, platform.ToString().Replace(" ", ""), packageName);
|
||||
}
|
||||
}
|
||||
|
||||
public class UploadResourcesEditor : OdinEditorWindow
|
||||
{
|
||||
[MenuItem("Tool/Upload Resources")]
|
||||
static void GetWindow()
|
||||
{
|
||||
// GetWindow<UploadResourcesEditor>().Show();
|
||||
var window = GetWindow<UploadResourcesEditor>();
|
||||
window.ossConfig = new OSSConfig();
|
||||
window.ossConfig.appVersion = "v1.0";
|
||||
window.ossConfig.platform = BuildTargetPlatform.StandaloneWindows;
|
||||
window.Show();
|
||||
}
|
||||
|
||||
public OSSConfig ossConfig;
|
||||
public ResourceConfig resourceConfig;
|
||||
|
||||
[Button("GetAssetVersion")]
|
||||
public void GetAssetVersion()
|
||||
{
|
||||
string _latestVersion;
|
||||
string versionRootPath = resourceConfig.GetPackageFolder();
|
||||
Debug.Log(versionRootPath);
|
||||
versionRootPath = Path.GetFullPath(versionRootPath);
|
||||
// 2. 检查版本根目录是否存在
|
||||
if (!Directory.Exists(versionRootPath))
|
||||
{
|
||||
Directory.CreateDirectory(serverPath);
|
||||
Debug.Log($"版本根目录不存在:{versionRootPath}\n请检查目录配置是否正确");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var path in paths)
|
||||
// 3. 获取所有版本目录(如2025-08-25-669)
|
||||
var versionDirectories = Directory.GetDirectories(versionRootPath)
|
||||
.Select(Path.GetFileName)
|
||||
.Where(dir => IsValidDateVersionFormat(dir)) // 过滤日期格式的目录
|
||||
.ToList();
|
||||
|
||||
if (versionDirectories.Count == 0)
|
||||
{
|
||||
var fileInfo = new FileInfo(path);
|
||||
var combine = Path.Combine(serverPath, fileInfo.Name);
|
||||
fileInfo.CopyTo(combine, true);
|
||||
Debug.Log($"未找到任何版本目录:{versionRootPath}\n请确认已构建资源");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"Upload Resources version is {strings[0]}");
|
||||
// 4. 按日期排序(最新的日期在最后)
|
||||
var sortedVersions = versionDirectories
|
||||
.OrderBy(dir => ParseDateFromVersion(dir)) // 按日期升序
|
||||
.ToList();
|
||||
|
||||
// 5. 最新版本是最后一个
|
||||
_latestVersion = sortedVersions.Last();
|
||||
|
||||
resourceConfig.latestVersionPath = Path.Combine(versionRootPath, _latestVersion);
|
||||
ossConfig.platform = resourceConfig.platform;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证目录名是否为日期格式(如2025-08-25-669)
|
||||
/// </summary>
|
||||
private bool IsValidDateVersionFormat(string dirName)
|
||||
{
|
||||
// 分割格式:日期-编号(如2025-08-25-669 → 前3部分是日期)
|
||||
string[] parts = dirName.Split('-');
|
||||
if (parts.Length < 3)
|
||||
return false;
|
||||
|
||||
// 尝试解析日期部分(前3段:年-月-日)
|
||||
return DateTime.TryParse($"{parts[0]}-{parts[1]}-{parts[2]}", out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从目录名中解析日期(用于排序)
|
||||
/// </summary>
|
||||
private DateTime ParseDateFromVersion(string dirName)
|
||||
{
|
||||
string[] parts = dirName.Split('-');
|
||||
DateTime.TryParse($"{parts[0]}-{parts[1]}-{parts[2]}", out DateTime date);
|
||||
return date;
|
||||
}
|
||||
|
||||
CancellationTokenSource source;
|
||||
bool isUploading = false;
|
||||
|
||||
[ReadOnly] [ShowIf("isUploading")] [ProgressBar(0, 100, 0, 255, 0)]
|
||||
public float progress;
|
||||
|
||||
[Button("上传资源到本地服务器")]
|
||||
public async void UploadResources()
|
||||
{
|
||||
Debug.Log("Upload Resources Start");
|
||||
isUploading = true;
|
||||
progress = 0;
|
||||
GetAssetVersion();
|
||||
|
||||
var ossUploadUrl = ossConfig.GetOssUploadUrl();
|
||||
Debug.Log(ossUploadUrl);
|
||||
|
||||
AliyunOSSManager.Instance.Initialize(ossConfig);
|
||||
source = new CancellationTokenSource();
|
||||
await AliyunOSSManager.Instance.UploadDirectoryAsync(resourceConfig.latestVersionPath, ossUploadUrl,
|
||||
source.Token,
|
||||
ProgressCallback);
|
||||
isUploading = false;
|
||||
Debug.Log("Upload Resources Finished");
|
||||
}
|
||||
|
||||
[ShowIf("isUploading")]
|
||||
[Button("取消上传资源到本地服务器")]
|
||||
public void CancelUploadResources()
|
||||
{
|
||||
progress = 0;
|
||||
source.Cancel();
|
||||
}
|
||||
|
||||
private void ProgressCallback(int arg1, int arg2)
|
||||
{
|
||||
progress = ((float)arg1 / arg2) * 100;
|
||||
Debug.Log($"progress {arg1}/{arg2}");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using YooAsset.Editor;
|
||||
|
||||
/// <summary>
|
||||
/// YooAsset编辑器工具:获取本地构建的最新版本号
|
||||
/// </summary>
|
||||
public class YooAssetLocalVersionFetcher : EditorWindow
|
||||
{
|
||||
// 目录配置(根据你的实际路径填写)
|
||||
private string _rootBuildFolder = "Bundles"; // 根构建目录
|
||||
private string _platformFolder = "StandaloneWindows64"; // 平台目录
|
||||
private string _packageFolder = "DefaultPackage"; // 资源包目录
|
||||
private string _latestVersion = "未找到版本信息";
|
||||
|
||||
// 打开工具窗口
|
||||
[MenuItem("YooAsset/获取本地最新版本号(日期格式)")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
GetWindow<YooAssetLocalVersionFetcher>("本地版本号查询");
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.Label("版本目录配置", EditorStyles.boldLabel);
|
||||
|
||||
// 配置目录层级(与你的实际路径对应)
|
||||
_rootBuildFolder = EditorGUILayout.TextField("根构建目录", _rootBuildFolder);
|
||||
_platformFolder = EditorGUILayout.TextField("平台目录", _platformFolder);
|
||||
_packageFolder = EditorGUILayout.TextField("资源包目录", _packageFolder);
|
||||
|
||||
// 配置目录层级(与你的实际路径对应)
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
// 点击获取最新版本
|
||||
if (GUILayout.Button("获取本地最新版本号"))
|
||||
{
|
||||
FetchLatestVersion();
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
GUILayout.Label($"最新本地版本目录:{_latestVersion}", EditorStyles.label);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从日期格式的版本目录中获取最新版本
|
||||
/// </summary>
|
||||
private void FetchLatestVersion()
|
||||
{
|
||||
// 1. 计算完整的版本根目录路径
|
||||
// 你的目录结构:Bundles\StandaloneWindows64\DefaultPackage\版本目录
|
||||
string versionRootPath = Path.Combine(_rootBuildFolder, _platformFolder, _packageFolder);
|
||||
;
|
||||
// 标准化路径(处理斜杠方向)
|
||||
versionRootPath = Path.GetFullPath(versionRootPath);
|
||||
|
||||
// 2. 检查版本根目录是否存在
|
||||
if (!Directory.Exists(versionRootPath))
|
||||
{
|
||||
_latestVersion = $"版本根目录不存在:{versionRootPath}\n请检查目录配置是否正确";
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 获取所有版本目录(如2025-08-25-669)
|
||||
var versionDirectories = Directory.GetDirectories(versionRootPath)
|
||||
.Select(Path.GetFileName)
|
||||
.Where(dir => IsValidDateVersionFormat(dir)) // 过滤日期格式的目录
|
||||
.ToList();
|
||||
|
||||
if (versionDirectories.Count == 0)
|
||||
{
|
||||
_latestVersion = $"未找到任何版本目录:{versionRootPath}\n请确认已构建资源";
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 按日期排序(最新的日期在最后)
|
||||
var sortedVersions = versionDirectories
|
||||
.OrderBy(dir => ParseDateFromVersion(dir)) // 按日期升序
|
||||
.ToList();
|
||||
|
||||
// 5. 最新版本是最后一个
|
||||
_latestVersion = sortedVersions.Last();
|
||||
|
||||
// 6. 验证该版本目录是否包含清单文件
|
||||
string manifestPath = Path.Combine(versionRootPath, _latestVersion, "PackageManifest.manifest");
|
||||
if (!File.Exists(manifestPath))
|
||||
{
|
||||
_latestVersion += "(警告:未找到PackageManifest.manifest,构建可能不完整)";
|
||||
}
|
||||
|
||||
var v = Path.Combine(versionRootPath, _latestVersion);
|
||||
Debug.Log(v);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证目录名是否为日期格式(如2025-08-25-669)
|
||||
/// </summary>
|
||||
private bool IsValidDateVersionFormat(string dirName)
|
||||
{
|
||||
// 分割格式:日期-编号(如2025-08-25-669 → 前3部分是日期)
|
||||
string[] parts = dirName.Split('-');
|
||||
if (parts.Length < 3)
|
||||
return false;
|
||||
|
||||
// 尝试解析日期部分(前3段:年-月-日)
|
||||
return DateTime.TryParse($"{parts[0]}-{parts[1]}-{parts[2]}", out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从目录名中解析日期(用于排序)
|
||||
/// </summary>
|
||||
private DateTime ParseDateFromVersion(string dirName)
|
||||
{
|
||||
string[] parts = dirName.Split('-');
|
||||
DateTime.TryParse($"{parts[0]}-{parts[1]}-{parts[2]}", out DateTime date);
|
||||
return date;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 334914fe30cd4b55acd8eacfc26f81e4
|
||||
timeCreated: 1757820725
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6ce5fef283ca4959b4f901c1ee2baa4c
|
||||
timeCreated: 1757755894
|
Binary file not shown.
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"FileVersion": "1.0.0",
|
||||
"PackageName": "DefaultPackage",
|
||||
"PackageVersion": "2025-09-13-1017",
|
||||
"PackageVersion": "2025-09-14-655",
|
||||
"Wrappers": [
|
||||
{
|
||||
"BundleGUID": "01184a0f7f1c00a9e28a6932cfbe1a4f",
|
||||
|
@ -215,10 +215,6 @@
|
|||
"BundleGUID": "7cdae5f0ebfa5de1da41fb5c09c99067",
|
||||
"FileName": "7cdae5f0ebfa5de1da41fb5c09c99067.bundle"
|
||||
},
|
||||
{
|
||||
"BundleGUID": "808c5749e9d58b4510e99bfaf20051c1",
|
||||
"FileName": "808c5749e9d58b4510e99bfaf20051c1.bundle"
|
||||
},
|
||||
{
|
||||
"BundleGUID": "841bbbe552b1ec1bd00e171133dab21a",
|
||||
"FileName": "841bbbe552b1ec1bd00e171133dab21a.bundle"
|
||||
|
@ -331,6 +327,10 @@
|
|||
"BundleGUID": "e03614dd4c6ad7770669e29557b70dac",
|
||||
"FileName": "e03614dd4c6ad7770669e29557b70dac.bundle"
|
||||
},
|
||||
{
|
||||
"BundleGUID": "e346af9f6e3ca11a3a3f5dcd881d1cd7",
|
||||
"FileName": "e346af9f6e3ca11a3a3f5dcd881d1cd7.bundle"
|
||||
},
|
||||
{
|
||||
"BundleGUID": "e51760044ed310a548e29a10e5c9e6c3",
|
||||
"FileName": "e51760044ed310a548e29a10e5c9e6c3.bundle"
|
||||
|
|
|
@ -1 +1 @@
|
|||
2025-09-13-1017
|
||||
2025-09-14-655
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
4198c757
|
Loading…
Reference in New Issue