private static void ParseAnimations(SpineArmatureEditor armatureEditor, Bones2D.JSONClass armtureObj) { if (armtureObj.ContainKey("animations")) { Bones2D.JSONClass anims = armtureObj["animations"].AsObject; List <SpineData.AnimationData> animList = new List <SpineData.AnimationData>(); foreach (string animName in anims.GetKeys()) { SpineData.AnimationData animData = new SpineData.AnimationData(); animData.name = animName; animList.Add(animData); Bones2D.JSONClass animObj = anims[animName].AsObject; if (animObj.ContainKey("bones")) { Bones2D.JSONClass bonesObj = animObj["bones"].AsObject; animData.boneAnims = ParseAnimBones(armatureEditor, bonesObj).ToArray(); } if (animObj.ContainKey("slots")) { Bones2D.JSONClass slotsObj = animObj["slots"].AsObject; animData.slotAnims = ParseAnimSlots(slotsObj).ToArray(); } if (animObj.ContainKey("ik")) { } if (animObj.ContainKey("deform")) { Bones2D.JSONClass deformObj = animObj["deform"].AsObject; animData.deforms = ParseAnimDeform(armatureEditor, deformObj).ToArray(); } else if (animObj.ContainKey("ffd")) { Bones2D.JSONClass deformObj = animObj["ffd"].AsObject; animData.deforms = ParseAnimDeform(armatureEditor, deformObj).ToArray(); } if (animObj.ContainKey("events")) { Bones2D.JSONArray eventsArray = animObj["events"].AsArray; animData.events = ParseAnimEvents(eventsArray).ToArray(); } if (animObj.ContainKey("drawOrder")) { Bones2D.JSONArray drawOrderArray = animObj["drawOrder"].AsArray; animData.drawOrders = ParseDrawOrders(armatureEditor, drawOrderArray).ToArray(); } else if (animObj.ContainKey("draworder")) { Bones2D.JSONArray drawOrderArray = animObj["draworder"].AsArray; animData.drawOrders = ParseDrawOrders(armatureEditor, drawOrderArray).ToArray(); } } armatureEditor.armatureData.animations = animList.ToArray(); } }
public static void CreateAnimFile(SpineArmatureEditor armatureEditor) { armatureEditor.animList.Clear(); slotPathKV = new Dictionary <string, string>(); tempZNumber = 0; string path = AssetDatabase.GetAssetPath(armatureEditor.animTextAsset); path = path.Substring(0, path.LastIndexOf('/')) + "/" + armatureEditor.armature.name + "_Anims"; if (!AssetDatabase.IsValidFolder(path)) { Directory.CreateDirectory(path); } path += "/"; Animator animator = armatureEditor.armature.gameObject.AddComponent <Animator>(); AnimatorController controller = AssetDatabase.LoadAssetAtPath <AnimatorController>(path + armatureEditor.armature.name + ".controller"); if (armatureEditor.genAnimations) { AnimatorStateMachine rootStateMachine = null; if (controller == null) { controller = AnimatorController.CreateAnimatorControllerAtPath(path + armatureEditor.armature.name + ".controller"); rootStateMachine = controller.layers[0].stateMachine; } animator.runtimeAnimatorController = controller; if (armatureEditor.armatureData.animations != null) { //add empty state string clipPath = path + "pose.anim"; poseClip = AssetDatabase.LoadAssetAtPath <AnimationClip>(clipPath); if (poseClip == null) { poseClip = new AnimationClip(); AssetDatabase.CreateAsset(poseClip, clipPath); } else { poseClip.ClearCurves(); } if (rootStateMachine != null) { rootStateMachine.AddState("None"); // state.motion = poseClip; } //save SerializedObject serializedClip = new SerializedObject(poseClip); Bones2D.AnimationClipSettings clipSettings = new Bones2D.AnimationClipSettings(serializedClip.FindProperty("m_AnimationClipSettings")); clipSettings.loopTime = false; serializedClip.ApplyModifiedProperties(); for (int i = 0; i < armatureEditor.armatureData.animations.Length; ++i) { SpineData.AnimationData animationData = armatureEditor.armatureData.animations[i]; armatureEditor.animList.Add(animationData.name); clipPath = path + animationData.name + ".anim"; AnimationClip clip = AssetDatabase.LoadAssetAtPath <AnimationClip>(clipPath); bool loopTime = true; if (clip == null) { clip = new AnimationClip(); AssetDatabase.CreateAsset(clip, clipPath); } else { loopTime = clip.isLooping; clip.ClearCurves(); } clip.name = animationData.name; clip.frameRate = armatureEditor.armatureData.frameRate; if (animationData.slotAnims != null) { CreateAnimSlot(armatureEditor, clip, animationData.slotAnims); } if (animationData.boneAnims != null) { bool sucess = CreateAnimBone(armatureEditor, clip, animationData.boneAnims); if (!sucess) { return; } } if (animationData.deforms != null) { CreateAnimDeform(armatureEditor, clip, animationData.deforms); } if (animationData.events != null) { CreateAnimEvent(armatureEditor, clip, animationData.events); } if (animationData.drawOrders != null) { CreateAnimDrawOrder(armatureEditor, clip, animationData.drawOrders); } serializedClip = new SerializedObject(clip); clipSettings = new Bones2D.AnimationClipSettings(serializedClip.FindProperty("m_AnimationClipSettings")); clipSettings.loopTime = loopTime; serializedClip.ApplyModifiedProperties(); if (rootStateMachine != null) { AnimatorState state = rootStateMachine.AddState(clip.name); state.motion = clip; } } } if (rootStateMachine != null && rootStateMachine.states != null && rootStateMachine.states.Length > 0) { rootStateMachine.defaultState = rootStateMachine.states[0].state; } } else { animator.runtimeAnimatorController = controller; for (int i = 0; i < armatureEditor.armatureData.animations.Length; ++i) { SpineData.AnimationData animationData = armatureEditor.armatureData.animations[i]; armatureEditor.animList.Add(animationData.name); } } //createAvatarMask if (armatureEditor.genAvatar) { CreateAvatar(armatureEditor, animator, path); } AssetDatabase.SaveAssets(); }