예제 #1
0
        // Main editor window
        public void OnGUI()
        {
            if (AnimationMode.InAnimationMode())
            {
                AnimationMode.StopAnimationMode();
            }

            // Wait for user to select a GameObject
            if (bakeObject == null)
            {
                EditorGUILayout.HelpBox("Please select a GameObject", MessageType.Info);
                return;
            }

            if (buffer == null)
            {
                buffer = new VertaBuffer();
            }

            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Selected object: " + bakeObject.name);

            modelName = EditorGUILayout.TextField("Model Name", modelName);

            animationClip = EditorGUILayout.ObjectField(animationClip, typeof(AnimationClip), false) as AnimationClip;
            if (animationClip != null)
            {
                frameCount = GetFramesCount(animationClip);
                EditorGUILayout.LabelField("Frames to bake: " + frameCount);

                readyToBake = true;
            }


            if (GUILayout.Button("Bake mesh animations.") && readyToBake && !EditorApplication.isPlaying)
            {
                lockSelection = true;
                BakeMesh();
                lockSelection = false;
            }

            EditorGUILayout.EndVertical();
        }
예제 #2
0
        // Main editor window
        public void OnGUI()
        {
            if (AnimationMode.InAnimationMode())
            {
                AnimationMode.StopAnimationMode();
            }

            int needSize = 110;

            // Wait for user to select a GameObject
            if (bakeObject == null)
            {
                EditorGUILayout.HelpBox("Please select a GameObject", MessageType.Info);
                return;
            }

            if (buffer == null)
            {
                buffer = new VertaBuffer();
            }

            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Selected object: " + bakeObject.name);

            modelName = EditorGUILayout.TextField("Model Name", modelName);

            targetPathObject = EditorGUILayout.ObjectField("Output folder", targetPathObject, typeof(Object), true);

            bakeOnlyMesh = EditorGUILayout.Toggle("No animations", bakeOnlyMesh);

            if (!bakeOnlyMesh)
            {
                needSize += 20;
            }

            debugMeshOutput = EditorGUILayout.Toggle("Output debug mesh", debugMeshOutput);


            if (!bakeOnlyMesh)
            {
                int newLen = EditorGUILayout.IntField("Number of clips:", animationClips.Length);
                newLen = Math.Min(newLen, 5);
                if (newLen != animationClips.Length)
                {
                    Array.Resize(ref animationClips, newLen);
                }

                EditorGUILayout.BeginVertical();
                for (int i = 0; i < animationClips.Length; i++)
                {
                    animationClips[i] = EditorGUILayout.ObjectField(animationClips[i], typeof(AnimationClip), false) as AnimationClip;
                    needSize         += 19;
                }
                EditorGUILayout.EndVertical();

                if (animationClips != null && animationClips.Length > 0)
                {
                    int tmpFrameCount = 0;
                    foreach (AnimationClip clip in animationClips)
                    {
                        tmpFrameCount += GetFramesCount(clip);
                    }

                    frameCount = tmpFrameCount;
                    EditorGUILayout.LabelField("Frames to bake: " + frameCount);
                    needSize += 10;
                }
            }
            else
            {
                frameCount = 1;
            }

            minSize = new Vector2(300, needSize);
            maxSize = new Vector2(300, needSize);

            bool clipsReady = animationClips != null && animationClips.Length > 0;

            if (clipsReady)
            {
                clipsReady = animationClips.All(clip => clip != null);
            }

            readyToBake = (clipsReady || bakeOnlyMesh) && !EditorApplication.isPlaying &&
                          !modelName.Equals("");

            if (GUILayout.Button("Bake mesh animations.") && readyToBake)
            {
                lockSelection = true;
                BakeMesh();
                lockSelection = false;
            }

            EditorGUILayout.EndVertical();
        }