I noticed that the Animator API relies heavily on HashIDs per: http://unity3d.com/learn/tutorials/projects/stealth/hashids I'm not about to hardcode all the strings though. I'm dealing with Mixamo and all the animate states get the .anim filename. That would be a lot of manual hardcoding. Code (csharp): int dyingState = Animator.StringToHash("Base Layer.Dying"); I wanted a way to just get the string from the AnimatorStateInfo. I just call the following from my custom inspectors and panels so that I can display the friendly names. First I build the layers and hashes in my custom inspector OnEnable. Code (csharp): private void OnEnable() { AnimatorEx.BuildLayers(); AnimatorEx.BuildStateHash(); } And then I can display the friendly name in OnInspectorGUI. Code (csharp): EditorGUILayout.TextField("State Name", AnimatorEx.HashToString(info.nameHash)); Here's the class to auto build the string lists by searching for .anim files and looking for Animator objects in your scene. Code (csharp): using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; public static class AnimatorEx { private static List<string> m_layers = new List<string>(); public static void BuildLayers() { foreach (Animator animator in GameObject.FindObjectsOfType(typeof (Animator))) { if (animator) { for (int index = 0; index < animator.layerCount; ++index) { string layer = animator.GetLayerName(index); if (!m_layers.Contains(layer)) { m_layers.Add(layer); //Debug.Log(layer); } } } } } private static Dictionary<int, string> m_stateHash = new Dictionary<int, string>(); public static string HashToString(int hash) { if (m_stateHash.ContainsKey(hash)) { return m_stateHash[hash]; } else { return hash.ToString(); } } public static void BuildStateHash() { m_stateHash.Clear(); foreach (string path in AssetDatabase.GetAllAssetPaths()) { if (path.ToLower().EndsWith(".anim")) { foreach (string layer in m_layers) { string name = layer + "." + Path.GetFileNameWithoutExtension(path); int hash = Animator.StringToHash(name); //Debug.Log(string.Format("hash: {0} name={1}", hash, name)); m_stateHash[hash] = name; } } } } }
For my next trick, I'm trying to script access to the motion property of the state. I need to be able to assign a different animation so that I can trim the existing animation. Is there a way? I'll have to dig with reflection and inspection... Thanks