Advertisement
Guest User

UIElement

a guest
Jan 30th, 2013
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class UIElement : MonoBehaviour {
  4.     private const float RATIO = 100.0f;
  5.  
  6.     public const int UI_LAYER = 8;
  7.     public const int INVISIBLE_LAYER = 9;
  8.  
  9.     private Transform goTransform;
  10.     public UILayerUpdater layerUpdater;
  11.  
  12.     protected Transform UITransform {
  13.         get { return goTransform ?? (goTransform = transform); }
  14.     }
  15.  
  16.     public Transform Parent {
  17.         get { return UITransform.parent; }
  18.         set { UITransform.parent = value; }
  19.     }
  20.  
  21.     public Vector3 LocalPosition {
  22.         get { return UITransform.localPosition; }
  23.         set { UITransform.localPosition = value; }
  24.     }
  25.  
  26.     public Vector3 Position {
  27.         get { return UITransform.position; }
  28.         set { UITransform.position = value; }
  29.     }
  30.  
  31.     public Quaternion Rotation {
  32.         get { return UITransform.rotation; }
  33.         set { UITransform.rotation = value; }
  34.     }
  35.  
  36.     public Vector3 Scale {
  37.         get { return UITransform.localScale; }
  38.         set { UITransform.localScale = value; }
  39.     }
  40.  
  41.     public virtual bool Show {
  42.         set {
  43.             if (layerUpdater != null) gameObject.layer = value ? layerUpdater.visibleLayer : INVISIBLE_LAYER;
  44.             else gameObject.layer = value ? Parent.gameObject.layer : INVISIBLE_LAYER;
  45.         }
  46.         get { return gameObject.layer != INVISIBLE_LAYER; }
  47.     }
  48.  
  49.     public virtual int Depth {
  50.         get { return Mathf.RoundToInt(LocalPosition.z*RATIO); }
  51.  
  52.         set { LocalPosition = new Vector3(LocalPosition.x, LocalPosition.y, value/RATIO); }
  53.     }
  54.  
  55.  
  56.     public UIElement Instantiate() {
  57.         var go = (GameObject) Instantiate(gameObject);
  58.         return go.GetComponent<UIElement>();
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement