public void OnWizardCreate() { try{ Debug.ClearDeveloperConsole(); if (animTextAsset == null || altasTexture == null || altasTextAsset == null) { return; } if (altasTexture && !string.IsNullOrEmpty(altasTextAsset)) { SetAtlasTextureImporter(AssetDatabase.GetAssetPath(altasTexture)); SpineJsonParse.ParseTextureAtlas(this, altasTexture, altasTextAsset); } if (otherTextures != null) { foreach (Atlas atlas in otherTextures) { SetAtlasTextureImporter(AssetDatabase.GetAssetPath(atlas.texture)); SpineJsonParse.ParseTextureAtlas(this, atlas.texture, atlas.atlasText); } } CreateTextureFramesAndMaterails(); SpineJsonParse.ParseAnimJsonData(this); }finally{ SpineAnimFile.Dispose(); SpineShowArmature.Dispose(); bonesKV = null; slotsKV = null; slotsDataKV = null; spriteKV = null; atlasKV = null; ffdKV = null; spriteMeshUsedMatKV = null; animList = null; bonePoseKV = null; bones = null; slots = null; m_TextureFrames = null; DestroyImmediate(this); System.GC.Collect(); } }
//init public void InitShow() { SpineShowArmature.AddBones(this); SpineShowArmature.AddSlot(this); SpineShowArmature.ShowBones(this); SpineShowArmature.ShowSlots(this); SpineShowArmature.ShowSkin(this); SpineShowArmature.SetIKs(this); SpineAnimFile.CreateAnimFile(this); Armature armature = _armature.GetComponent <Armature>(); armature.textureFrames = m_TextureFrames; //update slot display for (int s = 0; s < slots.Count; ++s) { slots[s].displayIndex = slots[s].displayIndex; } if (armature.isUGUI) { UnityEngine.UI.MaskableGraphic[] renders = _armature.GetComponentsInChildren <UnityEngine.UI.MaskableGraphic>(true); armature.uiAttachments = renders; armature.attachments = new Renderer[0]; } else { Renderer[] renders = _armature.GetComponentsInChildren <Renderer>(true); armature.attachments = renders; armature.uiAttachments = new UnityEngine.UI.MaskableGraphic[0]; } armature.slots = slots.ToArray(); armature.bones = bones.ToArray(); armature.anims = animList.ToArray(); armature.zSpace = zoffset; armature.ResetSlotZOrder(); string path = AssetDatabase.GetAssetPath(animTextAsset); path = path.Substring(0, path.LastIndexOf('/')) + "/" + _armature.name; //create pose data PoseData poseData = AssetDatabase.LoadAssetAtPath <PoseData>(path + "_Pose.asset"); if (poseData == null) { poseData = ScriptableObject.CreateInstance <PoseData>(); AssetDatabase.CreateAsset(poseData, path + "_Pose.asset"); } poseData.slotDatas = new PoseData.SlotData[armature.slots.Length]; for (int i = 0; i < armature.slots.Length; ++i) { poseData.slotDatas[i] = new PoseData.SlotData(); poseData.slotDatas[i].color = armature.slots[i].color; poseData.slotDatas[i].displayIndex = armature.slots[i].displayIndex; poseData.slotDatas[i].zorder = armature.slots[i].z; armature.slots[i].SendMessage("UpdateSlotByInheritSlot", SendMessageOptions.DontRequireReceiver); } poseData.boneDatas = new PoseData.TransformData[armature.bones.Length]; for (int i = 0; i < armature.bones.Length; ++i) { poseData.boneDatas[i] = new PoseData.TransformData(); poseData.boneDatas[i].x = armature.bones[i].localPosition.x; poseData.boneDatas[i].y = armature.bones[i].localPosition.y; poseData.boneDatas[i].sx = armature.bones[i].localScale.x; poseData.boneDatas[i].sy = armature.bones[i].localScale.y; poseData.boneDatas[i].rotation = armature.bones[i].localEulerAngles.z; } if (isUGUI) { poseData.displayDatas = new PoseData.DisplayData[armature.uiAttachments.Length]; for (int i = 0; i < armature.uiAttachments.Length; ++i) { poseData.displayDatas[i] = new PoseData.DisplayData(); UnityEngine.UI.MaskableGraphic render = armature.uiAttachments[i]; UIFrame sf = render.GetComponent <UIFrame>(); if (sf) { poseData.displayDatas[i].type = PoseData.AttachmentType.IMG; poseData.displayDatas[i].color = sf.color; } else { UIMesh sm = render.GetComponent <UIMesh>(); if (sm) { poseData.displayDatas[i].type = PoseData.AttachmentType.MESH; poseData.displayDatas[i].color = sm.color; poseData.displayDatas[i].vertex = (Vector3[])sm.vertices.Clone(); } else { UnityEngine.UI.Image sr = render.GetComponent <UnityEngine.UI.Image>(); if (sr) { poseData.displayDatas[i].type = PoseData.AttachmentType.IMG; poseData.displayDatas[i].color = sr.color; } else { poseData.displayDatas[i].type = PoseData.AttachmentType.BOX; } } } poseData.displayDatas[i].transform = new PoseData.TransformData(); poseData.displayDatas[i].transform.x = render.transform.localPosition.x; poseData.displayDatas[i].transform.y = render.transform.localPosition.y; poseData.displayDatas[i].transform.sx = render.transform.localScale.x; poseData.displayDatas[i].transform.sy = render.transform.localScale.y; poseData.displayDatas[i].transform.rotation = render.transform.localEulerAngles.z; render.transform.localScale *= unit; } } else { poseData.displayDatas = new PoseData.DisplayData[armature.attachments.Length]; for (int i = 0; i < armature.attachments.Length; ++i) { poseData.displayDatas[i] = new PoseData.DisplayData(); Renderer render = armature.attachments[i]; SpriteFrame sf = render.GetComponent <SpriteFrame>(); if (sf) { poseData.displayDatas[i].type = PoseData.AttachmentType.IMG; poseData.displayDatas[i].color = sf.color; } else { SpriteMesh sm = render.GetComponent <SpriteMesh>(); if (sm) { poseData.displayDatas[i].type = PoseData.AttachmentType.MESH; poseData.displayDatas[i].color = sm.color; poseData.displayDatas[i].vertex = (Vector3[])sm.vertices.Clone(); } else { SpriteRenderer sr = render.GetComponent <SpriteRenderer>(); if (sr) { poseData.displayDatas[i].type = PoseData.AttachmentType.IMG; poseData.displayDatas[i].color = sr.color; } else { poseData.displayDatas[i].type = PoseData.AttachmentType.BOX; } } } poseData.displayDatas[i].transform = new PoseData.TransformData(); poseData.displayDatas[i].transform.x = render.transform.localPosition.x; poseData.displayDatas[i].transform.y = render.transform.localPosition.y; poseData.displayDatas[i].transform.sx = render.transform.localScale.x; poseData.displayDatas[i].transform.sy = render.transform.localScale.y; poseData.displayDatas[i].transform.rotation = render.transform.localEulerAngles.z; } } armature.poseData = poseData; AssetDatabase.Refresh(); EditorUtility.SetDirty(poseData); AssetDatabase.SaveAssets(); if (armature.textureFrames && armature.textureFrames.materials != null && armature.textureFrames.materials.Length > 0) { armature.preMultiplyAlpha = armature.textureFrames.materials[0].GetFloat("_BlendSrc") == (int)UnityEngine.Rendering.BlendMode.One; } else { armature.preMultiplyAlpha = true; } if (armature.isUGUI) { GameObject canvas = GameObject.Find("/Canvas"); if (canvas) { _armature.SetParent(canvas.transform); _armature.localScale = Vector3.one / unit; _armature.localPosition = Vector3.zero; } } if (genPrefab) { string prefabPath = path + ".prefab"; GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath); if (!prefab) { PrefabUtility.CreatePrefab(prefabPath, _armature.gameObject, ReplacePrefabOptions.ConnectToPrefab); } else { PrefabUtility.ReplacePrefab(_armature.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab); } } }