BakeToPrefab() public static method

public static BakeToPrefab ( SkeletonDataAsset skeletonDataAsset, ExposedList skins, string outputPath = "", bool bakeAnimations = true, bool bakeIK = true, SendMessageOptions eventOptions = SendMessageOptions.DontRequireReceiver ) : void
skeletonDataAsset SkeletonDataAsset
skins ExposedList
outputPath string
bakeAnimations bool
bakeIK bool
eventOptions SendMessageOptions
return void
        static void Bake(bool skippExist = false)
        {
            DirectoryInfo[] inputDirList = new DirectoryInfo(_InputDir).GetDirectories();
            foreach (DirectoryInfo inputDir in inputDirList)
            {
                string outPath = _OutputDir + "/Char_" + inputDir.Name;
                if (Directory.Exists(outPath))
                {
                    if (skippExist)
                    {
                        continue;
                    }
                }
                else
                {
                    Directory.CreateDirectory(outPath);
                }

                string            inPath = _InputDir + "/" + inputDir.Name + "/" + inputDir.Name + "_SkeletonData.asset";
                SkeletonDataAsset data   = AssetDatabase.LoadAssetAtPath <SkeletonDataAsset>(inPath);
                SkeletonBaker.BakeToPrefab(data, data.GetSkeletonData(false).Skins, outPath, true, true, SendMessageOptions.DontRequireReceiver);
            }
        }
        void DrawUnityTools()
        {
                        #if SPINE_SKELETON_ANIMATOR
            using (new SpineInspectorUtility.BoxScope()) {
                isMecanimExpanded = EditorGUILayout.Foldout(isMecanimExpanded, new GUIContent("SkeletonAnimator", Icons.unityIcon));
                if (isMecanimExpanded)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(controller, new GUIContent("Controller", Icons.controllerIcon));
                    if (controller.objectReferenceValue == null)
                    {
                        // Generate Mecanim Controller Button
                        using (new GUILayout.HorizontalScope()) {
                            GUILayout.Space(EditorGUIUtility.labelWidth);
                            if (GUILayout.Button(new GUIContent("Generate Mecanim Controller"), GUILayout.Height(20)))
                            {
                                SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);
                            }
                        }
                        EditorGUILayout.HelpBox("SkeletonAnimator is the Mecanim alternative to SkeletonAnimation.\nIt is not required.", MessageType.Info);
                    }
                    else
                    {
                        // Update AnimationClips button.
                        using (new GUILayout.HorizontalScope()) {
                            GUILayout.Space(EditorGUIUtility.labelWidth);
                            if (GUILayout.Button(new GUIContent("Force Update AnimationClips"), GUILayout.Height(20)))
                            {
                                SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);
                            }
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }
                        #endif

                        #if SPINE_BAKING
            bool pre = isBakingExpanded;
            isBakingExpanded = EditorGUILayout.Foldout(isBakingExpanded, new GUIContent("Baking", Icons.unityIcon));
            if (pre != isBakingExpanded)
            {
                EditorPrefs.SetBool(ShowBakingPrefsKey, isBakingExpanded);
            }

            if (isBakingExpanded)
            {
                EditorGUI.indentLevel++;
                const string BakingWarningMessage =
//					"WARNING!" +
//					"\nBaking is NOT the same as SkeletonAnimator!" +
//					"\n\n" +
                    "The main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)" +

                    "\n\nBaking does not support the following:" +
                    "\n\tDisabled transform inheritance" +
                    "\n\tShear" +
                    "\n\tColor Keys" +
                    "\n\tDraw Order Keys" +
                    "\n\tAll Constraint types" +

                    "\n\nCurves are sampled at 60fps and are not realtime." +
                    "\nPlease read SkeletonBaker.cs comments for full details.";
                EditorGUILayout.HelpBox(BakingWarningMessage, MessageType.Info, true);

                EditorGUI.indentLevel++;
                bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
                using (new EditorGUI.DisabledGroupScope(!bakeAnimations)) {
                    EditorGUI.indentLevel++;
                    bakeIK           = EditorGUILayout.Toggle("Bake IK", bakeIK);
                    bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions);
                    EditorGUI.indentLevel--;
                }

                // Bake Skin buttons.
                using (new GUILayout.HorizontalScope()) {
                    if (GUILayout.Button(new GUIContent("Bake All Skins", Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150)))
                    {
                        SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);
                    }

                    if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null)
                    {
                        Skin bakeSkin = m_skeletonAnimation.skeleton.Skin;

                        string skinName = "<No Skin>";
                        if (bakeSkin == null)
                        {
                            skinName = "Default";
                            bakeSkin = m_skeletonData.Skins.Items[0];
                        }
                        else
                        {
                            skinName = m_skeletonAnimation.skeleton.Skin.Name;
                        }

                        using (new GUILayout.VerticalScope()) {
                            if (GUILayout.Button(new GUIContent("Bake \"" + skinName + "\"", Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250)))
                            {
                                SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new ExposedList <Skin>(new [] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
                            }
                            using (new GUILayout.HorizontalScope()) {
                                GUILayout.Label(new GUIContent("Skins", Icons.skinsRoot), GUILayout.Width(50));
                                if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196)))
                                {
                                    DrawSkinDropdown();
                                }
                            }
                        }
                    }
                }

                EditorGUI.indentLevel--;
                EditorGUI.indentLevel--;
            }
                        #endif
        }
