146 lines
4.6 KiB
C#
146 lines
4.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using UnityEditor;
|
||
using UnityEditor.U2D;
|
||
using UnityEngine;
|
||
using UnityEngine.U2D;
|
||
|
||
namespace Stary.Evo.Editor
|
||
{
|
||
public class MarkAdressable
|
||
{
|
||
public static string DomainRoot
|
||
{
|
||
get { return Application.dataPath + "/Modules"; }
|
||
}
|
||
[MenuItem("Evo/ARMaz/一键标记所有模块")]
|
||
/// <summary>
|
||
/// 一键标记所有模块
|
||
/// </summary>
|
||
public static void AddMarkAll()
|
||
{
|
||
// //清空主包旧数据
|
||
AssetDatabase.RemoveUnusedAssetBundleNames(); // 清理无用标签
|
||
DirectoryInfo[] dirs = new DirectoryInfo(DomainRoot).GetDirectories();
|
||
foreach (var dir in dirs)
|
||
{
|
||
AddDomainMark(dir.Name);
|
||
}
|
||
}
|
||
|
||
public static void AddDomainMark(string domainName)
|
||
{
|
||
string resPath =
|
||
$"Assets/Modules/{domainName}/Main/Res";
|
||
|
||
MarkDomain(domainName);
|
||
|
||
|
||
CreateRes(domainName,
|
||
$"{DomainRoot}/{domainName}/Main/Res",
|
||
$"{DomainRoot}/{domainName}/Main/Scripts");
|
||
}
|
||
|
||
|
||
// [MenuItem("Evo/Hotfix/一键Res")]
|
||
public static void CreateRes(string domain, string resPath, string outputPath)
|
||
{
|
||
ResFileGet.CreateClass("Res", domain, outputPath,
|
||
(a) => { ResFileGet.CreateContent(a, resPath, "\t"); });
|
||
}
|
||
|
||
#region 自动标记
|
||
|
||
public static Dictionary<string, string> addressDic = new Dictionary<string, string>();
|
||
|
||
|
||
public static void MarkDomain(string domainName)
|
||
{
|
||
addressDic.Clear();
|
||
|
||
///创建分组
|
||
string remotedRoot = $"{DomainRoot}/{domainName}/Main/Res";
|
||
//DirectoryInfo[] dirs = new DirectoryInfo(remotedRoot).GetDirectories();
|
||
//TopDirectoryOnly 只扫当前目录;AllDirectories 递归
|
||
string[] fileAll = Directory.GetFiles(remotedRoot, "*", SearchOption.AllDirectories);
|
||
|
||
|
||
//检测Packages是否存在Group
|
||
foreach (var info in fileAll)
|
||
{
|
||
AutoMarkRootAddress(domainName, info);
|
||
// if (info.Name != "SpriteAtlas" && info.Name != "Atlas")
|
||
// AutoMark(info.Name);
|
||
}
|
||
|
||
Debug.Log("MarkAsset Successful");
|
||
}
|
||
|
||
public static void AutoMarkRootAddress(string packageName, string file)
|
||
{
|
||
if (!string.IsNullOrEmpty(file) && Path.GetExtension(file) != ".meta" &&
|
||
Path.GetExtension(file) != ".spriteatlas")
|
||
{
|
||
string assetPath = FilesUtils.AbsoluteToRelativePath("Assets", file); //Asset到文件的路径
|
||
|
||
AssetImporter.GetAtPath(assetPath).assetBundleName = $"module_assetbundle_{packageName}";
|
||
|
||
file = file.Replace(" ", "").Replace("/", "\\"); // 保留点号替换为下划线
|
||
Debug.Log("file:" + file + "----GetAssetAddress:" + GetAssetAddress(file));
|
||
|
||
AddAddressInfo( file, GetAssetAddress(file));
|
||
}
|
||
}
|
||
|
||
private static void AddAddressInfo(string assetPath, string address)
|
||
{
|
||
if (addressDic.ContainsKey(assetPath))
|
||
{
|
||
Debug.LogError("命名重复,已经存在:" + assetPath);
|
||
}
|
||
else
|
||
{
|
||
addressDic.Add(assetPath, address);
|
||
}
|
||
}
|
||
|
||
private static string GetAssetAddress(string assetPath)
|
||
{
|
||
string fileName = Path.GetFileNameWithoutExtension(assetPath);
|
||
//FileInfo fileInfo = new FileInfo(assetPath);
|
||
//return $"{fileInfo.Directory.Name}_{fileName}";
|
||
return $"{fileName}";
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
/// <summary>
|
||
/// 获取全部作用域名
|
||
/// </summary>
|
||
private static List<string> GetCreatDomainAllName()
|
||
{
|
||
string domainPath = $"{Application.dataPath}/Modules";
|
||
|
||
|
||
string[] domains;
|
||
// 新增目录获取代码
|
||
if (Directory.Exists(domainPath))
|
||
{
|
||
var dirInfo = new DirectoryInfo(domainPath);
|
||
// 获取直接子目录(不递归)
|
||
domains = dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly)
|
||
.Select(d => d.Name)
|
||
.ToArray();
|
||
}
|
||
else
|
||
{
|
||
domains = new[] { "Default" };
|
||
}
|
||
|
||
return domains.ToList();
|
||
}
|
||
}
|
||
} |