【m】框架大更新
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
public static class ArtLoadAssetLocal
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 获取本地全部作用域
|
||||
/// </summary>
|
||||
public static string[] GetLocalDomainAllName()
|
||||
{
|
||||
var creatDomainEntities = GetLocalDomainAll();
|
||||
string[] domains = new string[creatDomainEntities.Count];
|
||||
for (int i = 0; i < creatDomainEntities.Count; i++)
|
||||
{
|
||||
domains[i] = creatDomainEntities[i].DomainName;
|
||||
}
|
||||
|
||||
return domains;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全部作用域
|
||||
/// </summary>
|
||||
public static List<CreatArtDomainEntity> GetLocalDomainAll()
|
||||
{
|
||||
string domainPath = $"{Application.dataPath}/Art";
|
||||
string[] domains;
|
||||
// 新增目录获取代码
|
||||
if (Directory.Exists(domainPath))
|
||||
{
|
||||
var dirInfo = new DirectoryInfo(domainPath);
|
||||
// 获取直接子目录(不递归)
|
||||
domains = dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly)
|
||||
.Select(d => d.Name)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
domains = Array.Empty<string>();
|
||||
}
|
||||
|
||||
List<CreatArtDomainEntity> domainList = new List<CreatArtDomainEntity>();
|
||||
foreach (var item in domains)
|
||||
{
|
||||
if (File.Exists($"{domainPath}/{item}/Scenes/TestScene.unity"))
|
||||
{
|
||||
CreatArtDomainEntity domainEntity = new CreatArtDomainEntity(domainList)
|
||||
{
|
||||
DomainName = item,
|
||||
domainPath = $"{domainPath}/{item}"
|
||||
};
|
||||
domainList.Add(domainEntity);
|
||||
}
|
||||
}
|
||||
|
||||
return domainList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0b4f8af6dd9440e94d32f7cc565a430
|
||||
timeCreated: 1761727096
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using Stary.Evo;
|
||||
using Stary.Evo.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ArtSceneData))]
|
||||
public class ArtSceneDataEditor : OdinEditor
|
||||
{
|
||||
// /// <summary>
|
||||
// /// 序列化属性,在OnEnable中获取
|
||||
// /// </summary>
|
||||
// [HideInInspector] private SerializedProperty artScenes;
|
||||
private void OnEnable()
|
||||
{
|
||||
//artScenes = serializedObject.FindProperty("artScenes");
|
||||
ArtSceneData artSceneData = (ArtSceneData)target;
|
||||
List<ArtScene> artScenesList = artSceneData.artScenes;
|
||||
List<int> removeIndexList = new List<int>();
|
||||
for (int i = 0; i < artScenesList.Count; i++)
|
||||
{
|
||||
ArtScene artScene = artScenesList[i];
|
||||
if (artScene.sceneAsset==null)
|
||||
{
|
||||
removeIndexList.Add(i);
|
||||
}
|
||||
}
|
||||
for (int i = removeIndexList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
int index = removeIndexList[i];
|
||||
artScenesList.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5762b2ce1b7e4184afd8785c147d42da
|
||||
timeCreated: 1761301851
|
||||
@@ -0,0 +1,182 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
public class ArtServerManageWindow : OdinEditorWindow
|
||||
{
|
||||
|
||||
[MenuItem("Evo/Art/服务器数据管理工具", false, 2)]
|
||||
static void Init()
|
||||
{
|
||||
// Get existing open window or if none, make a new one:
|
||||
ArtServerManageWindow window = (ArtServerManageWindow)EditorWindow.GetWindow(typeof(ArtServerManageWindow));
|
||||
window.Show();
|
||||
}
|
||||
|
||||
[TitleGroup("创建Art作用域")] public string domain;
|
||||
|
||||
[TitleGroup("创建Art作用域")]
|
||||
[Button("创建Art", ButtonSizes.Large)]
|
||||
public async void CreatDomain()
|
||||
{
|
||||
// if (GetCreatDomainAll().Count>0)
|
||||
// {
|
||||
// EditorUtility.DisplayDialog("错误!", "Domain仅可以创建一个,请在下方删除存在的Domain", "确定");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (string.IsNullOrEmpty(domain))
|
||||
{
|
||||
EditorUtility.DisplayDialog("错误!", "请输入将要创建Art的编号", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
string artDomainPath = $"{Application.dataPath}/Art/{domain}";
|
||||
if (!Directory.Exists(artDomainPath))
|
||||
{
|
||||
Directory.CreateDirectory(artDomainPath);
|
||||
|
||||
if (!Directory.Exists(artDomainPath))
|
||||
//创建Animation文件夹
|
||||
CreatDirectory(artDomainPath + "/Animation");
|
||||
//创建Effects文件夹
|
||||
CreatDirectory(artDomainPath + "/Effects");
|
||||
//创建Fbx文件夹
|
||||
CreatDirectory(artDomainPath + "/Fbx");
|
||||
//创建Font文件夹
|
||||
CreatDirectory(artDomainPath + "/Font");
|
||||
//创建Materials文件夹
|
||||
CreatDirectory(artDomainPath + "/Materials");
|
||||
//创建Prefabs文件夹
|
||||
CreatDirectory(artDomainPath + "/Prefabs");
|
||||
//创建Scenes文件夹
|
||||
CreatDirectory(artDomainPath + "/Scenes");
|
||||
//创建/Scenes/Test文件夹
|
||||
CreatDirectory(artDomainPath + "/Scenes");
|
||||
//创建Shader文件夹
|
||||
CreatDirectory(artDomainPath + "/Shader");
|
||||
//创建Textures文件夹
|
||||
CreatDirectory(artDomainPath + "/Textures");
|
||||
|
||||
//创建Config文件夹
|
||||
CreatDirectory(artDomainPath + "/Config");
|
||||
|
||||
File.WriteAllTextAsync(
|
||||
$"{artDomainPath}/这里放所有美术的资源,因涉及打包依赖等原因,不建议在上一层节点新增文件夹,如涉及文件夹规范等问题请@张铮.hint", "");
|
||||
}
|
||||
|
||||
//创建Art 测试场景
|
||||
/* 2. 再建 Scenes/Test */
|
||||
string sceneDir = $"{artDomainPath}/Scenes";
|
||||
if (!Directory.Exists(sceneDir))
|
||||
{
|
||||
Directory.CreateDirectory(sceneDir);
|
||||
}
|
||||
/* 3. 创建新场景 */
|
||||
var newScene = UnityEditor.SceneManagement.EditorSceneManager.NewScene(
|
||||
UnityEditor.SceneManagement.NewSceneSetup.DefaultGameObjects,
|
||||
UnityEditor.SceneManagement.NewSceneMode.Single);
|
||||
|
||||
/* 4. 删除默认相机(和灯光)*/
|
||||
foreach (var go in newScene.GetRootGameObjects())
|
||||
{
|
||||
if (go.name == "Main Camera" || go.name == "Directional Light")
|
||||
GameObject.DestroyImmediate(go);
|
||||
}
|
||||
|
||||
/* 5. 载入并实例化 RKCameraRig.prefab */
|
||||
string prefabPath = "Prefabs/BaseSetting/RKCameraRig";
|
||||
|
||||
var prefab = Resources.Load<GameObject>(prefabPath);
|
||||
var spawned = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
|
||||
spawned.name = "RKCameraRigTest";
|
||||
|
||||
/* 6. 保存场景 */
|
||||
string scenePath = Path.Combine("Assets/Art", domain, "Scenes", "TestScene.unity");
|
||||
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(newScene, scenePath);
|
||||
//创建Art 测试场景配置文件
|
||||
string configDir = $"{artDomainPath}/Config";
|
||||
if (!Directory.Exists(configDir))
|
||||
{
|
||||
Directory.CreateDirectory(configDir);
|
||||
}
|
||||
//模块配置资源
|
||||
ArtSceneData artSceneData = CreateInstance<ArtSceneData>();
|
||||
|
||||
|
||||
AssetDatabase.CreateAsset(artSceneData, $"Assets/Art/{domain}/Config/ArtSceneData.asset");
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
|
||||
[ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false,
|
||||
HideRemoveButton = true, HideAddButton = true)]
|
||||
public List<CreatArtServerDomainEntity> domainList;
|
||||
|
||||
protected override async void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if (domainList != null)
|
||||
domainList.Clear();
|
||||
var resDmainResponse = await ArtLoadAssetServer.GetServerDomainAll();
|
||||
foreach (var response in resDmainResponse)
|
||||
{
|
||||
string domainPath = $"{Application.dataPath}/Art/{response.DomainName}";
|
||||
var domainEntity = new CreatArtServerDomainEntity(domainList);
|
||||
domainEntity.SetDomainData(response.DomainName, domainPath,response, ArtLoadAssetServer.ip);
|
||||
domainList.Add(domainEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static void CreatDirectory(string artDomainPath)
|
||||
{
|
||||
if (!Directory.Exists(artDomainPath))
|
||||
{
|
||||
//创建Animation文件夹
|
||||
Directory.CreateDirectory(artDomainPath);
|
||||
}
|
||||
}
|
||||
public static void CreateDomainDirectory(string domain)
|
||||
{
|
||||
string artDomainPath = $"{Application.dataPath}/Art/{domain}";
|
||||
if (!Directory.Exists(artDomainPath))
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", $"不存在此Domain:{domain},无法创建", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
//创建Animation文件夹
|
||||
CreatDirectory(artDomainPath + "/Animation");
|
||||
//创建Effects文件夹
|
||||
CreatDirectory(artDomainPath + "/Effects");
|
||||
//创建Fbx文件夹
|
||||
CreatDirectory(artDomainPath + "/Fbx");
|
||||
//创建Font文件夹
|
||||
CreatDirectory(artDomainPath + "/Font");
|
||||
//创建Materials文件夹
|
||||
CreatDirectory(artDomainPath + "/Materials");
|
||||
//创建Prefabs文件夹
|
||||
CreatDirectory(artDomainPath + "/Prefabs");
|
||||
//创建Scenes文件夹
|
||||
CreatDirectory(artDomainPath + "/Scenes");
|
||||
//创建/Scenes/Test文件夹
|
||||
CreatDirectory(artDomainPath + "/Scenes/Test");
|
||||
//创建Shader文件夹
|
||||
CreatDirectory(artDomainPath + "/Shader");
|
||||
//创建Textures文件夹
|
||||
CreatDirectory(artDomainPath + "/Textures");
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59d31311b3e14ae99453fab351e1fcf3
|
||||
timeCreated: 1761545309
|
||||
@@ -0,0 +1,526 @@
|
||||
/****************************************************
|
||||
文件:BuildAssetWindow.cs
|
||||
作者:xosmo_
|
||||
邮箱:
|
||||
日期:2025/3/10 10:43:20
|
||||
功能:
|
||||
*****************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using YooAsset.Editor;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
public class BuildArtAssetWindow : OdinEditorWindow
|
||||
{
|
||||
public static OdinEditorWindow window;
|
||||
private HotfixMainResDomain hotfixMainResDomain;
|
||||
|
||||
[MenuItem("Evo/Art/Art资源打包工具", false, 1)]
|
||||
static void ShowWindows()
|
||||
{
|
||||
|
||||
window = (BuildArtAssetWindow)EditorWindow.GetWindow(typeof(BuildArtAssetWindow));
|
||||
window.Show();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
EditorUtility.ClearProgressBar();
|
||||
packageName = "";
|
||||
}
|
||||
|
||||
protected override async void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
//初始化读取资源配置表
|
||||
hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
|
||||
if (hotfixMainResDomain == null)
|
||||
{
|
||||
Debug.LogError($"UnityEvo:读取资源配置表失败【HotfixMainResDomain】...表在Resources下不存在,请创建");
|
||||
}
|
||||
else
|
||||
{
|
||||
ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
|
||||
EditorPrefs.SetString("ip", ip);
|
||||
userName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
|
||||
password = hotfixMainResDomain.hotfixMainResDomainEntity.password;
|
||||
}
|
||||
|
||||
GetBuildPackageNames();
|
||||
if (string.IsNullOrEmpty(ip))
|
||||
{
|
||||
buildAssetType = BuildAssetType.Login;
|
||||
return;
|
||||
}
|
||||
|
||||
bool isValidateToken = await WebRequestSystem.GetValidateToken(ip + "/Authentication/validateToken");
|
||||
if (isValidateToken)
|
||||
{
|
||||
buildAssetType = BuildAssetType.Build;
|
||||
}
|
||||
else
|
||||
{
|
||||
buildAssetType = BuildAssetType.Login;
|
||||
}
|
||||
|
||||
|
||||
//初始化打包管线
|
||||
_buildPipelineViewer = new ScriptableBuildPipelineViewer(packageName,
|
||||
EBuildPipeline.ScriptableBuildPipeline.ToString(), _packageVersion);
|
||||
_buildPipelineViewer.clearBuildCacheToggle = true;
|
||||
_buildPipelineViewer.useAssetDependencyDBToggle = false;
|
||||
_buildPipelineViewer.SetBuildCacheToggle();
|
||||
_buildPipelineViewer.SetUseAssetDependencyDB();
|
||||
}
|
||||
|
||||
public static void RemoveBuildAssetWindow()
|
||||
{
|
||||
if (window != null)
|
||||
window.Close();
|
||||
}
|
||||
|
||||
[EnumToggleButtons, HideLabel] public BuildAssetType buildAssetType;
|
||||
|
||||
#region BuildAssetLogin
|
||||
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Login")]
|
||||
[BoxGroup("Login", showLabel: false)]
|
||||
[OnValueChanged("SetWebRequestInfo")]
|
||||
public string ip, userName, password;
|
||||
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Login")]
|
||||
[BoxGroup("Login", showLabel: false)]
|
||||
[Button("登录", ButtonSizes.Large)]
|
||||
[InfoBox("@ message", InfoMessageType.Info)]
|
||||
public async void LoginButton()
|
||||
{
|
||||
string url = ip + "/Authentication/login";
|
||||
EditorUtility.DisplayProgressBar("提示", $"登陆中~", 0f);
|
||||
bool islogin = await WebRequestSystem.Login(url, userName, password);
|
||||
float progress = 0f;
|
||||
while (progress >= 1f)
|
||||
{
|
||||
progress += 0.1f;
|
||||
EditorUtility.DisplayProgressBar("提示", $"登陆中~", progress);
|
||||
await Task.Delay(TimeSpan.FromSeconds(0.2f));
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
UpdateMessage(islogin);
|
||||
}
|
||||
|
||||
private void SetWebRequestInfo()
|
||||
{
|
||||
if (hotfixMainResDomain != null)
|
||||
{
|
||||
hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig = ip;
|
||||
hotfixMainResDomain.hotfixMainResDomainEntity.username = userName;
|
||||
hotfixMainResDomain.hotfixMainResDomainEntity.password = password;
|
||||
EditorPrefs.SetString("ip", ip);
|
||||
EditorUtility.SetDirty(hotfixMainResDomain);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
|
||||
private string message;
|
||||
|
||||
public void UpdateMessage(bool islogin)
|
||||
{
|
||||
message = "当前登录状态为:" + islogin;
|
||||
if (islogin)
|
||||
{
|
||||
buildAssetType = BuildAssetType.Build;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected void OnSelectionChange()
|
||||
{
|
||||
// EditorUtility.SetDirty(BuildAssetDataSetting);
|
||||
// AssetDatabase.SaveAssets();
|
||||
//AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[Title("包裹列表", titleAlignment: TitleAlignments.Centered)]
|
||||
[HorizontalGroup("Build/BuildPipeline"), HideLabel]
|
||||
[ValueDropdown("GetBuildPackageNames")]
|
||||
[OnValueChanged("SetBuildPackageNames")]
|
||||
public string selectedPackageNames;
|
||||
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[Title("当前打包平台", titleAlignment: TitleAlignments.Centered)]
|
||||
[ReadOnly]
|
||||
[HorizontalGroup("Build/BuildPipeline"), HideLabel]
|
||||
public string buildTarget;
|
||||
|
||||
private static string packageName;
|
||||
|
||||
|
||||
[Title("版本号", titleAlignment: TitleAlignments.Centered)]
|
||||
[HorizontalGroup("Build/PackageVersion"), HideLabel]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[OnValueChanged("OnPackageValueChanged")]
|
||||
public string _packageVersion;
|
||||
|
||||
private string PackageVersion
|
||||
{
|
||||
get { return _packageVersion; }
|
||||
set
|
||||
{
|
||||
_packageVersion = value;
|
||||
if (_buildPipelineViewer != null)
|
||||
_buildPipelineViewer.SetBuildPackagePackageVersion(_packageVersion);
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractBuildPipelineViewer _buildPipelineViewer;
|
||||
|
||||
|
||||
#region BuildAsset
|
||||
|
||||
public void OnPackageValueChanged()
|
||||
{
|
||||
if (_buildPipelineViewer != null)
|
||||
_buildPipelineViewer.SetBuildPackageData(packageName, EBuildPipeline.ScriptableBuildPipeline.ToString(),
|
||||
_packageVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测当前所有包裹
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private List<string> GetBuildPackageNames()
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
foreach (var name in ArtLoadAssetLocal.GetLocalDomainAllName())
|
||||
{
|
||||
result.Add(name);
|
||||
}
|
||||
|
||||
if (selectedPackageNames.IsNullOrEmpty())
|
||||
{
|
||||
selectedPackageNames = result[0];
|
||||
}
|
||||
|
||||
SetBuildPackageNames();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前包裹
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetBuildPackageName()
|
||||
{
|
||||
return packageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置当前包裹
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private void SetBuildPackageNames()
|
||||
{
|
||||
if (selectedPackageNames != packageName)
|
||||
{
|
||||
GetHostBuildPackageVersion();
|
||||
Init();
|
||||
}
|
||||
|
||||
packageName = selectedPackageNames;
|
||||
OnPackageValueChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Update
|
||||
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[Title("打包本地资源", titleAlignment: TitleAlignments.Centered)]
|
||||
[HideLabel]
|
||||
public BuildAssetEntity onBuildPipelineEntity;
|
||||
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[Title("上传资源", titleAlignment: TitleAlignments.Centered)]
|
||||
[HideLabel]
|
||||
public BuildAssetEntity onUpdateBuildPipelineEntity;
|
||||
|
||||
|
||||
private void OnBuildPipeline()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示",
|
||||
$"开始构建资源包[{selectedPackageNames}],版本号为[{_buildPipelineViewer.packageVersion}]!", "Yes", "No"))
|
||||
{
|
||||
EditorTools.ClearUnityConsole();
|
||||
MarkAdressable.AddArtMark(() => { EditorApplication.delayCall += _buildPipelineViewer.ExecuteBuild; });
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[Build] 打包已经取消");
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnUpdateBuildPipeline()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示",
|
||||
$"开始上传至服务器[{selectedPackageNames}],,版本号为[{_buildPipelineViewer.packageVersion}", "Yes", "No"))
|
||||
{
|
||||
// 新增:打包为zip的逻辑
|
||||
string zipFilePath = BuildZip();
|
||||
await UpdateFileDataResDomain(zipFilePath);
|
||||
await Task.Delay(1000);
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
EditorUtility.DisplayDialog("提示", "Update] 上传已经取消", "确定");
|
||||
Debug.LogWarning("[Update] 上传已经取消");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string BuildZip()
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("提示", $"开始上传{packageName}(打包zip)", 0.0f);
|
||||
// 新增:打包为zip的逻辑
|
||||
string zipFileName =
|
||||
$"{packageName}_{_packageVersion}.zip";
|
||||
//原yooAsset目录
|
||||
var outputPackageDirectory =
|
||||
$"{AssetBundleBuilderHelper.GetDefaultBuildOutputRoot()}/{EditorUserBuildSettings.activeBuildTarget}/{packageName}";
|
||||
|
||||
//拷贝目录
|
||||
string outFilePath = $"{outputPackageDirectory}/{_packageVersion}";
|
||||
|
||||
var copyPackageDirectory =
|
||||
$"{Application.streamingAssetsPath}/{YooAssetSettingsData.GetDefaultYooFolderName()}/{packageName}";
|
||||
//拷贝BuildinCatalog文件
|
||||
CreateBuildinCatalogFile("BuildinCatalog.json", copyPackageDirectory, outFilePath);
|
||||
CreateBuildinCatalogFile("BuildinCatalog.bytes", copyPackageDirectory, outFilePath);
|
||||
|
||||
//输出目录
|
||||
string zipFilePath = Path.Combine(outputPackageDirectory, zipFileName);
|
||||
try
|
||||
{
|
||||
using (FileStream zipStream = new FileStream(zipFilePath, FileMode.Create))
|
||||
using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
|
||||
{
|
||||
// 指定需要压缩的后缀(例如:只压缩.json和.dll文件)
|
||||
//string[] targetExtensions = { ".bundle" };
|
||||
|
||||
// 遍历目录下所有文件
|
||||
// foreach (string filePath in Directory.GetFiles(outFilePath, "*.*", SearchOption.AllDirectories)
|
||||
// .Where(f => targetExtensions.Contains(Path.GetExtension(f),
|
||||
// StringComparer.OrdinalIgnoreCase)))
|
||||
foreach (string filePath in Directory.GetFiles(outFilePath, "*.*", SearchOption.AllDirectories))
|
||||
{
|
||||
// 获取文件在压缩包中的相对路径
|
||||
string entryName = Path.GetRelativePath(outFilePath, filePath);
|
||||
|
||||
// 创建zip条目
|
||||
ZipArchiveEntry entry = archive.CreateEntry(entryName,
|
||||
System.IO.Compression.CompressionLevel.Optimal);
|
||||
|
||||
// 写入文件内容
|
||||
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
using (Stream entryStream = entry.Open())
|
||||
{
|
||||
fileStream.CopyTo(entryStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"成功打包为zip:{zipFilePath}");
|
||||
EditorUtility.DisplayProgressBar("提示", $"开始上传{packageName}(打包zip)", 0.25f);
|
||||
return zipFilePath;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"打包zip失败:{ex.Message}");
|
||||
EditorUtility.ClearProgressBar();
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateBuildinCatalogFile(string fileName, string copyPackageDirectory, string outFilePath)
|
||||
{
|
||||
// 假设 BuildinCatalog 文件名为 BuildinCatalog.json
|
||||
|
||||
string sourcePath = Path.Combine(copyPackageDirectory, fileName); // 源文件路径
|
||||
string destinationPath = Path.Combine(outFilePath, fileName); // 目标文件路径
|
||||
|
||||
// 如果目标文件已存在,则覆盖
|
||||
if (File.Exists(destinationPath))
|
||||
{
|
||||
File.Delete(destinationPath);
|
||||
}
|
||||
|
||||
// 执行拷贝操作
|
||||
File.Copy(sourcePath, destinationPath);
|
||||
}
|
||||
|
||||
public async Task UpdateFileDataResDomain(string zipFilePath)
|
||||
{
|
||||
//初始化读取资源配置表
|
||||
HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
|
||||
if (hotfixMainResDomain == null)
|
||||
{
|
||||
Debug.LogError($"UnityEvo:读取资源配置表失败【HotfixMainResDomain】...表不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
var ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
|
||||
var messageEntity = await WebRequestSystem.PostFile(ip + "/FileLoad/UpLoadFile", new[] { zipFilePath });
|
||||
EditorUtility.DisplayProgressBar("提示", $"开始上传{packageName}(上传zip文件)", 0.5f);
|
||||
if (messageEntity.code == 200)
|
||||
{
|
||||
List<ResultMessageEntity> resultMessageEntities =
|
||||
JsonConvert.DeserializeObject<List<ResultMessageEntity>>(messageEntity.data.ToString());
|
||||
if (resultMessageEntities.Count > 0)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("提示", "开始上传(更新数据库)", 0.75f);
|
||||
foreach (var resultMessageEntity in resultMessageEntities)
|
||||
{
|
||||
var data = JsonConvert.DeserializeObject(resultMessageEntity.data.ToString()) as JObject;
|
||||
string fileId = data["id"].ToString();
|
||||
ResDmainAddRequst resDmainAddRequst = new ResDmainAddRequst()
|
||||
{
|
||||
ProductName = Application.identifier,
|
||||
DomainName = packageName,
|
||||
Platform = EditorUserBuildSettings.activeBuildTarget.ToString(),
|
||||
PackageVersion = _packageVersion,
|
||||
DocumentFileId = fileId
|
||||
};
|
||||
var resResultMessage = await WebRequestSystem.Post(ip + "/ResDomain/AddResDomain",
|
||||
JsonConvert.SerializeObject(resDmainAddRequst));
|
||||
//如果低于服务器版本,更新版本号
|
||||
if (resResultMessage.code == 1009)
|
||||
{
|
||||
ResDmainVersionResponse dmainVersionResponse =
|
||||
JsonConvert.DeserializeObject<ResDmainVersionResponse>(resResultMessage.data
|
||||
.ToString());
|
||||
|
||||
|
||||
bool isEndWithDigit =
|
||||
System.Text.RegularExpressions.Regex.IsMatch(dmainVersionResponse.PackageVersion,
|
||||
@"\d$");
|
||||
if (isEndWithDigit)
|
||||
{
|
||||
// 提取版本号结尾的数字部分
|
||||
string versionEndDigits = System.Text.RegularExpressions.Regex
|
||||
.Match(dmainVersionResponse.PackageVersion, @"(\d+)$").Groups[1].Value;
|
||||
int versionEndDigit = int.Parse(versionEndDigits) + 1;
|
||||
// 或者移除版本号结尾的数字
|
||||
string versionWithoutEndDigits =
|
||||
System.Text.RegularExpressions.Regex.Replace(dmainVersionResponse.PackageVersion,
|
||||
@"\d+$", "");
|
||||
PackageVersion = versionWithoutEndDigits + versionEndDigit;
|
||||
}
|
||||
|
||||
EditorUtility.DisplayDialog("提示",
|
||||
$"{resResultMessage.message + $"\n{resResultMessage.data.ToString()},已更新为{_packageVersion},请重新打包上传"}",
|
||||
"确定");
|
||||
}
|
||||
}
|
||||
|
||||
EditorUtility.DisplayProgressBar("提示", $"开始上传{packageName}(更新数据库)", 1f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("提示", $"{messageEntity.message}", 1f);
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
EditorUtility.ClearProgressBar();
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务器上版本号
|
||||
/// </summary>
|
||||
private async void GetHostBuildPackageVersion()
|
||||
{
|
||||
var resDmainAddRequst = new ResDmainRequst()
|
||||
{
|
||||
ProductName = Application.identifier,
|
||||
DomainName = selectedPackageNames,
|
||||
Platform = EditorUserBuildSettings.activeBuildTarget.ToString(),
|
||||
};
|
||||
var resResultMessage = await WebRequestSystem.Post(ip + "/ResDomain/GetResDomainByDomain",
|
||||
JsonConvert.SerializeObject(resDmainAddRequst));
|
||||
//如果低于服务器版本,更新版本号
|
||||
if (resResultMessage.code != 1011)
|
||||
{
|
||||
if (resResultMessage.data != null)
|
||||
{
|
||||
ResDmainResponse domainResponse =
|
||||
JsonConvert.DeserializeObject<ResDmainResponse>(resResultMessage.data
|
||||
.ToString());
|
||||
PackageVersion = domainResponse.PackageVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"UnityEvo:获取服务器版本失败,resResultMessage.data为空");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示",
|
||||
$"{resResultMessage.message},默认test_1.0版本 ", "确定");
|
||||
PackageVersion = "test_1.0";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected void Init()
|
||||
{
|
||||
//Update
|
||||
buildTarget = EditorUserBuildSettings.activeBuildTarget.ToString();
|
||||
onBuildPipelineEntity =
|
||||
new BuildAssetEntity("打包", $"打包资源包【版本:{_packageVersion}】", OnBuildPipeline);
|
||||
onUpdateBuildPipelineEntity =
|
||||
new BuildAssetEntity("更新", $"更新至服务器【版本:{_packageVersion}】",
|
||||
OnUpdateBuildPipeline);
|
||||
}
|
||||
|
||||
private Vector2 scroll;
|
||||
|
||||
protected override void DrawEditor(int index)
|
||||
{
|
||||
scroll = GUILayout.BeginScrollView(scroll);
|
||||
{
|
||||
base.DrawEditor(index);
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
UpdateBuildPipelineButtonName();
|
||||
}
|
||||
|
||||
public void UpdateBuildPipelineButtonName()
|
||||
{
|
||||
onBuildPipelineEntity.SetButtonName($"打包资源包【版本:{_packageVersion}】");
|
||||
onUpdateBuildPipelineEntity.SetButtonName($"更新至服务器【版本:{_packageVersion}】");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be7ec9bc4c8d40b0850b440246ea122f
|
||||
timeCreated: 1761198971
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using EditorFramework;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class CreatArtDomainEntity
|
||||
{
|
||||
private List<CreatArtDomainEntity> domainList;
|
||||
|
||||
[HorizontalGroup] [ReadOnly] public string DomainName;
|
||||
[ReadOnly]
|
||||
public string domainPath;
|
||||
|
||||
|
||||
public CreatArtDomainEntity(List<CreatArtDomainEntity> domainList)
|
||||
{
|
||||
this.domainList = domainList;
|
||||
}
|
||||
[HorizontalGroup(Width = 60)]
|
||||
[Button("", Icon = SdfIconType.ArrowRepeat, IconAlignment = IconAlignment.RightEdge)]
|
||||
public void CreatDomain()
|
||||
{
|
||||
if (DomainName == "Main")
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "主包Main作用域无法再次创建", "确定");
|
||||
return;
|
||||
}
|
||||
bool isOk = EditorUtility.DisplayDialog("提示", "是否检索并创建缺失目录", "是", "否");
|
||||
if (isOk)
|
||||
{
|
||||
ArtServerManageWindow.CreateDomainDirectory(DomainName);
|
||||
}
|
||||
}
|
||||
[HorizontalGroup(Width = 60)]
|
||||
[Button("", Icon = SdfIconType.XCircle, IconAlignment = IconAlignment.RightEdge)]
|
||||
public void CloseDomain()
|
||||
{
|
||||
if (DomainName == "Main")
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "主包Main作用域无法删除", "确定");
|
||||
return;
|
||||
}
|
||||
bool isOk = EditorUtility.DisplayDialog("提示", "是否删除此Art", "是", "否");
|
||||
if (isOk)
|
||||
{
|
||||
BuildArtAssetWindow.RemoveBuildAssetWindow();
|
||||
EditorFrameworkUtils.DeleteAllChild(domainPath, FileAttributes.Normal);
|
||||
domainList.Clear();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6799dae03a614d0cbd6263333517b6af
|
||||
timeCreated: 1761274861
|
||||
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using EditorFramework;
|
||||
using Newtonsoft.Json;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class CreatArtServerDomainEntity
|
||||
{
|
||||
private string ip;
|
||||
|
||||
private List<CreatArtServerDomainEntity> domainList;
|
||||
|
||||
[HorizontalGroup] [ReadOnly] public string DomainName;
|
||||
|
||||
private bool IsValidPath => IsValidProjectPath(domainPath);
|
||||
|
||||
[ReadOnly] [InfoBox("当前路径在Unity项目中不存在,请检查路径是否需要删除", InfoMessageType.Error, "IsValidPath")]
|
||||
public string domainPath;
|
||||
|
||||
private ResDmainResponse resDmainResponse;
|
||||
|
||||
|
||||
[InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)]
|
||||
[HideLabel]
|
||||
public ArtSceneData artSceneData;
|
||||
public CreatArtServerDomainEntity(List<CreatArtServerDomainEntity> domainList)
|
||||
{
|
||||
this.domainList = domainList;
|
||||
}
|
||||
public void SetDomainData(string domainName, string domainPath, ResDmainResponse response, string ip)
|
||||
{
|
||||
resDmainResponse = response;
|
||||
DomainName = domainName;
|
||||
this.domainPath = domainPath;
|
||||
this.ip = ip;
|
||||
if (!resDmainResponse.IsEnable)
|
||||
{
|
||||
_endableBtnName = "启用";
|
||||
_endableBtnColor = Color.green;
|
||||
}
|
||||
else
|
||||
{
|
||||
_endableBtnName = "禁用";
|
||||
_endableBtnColor = Color.red;
|
||||
}
|
||||
string artSceneDataPath =
|
||||
$"Assets/Art/{domainName}/Config/ArtSceneData.asset";
|
||||
ArtSceneData artSceneData =
|
||||
AssetDatabase.LoadAssetAtPath<ArtSceneData>(artSceneDataPath);
|
||||
if (artSceneData != null)
|
||||
{
|
||||
this.artSceneData = artSceneData;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"UnityEvo:ArtSceneData 不存在,请检查路径{artSceneDataPath}");
|
||||
}
|
||||
}
|
||||
[HorizontalGroup(Width = 60)]
|
||||
[Button("", Icon = SdfIconType.ArrowRepeat, IconAlignment = IconAlignment.RightEdge)]
|
||||
public void CreatDomain()
|
||||
{
|
||||
if (DomainName == "Main")
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "主包Main作用域无法再次创建", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
bool isOk = EditorUtility.DisplayDialog("提示", "是否检索并创建缺失目录", "是", "否");
|
||||
if (isOk)
|
||||
{
|
||||
ArtServerManageWindow.CreateDomainDirectory(DomainName);
|
||||
}
|
||||
}
|
||||
|
||||
[HorizontalGroup(Width = 60)]
|
||||
[Button("", Icon = SdfIconType.XCircle, IconAlignment = IconAlignment.RightEdge)]
|
||||
public async void CloseDomain()
|
||||
{
|
||||
if (DomainName == "Main")
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "主包Main作用域无法删除", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
bool isOk = EditorUtility.DisplayDialog("提示", "是否删除此Art", "是", "否");
|
||||
if (isOk)
|
||||
{
|
||||
string url = $"{ip}/ResDomain/DeleteResDomain";
|
||||
var requst = new ResDmainRequst()
|
||||
{
|
||||
ProductName = Application.identifier,
|
||||
Platform = UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString(),
|
||||
DomainName = DomainName,
|
||||
};
|
||||
var resDmainMessageEntity =
|
||||
await WebRequestSystem.Post(url, JsonConvert.SerializeObject(requst));
|
||||
if (resDmainMessageEntity.code == 200)
|
||||
{
|
||||
BuildArtAssetWindow.RemoveBuildAssetWindow();
|
||||
EditorFrameworkUtils.DeleteAllChild(domainPath, FileAttributes.Normal);
|
||||
domainList.Remove(this);
|
||||
AssetDatabase.Refresh();
|
||||
AssetDatabase.SaveAssets();
|
||||
EditorUtility.DisplayDialog("提示", "删除成功", "确定");
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", $"删除失败,错误码:{resDmainMessageEntity.code}", "确定");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _endableBtnName = "";
|
||||
private Color _endableBtnColor = Color.white;
|
||||
private bool IsReadOnly = false; // 或者根据条件动态判断
|
||||
|
||||
[HorizontalGroup(Width = 60)]
|
||||
[Button("@ _endableBtnName", IconAlignment = IconAlignment.RightEdge)]
|
||||
[GUIColor("@ _endableBtnColor")]
|
||||
[DisableIf("@ IsReadOnly")]
|
||||
public async void IsEndable()
|
||||
{
|
||||
if (DomainName == "Main")
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "主包Main作用域设置", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
resDmainResponse.IsEnable = !resDmainResponse.IsEnable;
|
||||
|
||||
if (!resDmainResponse.IsEnable)
|
||||
{
|
||||
_endableBtnName = "启用";
|
||||
_endableBtnColor = Color.green;
|
||||
}
|
||||
else
|
||||
{
|
||||
_endableBtnName = "禁用";
|
||||
_endableBtnColor = Color.red;
|
||||
}
|
||||
string url = $"{ip}/ResDomain/UpdateResDomain";
|
||||
var requst = new ResDmainUpdateRequst()
|
||||
{
|
||||
ProductName = Application.identifier,
|
||||
Platform = UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString(),
|
||||
DomainName = DomainName,
|
||||
IsEnabled = resDmainResponse.IsEnable,
|
||||
};
|
||||
IsReadOnly = true;
|
||||
//获取服务器版本
|
||||
var resDmainMessageEntity =
|
||||
await WebRequestSystem.Put(url, JsonConvert.SerializeObject(requst));
|
||||
IsReadOnly = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查给定路径是否在Unity项目中存在
|
||||
/// </summary>
|
||||
/// <param name="path">要检查的路径</param>
|
||||
/// <returns>路径是否存在</returns>
|
||||
private bool IsValidProjectPath(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
// 将相对路径转换为绝对路径进行检查
|
||||
string fullPath = Path.GetFullPath(path);
|
||||
string projectPath = Path.GetFullPath(Application.dataPath + "/../");
|
||||
|
||||
// 确保路径在项目目录内
|
||||
if (!fullPath.StartsWith(projectPath))
|
||||
return false;
|
||||
|
||||
// 检查路径是否存在
|
||||
return !(Directory.Exists(path) || File.Exists(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3d6da1969234ea5b6e6f0b168d91da5
|
||||
timeCreated: 1761617923
|
||||
Reference in New Issue
Block a user