Game Development Reference
In-Depth Information
“base” component in that all GUI game objects (at least, those wanting to be positioned relatively)
should have the GUIObject component attached (see Listing 8-2 for the full GUIObject source code).
Comments follow.
Listing 8-2. GUIObject.cs: A GUI Positioning Component
01 //------------------------------------------------
02 using UnityEngine;
03 using System.Collections;
04 [ExecuteInEditMode]
05 //------------------------------------------------
06 public class GUIObject : MonoBehaviour
07 {
08 [System.Serializable]
09 public class PixelPadding
10 {
11 public float LeftPadding;
12 public float RightPadding;
13 public float TopPadding;
14 public float BottomPadding;
15 }
16
17 //Pixel Padding
18 public PixelPadding Padding;
19
20 //HALIGN
21 public enum HALIGN {left=0, right=1};
22
23 //VALIGN
24 public enum VALIGN {top=0, bottom=1};
25
26 //Alignment
27 public HALIGN HorzAlign = HALIGN.left;
28 public VALIGN VertAlign = VALIGN.top;
29
30 //Reference to GUICamera for this object
31 public GUICam GUICamera = null;
32
33 //Reference to cached transform
34 private Transform ThisTransform = null;
35
36 //------------------------------------------------
37 // Use this for initialization
38 void Start ()
39 {
40 //Get cached transform
41 ThisTransform = transform;
42 }
43 //------------------------------------------------
 
Search WWH ::




Custom Search