private void Initialize() { if (Manager.MouseOverObject == null) { return; } ConstraintGameObject = TryCreateConstraint(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), Manager.MouseOverObject, ConstrainedDofTypes, "PickHandlerToolConstraint"); if (ConstraintGameObject == null) { return; } m_distanceFromCamera = PickHandler.FindDistanceFromCamera(SceneView.currentDrawingSceneView.camera, Constraint.AttachmentPair.ReferenceFrame.Position); Constraint.DrawGizmosEnable = false; VisualSphereReference.Color = PickHandler.ReferenceSphereColor; VisualSphereConnected.Color = PickHandler.ConnectedSphereColor; VisualCylinder.Color = PickHandler.ConnectingCylinderColor; VisualSphereReference.Pickable = false; VisualSphereConnected.Pickable = false; VisualCylinder.Pickable = false; PickHandler.SetComplianceDamping(Constraint); }
public override void OnSceneViewGUI(SceneView sceneView) { // Remove us if the constraint never were created or at the mouse up event. if (ConstraintGameObject == null || m_removePredicate(Event.current)) { PerformRemoveFromParent(); return; } Constraint constraint = Constraint; UpdateVisual(constraint); // NOTE: camera.ScreenToWorldPoint is not stable during all types of events. Pick one! if (!Event.current.isMouse) { return; } constraint.AttachmentPair.ConnectedFrame.Position = sceneView.camera.ScreenToWorldPoint(new Vector3(Event.current.mousePosition.x, sceneView.camera.pixelHeight - Event.current.mousePosition.y, m_distanceFromCamera)); PickHandler.SetComplianceDamping(constraint); }