Exemple #1
0
    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();
    }
Exemple #2
0
    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();
    }
Exemple #3
0
 /// <summary>
 /// 全路径
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 static string GetFull(string path)
 {
     return(EditorPathTool.GetFullAssetsPath(path));
 }
Exemple #4
0
    /*  批量修改预设名字
     * [MenuItem("Assets/GameTools/Tools/Test", priority = 10002)]
     * static void  Change ()
     * {
     *  Debug.Log("start================");
     *  Object _obj = Selection.activeObject;
     *  string _path = AssetDatabase.GetAssetPath(_obj);
     *  string[] _dirs =  Directory.GetDirectories(_path);
     *  foreach (var item in _dirs)
     *  {
     *      DirectoryInfo _dirInfo = new DirectoryInfo(item);
     *      string[] _subFiles = Directory.GetFiles(item, "*.*", SearchOption.TopDirectoryOnly);
     *      foreach (var it in _subFiles)
     *      {
     *          if (it.EndsWith(".meta"))
     *              continue;
     *          string _newPath;
     *          try
     *          {
     *              string _newName = it.Replace("@" + _dirInfo.Name + "_", "@");
     *              FileInfo _info = new FileInfo(_newName);
     *              _newPath = AssetDatabase.RenameAsset(GetRelative(it), _info.Name.Replace(_info.Extension, ""));
     *          }
     *          catch (System.Exception)
     *          {
     *              continue;
     *          }
     *      }
     *  }
     *  AssetDatabase.SaveAssets();
     *  AssetDatabase.Refresh();
     * }
     *
     * [MenuItem("Assets/GameTools/Tools/Test2", priority = 10003)]
     * static void Change2()
     * {
     *  Debug.Log("start================");
     *  Object _obj = Selection.activeObject;
     *  string _path = AssetDatabase.GetAssetPath(_obj);
     *  string[] _dirs = Directory.GetDirectories(_path);
     *  foreach (var item in _dirs)
     *  {
     *      DirectoryInfo _dirInfo = new DirectoryInfo(item);
     *      string[] _subFiles = Directory.GetFiles(item, "*.*", SearchOption.TopDirectoryOnly);
     *      foreach (var it in _subFiles)
     *      {
     *          if (it.EndsWith(".meta"))
     *              continue;
     *          string _newPath;
     *          try
     *          {
     *
     *              string _str = _dirInfo.Name + "@" + _dirInfo.Name;
     *              if (it.Contains(_str) == false)
     *                  continue;
     *              string _newName = it.Replace(_str, _dirInfo.Name);
     *              FileInfo _info = new FileInfo(_newName);
     *              _newPath = AssetDatabase.RenameAsset(GetRelative(it), _info.Name.Replace(_info.Extension, ""));
     *          }
     *          catch (System.Exception)
     *          {
     *              continue;
     *          }
     *      }
     *  }
     *  AssetDatabase.SaveAssets();
     *  AssetDatabase.Refresh();
     * }
     */

    /// <summary>
    /// 获取相对于Project目录下的路径
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    static string GetRelative(string path)
    {
        return(EditorPathTool.GetRelativePath(path));
    }