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); }
public bool DoBoneRotation(Transform boneTransform, out float deltaAngle) { deltaAngle = 0f; Transform pivotTransform; if (!FindPivotTransform(boneTransform, out pivotTransform)) { pivotTransform = boneTransform; } if (TryActivateAction(boneTransform, BoneGizmoAction.Rotate)) { m_RotateBoneControlID = m_HoveredBoneBodyControlID; m_RotationPivot = pivotTransform.position; m_SliderPosition = m_GUIWapper.GUIToWorld(m_GUIWapper.mousePosition, pivotTransform.forward, pivotTransform.position); } if (m_HotBoneTransform != boneTransform) { return(false); } Vector3 newPosition; if (m_GUIWapper.DoSlider(m_RotateBoneControlID, m_SliderPosition, pivotTransform.forward, pivotTransform.up, pivotTransform.right, out newPosition)) { var fromVector = m_SliderPosition - m_RotationPivot; var toVector = newPosition - m_RotationPivot; deltaAngle = Vector3.SignedAngle(fromVector, toVector, pivotTransform.forward); m_SliderPosition = newPosition; return(true); } return(false); }
public void OnGUI() { m_ControlID = m_GUIWrapper.GetControlID(kBrushHashCode, FocusType.Passive); var eventType = m_GUIWrapper.eventType; if (!m_GUIWrapper.isAltDown) { m_GUIWrapper.LayoutControl(controlID, 0f); } if (isActivable) { m_SliderData.position = m_GUIWrapper.GUIToWorld(m_GUIWrapper.mousePosition); if (m_GUIWrapper.IsMouseDown(0)) { m_DeltaAcc = 0f; onStrokeBegin(this); onStrokeStep(this); m_GUIWrapper.SetGuiChanged(true); } if (eventType == EventType.MouseMove) { onMove(this); m_GUIWrapper.UseCurrentEvent(); } if (m_GUIWrapper.isShiftDown && eventType == EventType.ScrollWheel) { var sizeDelta = HandleUtility.niceMouseDeltaZoom * kWheelSizeSpeed; size = Mathf.Max(1f, size + sizeDelta); onSize(this); m_GUIWrapper.UseCurrentEvent(); } } if (isHot && m_GUIWrapper.IsMouseUp(0)) { onStrokeEnd(this); } if (m_GUIWrapper.IsRepainting() && (isHot || isActivable)) { onRepaint(this); } Vector3 position; if (m_GUIWrapper.DoSlider(m_ControlID, m_SliderData, out position)) { step = Mathf.Max(step, 1f); var delta = position - m_SliderData.position; var direction = delta.normalized; var magnitude = delta.magnitude; m_SliderData.position -= direction * m_DeltaAcc; m_DeltaAcc += magnitude; if (m_DeltaAcc >= step) { var stepVector = direction * step; while (m_DeltaAcc >= step) { m_SliderData.position += stepVector; onMove(this); onStrokeStep(this); m_DeltaAcc -= step; } } m_SliderData.position = position; onStrokeDelta(this); } }
public Vector3 GetMouseWorldPosition(Vector3 planeNormal, Vector3 planePosition) { return(m_GUIWrapper.GUIToWorld(m_GUIWrapper.mousePosition, planeNormal, planePosition)); }