111
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEditor.U2D;
|
||||
using UnityEngine;
|
||||
@@ -16,28 +15,123 @@ namespace Stary.Evo.Editor
|
||||
private static string _packageName;
|
||||
|
||||
|
||||
public static string ArtRoot
|
||||
public static string AbsoluteMemberRoot
|
||||
{
|
||||
get { return Application.dataPath + "/Art"; }
|
||||
get { return Application.dataPath + "/Member"; }
|
||||
}
|
||||
|
||||
public static string RelativeMemberRoot
|
||||
{
|
||||
get { return "Assets/Member"; }
|
||||
}
|
||||
|
||||
public static void CopyArtScenes()
|
||||
{
|
||||
List<ArtScene> artScenes = new List<ArtScene>();
|
||||
string artSceneDataPath =
|
||||
$"Assets/Member/{_packageName}/Config/ArtSceneData.asset";
|
||||
ArtSceneData artSceneData =
|
||||
AssetDatabase.LoadAssetAtPath<ArtSceneData>(artSceneDataPath);
|
||||
if (artSceneData != null)
|
||||
{
|
||||
artScenes = artSceneData.artScenes;
|
||||
foreach (var artScene in artSceneData.artScenes)
|
||||
{
|
||||
artScene.LoadScenePath();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"UnityEvo:ArtSceneData不存在,无法打包,请检查路径{artSceneDataPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
string destPath = $"{AbsoluteMemberRoot}/{_packageName}/Scenes";
|
||||
if (Directory.Exists(destPath))
|
||||
{
|
||||
Directory.Delete(destPath, true);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(destPath);
|
||||
|
||||
foreach (var artScene in artScenes)
|
||||
{
|
||||
string scenePath = artScene.scenePath;
|
||||
bool success = CopyUnityAsset(scenePath,
|
||||
$"{RelativeMemberRoot}/{_packageName}/Scenes/{artScene.sceneAsset.name}.unity");
|
||||
|
||||
if (success)
|
||||
{
|
||||
Debug.Log("场景复制成功!");
|
||||
}
|
||||
|
||||
// string destScenePath = $"{destPath}/{artScene.sceneAsset.name}.unity";
|
||||
// File.Copy(sceneAsset.path, destScenePath, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝Unity资源文件(推荐方法)
|
||||
/// </summary>
|
||||
/// <param name="sourcePath">源文件在Assets下的相对路径</param>
|
||||
/// <param name="destPath">目标文件在Assets下的相对路径</param>
|
||||
/// <returns>是否拷贝成功</returns>
|
||||
public static bool CopyUnityAsset(string sourcePath, string destPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(destPath))
|
||||
{
|
||||
Debug.LogError("源路径或目标路径为空!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AssetDatabase.IsValidFolder(System.IO.Path.GetDirectoryName(destPath)))
|
||||
{
|
||||
Debug.LogError($"目标目录不存在: {System.IO.Path.GetDirectoryName(destPath)}");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 使用AssetDatabase拷贝资源
|
||||
bool result = AssetDatabase.CopyAsset(sourcePath, destPath);
|
||||
if (!result)
|
||||
{
|
||||
Debug.LogError($"拷贝失败: {sourcePath} -> {destPath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
Debug.Log($"成功拷贝资源: {sourcePath} -> {destPath}");
|
||||
AssetDatabase.Refresh(); // 刷新资源数据库
|
||||
return true;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError($"拷贝资源时出错: {e.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddArtMark(Action complete)
|
||||
{
|
||||
_packageName = BuildArtAssetWindow.GetBuildPackageName();
|
||||
CopyArtScenes();
|
||||
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
|
||||
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||
{
|
||||
if (package.PackageName ==_packageName)
|
||||
if (package.PackageName == _packageName)
|
||||
{
|
||||
assetBundleCollectorPackage = package;
|
||||
}
|
||||
}
|
||||
|
||||
if (assetBundleCollectorPackage != null)
|
||||
{
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.RemovePackage(assetBundleCollectorPackage);
|
||||
}
|
||||
|
||||
MarkArt();
|
||||
CollectSVC(ArtRoot, _packageName,complete);
|
||||
CollectSVC(AbsoluteMemberRoot, _packageName, complete);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +147,7 @@ namespace Stary.Evo.Editor
|
||||
addressDic.Clear();
|
||||
collectorGroupDic.Clear();
|
||||
///创建分组
|
||||
string remotedRoot = $"{ArtRoot}/{_packageName}";
|
||||
string remotedRoot = $"{AbsoluteMemberRoot}/{_packageName}";
|
||||
DirectoryInfo[] dirs = new DirectoryInfo(remotedRoot).GetDirectories();
|
||||
|
||||
var setting = YooAsset.Editor.AssetBundleCollectorSettingData.Setting;
|
||||
@@ -74,7 +168,7 @@ namespace Stary.Evo.Editor
|
||||
{
|
||||
string groupName = info.Name;
|
||||
|
||||
if (info.Name == "Scenes"||info.Name == "Config")
|
||||
if (info.Name == "Scenes" || info.Name == "Config")
|
||||
{
|
||||
AssetBundleCollectorGroup collectorGroup =
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(package, groupName);
|
||||
@@ -87,9 +181,11 @@ namespace Stary.Evo.Editor
|
||||
{
|
||||
Debug.LogError("分组 : " + groupName + "已存在,请检查资源目录,避免重复");
|
||||
}
|
||||
|
||||
AutoMarkRootAddress(info);
|
||||
}
|
||||
}
|
||||
|
||||
// AssetDatabase.SaveAssets();
|
||||
// AssetDatabase.Refresh();
|
||||
MarkStatus();
|
||||
@@ -165,120 +261,6 @@ namespace Stary.Evo.Editor
|
||||
}
|
||||
}
|
||||
|
||||
#region 图集
|
||||
|
||||
public static void AutoCreateSpriteAtlas(string domainRootRes)
|
||||
{
|
||||
string AtlasRemotedRoot = domainRootRes + "/SpriteAtlas";
|
||||
string SpriteRemotedAtlas = domainRootRes + "/Sprites";
|
||||
DirectoryInfo[] remotedirs = new DirectoryInfo(SpriteRemotedAtlas).GetDirectories();
|
||||
foreach (var info in remotedirs)
|
||||
{
|
||||
AddSpriteAtlas(SpriteRemotedAtlas + "/" + info.Name, SpriteRemotedAtlas,
|
||||
AtlasRemotedRoot, info);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动创建图集
|
||||
/// </summary>
|
||||
/// <param name="path">路径</param>
|
||||
/// <param name="dir">文件夹</param>
|
||||
private static void AddSpriteAtlas(string path, string atlasRoot, string spriteAtlas, DirectoryInfo dir)
|
||||
{
|
||||
var groupname = "SpriteAtlas";
|
||||
var dirs = dir.GetDirectories();
|
||||
if (dirs == null || dirs.Length == 0)
|
||||
{
|
||||
string name = path.Replace(atlasRoot + "/", string.Empty).Replace("/", "_");
|
||||
string filePath = $"{spriteAtlas}/{name}.spriteatlas";
|
||||
// string[] dirSplit =
|
||||
// filePath.Split(new string[] { $"AddressableRes/{Path.GetFileName(spriteAtlas)}" },
|
||||
// StringSplitOptions.RemoveEmptyEntries);
|
||||
// string address = (dirSplit[dirSplit.Length - 1]).Substring(1).Replace("\\", "/");
|
||||
// Debug.Log("spriteatlasaddress:" + address);
|
||||
int assetIndex = filePath.IndexOf("Assets");
|
||||
string guidPath = filePath.Remove(0, assetIndex);
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
SpriteAtlas atlas = new SpriteAtlas();
|
||||
//设置打包参数
|
||||
SpriteAtlasPackingSettings packSetting = new SpriteAtlasPackingSettings()
|
||||
{
|
||||
blockOffset = 1,
|
||||
enableRotation = true,
|
||||
enableTightPacking = false,
|
||||
padding = 2,
|
||||
};
|
||||
atlas.SetPackingSettings(packSetting);
|
||||
|
||||
//设置打包后Texture图集信息
|
||||
SpriteAtlasTextureSettings textureSettings = new SpriteAtlasTextureSettings()
|
||||
{
|
||||
readable = false,
|
||||
generateMipMaps = false,
|
||||
sRGB = true,
|
||||
filterMode = FilterMode.Bilinear,
|
||||
};
|
||||
atlas.SetTextureSettings(textureSettings);
|
||||
|
||||
//设置平台图集大小压缩等信息
|
||||
TextureImporterPlatformSettings platformSettings = new TextureImporterPlatformSettings()
|
||||
{
|
||||
maxTextureSize = 4096,
|
||||
format = TextureImporterFormat.Automatic,
|
||||
crunchedCompression = true,
|
||||
textureCompression = TextureImporterCompression.Compressed,
|
||||
compressionQuality = 50,
|
||||
};
|
||||
atlas.SetPlatformSettings(platformSettings);
|
||||
AssetDatabase.CreateAsset(atlas, guidPath);
|
||||
int pathIndex = path.IndexOf("Assets");
|
||||
string spritePath = path.Remove(0, pathIndex);
|
||||
UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(spritePath, typeof(UnityEngine.Object));
|
||||
atlas.Add(new[] { obj });
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
var guid = AssetDatabase.AssetPathToGUID(guidPath);
|
||||
|
||||
var group = collectorGroupDic[groupname];
|
||||
if (group != null)
|
||||
{
|
||||
AssetBundleCollector collector = new AssetBundleCollector()
|
||||
{
|
||||
CollectPath = guidPath,
|
||||
CollectorGUID = guid,
|
||||
CollectorType = ECollectorType.MainAssetCollector,
|
||||
AddressRuleName = nameof(AddressByFolderAndFileName),
|
||||
AssetTags = groupname,
|
||||
};
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(group, collector);
|
||||
|
||||
|
||||
AddAddressInfo(path, GetAssetAddress(path));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("分组 = " + GetAssetAddress(path) + "不存在");
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dirs.Length > 0)
|
||||
{
|
||||
foreach (var info in dirs)
|
||||
{
|
||||
AddSpriteAtlas(path + "/" + info.Name, atlasRoot, spriteAtlas, info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static void AddAddressInfo(string assetPath, string address)
|
||||
{
|
||||
@@ -326,7 +308,7 @@ namespace Stary.Evo.Editor
|
||||
}
|
||||
}
|
||||
|
||||
public static void CollectSVC(string root,string packageName,Action complete)
|
||||
public static void CollectSVC(string root, string packageName, Action complete)
|
||||
{
|
||||
string remotedRoot = $"{root}/{packageName}/ShaderVariants";
|
||||
string remotedRootFileName = $"{remotedRoot}/{packageName}.shadervariants";
|
||||
|
||||
Reference in New Issue
Block a user