akadoc/Assets/scripts/Gui_AbilityButton.cs

63 lines
1.1 KiB
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 11:37:52 +00:00
public enum AbilityType{
Spell, Ultimate
}
2015-03-05 22:54:33 +00:00
2015-03-06 11:37:52 +00:00
public AbilityType type;
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 11:37:52 +00:00
switch(type){
case AbilityType.Spell:
SetAbilityID(Game.Get().GetMainPlayer().spellID);
break;
case AbilityType.Ultimate:
SetAbilityID(Game.Get().GetMainPlayer().ultiID);
break;
}
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){
2015-04-01 19:47:43 +00:00
Debug.LogWarning("Could not open "+sIcon);
2015-03-05 22:54:33 +00:00
}
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");
});
}
2015-03-06 11:37:52 +00:00
private int abilityID;
2015-03-05 22:54:33 +00:00
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
}