akadoc/Assets/scripts/Gui_AbilityButton.cs

52 lines
932 B
C#
Raw Normal View History

2015-03-05 22:54:33 +00:00
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Gui_AbilityButton : MonoBehaviour{
2015-03-06 10:34:19 +00:00
public int abilityID;
2015-03-05 22:54:33 +00:00
void Awake(){
button = GetComponent<Button>();
icon = GetComponent<Image>();
2015-03-06 10:02:03 +00:00
name = GetComponentInChildren<Text>();
2015-03-05 22:54:33 +00:00
}
void Start(){
2015-03-06 10:34:19 +00:00
SetAbilityID(abilityID);
2015-03-05 22:54:33 +00:00
}
2015-03-06 10:34:19 +00:00
void SetAbilityID(int _abilityID){
abilityID = _abilityID;
2015-03-05 22:54:33 +00:00
//Set image, callback
2015-03-06 10:34:19 +00:00
var st = Rdb.GetTable("abilities");
2015-03-05 22:54:33 +00:00
2015-03-06 10:02:03 +00:00
//Set icon
2015-03-06 10:34:19 +00:00
string sIcon = st.GetValue<string>(abilityID, "icon");
2015-03-05 22:54:33 +00:00
var iconImage = Resources.Load<Sprite>(sIcon);
if(iconImage==null){
Debug.LogError("Could not open "+sIcon);
}
else
icon.sprite = iconImage;
2015-03-06 10:02:03 +00:00
//Set name
2015-03-06 10:34:19 +00:00
name.text = Rdb.GetStrRef(st.GetValue<int>(abilityID, "name_strref"));
2015-03-06 10:02:03 +00:00
//Execute script
2015-03-05 22:54:33 +00:00
button.onClick.AddListener(()=>{
Debug.Log("Clicked");
});
}
private int i;
private Button button;
private Image icon;
2015-03-06 10:02:03 +00:00
private Text name;
2015-03-05 22:54:33 +00:00
}