• RenameAssets


    using UnityEngine;
    using System.Collections;
    using UnityEditor;
    using System.Collections.Generic;
    /// <summary>
    /// 对Project下选中的物体重命名
    /// </summary>
    public class RenameAssets : EditorWindow {
     
     private string BaseName = "";
     private string Prefix = "";
     private string Suffix = "";
     private string LabelBase = "Base";      //提示标签
     private string LabelPrefix = "Prefix";  //提示标签
     private string LabelSuffix = "Suffix";  //提示标签
     private bool Numberd = false;     //是否添加数字后缀
     private Object[] selList = null;  //物体是否选中
     private string NewName = "";
     /// <summary>
     /// 创建显示窗体
     /// </summary>
     [@MenuItem("Custom/Effect/RenameAssets")]
     static void Init()
     {
      RenameAssets window = (RenameAssets)EditorWindow.GetWindow(typeof(RenameAssets));
      //win.ShowNotification(new GUIContent("注意:!"));
      window.Show ();
     }
     private void OnGUI()
     {
      /// <summary>
      /// 添加界面
      /// </summary>
      GUI.Label (new Rect (20, 20, 160, 18), LabelBase);
      BaseName = GUI.TextField(new Rect(100,20,120,18), BaseName, 40);
      GUI.Label (new Rect (20, 60, 160, 18), LabelPrefix);
      Prefix = GUI.TextField(new Rect(100,60,120,18), Prefix, 40);
      GUI.Label (new Rect (20, 100, 160, 18), LabelSuffix);
      Suffix = GUI.TextField(new Rect(100,100,120,18), Suffix, 40);
      Numberd = GUI.Toggle (new Rect (20, 140, 120, 40), Numberd, "  Numbered");
      if (GUI.Button(new Rect(120f, 135f, 100f, 20f), "RENAME"))
      {
       RenameObject(BaseName, Prefix, Suffix, Numberd);
      }
     }
     private void RenameObject(string BaseName, string Prefix, string Suffix, bool Numberd)
     {
      selList = Selection.objects;
      if (selList.Length != 0)
      {
       if ("" == Prefix.Trim() )
       {
        Prefix = Prefix;
       }
       else
       {
        Prefix = Prefix + "_";
       }
       
       if ("" == Suffix.Trim())
       {
        Suffix = Suffix;
       }
       else
       {
        Suffix =  "_" + Suffix;
       }
       
       
       if(selList.Length != 0 && BaseName.Trim() != "" )
       {
        if(Numberd == false)  //不添加编号
        {
         for (int i = 0; i < selList.Length; i++)
         {
          string oldName = AssetDatabase.GetAssetPath(selList[i]);  //Assets/Art/Characters/Ailuen/Effects/Resources/Ailuen01_FBX
          string newName = selList[i].name.Replace( selList[i].name, (Prefix  + BaseName + Suffix) );
          AssetDatabase.RenameAsset(oldName, newName);
         }
        }
        else                  //添加编号
        {
         for (int i = 0; i < selList.Length; i++)
         {
          string oldName = AssetDatabase.GetAssetPath(selList[i]);  //Assets/Art/Characters/Ailuen/Effects/Resources/Ailuen01_FBX
          string newName = selList[i].name.Replace( selList[i].name, (Prefix  + BaseName + Suffix + "_0" + (i + 1) ) );
          AssetDatabase.RenameAsset(oldName, newName);
         }
        }
       }
       else if(selList.Length != 0 && BaseName.Trim() == "" )
       {
        if(Numberd == false)  //不添加编号
        {
         for (int i = 0; i < selList.Length; i++)
         {
          string oldName = AssetDatabase.GetAssetPath(selList[i]);  //Assets/Art/Characters/Ailuen/Effects/Resources/Ailuen01_FBX
          string newName = selList[i].name.Replace( selList[i].name, (Prefix +  selList[i].name +  Suffix + "") );
          AssetDatabase.RenameAsset(oldName, newName);
         }
        }
        else                  //添加编号
        {
         for (int i = 0; i < selList.Length; i++)
         {
          string oldName = AssetDatabase.GetAssetPath(selList[i]);  //Assets/Art/Characters/Ailuen/Effects/Resources/Ailuen01_FBX
          string newName = selList[i].name.Replace( selList[i].name, (Prefix +  selList[i].name + Suffix + "_0" + (i + 1) ) );
          AssetDatabase.RenameAsset(oldName, newName);
         }
        }
       }
      }
      else
      {
       this.ShowNotification (new GUIContent("Project没有物体选中"));
      }
     }
    }
  • 相关阅读:
    image 和 barplot 的组合
    par函数mgp 参数-控制坐标轴的位置
    R语言绘图时的边界碰撞问题
    R语言绘制花瓣图flower plot
    mothur 计算稀释性曲线
    R语言 vegan包计算物种累计曲线
    R语言数据框小技巧
    tophat-fusion 鉴定融合基因
    FusionCancer-人类癌症相关的融合基因的数据库
    rrnDB数据库简介-16S基因多拷贝数的证据
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/4561655.html
Copyright © 2020-2023  润新知