public static Vector3 PixelToWorld(Vector2Int pixelPosition, Transform transform, Sprite sprite, bool clamp) { Vector2 uvPosition = Utility.PixelToUv(pixelPosition, sprite, clamp); Vector3 localPosition = Utility.UvToLocal(uvPosition, sprite, clamp); Vector2 worldPosition = Utility.LocalToWorld(localPosition, transform); return(worldPosition); }
public static Vector2 PixelToScreen(Vector2Int pixelPosition, Transform transform, Sprite sprite, bool clamp) { Vector2 uvPosition = Utility.PixelToUv(pixelPosition, sprite, clamp); Vector3 localPosition = Utility.UvToLocal(uvPosition, sprite, clamp); Vector2 screenPosition = Utility.LocalToScreen(localPosition, transform); return(screenPosition); }
public void OnSceneGui(RagePixelState state) { Initialize(state); Vector2 uvPos = Utility.PixelToUv(_size, state.Sprite, false); Vector3 localPos = Utility.UvToLocal(uvPos, state.Sprite, false); Vector3 worldPos = Utility.LocalToWorld(localPos, state.Transform); EditorGUI.BeginChangeCheck(); worldPos = Handles.FreeMoveHandle(worldPos, Quaternion.identity, HandleUtility.GetHandleSize(worldPos) * 0.1f, Vector3.zero, Handles.RectangleHandleCap); if (EditorGUI.EndChangeCheck()) { localPos = Utility.WorldToLocal(worldPos, state.Transform); uvPos = Utility.LocalToUv(localPos, state.Sprite, false); _size = Utility.UvToPixel(uvPos, state.Sprite, false); _size = new Vector2Int((int)Mathf.Clamp(_size.x, MinSize, MaxSize), (int)Mathf.Clamp(_size.y, MinSize, MaxSize)); state.Repaint(); } }