Exemplo n.º 1
0
    private static int[] GetStateKeys(Animator animator, int layer)
    {
        List <int> stateKeys = new List <int>();

        UnityEditorInternal.AnimatorController ac           = animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
        UnityEditorInternal.StateMachine       stateMachine = ac.GetLayer(layer).stateMachine;

        FromStateMachineToStateKey(stateMachine, stateKeys);

        return(stateKeys.ToArray());
    }
Exemplo n.º 2
0
    private static string[] GetTransitionNames(Animator animator, int layer)
    {
        List <string> transitionNames = new List <string>();

        UnityEditorInternal.AnimatorController ac           = animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
        UnityEditorInternal.StateMachine       stateMachine = ac.GetLayer(layer).stateMachine;

        FromStateMachineToTransitionName(stateMachine, transitionNames);

        return(transitionNames.ToArray());
    }
Exemplo n.º 3
0
    void OnGUI()
    {
        if (GUI.Button(new Rect(0, 100, 100, 40), new GUIContent("获取State")))
        {
            UnityEditorInternal.AnimatorController animController = Animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController;

            int layerCount = animController.layerCount;
            Debug.Log(string.Format("动画层数量: {0}", layerCount));

            // 动画层名称
            for (int layer = 0; layer < layerCount; layer++)
            {
                Debug.Log(string.Format("Layer {0}: {1}", layer, animController.GetLayer(layer).name));
            }

            // 动画层0上面的State
            UnityEditorInternal.StateMachine sm = animController.GetLayer(0).stateMachine;
            for (int i = 0; i < sm.stateCount; i++)
            {
                UnityEditorInternal.State state = sm.GetState(i);
                Debug.Log(string.Format("State: {0}, 唯一名称: {1}", state.name, state.uniqueName));
            }
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Gets the count of transitions in a layer.
    /// </summary>
    /// <returns>
    /// The transition count.
    /// </returns>
    /// <param name='animator'>
    /// Animator.
    /// </param>
    /// <param name='layer'>
    /// Layer.
    /// </param>
    public static int GetTransitionsCount(Animator animator, int layer)
    {
        UnityEditorInternal.AnimatorController ac           = animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
        UnityEditorInternal.StateMachine       stateMachine = ac.GetLayer(layer).stateMachine;

        int counter = 0;

        for (int i = 0; i < stateMachine.stateCount; i++)
        {
            Transition[] trans = stateMachine.GetTransitionsFromState(stateMachine.GetState(i));
            counter += trans.Length;
        }

        return(counter);

//		return stateMachine.transitionCount;
    }