Last active
May 9, 2024 10:43
-
-
Save s-saens/e50303677c903f186fb095a0a352b309 to your computer and use it in GitHub Desktop.
Create/Modify/Delete AnimationClip in AnimatorController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_EDITOR | |
using System.IO; | |
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.Animations; | |
public class AnimationClipManager | |
{ | |
[MenuItem("Assets/Animation/Create Anim Clip", false, 1)] | |
static void Create() | |
{ | |
var animController = Selection.activeObject; | |
if (animController.GetType() != typeof(AnimatorController)) | |
{ | |
Debug.LogWarning("Could not create because the selected object is not an animator controller."); | |
return; | |
} | |
var animClip = new AnimationClip() {name = AnimationClipNameSetter.clipName}; | |
AssetDatabase.AddObjectToAsset(animClip, animController); | |
string animClipPath = AssetDatabase.GetAssetPath(animClip); | |
// This script changes the "*.controller" asset file | |
// so until it is saved, the changes will not be displayed on the editor view. | |
AssetDatabase.SaveAssets(); | |
} | |
[MenuItem("Assets/Animation/Delete Anim Clip", false, 1)] | |
static void Delete() | |
{ | |
var animClip = Selection.activeObject; | |
if(animClip.GetType() != typeof(AnimationClip)) | |
{ | |
Debug.LogWarning("Could not delete because the selected object is not an animator clip."); | |
return; | |
} | |
AssetDatabase.RemoveObjectFromAsset(animClip); | |
// See line 25 | |
AssetDatabase.SaveAssets(); | |
} | |
[MenuItem("Assets/Animation/Rename Anim Clip", false, 3)] | |
static void Rename() | |
{ | |
var animClip = Selection.activeObject; | |
if (animClip.GetType() != typeof(AnimationClip)) | |
{ | |
Debug.LogWarning("Could not rename because the selected object is not an animator clip."); | |
return; | |
} | |
animClip.name = AnimationClipNameSetter.clipName; | |
AssetDatabase.SaveAssets(); | |
} | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_EDITOR | |
using UnityEngine; | |
using UnityEditor; | |
public class AnimationClipNameSetter : EditorWindow | |
{ | |
public static string clipName = "clip name"; | |
[MenuItem("SAENS/Animation Clip Name Setter")] | |
private static void ShowWindow() | |
{ | |
var window = GetWindow<AnimationClipNameSetter>(); | |
window.titleContent = new GUIContent("Animation Clip Name Setter"); | |
window.Show(); | |
} | |
private void OnGUI() | |
{ | |
EditorGUILayout.BeginHorizontal(); | |
clipName = EditorGUILayout.TextField("Clip Name", clipName); | |
EditorGUILayout.EndHorizontal(); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment