Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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();
            }
        }