UAVSkillInfo.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class UAVSkillInfo : MonoBehaviour {
  6. public Text titleTxt;
  7. public Image icon;
  8. public Text descTxt;
  9. void Awake()
  10. {
  11. titleTxt.text = Language.GetStr ("PowerTip", "extraPower");
  12. }
  13. public void SetData(Equipment equipment)
  14. {
  15. UAVData uavData = UAVManager.GetInstance ().GetDataByEquipId (equipment.GetData().id);
  16. string desc = "";
  17. for(int i=0; i<uavData.powers.Length; i++)
  18. {
  19. int powerId = uavData.powers [i];
  20. PowerData powerData = PowerDataManager.GetInstance ().GetData (powerId);
  21. if(powerData.effect == Power.PowerEffect.Heal.GetHashCode())
  22. {
  23. desc += GetHealDesc (powerData);
  24. }
  25. if(powerData.buff > 0)
  26. {
  27. desc += GetBuffDesc (powerData.buff);
  28. }
  29. desc += "\n" + Language.GetStr ("PowerTip", "coolDown").Replace("%SEC%", powerData.cd.ToString());
  30. icon.sprite = Power.GetIcon (powerData);
  31. if(i < uavData.powers.Length - 1)
  32. desc += "\n\n";
  33. }
  34. descTxt.text = desc;
  35. }
  36. private string GetTarget(PowerData powerData)
  37. {
  38. if (powerData.target == Power.TargetRange.Self.GetHashCode ())
  39. return Language.GetStr ("PowerTip", "tarSelf");
  40. return "";
  41. }
  42. private string GetValue(PowerData powerData)
  43. {
  44. if (powerData.value_type == Power.ValueType.Percent.GetHashCode ()) {
  45. return powerData.value + "%";
  46. }
  47. else if(powerData.value_type == Power.ValueType.Constant.GetHashCode()) {
  48. return powerData.value.ToString ();
  49. }
  50. return "";
  51. }
  52. private string GetHealDesc(PowerData powerData)
  53. {
  54. string str = Language.GetStr ("PowerTip", "heal");
  55. str = str.Replace ("%TAR%", GetTarget(powerData));
  56. str = str.Replace ("%NUM%", GetValue(powerData));
  57. return str;
  58. }
  59. private string GetBuffTarget(BuffData buffData)
  60. {
  61. if (buffData.target == Buff.TargetType.Launcher.GetHashCode())
  62. return Language.GetStr ("PowerTip", "tarSelf");
  63. return "";
  64. }
  65. private string GetBuffValue(BuffData buffData, int index)
  66. {
  67. if (buffData.value_type[index] == ConfigValue.ValueType.Percentage.GetHashCode ())
  68. return buffData.value[index] + "%";
  69. return "";
  70. }
  71. private string GetBuffDesc(int buffId)
  72. {
  73. BuffData buffData = BuffManager.GetInstance ().GetData (buffId);
  74. string str = "";
  75. for(int i=0; i<buffData.buff_type.Length; i++)
  76. {
  77. int buffType = buffData.buff_type [i];
  78. if(buffType == Buff.BuffType.SpeedUp.GetHashCode())
  79. {
  80. str += Language.GetStr ("PowerTip", "speedUp");
  81. str = str.Replace ("%TAR%", GetBuffTarget(buffData));
  82. str = str.Replace ("%NUM%", GetBuffValue(buffData, i));
  83. }
  84. str += ", " + Language.GetStr ("PowerTip", "duration").Replace ("%SEC%", buffData.duration.ToString());
  85. if(i < buffData.buff_type.Length - 1)
  86. str += "\n";
  87. }
  88. return str;
  89. }
  90. }