Beispiel #1
0
        public void ReparentItems(int parentIndex, int[] draggedItemIndex, bool hasCharacter, SkinningMode mode, bool shouldReparent)
        {
            m_Model.hasCharacter.Returns(hasCharacter);
            m_Model.mode.Returns(mode);
            var skeleton = Substitute.For <SkeletonCache>();
            var bones    = new[]
            {
                Substitute.For <BoneCache>(),
                Substitute.For <BoneCache>(),
                Substitute.For <BoneCache>(),
                Substitute.For <BoneCache>(),
            };

            bones[0].name = "Bone_1";
            bones[1].name = "Bone_1_1";
            bones[2].name = "Bone_1_1_1";
            bones[3].name = "Bone_2";

            var b = bones[2];

            b.parentBone.Returns(bones[1]);
            b = bones[1];
            b.parentBone.Returns(bones[0]);
            bones[0].siblingIndex.Returns(0);
            bones[1].siblingIndex.Returns(0);
            bones[2].siblingIndex.Returns(0);
            bones[3].siblingIndex.Returns(1);

            skeleton.bones.Returns(bones);
            m_Model.GetSelectedSkeleton().Returns(skeleton);
            var treeViewItem = m_Controller.BuildTreeView();

            treeViewItem[0].AddChild(treeViewItem[1]);
            treeViewItem[1].AddChild(treeViewItem[2]);

            var parentItem  = treeViewItem[parentIndex] as TreeViewItemBase <BoneCache>;
            var draggedItem = new List <TreeViewItem>();

            foreach (var i in draggedItemIndex)
            {
                draggedItem.Add(treeViewItem[i]);
            }

            var eventCalled = 0;
            UnityAction <SkeletonCache> callback = x =>
            {
                ++eventCalled;
            };

            m_EventSystem.skeletonTopologyChanged.AddListener(callback);
            m_Controller.ReparentItems(parentItem, draggedItem, 0);
            m_EventSystem.skeletonTopologyChanged.RemoveListener(callback);
            if (shouldReparent)
            {
                Assert.AreEqual(draggedItem.Count, eventCalled);
                m_Model.Received(draggedItem.Count).SetBoneParent(Arg.Any <BoneCache>(), Arg.Any <BoneCache>(), 0);
                for (int i = 0; i < draggedItem.Count; ++i)
                {
                    m_Model.Received(1).SetBoneParent(Arg.Is <BoneCache>(x => x == parentItem.customData), Arg.Is <BoneCache>(y => y == ((TreeViewItemBase <BoneCache>)draggedItem[i]).customData), 0);
                }
            }
            else
            {
                m_Model.DidNotReceiveWithAnyArgs().SetBoneParent(Arg.Any <BoneCache>(), Arg.Any <BoneCache>(), 0);
                Assert.AreEqual(0, eventCalled);
            }
        }