static void UpdateMecanimClips(SkeletonDataAsset skeletonDataAsset)
    {
        if (skeletonDataAsset.controller == null)
        {
            return;
        }

        SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
    }
Example #2
0
 void DrawMecanim()
 {
     EditorGUILayout.PropertyField(controller, new GUIContent("Controller", SpineEditorUtilities.Icons.controllerIcon));
     if (controller.objectReferenceValue == null)
     {
         if (GUILayout.Button(new GUIContent("Generate Mecanim Controller", SpineEditorUtilities.Icons.controllerIcon), GUILayout.Width(195), GUILayout.Height(20)))
         {
             SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);
         }
     }
 }
 void DrawMecanim()
 {
     EditorGUILayout.PropertyField(controller, new GUIContent("Controller", SpineEditorUtilities.Icons.controllerIcon));
     if (controller.objectReferenceValue == null)
     {
         GUILayout.BeginHorizontal();
         GUILayout.Space(32);
         if (GUILayout.Button(new GUIContent("Generate Mecanim Controller"), EditorStyles.toolbarButton, GUILayout.Width(195), GUILayout.Height(20)))
         {
             SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);
         }
         //GUILayout.Label(new GUIContent("Alternative to SkeletonAnimation, not a requirement.", SpineEditorUtilities.Icons.warning));
         GUILayout.EndHorizontal();
         EditorGUILayout.LabelField("Alternative to SkeletonAnimation, not required", EditorStyles.miniLabel);
     }
 }
        public static void DoSplit(string assetPath, string exportAnimationPath, int limitCount, bool fromBackUp = false)
        {
            SkeletonDataAsset skelAsset = (SkeletonDataAsset)AssetDatabase.LoadAssetAtPath(assetPath, typeof(SkeletonDataAsset));

            if (skelAsset == null)
            {
                return;
            }


            TextAsset _asset    = skelAsset.skeletonJSON;
            string    _skelPath = AssetDatabase.GetAssetPath(_asset);

            if (fromBackUp)
            {
                int       _length      = _skelPath.LastIndexOf(".");
                string    _backupPath  = _skelPath.Insert(_length, "_backup");
                TextAsset _assetBackup = AssetDatabase.LoadAssetAtPath(_backupPath, typeof(TextAsset)) as TextAsset;
                if (_assetBackup != null)
                {
                    AssetDatabase.CopyAsset(_backupPath, _skelPath);
                    AssetDatabase.Refresh();
                }
            }

            if (!_skelPath.ToLower().Contains(".skel"))
            {
                Debug.LogErrorFormat("skipped json format, path:{0}", assetPath);
                return;
            }

            // if (skelAsset.controller == null) //没有生成,有了更新。
            // SkeletonBaker.GenerateMecanimAnimationClips(skelAsset);
            SkeletonBaker.GenerateMecanimAnimationClips(skelAsset);

            //拆分并备份
            GetRequiredAtlasRegions(_skelPath, exportAnimationPath, limitCount);

            skelAsset.Clear();
            skelAsset.GetSkeletonData(true);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    public static SkeletonAnimator InstantiateSkeletonAnimator(SkeletonDataAsset skeletonDataAsset, Skin skin = null)
    {
        GameObject go = new GameObject(skeletonDataAsset.name.Replace("_SkeletonData", ""), typeof(MeshFilter), typeof(MeshRenderer), typeof(Animator), typeof(SkeletonAnimator));

        if (skeletonDataAsset.controller == null)
        {
            SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
        }

        go.GetComponent <Animator>().runtimeAnimatorController = skeletonDataAsset.controller;

        SkeletonAnimator anim = go.GetComponent <SkeletonAnimator>();

        anim.skeletonDataAsset = skeletonDataAsset;

        bool requiresNormals = false;

        foreach (AtlasAsset atlasAsset in anim.skeletonDataAsset.atlasAssets)
        {
            foreach (Material m in atlasAsset.materials)
            {
                if (m.shader.name.Contains("Lit"))
                {
                    requiresNormals = true;
                    break;
                }
            }
        }

        anim.calculateNormals = requiresNormals;

        SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

        if (data == null)
        {
            for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++)
            {
                string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
                skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
            }

            data = skeletonDataAsset.GetSkeletonData(true);
        }

        if (skin == null)
        {
            skin = data.DefaultSkin;
        }

        if (skin == null)
        {
            skin = data.Skins[0];
        }

        anim.Reset();

        anim.skeleton.SetSkin(skin);
        anim.initialSkinName = skin.Name;

        anim.skeleton.Update(1);
        anim.skeleton.UpdateWorldTransform();
        anim.LateUpdate();

        return(anim);
    }
    void DrawUnityTools()
    {
        bool pre = showUnity;

        showUnity = EditorGUILayout.Foldout(showUnity, new GUIContent("Unity Tools", SpineEditorUtilities.Icons.unityIcon));
        if (pre != showUnity)
        {
            EditorPrefs.SetBool("SkeletonDataAssetInspector_showUnity", showUnity);
        }

        if (showUnity)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.LabelField("SkeletonAnimator", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;
            DrawMecanim();
            EditorGUI.indentLevel--;
            GUILayout.Space(32);
            EditorGUILayout.LabelField("Baking", EditorStyles.boldLabel);
            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++;
            GUILayout.BeginHorizontal();
            {
                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;
                    }

                    bool oops = false;

                    try {
                        GUILayout.BeginVertical();
                        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);
                        }

                        GUILayout.BeginHorizontal();
                        GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50));
                        if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196)))
                        {
                            SelectSkinContext();
                        }
                        GUILayout.EndHorizontal();
                    } catch {
                        oops = true;
                        //GUILayout.BeginVertical();
                    }



                    if (!oops)
                    {
                        GUILayout.EndVertical();
                    }
                }
            }
            GUILayout.EndHorizontal();
            EditorGUI.indentLevel--;
            EditorGUI.indentLevel--;
        }
    }
