Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class UIElement : MonoBehaviour {
- private const float RATIO = 100.0f;
- public const int UI_LAYER = 8;
- public const int INVISIBLE_LAYER = 9;
- private Transform goTransform;
- public UILayerUpdater layerUpdater;
- protected Transform UITransform {
- get { return goTransform ?? (goTransform = transform); }
- }
- public Transform Parent {
- get { return UITransform.parent; }
- set { UITransform.parent = value; }
- }
- public Vector3 LocalPosition {
- get { return UITransform.localPosition; }
- set { UITransform.localPosition = value; }
- }
- public Vector3 Position {
- get { return UITransform.position; }
- set { UITransform.position = value; }
- }
- public Quaternion Rotation {
- get { return UITransform.rotation; }
- set { UITransform.rotation = value; }
- }
- public Vector3 Scale {
- get { return UITransform.localScale; }
- set { UITransform.localScale = value; }
- }
- public virtual bool Show {
- set {
- if (layerUpdater != null) gameObject.layer = value ? layerUpdater.visibleLayer : INVISIBLE_LAYER;
- else gameObject.layer = value ? Parent.gameObject.layer : INVISIBLE_LAYER;
- }
- get { return gameObject.layer != INVISIBLE_LAYER; }
- }
- public virtual int Depth {
- get { return Mathf.RoundToInt(LocalPosition.z*RATIO); }
- set { LocalPosition = new Vector3(LocalPosition.x, LocalPosition.y, value/RATIO); }
- }
- public UIElement Instantiate() {
- var go = (GameObject) Instantiate(gameObject);
- return go.GetComponent<UIElement>();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement