简要代码如下:
using UnityEditor;using UnityEngine;using System.IO;using System.Collections;using System.Collections.Generic;public class RenameEffect { [MenuItem("XiYouEditor/Effect/RenameEffect-AddPrefix")] static void Execute() { foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets)) { if (!(o is Object)) continue; AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(o), "P-" + o.name); } }}
其处理拷贝动作文件:
using UnityEditor;using UnityEngine;using System.IO;using System.Collections;using System.Collections.Generic;public class AnimationBatch{ [MenuItem("XiYouEditor/Animation/Copy Batch")] static void Execute() { ListlstAnimName = new List (); foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets)) { if (!(o is GameObject)) continue; if (!o.name.Contains("@")) continue; GameObject charFbx = (GameObject)o; string strClipName = charFbx.name; int nIndex = strClipName.LastIndexOf('@'); strClipName = strClipName.Substring(nIndex + 1, strClipName.Length - nIndex - 1); AnimationClip newClip = new AnimationClip(); EditorUtility.CopySerialized(charFbx.animation.GetClip(strClipName), newClip); string strNewAnim = AssetDatabase.GetAssetPath(charFbx); strNewAnim = strNewAnim.Substring(0, strNewAnim.LastIndexOf('/') + 1); strNewAnim += strClipName; strNewAnim += ".anim"; if(!File.Exists(strNewAnim)) AssetDatabase.CreateAsset(newClip, strNewAnim); lstAnimName.Add(strClipName); } foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets)) { if (!(o is GameObject)) continue; if (o.name.Contains("@")) continue; GameObject charFbx = (GameObject)o; string CharDirPath = AssetDatabase.GetAssetPath(charFbx); CharDirPath = CharDirPath.Substring(0, CharDirPath.LastIndexOf('/') + 1); // 清空默认动作 charFbx.animation.clip = null; foreach (string name in lstAnimName) { AnimationClip DestClip = (AnimationClip)AssetDatabase.LoadAssetAtPath(CharDirPath + name + ".anim", typeof(AnimationClip)); charFbx.animation.RemoveClip(name); charFbx.animation.AddClip(DestClip, name); } // 重设默认动作 AnimationClip defaultClip = charFbx.animation.GetClip("Idle1"); if (defaultClip != null) charFbx.animation.clip = defaultClip; charFbx.animation.cullingType = AnimationCullingType.AlwaysAnimate; EditorUtility.SetDirty(o); } }}
具体代码根据项目需求进行定制~