public static Vector2Int WorldToPixel(Vector2 worldPosition, Transform transform, Sprite sprite, bool clamp) { Vector3 localPosition = Utility.WorldToLocal(worldPosition, transform); Vector2 uvPosition = Utility.LocalToUv(localPosition, sprite, clamp); Vector2Int pixelPosition = Utility.UvToPixel(uvPosition, sprite, clamp); return(pixelPosition); }
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(); } }