Example #7
0
    void DrawBaking()
    {
        bool pre = showBaking;

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

        if (showBaking)
        {
            EditorGUI.indentLevel++;
            bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
            EditorGUI.BeginDisabledGroup(bakeAnimations == false);
            {
                EditorGUI.indentLevel++;
                bakeIK           = EditorGUILayout.Toggle("Bake IK", bakeIK);
                bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions);
                EditorGUI.indentLevel--;
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.indentLevel++;
            GUILayout.BeginHorizontal();
            {
                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[0];
                    }
                    else
                    {
                        skinName = m_skeletonAnimation.skeleton.Skin.Name;
                    }

                    bool oops = false;

                    try {
                        GUILayout.BeginVertical();
                        if (GUILayout.Button(new GUIContent("Bake " + skinName, SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250)))
                        {
                            SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new List <Skin>(new Skin[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
                        }

                        GUILayout.BeginHorizontal();
                        GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50));
                        if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196)))
                        {
                            SelectSkinContext();
                        }
                        GUILayout.EndHorizontal();
                    } catch {
                        oops = true;
                        //GUILayout.BeginVertical();
                    }



                    if (!oops)
                    {
                        GUILayout.EndVertical();
                    }
                }
            }
            GUILayout.EndHorizontal();
            EditorGUI.indentLevel--;
            EditorGUI.indentLevel--;
        }
    }
Example #8
0
    public static Object InstantiateSkeletonUnit(SkeletonDataAsset skeletonDataAsset, Skin skin = null)
    {
        if (!File.Exists("Assets/ExternalRes/Unit/Unit.json"))
        {
            return(null);
        }

        JSONNode jsonConfig = null;

        using (FileStream fs = new FileStream("Assets/ExternalRes/Unit/Unit.json", FileMode.Open))
        {
            string     sr     = new StreamReader(fs).ReadToEnd();
            JSONParser parser = new JSONParser();
            jsonConfig = parser.Parse(new FlashCompatibleTextReader(sr));
        }

        //读取配置文件
        Dictionary <string, UnitConfig> UnitConfigs = new Dictionary <string, UnitConfig>();
        TextAsset   textAsset = AssetDatabase.LoadAssetAtPath("Assets/ExternalRes/Config/UnitConfig.xml", typeof(TextAsset)) as TextAsset;
        XMLInStream stream    = new XMLInStream(textAsset.text);

        stream.List("item", delegate(XMLInStream itemStream)
        {
            UnitConfig ufg = new UnitConfig(itemStream);
            if (!UnitConfigs.ContainsKey(ufg.ResourceIcon))
            {
                UnitConfigs.Add(ufg.ResourceIcon, ufg);
            }
        });

        string path  = AssetDatabase.GetAssetPath(skeletonDataAsset);
        string fpath = path.Replace("_SkeletonData", "_Controller").Replace(".asset", ".controller");
        string mpath = path.Replace("_SkeletonData", "_Controller").Replace(".asset", ".controller.meta");

        if (File.Exists(fpath))
        {
            File.Delete(fpath);
            File.Delete(mpath);
            Debug.Log("删除旧的Controller:" + fpath);
        }
        fpath = path.Replace("_SkeletonData", "").Replace(".asset", ".prefab");
        mpath = path.Replace("_SkeletonData", "").Replace(".asset", ".prefab.meta");
        if (File.Exists(fpath))
        {
            File.Delete(fpath);
            File.Delete(mpath);
            Debug.Log("删除旧的Prefab:" + fpath);
        }

        skeletonDataAsset.controller = null;
        // 创建状态机
        SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset, jsonConfig);
        // 创建Animator Object
        GameObject go = GenerateAnimatorObject(skeletonDataAsset, skin);

        // 伙伴RectTransform
        go.AddComponent <RectTransform>();
        RectTransform rt = go.GetComponent <RectTransform>();

        rt.pivot = new Vector2(0.5f, 0);
        // 伙伴UnitSoundBehaviour
        UnitSoundBehaviour usb = go.AddComponent <UnitSoundBehaviour>();

        //伙伴UnitIdleChangeBehaviour
        go.AddComponent <UnitIdleChangeBehaviour>();
        // 创建Audio Object
        string name = path.Replace("Assets/ExternalRes/Unit/", "").Replace("_SkeletonData.asset", "");

        name = name.Substring(name.IndexOf("/") + 1);
        if (UnitConfigs.ContainsKey(name))
        {
            usb.SetSoundSource(AutoPrefab.GenerateAudioObject(go, UnitConfigs[name]));
        }
        // 创建Prefab
        string dataPath   = AssetDatabase.GetAssetPath(skeletonDataAsset);
        string prefabPath = dataPath.Replace("_SkeletonData", "").Replace(".asset", ".prefab");
        Object prefab     = AutoPrefab.GenerateUnitPrefab(go, prefabPath);

        // 销毁Animator Object
        Object.DestroyImmediate(go);
        // 设置asset bundle name
        AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(prefab)).assetBundleName = "units/" + name;
        return(prefab);
    }