public static Vector2 ConvertScreenPixelsToPoints(Vector2 screenPixels) { #if UNITY_5_4_OR_NEWER return(EditorGUIUtility.PixelsToPoints(screenPixels)); #else // Pre 5.4 assume that 1 pixel = 1 point return(screenPixels); #endif }
private static Vector3 WorldToGUIPoint(this SceneView sceneView, Vector3 world) { // Does the same as this, but reimplemented to also work outside Handles.GUI scope // return HandleUtility.WorldToGUIPoint(worldPoint); world = Handles.matrix.MultiplyPoint(world); var screen = sceneView.camera.WorldToScreenPoint(world); var points = EditorGUIUtility.PixelsToPoints(screen); points.y = sceneView.GetInnerGuiPosition().height - points.y; return(new Vector3(points.x, points.y, screen.z)); }
public void OnGUI() { var sceneView = SceneView.currentDrawingSceneView; if (sceneView == null) { return; } var rect = EditorGUIUtility.PixelsToPoints(sceneView.camera.pixelRect); OnGUI(sceneView, rect); }
public static Vector2 ConvertMousePixelPosition(Vector2 sourceMousePosition, bool convertPixelsToPoints = true) { #if UNITY_5_4_OR_NEWER if (convertPixelsToPoints) { sourceMousePosition = EditorGUIUtility.PixelsToPoints(sourceMousePosition); } // Flip the direction of Y and remove the Scene View top toolbar's height sourceMousePosition.y = (Screen.height / EditorGUIUtility.pixelsPerPoint) - sourceMousePosition.y - (TOOLBAR_HEIGHT); #else // Flip the direction of Y and remove the Scene View top toolbar's height sourceMousePosition.y = Screen.height - sourceMousePosition.y - TOOLBAR_HEIGHT; #endif return(sourceMousePosition); }
// Helper function for doing arrows. public static float CalcLineTranslation(Vector2 start, Vector2 end, Vector3 origin, Vector3 direction) { // Apply handle matrix //origin = Handles.matrix.MultiplyPoint(origin); //direction = Handles.matrix.MultiplyVector(direction); // The constrained direction is facing towards the camera, THATS BAD when the handle is close to the camera // The origin goes through to the other side of the camera float invert = 1.0F; Vector3 cameraForward = Camera.current.transform.forward; if (Vector3.Dot(direction, cameraForward) < 0.0F) { invert = -1.0F; } // Ok - Get the parametrization of the line // p1 = start position, p2 = p1 + ConstraintDir. // we then parametrize the perpendicular position of end into the line (p1-p2) Vector3 cd = direction; cd.y = -cd.y; Camera cam = Camera.current; Vector2 p1 = EditorGUIUtility.PixelsToPoints(cam.WorldToScreenPoint(origin)); Vector2 p2 = EditorGUIUtility.PixelsToPoints(cam.WorldToScreenPoint(origin + direction * invert)); Vector2 p3 = end; Vector2 p4 = start; if (p1 == p2) { return(0); } p3.y = -p3.y; p4.y = -p4.y; var lineDirection = p2 - p1; float t0 = PointOnLineParameter(p4, p1, lineDirection); float t1 = PointOnLineParameter(p3, p1, lineDirection); float output = (t1 - t0) * invert; return(output); }
public static Vector2 PixelsToPoints(Vector2 position) { return(EditorGUIUtility.PixelsToPoints(position)); }
public static Rect PixelsToPoints(Rect rect) { return(EditorGUIUtility.PixelsToPoints(rect)); }