public static IntVector2 WorldToPixel(Vector2 worldPosition, Transform transform, Sprite sprite, bool clamp) { Vector3 localPosition = Utility.WorldToLocal(worldPosition, transform); Vector2 uvPosition = Utility.LocalToUV(localPosition, sprite, clamp); IntVector2 pixelPosition = Utility.UVToPixel(uvPosition, sprite, clamp); return(pixelPosition); }
public void OnSceneGUI(RagePixelState state) { Initialize(state); Vector2 uvPos = Utility.PixelToUV(m_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.RectangleCap); if (EditorGUI.EndChangeCheck()) { localPos = Utility.WorldToLocal(worldPos, state.transform); uvPos = Utility.LocalToUV(localPos, state.sprite, false); m_Size = Utility.UVToPixel(uvPos, state.sprite, false); m_Size = new IntVector2((int)Mathf.Clamp(m_Size.x, k_MinSize, k_MaxSize), (int)Mathf.Clamp(m_Size.y, k_MinSize, k_MaxSize)); state.Repaint(); } }