Пример #1
0
        public void RotateBone_MultipleSelection_BonesNotInSamePlane()
        {
            m_SpriteSkin.boneTransforms[1].Rotate(Vector3.up, 45f);

            m_HotAction = SkeletonAction.RotateBone;
            m_HotBoneID = m_SpriteSkin.boneTransforms[0].GetInstanceID();

            float deltaAngle;

            m_SkeletonView.DoRotateBone(Arg.Any <Vector3>(), Arg.Any <Vector3>(), out deltaAngle).Returns(x =>
            {
                x[2] = 90f;
                return(true);
            });

            var objectList = new List <Object>();

            foreach (var t in m_SpriteSkin.boneTransforms)
            {
                objectList.Add(t.gameObject);
            }

            Selection.objects = objectList.ToArray();

            m_BoneGizmoController.OnSelectionChanged();
            m_BoneGizmoController.OnGUI();

            Assert.That(m_SpriteSkin.boneTransforms[0].rotation, Is.EqualTo(new Quaternion(0f, 0f, 0.5560408f, 0.8311549f)).Using(quatCompare));
            Assert.That(m_SpriteSkin.boneTransforms[1].rotation, Is.EqualTo(new Quaternion(-0.008831382f, 0.3825816f, 0.9236336f, -0.02132094f)).Using(quatCompare));
        }
Пример #2
0
        public void Setup()
        {
            var go = new GameObject("TestObject");

            m_SkinnedSprite = Resources.Load <Sprite>("bird");
            m_SpriteSkin    = go.AddComponent <SpriteSkin>();
            m_SpriteSkin.spriteRenderer.sprite = m_SkinnedSprite;
            m_SpriteSkin.CreateBoneHierarchy();

            m_SkeletonView = Substitute.For <ISkeletonView>();
            m_SkeletonView.hotBoneID.Returns(x => m_HotBoneID);
            m_SkeletonView.hoveredBoneID.Returns(x => m_HoveredBoneID);
            m_SkeletonView.hoveredBodyID.Returns(x => m_HoveredBodyID);
            m_SkeletonView.hoveredJointID.Returns(x => m_HoveredJointID);
            m_SkeletonView.hoveredTailID.Returns(x => m_HoveredTailID);
            m_SkeletonView.IsActionHot(Arg.Any <SkeletonAction>()).Returns(x => m_HotAction == (SkeletonAction)x[0]);
            m_SkeletonView.CanLayout().Returns(x => true);

            m_Undo            = Substitute.For <IUndo>();
            m_BoneGizmoToggle = Substitute.For <IBoneGizmoToggle>();
            m_BoneGizmoToggle.enableGizmos.Returns(x => true);

            m_BoneGizmoController = new BoneGizmoController(m_SkeletonView, m_Undo, m_BoneGizmoToggle);

            m_HotBoneID      = 0;
            m_HoveredBodyID  = 0;
            m_HoveredBoneID  = 0;
            m_HoveredJointID = 0;
            m_HoveredTailID  = 0;
            m_HotAction      = SkeletonAction.None;
        }
Пример #3
0
        public bool IsActionTriggering(SkeletonAction action)
        {
            if (!IsActionActive(action))
            {
                return(false);
            }

            if (action == SkeletonAction.Remove)
            {
                if ((m_GUIWrapper.eventType == EventType.ValidateCommand || m_GUIWrapper.eventType == EventType.ExecuteCommand) &&
                    (m_GUIWrapper.commandName == kSoftDeleteCommandName || m_GUIWrapper.commandName == kDeleteCommandName))
                {
                    if (m_GUIWrapper.eventType == EventType.ExecuteCommand)
                    {
                        return(true);
                    }

                    m_GUIWrapper.UseCurrentEvent();
                }

                return(false);
            }

            return(m_GUIWrapper.IsMouseDown(0));
        }
Пример #4
0
        public bool IsActionHot(SkeletonAction action)
        {
            if (action == SkeletonAction.None)
            {
                return(m_GUIWrapper.IsControlHot(0) && m_GUIWrapper.IsMultiStepControlHot(0));
            }

            if (action == SkeletonAction.RotateBone)
            {
                return(m_GUIWrapper.IsControlHot(m_RotateControlID));
            }

            if (action == SkeletonAction.MoveBone)
            {
                return(m_GUIWrapper.IsControlHot(m_MoveControlID));
            }

            if (action == SkeletonAction.FreeMoveBone)
            {
                return(m_GUIWrapper.IsControlHot(m_FreeMoveControlID));
            }

            if (action == SkeletonAction.MoveJoint)
            {
                return(m_GUIWrapper.IsControlHot(m_MoveJointControlID));
            }

            if (action == SkeletonAction.MoveEndPosition)
            {
                return(m_GUIWrapper.IsControlHot(m_MoveEndPositionControlID));
            }

            if (action == SkeletonAction.ChangeLength)
            {
                return(m_GUIWrapper.IsControlHot(m_ChangeLengthControlID));
            }

            if (action == SkeletonAction.CreateBone)
            {
                return(m_GUIWrapper.IsMultiStepControlHot(m_CreateBoneControlID) && !m_GUIWrapper.isAltDown);
            }

            return(false);
        }
Пример #5
0
        public void RotateBone_SingleSelection()
        {
            m_HotAction = SkeletonAction.RotateBone;
            m_HotBoneID = m_SpriteSkin.boneTransforms[0].GetInstanceID();

            float deltaAngle;

            m_SkeletonView.DoRotateBone(Arg.Any <Vector3>(), Arg.Any <Vector3>(), out deltaAngle).Returns(x =>
            {
                x[2] = 90f;
                return(true);
            });

            Selection.activeGameObject = m_SpriteSkin.boneTransforms[0].gameObject;
            m_BoneGizmoController.OnSelectionChanged();
            m_BoneGizmoController.OnGUI();

            Assert.That(m_SpriteSkin.boneTransforms[0].rotation, Is.EqualTo(new Quaternion(0f, 0f, 0.5560408f, 0.8311549f)).Using(quatCompare));
        }
Пример #6
0
        public bool IsActionFinishing(SkeletonAction action)
        {
            if (!IsActionHot(action) || !IsCapable(action))
            {
                return(false);
            }

            if (m_GUIWrapper.IsEventOutsideWindow())
            {
                return(true);
            }

            if (action == SkeletonAction.CreateBone)
            {
                return(m_GUIWrapper.IsMouseDown(0));
            }

            return(m_GUIWrapper.IsMouseUp(0));
        }
Пример #7
0
        private bool DoSliderAction(SkeletonAction action, int controlID, ref int actionControlID, out Vector3 newPosition)
        {
            newPosition = m_HoveredSliderData.position;

            if (IsActionTriggering(action))
            {
                actionControlID = controlID;
                m_HotSliderData = m_HoveredSliderData;
                m_HotBoneID     = hoveredBoneID;
            }

            if (m_GUIWrapper.DoSlider(actionControlID, m_HotSliderData, out newPosition))
            {
                m_HotSliderData.position = newPosition;
                return(true);
            }

            return(false);
        }
Пример #8
0
 private bool IsCapable(SkeletonAction action)
 {
     return(((int)mode & (int)action) != 0);
 }
Пример #9
0
        public bool IsActionActive(SkeletonAction action)
        {
            if (m_GUIWrapper.isAltDown || !m_GUIWrapper.IsControlHot(0) || !m_GUIWrapper.IsMultiStepControlHot(0))
            {
                return(false);
            }

            if (action == SkeletonAction.None)
            {
                return(m_GUIWrapper.IsControlNearest(defaultControlID));
            }

            if (!IsCapable(action))
            {
                return(false);
            }

            if (action == SkeletonAction.RotateBone)
            {
                return(m_GUIWrapper.IsControlNearest(m_HoveredBodyControlID));
            }

            if (action == SkeletonAction.ChangeLength)
            {
                return(m_GUIWrapper.IsControlNearest(m_HoveredTailControlID) && !m_GUIWrapper.isShiftDown);
            }

            if (action == SkeletonAction.MoveJoint)
            {
                return(m_GUIWrapper.IsControlNearest(m_HoveredJointControlID));
            }

            if (action == SkeletonAction.MoveEndPosition)
            {
                return(m_GUIWrapper.IsControlNearest(m_HoveredTailControlID) && !m_GUIWrapper.isShiftDown);
            }

            if (action == SkeletonAction.FreeMoveBone)
            {
                return(m_GUIWrapper.IsControlNearest(m_HoveredBodyControlID));
            }

            if (action == SkeletonAction.MoveBone)
            {
                return(m_GUIWrapper.IsControlNearest(m_HoveredJointControlID));
            }

            bool canCreateBone = IsCapable(SkeletonAction.CreateBone) && m_GUIWrapper.IsControlNearest(m_CreateBoneControlID);
            bool canSplitBone  = IsCapable(SkeletonAction.SplitBone) && m_GUIWrapper.IsControlNearest(m_HoveredBodyControlID);

            if (action == SkeletonAction.CreateBone)
            {
                return(canCreateBone);
            }

            if (action == SkeletonAction.SplitBone)
            {
                return(canSplitBone);
            }

            if (action == SkeletonAction.Select)
            {
                return((m_GUIWrapper.IsControlNearest(m_HoveredBodyControlID) && !canSplitBone) ||
                       m_GUIWrapper.IsControlNearest(m_HoveredJointControlID) ||
                       (m_GUIWrapper.IsControlNearest(m_HoveredTailControlID) && !canCreateBone));
            }

            if (action == SkeletonAction.Remove)
            {
                return(true);
            }

            return(false);
        }