private void AppendSpriteBoneDataRecursively(List <UnityEngine.U2D.SpriteBone> spriteBones, BoneCache bone, int parentIndex) { int currentParentIndex = spriteBones.Count; var spriteBone = new UnityEngine.U2D.SpriteBone(); spriteBone.name = bone.name; spriteBone.parentId = parentIndex; if (parentIndex == -1 && bone.parentBone != null) { spriteBone.position = bone.position; spriteBone.rotation = bone.rotation; } else { spriteBone.position = bone.localPosition; spriteBone.rotation = bone.localRotation; } spriteBone.position = new Vector3(spriteBone.position.x, spriteBone.position.y, bone.depth); spriteBone.length = bone.localLength; spriteBones.Add(spriteBone); foreach (var child in bone) { var childBone = child as BoneCache; if (childBone != null) { AppendSpriteBoneDataRecursively(spriteBones, childBone, currentParentIndex); } } }
private static List <UnityEngine.U2D.SpriteBone> Load(SerializedObject importer, SpriteImportMode mode, int index) { var sp = mode == SpriteImportMode.Multiple ? importer.FindProperty("m_SpriteSheet.m_Sprites").GetArrayElementAtIndex(index).FindPropertyRelative("m_Bones") : importer.FindProperty("m_SpriteSheet.m_Bones"); var spriteBone = new List <UnityEngine.U2D.SpriteBone>(sp.arraySize); for (int i = 0; i < sp.arraySize; ++i) { var boneSO = sp.GetArrayElementAtIndex(i); var sb = new UnityEngine.U2D.SpriteBone(); sb.length = boneSO.FindPropertyRelative("length").floatValue; sb.position = boneSO.FindPropertyRelative("position").vector3Value; sb.rotation = boneSO.FindPropertyRelative("rotation").quaternionValue; sb.parentId = boneSO.FindPropertyRelative("parentId").intValue; sb.name = boneSO.FindPropertyRelative("name").stringValue; spriteBone.Add(sb); } return(spriteBone); }