Esempio n. 1
0
        public void SetupBase()
        {
            m_EventType        = EventType.Layout;
            m_NearestDistance  = kPickDistance;
            m_NearestControl   = GetDefaultControlID();
            m_CurrentControlID = 0;
            m_MousePosition    = Vector2.zero;
            m_HotControl       = 0;

            m_GUIWrapper = Substitute.For <IGUIWrapper>();
            m_GUIWrapper.GetControlID(Arg.Any <int>(), Arg.Any <FocusType>()).Returns(x => GetControlID((int)x[0], (FocusType)x[1]));
            m_GUIWrapper.mousePosition.Returns(x => m_MousePosition);
            m_GUIWrapper.eventType.Returns(x => m_EventType);
            m_GUIWrapper.GUIToWorld(Arg.Any <Vector2>()).Returns(x => (Vector3)(Vector2)x[0]);
            m_GUIWrapper.GUIToWorld(Arg.Any <Vector2>(), Arg.Any <Vector3>(), Arg.Any <Vector3>()).Returns(x => (Vector3)(Vector2)x[0]);
            m_GUIWrapper.IsControlNearest(Arg.Any <int>()).Returns(x => (int)x[0] == nearestControl);
            m_GUIWrapper.IsControlHot(Arg.Any <int>()).Returns(x => (int)x[0] == m_HotControl);
            m_GUIWrapper.When(x => m_GUIWrapper.LayoutControl(Arg.Any <int>(), Arg.Any <float>())).Do(x =>
            {
                if (m_EventType != EventType.Layout)
                {
                    return;
                }

                int controlId  = (int)x[0];
                float distance = (float)x[1];

                if (distance <= m_NearestDistance)
                {
                    m_NearestDistance = distance;
                    m_NearestControl  = controlId;
                }
            });
            m_GUIWrapper.DistanceToCircle(Arg.Any <Vector3>(), Arg.Any <float>()).Returns(x =>
            {
                Vector2 center = (Vector3)x[0];
                float radius   = (float)x[1];

                float dist = (center - m_MousePosition).magnitude;
                if (dist < radius)
                {
                    return(0f);
                }
                return(dist - radius);
            });
            m_GUIWrapper.DistanceToSegment(Arg.Any <Vector3>(), Arg.Any <Vector3>()).Returns(x => HandleUtility.DistancePointToLineSegment(m_MousePosition, (Vector3)x[0], (Vector3)x[1]));
            m_GUIWrapper.DistanceToSegmentClamp(Arg.Any <Vector3>(), Arg.Any <Vector3>()).Returns(x => MathUtility.DistanceToSegmentClamp(m_MousePosition, (Vector3)x[0], (Vector3)x[1]));

            Vector3 sliderPos;

            m_GUIWrapper.DoSlider(Arg.Any <int>(), Arg.Any <SliderData>(), out sliderPos).ReturnsForAnyArgs(x => (int)x[0] == nearestControl);
            m_GUIWrapper.GetHandleSize(Arg.Any <Vector3>()).ReturnsForAnyArgs(x => 1f);
        }
Esempio n. 2
0
        public void LayoutBone(Transform boneTransform, float length)
        {
            if (IsLayerLocked(boneTransform))
            {
                return;
            }

            var position    = boneTransform.position;
            var endPosition = boneTransform.TransformPoint(Vector3.right * length);

            int boneBodyControlID = m_GUIWapper.GetControlID(boneBodyHashCode, FocusType.Passive);
            int boneHeadControlID = m_GUIWapper.GetControlID(boneHeadHashCode, FocusType.Passive);

            var headEnd = position + (endPosition - position).normalized * GetHandleSize(position) * 0.25f;

            m_GUIWapper.LayoutControl(boneBodyControlID, m_GUIWapper.DistanceToSegment(headEnd, endPosition));

            if (m_GUIWapper.IsControlNearest(boneBodyControlID))
            {
                m_HoveredBoneBodyControlID = boneBodyControlID;
                m_HoveredBoneTransform     = boneTransform;
            }

            m_GUIWapper.LayoutControl(boneHeadControlID, m_GUIWapper.DistanceToSegment(position, headEnd));

            if (m_GUIWapper.IsControlNearest(boneHeadControlID))
            {
                m_HoveredBoneHeadControlID = boneHeadControlID;
                m_HoveredBoneTransform     = boneTransform;
            }
        }
Esempio n. 3
0
        public void EndLayout()
        {
            m_GUIWrapper.LayoutControl(m_HoveredBodyControlID, m_NearestBodyDistance * 0.25f);
            m_GUIWrapper.LayoutControl(m_HoveredJointControlID, m_NearestJointDistance);
            m_GUIWrapper.LayoutControl(m_HoveredTailControlID, m_NearestTailDistance);

            if (m_GUIWrapper.IsControlNearest(m_HoveredBodyControlID))
            {
                m_HoveredBoneID = m_NearestBodyId;
                m_HoveredBodyID = m_NearestBodyId;
            }

            if (m_GUIWrapper.IsControlNearest(m_HoveredJointControlID))
            {
                m_HoveredBoneID  = m_NearestJointId;
                m_HoveredJointID = m_NearestJointId;
            }

            if (m_GUIWrapper.IsControlNearest(m_HoveredTailControlID))
            {
                m_HoveredBoneID = m_NearestTailId;
                m_HoveredTailID = m_NearestTailId;
            }

            if (m_GUIWrapper.eventType == EventType.Layout && m_PrevHoveredBoneID != m_HoveredBoneID)
            {
                m_GUIWrapper.Repaint();
            }
        }