Skip to content

Instantly share code, notes, and snippets.

@tlossen
Created June 25, 2015 09:50
Show Gist options
  • Save tlossen/358b44595434332e8d6d to your computer and use it in GitHub Desktop.
Save tlossen/358b44595434332e8d6d to your computer and use it in GitHub Desktop.
uquery is like jquery, but for the unity 4.6 ui elements. sort of.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class UQuery : MonoBehaviour
{
protected GameObject GO(GameObject go, params int[] indexes) {
return GO(go.transform, indexes);
}
protected GameObject GO(Transform t, params int[] indexes) {
foreach (int i in indexes) t = t.GetChild(i);
return t.gameObject;
}
protected GameObject GO(string name, params int[] indexes) {
return GO(GameObject.Find(name), indexes);
}
protected Image Image(GameObject go, params int[] indexes) {
return GO(go, indexes).GetComponent<Image>();
}
protected Image Image(Transform t, params int[] indexes) {
return Image(GO(t, indexes));
}
protected Image Image(string name, params int[] indexes) {
return Image(GO(name, indexes));
}
protected Text Text(GameObject go, params int[] indexes) {
return GO(go, indexes).GetComponent<Text>();
}
protected Text Text(Transform t, params int[] indexes) {
return Text(GO(t, indexes));
}
protected Text Text(string name, params int[] indexes) {
return Text(GO(name, indexes));
}
protected Button Button(GameObject go, params int[] indexes) {
return GO(go, indexes).GetComponent<Button>();
}
protected Button Button(Transform t, params int[] indexes) {
return Button(GO(t, indexes));
}
protected Button Button(string name, params int[] indexes) {
return Button(GO(name, indexes));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment