【工具】特效资源整理工具
parent
30b1091289
commit
eca086eabc
|
|
@ -0,0 +1,138 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class EffectResTools
|
||||
{
|
||||
|
||||
|
||||
private static Dictionary<string, int> Counter = new Dictionary<string, int>();
|
||||
|
||||
// 资源在这些路径下不做处理
|
||||
private static string[] _ExceptPath = new string[]{
|
||||
"Assets/ManagedResources/Atlas",
|
||||
"Assets/ManagedResources/BG",
|
||||
"Assets/ManagedResources/Effects",
|
||||
"Assets/ManagedResources/PublicArtRes",
|
||||
"Assets/ManagedResources/DynamicAtlas"
|
||||
};
|
||||
|
||||
// 判断资源是否不做处理
|
||||
private static bool CheckIsExcept(string path)
|
||||
{
|
||||
for (int i = 0; i < _ExceptPath.Length; i++)
|
||||
{
|
||||
if (path.StartsWith(_ExceptPath[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取资源类型文件夹名称
|
||||
private static string GetSubFolder(string ext)
|
||||
{
|
||||
ext = ext.ToLower();
|
||||
if(ext.Equals(".png")||ext.Equals(".tga")||ext.Equals(".jpg"))
|
||||
{
|
||||
return "Texture";
|
||||
}
|
||||
else if (ext.Equals(".mat"))
|
||||
{
|
||||
return "Material";
|
||||
}
|
||||
else if (ext.Equals(".controller")|| ext.Equals(".anim"))
|
||||
{
|
||||
return "Animation";
|
||||
}
|
||||
else if (ext.Equals(".shader"))
|
||||
{
|
||||
return "Shader";
|
||||
}
|
||||
else if (ext.Equals(".fbx")||ext.Equals(".obj"))
|
||||
{
|
||||
return "Models";
|
||||
}
|
||||
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
[MenuItem("Tools/Effect/检测重复引用的特效资源")]
|
||||
private static void CheckEffectRes()
|
||||
{
|
||||
List<string> assetPaths = new List<string>();
|
||||
assetPaths.Add("Assets/ManagedResources/EffectResSkill");
|
||||
assetPaths.Add("Assets/ManagedResources/EffectResUI");
|
||||
|
||||
// 开始时清除计数器
|
||||
Counter.Clear();
|
||||
|
||||
string[] allPath = AssetDatabase.FindAssets("t:Prefab", assetPaths.ToArray());
|
||||
for (int i = 0; i < allPath.Length; i++)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(allPath[i]);
|
||||
EditorUtility.DisplayProgressBar(string.Format("正在检查:({0}/{1})", i, allPath.Length), "路径:" + path, (float)i / allPath.Length);
|
||||
CheckSingleRes(path);
|
||||
}
|
||||
|
||||
// 结束时再次清除计数器
|
||||
Counter.Clear();
|
||||
}
|
||||
|
||||
// 单个资源检测
|
||||
private static void CheckSingleRes(string path)
|
||||
{
|
||||
var dependencies = AssetDatabase.GetDependencies(path);
|
||||
for (int j = 0; j < dependencies.Length; j++)
|
||||
{
|
||||
string ps = dependencies[j];
|
||||
if (CheckIsExcept(ps))
|
||||
continue;
|
||||
int outValue = 0;
|
||||
if (Counter.TryGetValue(ps, out outValue))
|
||||
{
|
||||
Counter[ps] = outValue + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Counter.Add(ps, 1);
|
||||
}
|
||||
|
||||
if (outValue > 0)
|
||||
{
|
||||
MoveToCommon(ps);
|
||||
// 动画要把引用的anim也一起移动
|
||||
string ext = Path.GetExtension(ps).ToLower();
|
||||
if (ext.Equals(".controller"))
|
||||
{
|
||||
CheckSingleRes(ps);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 移动到公用文件夹
|
||||
private static void MoveToCommon(string assetPath)
|
||||
{
|
||||
|
||||
if (!AssetDatabase.IsValidFolder("Assets/ManagedResources/EffectResCommon"))
|
||||
{
|
||||
AssetDatabase.CreateFolder("Assets/ManagedResources", "EffectResCommon");
|
||||
}
|
||||
string subFolderName = GetSubFolder(Path.GetExtension(assetPath));
|
||||
if (!AssetDatabase.IsValidFolder("Assets/ManagedResources/EffectResCommon/" + subFolderName))
|
||||
{
|
||||
AssetDatabase.CreateFolder("Assets/ManagedResources/EffectResCommon", subFolderName);
|
||||
}
|
||||
|
||||
string fileName = Path.GetFileName(assetPath);
|
||||
string tarPath = "Assets/ManagedResources/EffectResCommon/"+ subFolderName+ "/" + fileName;
|
||||
AssetDatabase.MoveAsset(assetPath, tarPath);
|
||||
Debug.LogWarning("MoveAsset " + assetPath + " to " + tarPath);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b1cd19bdc18a255489e2f8df5450e0c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -98,8 +98,8 @@ public class FindReferences
|
|||
count++;
|
||||
FilePath = ffs[index];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -139,8 +139,8 @@ public class FindReferences
|
|||
var gameObj = obj as GameObject;
|
||||
CheckResRef(gameObj.transform, gameObj.transform, Selection.activeObject.name);
|
||||
DebugChildName(gameObj.transform, gameObj.transform, Selection.activeObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
Debug.Log("匹配结束");
|
||||
|
|
@ -207,7 +207,7 @@ public class FindReferences
|
|||
|
||||
var spine1 = tran.GetComponent<Spine.Unity.SkeletonGraphic>();
|
||||
isShowPath |= spine1 != null && spine1.skeletonDataAsset != null && spine1.skeletonDataAsset.name == targetName;
|
||||
|
||||
|
||||
var spine2 = tran.GetComponent<Spine.Unity.SkeletonAnimation>();
|
||||
isShowPath |= spine2 != null && spine2.skeletonDataAsset != null && spine2.skeletonDataAsset.name == targetName;
|
||||
|
||||
|
|
@ -398,15 +398,15 @@ public class FindReferences
|
|||
if (Selection.activeObject is GameObject)
|
||||
{
|
||||
action(Selection.activeObject as GameObject);
|
||||
}
|
||||
}
|
||||
else if (Selection.activeObject is DefaultAsset)
|
||||
{
|
||||
string[] files = Directory.GetFiles(AssetDatabase.GetAssetPath(Selection.activeObject)).Where(s => !s.EndsWith(".meta")).ToArray();
|
||||
for(int i = 0; i < files.Length; i++)
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
Debug.LogError("查找路径:"+ files[i]);
|
||||
Debug.LogError("查找路径:" + files[i]);
|
||||
var obj = AssetDatabase.LoadAssetAtPath<Object>(GetRelativeAssetsPath(files[i]));
|
||||
if(obj is GameObject)
|
||||
if (obj is GameObject)
|
||||
{
|
||||
action(obj as GameObject);
|
||||
}
|
||||
|
|
@ -463,5 +463,123 @@ public class FindReferences
|
|||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private static string[] _CommonAtlas = new string[]{
|
||||
"CommonAtlas",
|
||||
"PopupAtlas",
|
||||
"PublicAtlas",
|
||||
"TagAtlas",
|
||||
"TagButtonAtlas"
|
||||
};
|
||||
|
||||
private static bool CheckIsCommonAtlas(string atlasName)
|
||||
{
|
||||
for(int i = 0; i < _CommonAtlas.Length; i++)
|
||||
{
|
||||
if (atlasName.Equals(_CommonAtlas[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[MenuItem("Tools/检查并移动ui预设中不规范引用的资源")]
|
||||
private static void SearchCommonDependencies()
|
||||
{
|
||||
List<string> assetPaths = new List<string>();
|
||||
assetPaths.Add("Assets/ManagedResources/Prefabs/UI");
|
||||
|
||||
//
|
||||
Dictionary<string, int> Counter = new Dictionary<string, int>();
|
||||
string[] allPath = AssetDatabase.FindAssets("t:Prefab", assetPaths.ToArray());
|
||||
for (int i = 0; i < allPath.Length; i++)
|
||||
{
|
||||
|
||||
EditorUtility.DisplayCancelableProgressBar("正在查找", allPath[i], (float)i / allPath.Length);
|
||||
|
||||
string path = AssetDatabase.GUIDToAssetPath(allPath[i]);
|
||||
Debug.LogError(path);
|
||||
|
||||
string tarFolder = path.Split('/')[4] + "Atlas";
|
||||
|
||||
var dependencies = AssetDatabase.GetDependencies(path);
|
||||
for (int j = 0; j < dependencies.Length; j++)
|
||||
{
|
||||
Debug.Log("Dependency: " + dependencies[j]);
|
||||
if (!dependencies[j].StartsWith("Assets/ManagedResources/Atlas"))
|
||||
continue;
|
||||
// 是公用文件
|
||||
string[] depArray = dependencies[j].Split('/');
|
||||
string depFolder = depArray[3];
|
||||
string subFolder= depArray[4];// 有可能是子文件夹 也有可能是文件名
|
||||
|
||||
if (CheckIsCommonAtlas(depFolder))
|
||||
continue;
|
||||
// 就在自己对应的文件夹内
|
||||
if (depFolder.Equals(tarFolder))
|
||||
continue;
|
||||
|
||||
string resName = depArray[depArray.Length - 1];
|
||||
int outValue = 0;
|
||||
if(Counter.TryGetValue(resName, out outValue))
|
||||
{
|
||||
tarFolder = "CommonAtlas";
|
||||
Counter[resName] = outValue + 1;
|
||||
}
|
||||
else{
|
||||
Counter.Add(resName, 1);
|
||||
}
|
||||
if (!AssetDatabase.IsValidFolder("Assets/ManagedResources/Atlas/" + tarFolder))
|
||||
{
|
||||
AssetDatabase.CreateFolder("Assets/ManagedResources/Atlas", tarFolder);
|
||||
}
|
||||
if (!AssetDatabase.IsValidFolder("Assets/ManagedResources/Atlas/" + tarFolder + "/ArtFont"))
|
||||
{
|
||||
AssetDatabase.CreateFolder("Assets/ManagedResources/Atlas/" + tarFolder, "ArtFont");
|
||||
}
|
||||
|
||||
string tarPath = "Assets/ManagedResources/Atlas/" + tarFolder;
|
||||
if (subFolder == "ArtFont")
|
||||
{
|
||||
tarPath += "/ArtFont";
|
||||
}
|
||||
tarPath += "/" + resName;
|
||||
AssetDatabase.MoveAsset(dependencies[j], tarPath);
|
||||
Debug.LogWarning("MoveAsset "+ dependencies[j] + " to "+ tarPath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
|
||||
// 检查大图资源
|
||||
[MenuItem("Tools/检查并移动Atlas中过大的资源")]
|
||||
private static void FindBigAtlas()
|
||||
{
|
||||
List<string> assetPaths = new List<string>();
|
||||
assetPaths.Add("Assets/ManagedResources/Atlas");
|
||||
|
||||
string[] allPath = AssetDatabase.FindAssets("t:Texture", assetPaths.ToArray());
|
||||
for (int i = 0; i < allPath.Length; i++)
|
||||
{
|
||||
EditorUtility.DisplayCancelableProgressBar("正在查找", allPath[i], (float)i / allPath.Length);
|
||||
|
||||
string path = AssetDatabase.GUIDToAssetPath(allPath[i]);
|
||||
var tex = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
|
||||
if(tex.width >= 512 || tex.height > 512)
|
||||
{
|
||||
Debug.LogError(path);
|
||||
string[] depArray = path.Split('/');
|
||||
string resName = depArray[depArray.Length - 1];
|
||||
AssetDatabase.MoveAsset(path, "Assets/ManagedResources/DynamicAtlas/"+ resName);
|
||||
}
|
||||
}
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue