static void RenameUI() { Dictionary <string, List <string> > _allFiles = new Dictionary <string, List <string> >(); foreach (var item in Selection.objects) { string _tempPath = AssetDatabase.GetAssetPath(item); List <string> _temp = new List <string>(); string[] _tempFileName = EditorPathTool.GetSubPatternFiles(_tempPath, new string[] { ".jpg", ".png", ".tga" }, SearchOption.AllDirectories); _temp.AddRange(_tempFileName); string _dir = EditorPathTool.GetSelectDirName(_tempPath); _allFiles.Add(_dir, _temp); } foreach (var item in _allFiles) { foreach (var it in item.Value) { string[] _tempNames = EditorPathTool.GetSelectFileName(it, true).Split('@'); string _tempName = _tempNames[0]; if (_tempNames.Length > 1) { _tempName = _tempNames[_tempNames.Length - 1]; } string _temp = AssetDatabase.RenameAsset(it, item.Key + "@" + _tempName); if (!string.IsNullOrEmpty(_temp)) { Debug.LogErrorFormat("重命名UI出错:{0}", _temp); } } } Debug.Log("RenameUI ok========="); AssetDatabase.Refresh(); }
static void RemoveBigUI() { List <string> _allFiles = new List <string>(); foreach (var item in Selection.objects) { string _tempPath = AssetDatabase.GetAssetPath(item); string[] _tempFileName = EditorPathTool.GetSubPatternFiles(_tempPath, new string[] { ".jpg", ".png" }, SearchOption.AllDirectories); _allFiles.AddRange(_tempFileName); } string _temp1 = "Assets/AssetBases/SourceAssets/UI"; string _temp2 = "Assets/AssetBases/SourceAssets/UI_Big"; EditorPathTool.CheckAndCreateDir(_temp2); Dictionary <string, string> _moveDic = new Dictionary <string, string>(); foreach (var item in _allFiles) { Texture _tex = AssetDatabase.LoadAssetAtPath <Texture>(item); int _W = _tex.width; int _H = _tex.height; Resources.UnloadAsset(_tex); if ((_W * _H) > (128 * 128)) { string _newPath = item.Replace(_temp1, _temp2); // string _testNewPath = EditorPathTool.CheckAndCreateDir(EditorPathTool.GetFileAssetsDir(_newPath)); _moveDic.Add(item, _newPath); } } AssetDatabase.Refresh(); foreach (var item in _moveDic) { AssetDatabase.MoveAsset(item.Key, item.Value); } //Debug.LogFormat("name={0},width={1},height={2}", _tex.name, _tex.width, _tex.height); Debug.Log("RemoveBigUI ok========="); AssetDatabase.Refresh(); }