Ejemplo n.º 3
0
        void OnGUI()
        {
            so = so ?? new SerializedObject(this);

            EditorGUIUtility.wideMode = true;
            EditorGUILayout.LabelField("Spine Skeleton Prefab Baking", EditorStyles.boldLabel);

            const string BakingWarningMessage = "\nSkeleton baking is not the primary use case for Spine skeletons." +
                                                "\nUse baking if you have specialized uses, such as simplified skeletons with movement driven by physics." +

                                                "\n\nBaked Skeletons do not support the following:" +
                                                "\n\tDisabled rotation or scale inheritance" +
                                                "\n\tLocal Shear" +
                                                "\n\tAll Constraint types" +
                                                "\n\tWeighted mesh verts with more than 4 bound bones" +

                                                "\n\nBaked Animations do not support the following:" +
                                                "\n\tMesh Deform Keys" +
                                                "\n\tColor Keys" +
                                                "\n\tDraw Order Keys" +

                                                "\n\nAnimation Curves are sampled at 60fps and are not realtime." +
                                                "\nConstraint animations are also baked into animation curves." +
                                                "\nSee SkeletonBaker.cs comments for full details.\n";

            EditorGUILayout.HelpBox(BakingWarningMessage, MessageType.Info, true);

            EditorGUI.BeginChangeCheck();
            var skeletonDataAssetProperty = so.FindProperty("skeletonDataAsset");

            EditorGUILayout.PropertyField(skeletonDataAssetProperty, SpineInspectorUtility.TempContent("SkeletonDataAsset", Icons.spine));
            if (EditorGUI.EndChangeCheck())
            {
                so.ApplyModifiedProperties();
                DataAssetChanged();
            }
            EditorGUILayout.Space();

            if (skeletonDataAsset == null)
            {
                return;
            }
            var skeletonData = skeletonDataAsset.GetSkeletonData(false);

            if (skeletonData == null)
            {
                return;
            }
            bool hasExtraSkins = skeletonData.Skins.Count > 1;

            using (new SpineInspectorUtility.BoxScope(false)) {
                EditorGUILayout.LabelField(skeletonDataAsset.name, EditorStyles.boldLabel);
                using (new SpineInspectorUtility.IndentScope()) {
                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Bones: " + skeletonData.Bones.Count, Icons.bone));
                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Slots: " + skeletonData.Slots.Count, Icons.slotRoot));

                    if (hasExtraSkins)
                    {
                        EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Skins: " + skeletonData.Skins.Count, Icons.skinsRoot));
                        EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Current skin attachments: " + (bakeSkin == null ? 0 : bakeSkin.Attachments.Count), Icons.skinPlaceholder));
                    }
                    else if (skeletonData.Skins.Count == 1)
                    {
                        EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Skins: 1 (only default Skin)", Icons.skinsRoot));
                    }

                    int totalAttachments = 0;
                    foreach (var s in skeletonData.Skins)
                    {
                        totalAttachments += s.Attachments.Count;
                    }
                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Total Attachments: " + totalAttachments, Icons.genericAttachment));
                }
            }
            using (new SpineInspectorUtility.BoxScope(false)) {
                EditorGUILayout.LabelField("Animations", EditorStyles.boldLabel);
                EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Animations: " + skeletonData.Animations.Count, Icons.animation));

                using (new SpineInspectorUtility.IndentScope()) {
                    bakeAnimations = EditorGUILayout.Toggle(SpineInspectorUtility.TempContent("Bake Animations", Icons.animationRoot), bakeAnimations);
                    using (new EditorGUI.DisabledScope(!bakeAnimations)) {
                        using (new SpineInspectorUtility.IndentScope()) {
                            bakeIK           = EditorGUILayout.Toggle(SpineInspectorUtility.TempContent("Bake IK", Icons.constraintIK), bakeIK);
                            bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup(SpineInspectorUtility.TempContent("Event Options", Icons.userEvent), bakeEventOptions);
                        }
                    }
                }
            }
            EditorGUILayout.Space();

            if (!string.IsNullOrEmpty(skinToBake) && UnityEngine.Event.current.type == EventType.Repaint)
            {
                bakeSkin = skeletonData.FindSkin(skinToBake) ?? skeletonData.DefaultSkin;
            }

            var prefabIcon = EditorGUIUtility.FindTexture("PrefabModel Icon");

            if (hasExtraSkins)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(so.FindProperty("skinToBake"));
                if (EditorGUI.EndChangeCheck())
                {
                    so.ApplyModifiedProperties();
                    Repaint();
                }

                if (SpineInspectorUtility.LargeCenteredButton(SpineInspectorUtility.TempContent(string.Format("Bake Skeleton with Skin ({0})", (bakeSkin == null ? "default" : bakeSkin.Name)), prefabIcon)))
                {
                    SkeletonBaker.BakeToPrefab(skeletonDataAsset, new ExposedList <Skin>(new[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
                }

                if (SpineInspectorUtility.LargeCenteredButton(SpineInspectorUtility.TempContent(string.Format("Bake All ({0} skins)", skeletonData.Skins.Count), prefabIcon)))
                {
                    SkeletonBaker.BakeToPrefab(skeletonDataAsset, skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);
                }
            }
            else
            {
                if (SpineInspectorUtility.LargeCenteredButton(SpineInspectorUtility.TempContent("Bake Skeleton", prefabIcon)))
                {
                    SkeletonBaker.BakeToPrefab(skeletonDataAsset, new ExposedList <Skin>(new[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
                }
            }
        }
        void DrawUnityTools()
        {
                        #if SPINE_SKELETON_ANIMATOR
            showMecanim = EditorGUILayout.Foldout(showMecanim, new GUIContent("SkeletonAnimator", SpineEditorUtilities.Icons.unityIcon));
            if (showMecanim)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(controller, new GUIContent("Controller", SpineEditorUtilities.Icons.controllerIcon));
                if (controller.objectReferenceValue == null)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Space(32);
                        if (GUILayout.Button(new GUIContent("Generate Mecanim Controller"), GUILayout.Width(195), GUILayout.Height(20)))
                        {
                            SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);
                        }
                    }
                    EditorGUILayout.LabelField("SkeletonAnimator is the Mecanim alternative to SkeletonAnimation. It is not required.", EditorStyles.miniLabel);
                }
                else
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Space(32);
                        if (GUILayout.Button(new GUIContent("Update Controller Animations"), GUILayout.Width(195), GUILayout.Height(20)))
                        {
                            SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);
                        }
                    }
                }
                EditorGUI.indentLevel--;
            }
                        #endif

            bool pre = showBaking;
            showBaking = EditorGUILayout.Foldout(showBaking, new GUIContent("Baking", SpineEditorUtilities.Icons.unityIcon));
            if (pre != showBaking)
            {
                EditorPrefs.SetBool("SkeletonDataAssetInspector_showUnity", showBaking);
            }

            if (showBaking)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.HelpBox("WARNING!\n\nBaking is NOT the same as SkeletonAnimator!\nDoes not support the following:\n\tFlipX or Y\n\tInheritScale\n\tColor Keys\n\tDraw Order Keys\n\tIK and Curves are sampled at 60fps and are not realtime.\n\tPlease read SkeletonBaker.cs comments for full details.\n\nThe main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)", MessageType.Warning, true);
                EditorGUI.indentLevel++;
                bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
                EditorGUI.BeginDisabledGroup(!bakeAnimations);
                {
                    EditorGUI.indentLevel++;
                    bakeIK           = EditorGUILayout.Toggle("Bake IK", bakeIK);
                    bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions);
                    EditorGUI.indentLevel--;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.indentLevel++;
                using (new EditorGUILayout.HorizontalScope()) {
                    if (GUILayout.Button(new GUIContent("Bake All Skins", SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150)))
                    {
                        SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);
                    }

                    string skinName = "<No Skin>";

                    if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null)
                    {
                        Skin bakeSkin = m_skeletonAnimation.skeleton.Skin;
                        if (bakeSkin == null)
                        {
                            skinName = "Default";
                            bakeSkin = m_skeletonData.Skins.Items[0];
                        }
                        else
                        {
                            skinName = m_skeletonAnimation.skeleton.Skin.Name;
                        }

                        using (new EditorGUILayout.VerticalScope()) {
                            if (GUILayout.Button(new GUIContent("Bake " + skinName, SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250)))
                            {
                                SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new ExposedList <Skin>(new [] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
                            }
                            using (new EditorGUILayout.HorizontalScope()) {
                                GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50));
                                if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196)))
                                {
                                    SelectSkinContext();
                                }
                            }
                        }
                    }
                }
                EditorGUI.indentLevel--;
                EditorGUI.indentLevel--;
            }
        }
        void OnGUI()
        {
            so = so ?? new SerializedObject(this);

            EditorGUIUtility.wideMode = true;
            EditorGUILayout.LabelField("Spine Skeleton Prefab Baking", EditorStyles.boldLabel);

            const string BakingWarningMessage = "\nThe main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)" +

                                                "\n\nBaking does not support the following:" +
                                                "\n\tDisabled transform inheritance" +
                                                "\n\tShear" +
                                                "\n\tColor Keys" +
                                                "\n\tDraw Order Keys" +
                                                "\n\tAll Constraint types" +

                                                "\n\nCurves are sampled at 60fps and are not realtime." +
                                                "\nPlease read SkeletonBaker.cs comments for full details.\n";

            EditorGUILayout.HelpBox(BakingWarningMessage, MessageType.Info, true);

            EditorGUI.BeginChangeCheck();
            var skeletonDataAssetProperty = so.FindProperty("skeletonDataAsset");

            EditorGUILayout.PropertyField(skeletonDataAssetProperty, SpineInspectorUtility.TempContent("SkeletonDataAsset", Icons.spine));
            if (EditorGUI.EndChangeCheck())
            {
                so.ApplyModifiedProperties();
                DataAssetChanged();
            }
            EditorGUILayout.Space();

            if (skeletonDataAsset == null)
            {
                return;
            }
            var skeletonData = skeletonDataAsset.GetSkeletonData(false);

            if (skeletonData == null)
            {
                return;
            }

            using (new SpineInspectorUtility.BoxScope(false)) {
                EditorGUILayout.LabelField(skeletonDataAsset.name, EditorStyles.boldLabel);
                using (new SpineInspectorUtility.IndentScope()) {
                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Bones: " + skeletonData.Bones.Count, Icons.bone));

                    int totalAttachments = 0;
                    foreach (var s in skeletonData.Skins)
                    {
                        totalAttachments += s.Attachments.Count;
                    }

                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Total Attachments: " + totalAttachments, Icons.genericAttachment));
                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Current skin attachments: " + (bakeSkin == null ? 0 : bakeSkin.Attachments.Count), Icons.skinPlaceholder));
                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Animations: " + skeletonData.Animations.Count, Icons.animation));
                }
            }
            using (new SpineInspectorUtility.BoxScope(false)) {
                EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);
                using (new SpineInspectorUtility.IndentScope()) {
                    bakeAnimations   = EditorGUILayout.Toggle(SpineInspectorUtility.TempContent("Bake Animations", Icons.animationRoot), bakeAnimations);
                    bakeIK           = EditorGUILayout.Toggle(SpineInspectorUtility.TempContent("Bake IK", Icons.constraintIK), bakeIK);
                    bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup(SpineInspectorUtility.TempContent("Event Options", Icons.userEvent), bakeEventOptions);
                }
            }
            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(so.FindProperty("skinToBake"));
            if (EditorGUI.EndChangeCheck())
            {
                so.ApplyModifiedProperties();
                Repaint();
            }

            if (!string.IsNullOrEmpty(skinToBake) && UnityEngine.Event.current.type == EventType.Repaint)
            {
                bakeSkin = skeletonData.FindSkin(skinToBake) ?? skeletonData.DefaultSkin;
            }

            var prefabIcon = EditorGUIUtility.FindTexture("PrefabModel Icon");

            if (SpineInspectorUtility.LargeCenteredButton(SpineInspectorUtility.TempContent(string.Format("Bake Skin ({0})", (bakeSkin == null ? "default" : bakeSkin.Name)), prefabIcon)))
            {
                SkeletonBaker.BakeToPrefab(skeletonDataAsset, new ExposedList <Skin>(new [] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
            }


            if (skeletonData.Skins.Count > 1)
            {
                if (SpineInspectorUtility.LargeCenteredButton(SpineInspectorUtility.TempContent(string.Format("Bake All ({0} skins)", skeletonData.Skins.Count), prefabIcon)))
                {
                    SkeletonBaker.BakeToPrefab(skeletonDataAsset, skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);
                }
            }
        }