3 using UnityEngine.EventSystems;
4 using System.Collections;
5 using System.Collections.Generic;
13 public Screen layoutScreen = Screen.center;
14 public AlignmentH layoutAlignHorizontal = AlignmentH.stretch;
15 public AlignmentV layoutAlignVertical = AlignmentV.stretch;
16 [Range(0, 99)]
public int layoutLayer = 0;
18 private Material textMaterial = null;
19 private Material imageMaterial = null;
24 Canvas cv = GetComponentInChildren (typeof(Canvas),
true) as Canvas;
26 cv.transform.localPosition = Vector3.zero;
32 public void UpdateMaterials()
34 if( textMaterial == null )
35 textMaterial =
new Material (Shader.Find (
"Custom/TextShader"));
36 if( imageMaterial == null )
37 imageMaterial =
new Material (Shader.Find (
"Custom/UIObject"));
41 texts = GetComponentsInChildren (typeof(Text),
true);
43 foreach (Text t
in texts)
44 t.material = textMaterial;
49 images = GetComponentsInChildren (typeof(Image),
true);
51 foreach (Image i
in images) {
52 if( i.material.name ==
"Default UI Material")
53 i.material = imageMaterial;
58 public void OnEnable()
61 layoutPosition.screen = layoutScreen;
62 layoutPosition.alignHorizontal = layoutAlignHorizontal;
63 layoutPosition.alignVertical = layoutAlignVertical;
64 UI.Core.instance.layoutSystem.addWidget (
this);
67 public void OnDisable()
69 UI.Core.instance.layoutSystem.removeWidget (
this);
72 public void OnDestroy()
74 UI.Core.instance.layoutSystem.removeWidget (
this);
79 layoutPosition = newPosition;
80 UI.Core.instance.layoutSystem.setWidgetPosition(
this, newPosition );
83 public void highlight()
85 imageMaterial.SetInt (
"_highlight", 1);
88 Vector3 pos = transform.localPosition;
89 pos.z = 100 - layoutLayer;
90 transform.localPosition = pos;
93 public void unHighlight()
95 imageMaterial.SetInt (
"_highlight", 0);
98 Vector3 pos = transform.localPosition;
99 pos.z = 200 - layoutLayer;
100 transform.localPosition = pos;