Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- public class RelativeRect {
- float _x;
- float _y;
- float _width;
- float _height;
- public float X {
- get {
- return _x;
- }
- set {
- _x = value;
- }
- }
- public float Y {
- get {
- return _y;
- }
- set {
- _y = value;
- }
- }
- public float Width {
- get {
- return _width;
- }
- set {
- _width = value;
- }
- }
- public float Height {
- get {
- return _height;
- }
- set {
- _height = value;
- }
- }
- public Rect ScreenCoordinates {
- get {
- return GetRelative(_x, _y, _width, _height);
- }
- }
- public RelativeRect(float x, float y, float width, float height) {
- _x = x;
- _y = y;
- _width = width;
- _height = height;
- }
- public static Rect GetRelative(float x, float y, float width, float height) {
- Rect rect = new Rect((x / 100) * Screen.width,
- (y / 100) * Screen.height,
- (width / 100) * Screen.width,
- (height / 100) * Screen.height);
- return rect;
- }
- public static Rect GetRelative(Rect position) {
- Rect rect = new Rect((position.x / 100) * Screen.width,
- (position.y / 100) * Screen.height,
- (position.width / 100) * Screen.width,
- (position.height / 100) * Screen.height);
- return rect;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment