// Bridging SetRawData for IHierarchy
        public void SetRawData(List <UniqueSpriteBone> rawBoneDatas, Vector3 offset)
        {
            m_Model.SetRawData(rawBoneDatas, offset);

            // This usually mean a fresh sprite rect selected, we should reset the state.
            state.Reset();
        }
        public void LoadExistingHierarchy_CreatingNewBone_NameCounterCountinueFromLargest()
        {
            var rawData = new List <UniqueSpriteBone>();

            var root = new UniqueSpriteBone();

            root.name     = "root";
            root.position = Vector2.up;
            root.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            root.length   = 1f;
            root.parentId = -1;

            var child1 = new UniqueSpriteBone();

            child1.name     = "bone_1";
            child1.position = Vector2.one;
            child1.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child1.length   = 1.0f;
            child1.parentId = 0;

            var child2 = new UniqueSpriteBone();

            child2.name     = "bone_100";
            child2.position = Vector2.one + Vector2.right;
            child2.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child2.length   = 1.0f;
            child2.parentId = 1;

            var child3 = new UniqueSpriteBone();

            child3.name     = "bone_2";
            child3.position = Vector2.right;
            child3.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child3.length   = 1.0f;
            child3.parentId = 1;

            var child4 = new UniqueSpriteBone();

            child4.name     = "bone_54";
            child4.position = Vector2.right * 2;
            child4.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child4.length   = 1.0f;
            child4.parentId = 3;

            rawData.Add(root);
            rawData.Add(child1);
            rawData.Add(child2);
            rawData.Add(child3);
            rawData.Add(child4);

            m_Model.SetRawData(rawData, Vector2.zero);

            var rootBone = m_Model.bones.ElementAt(0);
            var bone101  = m_Model.CreateNewChildBone(rootBone, Vector3.one);

            Assert.AreEqual("bone_101", bone101.name);
        }
        public void Setup()
        {
            m_SpriteId = GUID.Generate();

            m_BoneDPMock = Substitute.For <ISpriteBoneDataProvider>();
            m_MeshDPMock = Substitute.For <ISpriteMeshDataProvider>();

            m_CacheManager = new BoneCacheManager(m_BoneDPMock, m_MeshDPMock);

            m_OriginalVertices = new Vertex2DMetaData[10]
            {
                //0
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 0, weight0 = 1.0f
                    }
                },
                //1
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 0, weight0 = 0.5f,
                        boneIndex1 = 1, weight1 = 0.5f
                    }
                },
                //2
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 0, weight0 = 0.25f,
                        boneIndex1 = 2, weight1 = 0.25f,
                        boneIndex2 = 3, weight2 = 0.25f,
                        boneIndex3 = 4, weight3 = 0.25f
                    }
                },
                //3
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 2, weight0 = 0.3f,
                        boneIndex1 = 3, weight1 = 0.3f,
                        boneIndex2 = 4, weight2 = 0.3f
                    }
                },
                //4
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 1, weight0 = 0.5f,
                        boneIndex1 = 3, weight1 = 0.5f
                    }
                },
                //5
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 4, weight0 = 1.0f
                    }
                },
                //6
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 3, weight0 = 0.5f,
                        boneIndex1 = 4, weight1 = 0.5f
                    }
                },
                //7
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 0, weight0 = 0.3f,
                        boneIndex1 = 1, weight1 = 0.3f,
                        boneIndex2 = 5, weight2 = 0.3f
                    }
                },
                //8
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 3, weight0 = 0.5f,
                        boneIndex1 = 5, weight1 = 0.5f
                    }
                },
                //9
                new Vertex2DMetaData()
                {
                    boneWeight = new BoneWeight()
                    {
                        boneIndex0 = 0, weight0 = 0.25f,
                        boneIndex1 = 2, weight1 = 0.25f,
                        boneIndex2 = 4, weight2 = 0.25f,
                        boneIndex3 = 5, weight3 = 0.25f
                    }
                }
            };

            m_ExpectedVertices = new Vertex2DMetaData[m_OriginalVertices.Length];
            m_OriginalVertices.CopyTo(m_ExpectedVertices, 0);

            var spriteBones = new List <SpriteBone>();

            spriteBones.Add(new SpriteBone()
            {
                name = "root", parentId = -1, rotation = Quaternion.identity
            });
            spriteBones.Add(new SpriteBone()
            {
                name = "child_1", parentId = 0, rotation = Quaternion.identity
            });
            spriteBones.Add(new SpriteBone()
            {
                name = "child_1_1", parentId = 1, rotation = Quaternion.identity
            });
            spriteBones.Add(new SpriteBone()
            {
                name = "child_1_2", parentId = 1, rotation = Quaternion.identity
            });
            spriteBones.Add(new SpriteBone()
            {
                name = "child_1_2_1", parentId = 3, rotation = Quaternion.identity
            });
            spriteBones.Add(new SpriteBone()
            {
                name = "child_1_2_2", parentId = 3, rotation = Quaternion.identity
            });

            m_BoneDPMock.GetBones(m_SpriteId).Returns(spriteBones);
            m_MeshDPMock.GetVertices(m_SpriteId).Returns(m_OriginalVertices);

            var uniqueBone = m_CacheManager.GetSpriteBoneRawData(m_SpriteId);

            m_Model = new BoneModel(() => { });
            m_Model.SetRawData(uniqueBone, Vector3.zero);
        }