Exemplo n.º 1
0
        private void TryBake(Baker script)
        {
            switch (script.mode)
            {
            case Baker.Mode.AnimationClips:
                if (script.animator == null)
                {
                    EditorGUILayout.LabelField("No Animator found on Baker GameObject", EditorStyles.helpBox);
                    return;
                }

                if (script.animator.isHuman && script.animator.runtimeAnimatorController == null)
                {
                    EditorGUILayout.LabelField("Humanoid Animator needs to have a valid Controller assigned for clip baking (Unity crash bug)", EditorStyles.helpBox);
                    return;
                }

                if (script.animationClips.Length == 0)
                {
                    EditorGUILayout.LabelField("Please add AnimationClips to bake", EditorStyles.helpBox);
                    return;
                }

                foreach (AnimationClip clip in script.animationClips)
                {
                    if (clip == null)
                    {
                        EditorGUILayout.LabelField("One of the AnimationClips is null, can not bake.", EditorStyles.helpBox);
                        return;
                    }
                }

                if (GUILayout.Button("Bake Animation Clips"))
                {
                    script.BakeClip();
                }
                return;

            case Baker.Mode.AnimationStates:
                if (script.animator == null)
                {
                    EditorGUILayout.LabelField("No Animator found on Baker GameObject", EditorStyles.helpBox);
                    return;
                }

                if (script.animationStates.Length == 0)
                {
                    EditorGUILayout.LabelField("Please add Animation State names to bake. The Animator must contain AnimationStates with matching names. If AnimationState names match with clip names used in them, you can have the Baker fill the names in automatically by right-clicking on the component header and selecting 'Find Animation States'.", EditorStyles.helpBox);
                    return;
                }

                for (int i = 0; i < script.animationStates.Length; i++)
                {
                    if (script.animationStates[i] == string.Empty || script.animationStates[i] == "")
                    {
                        EditorGUILayout.LabelField("One of the animation state names in 'Animation States' is empty, can not bake.", EditorStyles.helpBox);
                        return;
                    }
                }

                if (GUILayout.Button("Bake Animation States"))
                {
                    script.BakeClip();
                }
                return;

            case Baker.Mode.PlayableDirector:
                if (script.director == null)
                {
                    EditorGUILayout.LabelField("No PlayableDirector found on Baker GameObject", EditorStyles.helpBox);
                    return;
                }

                if (GUILayout.Button("Bake Timeline"))
                {
                    script.BakeClip();
                }
                break;

            case Baker.Mode.Realtime:
                if (GUILayout.Button("Start Baking"))
                {
                    script.StartBaking();
                }
                return;
            }
        }