SebastianLawe

Untitled

Apr 22nd, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6.  
  7. public class RelativeRect {
  8.     float _x;
  9.     float _y;
  10.     float _width;
  11.     float _height;
  12.  
  13.     public float X {
  14.         get {
  15.             return _x;
  16.         }
  17.         set {
  18.             _x = value;
  19.         }
  20.     }
  21.     public float Y {
  22.         get {
  23.             return _y;
  24.         }
  25.         set {
  26.             _y = value;
  27.         }
  28.     }
  29.     public float Width {
  30.         get {
  31.             return _width;
  32.         }
  33.         set {
  34.             _width = value;
  35.         }
  36.     }
  37.     public float Height {
  38.         get {
  39.             return _height;
  40.         }
  41.         set {
  42.             _height = value;
  43.         }
  44.     }
  45.     public Rect ScreenCoordinates {
  46.         get {
  47.             return GetRelative(_x, _y, _width, _height);
  48.         }
  49.     }
  50.     public RelativeRect(float x, float y, float width, float height) {
  51.         _x = x;
  52.         _y = y;
  53.         _width = width;
  54.         _height = height;
  55.     }
  56.     public static Rect GetRelative(float x, float y, float width, float height) {
  57.         Rect rect = new Rect((x / 100) * Screen.width,
  58.             (y / 100) * Screen.height,
  59.             (width / 100) * Screen.width,
  60.             (height / 100) * Screen.height);
  61.         return rect;
  62.     }
  63.     public static Rect GetRelative(Rect position) {
  64.         Rect rect = new Rect((position.x / 100) * Screen.width,
  65.             (position.y / 100) * Screen.height,
  66.             (position.width / 100) * Screen.width,
  67.             (position.height / 100) * Screen.height);
  68.         return rect;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment