public string Serialize(SkinningCopyData skinningData)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(skinningData.GetType());

            using (StringWriter textWriter = new StringWriter())
            {
                xmlSerializer.Serialize(textWriter, skinningData);
                return(textWriter.ToString());
            }
        }
Esempio n. 2
0
        public SkinningCopyData CopySingle()
        {
            var skinningCopyData = new SkinningCopyData();

            skinningCopyData.pixelsPerUnit = pixelsPerUnit;

            BoneCache rootBone;
            var       selectedSprite = skinningCache.selectedSprite;
            var       selection      = skinningCache.skeletonSelection;

            if (selection.Count == 0)
            {
                if (selectedSprite == null || (skinningCache.mode == SkinningMode.SpriteSheet && skinningCache.hasCharacter))
                {
                    return(null);
                }
                var skeleton = skinningCache.GetEffectiveSkeleton(selectedSprite);
                if (skeleton.BoneCount == 0)
                {
                    return(null);
                }

                rootBone = skeleton.bones[0];
            }
            else
            {
                rootBone = selection.root;
            }

            var skinningSpriteData = new SkinningCopySpriteData();

            skinningCopyData.copyData.Add(skinningSpriteData);

            skinningSpriteData.spriteBones = GetSpriteBoneDataRecursively(rootBone);
            if (selectedSprite != null && skinningCache.mode == SkinningMode.Character)
            {
                // Offset the bones based on the currently selected Sprite in Character mode
                var characterPart = selectedSprite.GetCharacterPart();
                if (characterPart != null)
                {
                    var offset         = characterPart.position;
                    var rootSpriteBone = skinningSpriteData.spriteBones[0];
                    rootSpriteBone.position           = rootSpriteBone.position - offset;
                    skinningSpriteData.spriteBones[0] = rootSpriteBone;
                }
            }

            if (selectedSprite != null && meshTool != null)
            {
                CopyMeshFromSpriteCache(selectedSprite, skinningSpriteData);
            }
            return(skinningCopyData);
        }
        public SkinningCopyData CopyAll()
        {
            var skinningCopyData = new SkinningCopyData();

            skinningCopyData.pixelsPerUnit = pixelsPerUnit;

            var sprites = skinningCache.GetSprites();

            foreach (var sprite in sprites)
            {
                var skinningSpriteData = new SkinningCopySpriteData();
                skinningSpriteData.spriteName = sprite.name;

                var skeleton = skinningCache.GetEffectiveSkeleton(sprite);
                if (skeleton != null && skeleton.BoneCount > 0)
                {
                    if (skinningCache.hasCharacter)
                    {
                        skinningSpriteData.spriteBones = skeleton.bones.ToSpriteBone(Matrix4x4.identity).ToList();
                    }
                    else
                    {
                        skinningSpriteData.spriteBones = new List <SpriteBone>();
                        var bones = skeleton.bones.FindRoots();
                        foreach (var bone in bones)
                        {
                            GetSpriteBoneDataRecursively(skinningSpriteData.spriteBones, bone);
                        }
                    }
                }
                if (meshTool != null)
                {
                    CopyMeshFromSpriteCache(sprite, skinningSpriteData);
                }
                skinningCopyData.copyData.Add(skinningSpriteData);
            }

            if (meshTool != null)
            {
                meshTool.SetupSprite(null);
            }

            return(skinningCopyData);
        }
Esempio n. 4
0
 public string Serialize(SkinningCopyData skinningData)
 {
     return(JsonUtility.ToJson(skinningData));
 }
        public SkinningCopyData CopySingle(SpriteCache sprite)
        {
            var skinningCopyData = new SkinningCopyData();

            skinningCopyData.pixelsPerUnit = pixelsPerUnit;

            // Mesh
            var skinningSpriteData = new SkinningCopySpriteData();

            skinningCopyData.copyData.Add(skinningSpriteData);

            CopyMeshFromSpriteCache(sprite, skinningSpriteData);

            // Bones
            var rootBones = new List <BoneCache>();

            if (skinningCache.hasCharacter)
            {
                var characterPart = skinningCache.GetCharacterPart(sprite);
                if (characterPart != null && characterPart.bones != null)
                {
                    var bones = characterPart.bones.FindRoots();
                    foreach (var bone in bones)
                    {
                        rootBones.Add(bone);
                    }
                }
            }
            else
            {
                var skeleton = skinningCache.GetEffectiveSkeleton(sprite);
                if (skeleton != null && skeleton.BoneCount > 0)
                {
                    var bones = skeleton.bones.FindRoots();
                    foreach (var bone in bones)
                    {
                        rootBones.Add(bone);
                    }
                }
            }

            if (rootBones.Count > 0)
            {
                skinningSpriteData.spriteBones = new List <SpriteBone>();
                foreach (var rootBone in rootBones)
                {
                    var rootBoneIndex = skinningSpriteData.spriteBones.Count;
                    GetSpriteBoneDataRecursively(skinningSpriteData.spriteBones, rootBone);
                    if (skinningCache.hasCharacter)
                    {
                        // Offset the bones based on the currently selected Sprite in Character mode
                        var characterPart = sprite.GetCharacterPart();
                        if (characterPart != null)
                        {
                            var offset         = characterPart.position;
                            var rootSpriteBone = skinningSpriteData.spriteBones[rootBoneIndex];
                            rootSpriteBone.position = rootSpriteBone.position - offset;
                            skinningSpriteData.spriteBones[rootBoneIndex] = rootSpriteBone;
                        }
                    }
                }
            }

            return(skinningCopyData);
        }
Esempio n. 6
0
 public static string SerializeSkinningCopyDataToString(SkinningCopyData skinningData)
 {
     return(s_SkinningSerializer.Serialize(skinningData));
 }