ManaSign.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Xml;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. public class Sign
  8. {
  9. #region 变量
  10. public int Coin
  11. {
  12. get
  13. {
  14. if (RoundBuff.Equal(-1))
  15. {
  16. return Coin_;
  17. }
  18. else
  19. {
  20. return (int)(Coin_*RoundBuff*ManaSign.SignRound);
  21. }
  22. }
  23. set { Coin_ = value; }
  24. }
  25. public int Diamond
  26. {
  27. get
  28. {
  29. if (RoundBuff.Equal(-1))
  30. {
  31. return Diamond_;
  32. }
  33. else
  34. {
  35. return (int)(Diamond_ * RoundBuff * ManaSign.SignRound);
  36. }
  37. }
  38. set { Diamond_ = value; }
  39. }
  40. public int Coin_;
  41. public int Diamond_;
  42. public float RoundBuff;
  43. public Text Lab1;
  44. public Text Lab2;
  45. public Image Icon;
  46. public Image Mark;
  47. public List<int> FlowerList = new List<int>();
  48. #endregion
  49. public Sign(int index, Transform tra, XmlAttributeCollection attribute)
  50. {
  51. Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
  52. Auxiliary.CompileDic(tra, dic);
  53. Lab1 = dic["Lab1"].GetComponent<Text>();
  54. Lab2 = dic["Lab2"].GetComponent<Text>();
  55. Icon = dic["Icon1"].GetComponent<Image>();
  56. Mark = dic["Icon2"].GetComponent<Image>();
  57. Lab2.text = index.ToString();
  58. Coin = Auxiliary.IntParse(attribute[3].Value, 0);
  59. Diamond = Auxiliary.IntParse(attribute[2].Value, 0);
  60. FlowerList = Auxiliary.IntListParse(',', attribute[1].Value, new List<int>());
  61. RoundBuff = Auxiliary.FloatParse(attribute[4].Value, -1);
  62. SetUI();
  63. }
  64. public void Get()
  65. {
  66. Mark.SetActive(true);
  67. ManaSign.SignTime = ManaServer.Time;
  68. ManaSign.SignIndex++;
  69. if (ManaSign.SignIndex == 22)
  70. {
  71. ManaSign.SignIndex = 1;
  72. ManaSign.SignRound++;
  73. }
  74. if (FlowerList.Valid())
  75. {
  76. for (int i = 0; i < FlowerList.Count; i++)
  77. {
  78. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]];
  79. if (flowerInfo.Unlock == false)
  80. {
  81. ManaReso.SetText("Bb_InfoLabA", flowerInfo.Name);
  82. ManaReso.SetActive("Bb_IconA", true);
  83. ManaReso.SetSprite("Bb_IconA0", flowerInfo.Icon);
  84. ManaReso.Get<Image>("Bb_IconA0").Resize(0.65f, 0.65f);
  85. flowerInfo.Unlock = true;
  86. return;
  87. }
  88. }
  89. }
  90. if (Diamond > 0)
  91. {
  92. ManaReso.SetText("Bb_InfoLabB", Diamond.ToString());
  93. ManaReso.SetSprite("Bb_IconB", ManaReso.Load<Sprite>("钻石", Folder.UI));
  94. ManaReso.SetActive("Bb_IconB", true);
  95. ManaData.Diamond += Diamond;
  96. }
  97. else if (Coin > 0)
  98. {
  99. ManaReso.SetText("Bb_InfoLabB", Coin.ToString());
  100. ManaReso.SetSprite("Bb_IconB", ManaReso.Load<Sprite>("金币", Folder.UI));
  101. ManaReso.SetActive("Bb_IconB", true);
  102. ManaData.Coin += Coin;
  103. }
  104. else
  105. {
  106. throw new Exception();
  107. }
  108. }
  109. public void SetUI()
  110. {
  111. if (FlowerList.Valid())
  112. {
  113. for (int i = 0; i < FlowerList.Count; i++)
  114. {
  115. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]];
  116. if (flowerInfo.Unlock == false)
  117. {
  118. Icon.sprite = flowerInfo.Icon;
  119. Icon.Resize(0.2f, 0.2f);
  120. return;
  121. }
  122. }
  123. }
  124. if (Diamond > 0)
  125. {
  126. Icon.sprite = ManaReso.Load<Sprite>("钻石", Folder.UI);
  127. Lab1.text = Diamond.ToString();
  128. }
  129. else if (Coin > 0)
  130. {
  131. Icon.sprite = ManaReso.Load<Sprite>("金币", Folder.UI);
  132. Lab1.text = Coin.ToString();
  133. }
  134. }
  135. }
  136. public class ManaSign : Regist
  137. {
  138. #region 变量
  139. public static int SignIndex;
  140. public static int SignRound;
  141. public static DateTime SignTime;
  142. public static Dictionary<int, Sign> SignDic = new Dictionary<int, Sign>();
  143. #endregion
  144. public static void Get()
  145. {
  146. SignDic[SignIndex].Get();
  147. ManaData.SignAmt++;
  148. }
  149. public static void Reload()
  150. {
  151. SignTime = DateTime.Parse(Data.GetPlayerString("SignTime"));
  152. SignIndex = Data.GetPlayerInt("SignIndex");
  153. SignRound = Data.GetPlayerInt("SignRound");
  154. foreach (var kv in SignDic)
  155. {
  156. kv.Value.SetUI();
  157. kv.Value.Mark.SetActive(false);
  158. }
  159. for (int i = 1; i < SignIndex; i++)
  160. {
  161. SignDic[i].Mark.SetActive(true);
  162. }
  163. }
  164. public override void RegistValueB()
  165. {
  166. SignTime = DateTime.Parse(Data.GetPlayerString("SignTime"));
  167. SignIndex = Data.GetPlayerInt("SignIndex");
  168. SignRound = Data.GetPlayerInt("SignRound");
  169. Transform par = ManaReso.Get("Bb_Grid");
  170. List<XmlAttributeCollection> attributeList = Data.GetSignConfig();
  171. for (int i = 0; i < attributeList.Count; i++)
  172. {
  173. Transform tra = ManaReso.Get("SignItem", Folder.UI, false, par, false, ObjType.SignItem);
  174. SignDic.Add(i + 1, new Sign(i + 1, tra, attributeList[i]));
  175. }
  176. for (int i = 1; i < SignIndex; i++)
  177. {
  178. SignDic[i].Mark.SetActive(true);
  179. }
  180. }
  181. }