akadoc/Assets/scripts/Gui_AbilityButton.cs

52 lines
911 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{
public int spellID;
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(){
SetSpellID(spellID);
}
void SetSpellID(int _spellID){
2015-03-06 10:02:03 +00:00
spellID = _spellID;
2015-03-05 22:54:33 +00:00
//Set image, callback
var st = Rdb.GetTable("spells");
2015-03-06 10:02:03 +00:00
//Set icon
string sIcon = st.GetValue<string>(spellID, "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
name.text = Rdb.GetStrRef(st.GetValue<int>(spellID, "name_strref"));
//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
}