//init public void InitShow() { ShowArmature.AddBones(this); ShowArmature.AddSlot(this); ShowArmature.ShowBones(this); ShowArmature.ShowSlots(this); ShowArmature.ShowSkins(this); ShowArmature.SetIKs(this); AnimFile.CreateAnimFile(this); DragonBoneArmature dba = _armature.GetComponent <DragonBoneArmature>(); if (dba && (dba.updateMeshs == null || dba.updateMeshs.Length == 0) && (dba.updateFrames == null || dba.updateFrames.Length == 0)) { Object.DestroyImmediate(dba); } Renderer[] renders = _armature.GetComponentsInChildren <Renderer>(); foreach (Renderer r in renders) { if (!r.enabled) { r.enabled = true; r.gameObject.SetActive(false); } else if (r.GetComponent <SpriteMesh>() != null) { for (int i = 0; i < r.transform.childCount; ++i) { r.transform.GetChild(i).gameObject.SetActive(false); } } else if (r.GetComponent <SpriteFrame>()) { //optimize memory SpriteFrame sf = r.GetComponent <SpriteFrame>(); SpriteFrame.TextureFrame tf = sf.frame; sf.frames = new SpriteFrame.TextureFrame[] { tf }; } } string path = AssetDatabase.GetAssetPath(animTextAsset); path = path.Substring(0, path.LastIndexOf('/')) + "/" + _armature.name + ".prefab"; GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path); if (!prefab) { PrefabUtility.CreatePrefab(path, _armature.gameObject, ReplacePrefabOptions.ConnectToPrefab); } else { PrefabUtility.ReplacePrefab(_armature.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab); } }
//init public void InitShow() { ShowArmature.AddBones(this); ShowArmature.AddSlot(this); ShowArmature.ShowBones(this); ShowArmature.ShowSlots(this); ShowArmature.ShowSkins(this); ShowArmature.SetIKs(this); AnimFile.CreateAnimFile(this); DragonBoneArmature dba = _armature.GetComponent <DragonBoneArmature>(); //update slot display for (int s = 0; s < slots.Count; ++s) { slots[s].displayIndex = slots[s].displayIndex; } Renderer[] renders = _armature.GetComponentsInChildren <Renderer>(true); foreach (Renderer r in renders) { if (r.GetComponent <SpriteFrame>()) { //optimize memory SpriteFrame sf = r.GetComponent <SpriteFrame>(); TextureFrame tf = sf.frame; sf.frames = new TextureFrame[] { tf }; } } dba.attachments = renders; dba.slots = slots.ToArray(); dba.zSpace = zoffset; dba.ResetSlotZOrder(); string path = AssetDatabase.GetAssetPath(animTextAsset); path = path.Substring(0, path.LastIndexOf('/')) + "/" + _armature.name + ".prefab"; GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path); if (!prefab) { PrefabUtility.CreatePrefab(path, _armature.gameObject, ReplacePrefabOptions.ConnectToPrefab); } else { PrefabUtility.ReplacePrefab(_armature.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab); } }
//init public void InitShow() { ShowArmature.AddBones(this); ShowArmature.AddSlot(this); ShowArmature.ShowBones(this); ShowArmature.ShowSlots(this); ShowArmature.ShowSkins(this); ShowArmature.SetIKs(this); AnimFile.CreateAnimFile(this); DragonBoneArmature dba = _armature.GetComponent <DragonBoneArmature>(); bool canDeleteArmature = false; if (armature && (dba.updateMeshs == null || dba.updateMeshs.Length == 0) && (dba.updateFrames == null || dba.updateFrames.Length == 0)) { canDeleteArmature = true; } Renderer[] renders = _armature.GetComponentsInChildren <Renderer>(); List <SpriteMesh> sms = new List <SpriteMesh>(); foreach (Renderer r in renders) { if (!r.enabled) { r.enabled = true; r.gameObject.SetActive(false); } else if (r.GetComponent <SpriteMesh>() != null) { for (int i = 0; i < r.transform.childCount; ++i) { r.transform.GetChild(i).gameObject.SetActive(false); } sms.Add(r.GetComponent <SpriteMesh>()); canDeleteArmature = false; } else if (r.GetComponent <SpriteFrame>()) { //optimize memory SpriteFrame sf = r.GetComponent <SpriteFrame>(); TextureFrame tf = sf.frame; sf.frames = new TextureFrame[] { tf }; } } if (canDeleteArmature) { // Object.DestroyImmediate(dba);//don't destroy } else { dba.updateMeshs = sms.ToArray(); } dba.attachments = renders; dba.slots = slots.ToArray(); dba.zSpace = zoffset; dba.ResetSlotZOrder(); string path = AssetDatabase.GetAssetPath(animTextAsset); path = path.Substring(0, path.LastIndexOf('/')) + "/" + _armature.name + ".prefab"; GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path); if (!prefab) { PrefabUtility.CreatePrefab(path, _armature.gameObject, ReplacePrefabOptions.ConnectToPrefab); } else { PrefabUtility.ReplacePrefab(_armature.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab); } }
//init public void InitShow() { ShowArmature.AddBones(this); ShowArmature.AddSlot(this); ShowArmature.ShowBones(this); ShowArmature.ShowSlots(this); ShowArmature.ShowSkins(this); ShowArmature.SetIKs(this); AnimFile.CreateAnimFile(this); DragonBoneArmature dba = _armature.GetComponent <DragonBoneArmature>(); //update slot display for (int s = 0; s < slots.Count; ++s) { slots[s].displayIndex = slots[s].displayIndex; } Renderer[] renders = _armature.GetComponentsInChildren <Renderer>(true); foreach (Renderer r in renders) { if (r.GetComponent <SpriteFrame>()) { //optimize memory SpriteFrame sf = r.GetComponent <SpriteFrame>(); TextureFrame tf = sf.frame; sf.frames = new TextureFrame[] { tf }; } } dba.attachments = renders; dba.slots = slots.ToArray(); dba.bones = bones.ToArray(); dba.zSpace = zoffset; dba.ResetSlotZOrder(); string path = AssetDatabase.GetAssetPath(animTextAsset); path = path.Substring(0, path.LastIndexOf('/')) + "/" + _armature.name; //create pose data PoseData poseData = ScriptableObject.CreateInstance <PoseData>(); poseData.slotDatas = new PoseData.SlotData[slots.Count]; for (int i = 0; i < slots.Count; ++i) { poseData.slotDatas[i] = new PoseData.SlotData(); poseData.slotDatas[i].color = slots[i].color; poseData.slotDatas[i].displayIndex = slots[i].displayIndex; poseData.slotDatas[i].zorder = slots[i].z; } poseData.boneDatas = new PoseData.TransformData[bones.Count]; for (int i = 0; i < bones.Count; ++i) { poseData.boneDatas[i] = new PoseData.TransformData(); poseData.boneDatas[i].x = bones[i].localPosition.x; poseData.boneDatas[i].y = bones[i].localPosition.y; poseData.boneDatas[i].sx = bones[i].localScale.x; poseData.boneDatas[i].sy = bones[i].localScale.y; poseData.boneDatas[i].rotation = bones[i].localEulerAngles.z; } poseData.displayDatas = new PoseData.DisplayData[dba.attachments.Length]; for (int i = 0; i < dba.attachments.Length; ++i) { poseData.displayDatas[i] = new PoseData.DisplayData(); Renderer render = dba.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 = sm.vertices; } 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; } AssetDatabase.CreateAsset(poseData, path + "_Pose.asset"); dba.poseData = poseData; 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); } }