Auxiliary.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.Events;
  5. using System;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.Security.Cryptography;
  12. public class Auxiliary : MonoBehaviour
  13. {
  14. #region 变量
  15. public string String;
  16. public Font Font;
  17. public GameObject Go;
  18. public List<GameObject> GoList;
  19. public List<SpriteRenderer> SrList;
  20. public static bool AnyKeyUp;
  21. public static bool AnyKeyDown;
  22. public static Auxiliary Inst;
  23. public static DESCryptoServiceProvider Des
  24. {
  25. get
  26. {
  27. if (_Des == null)
  28. {
  29. _Des = new DESCryptoServiceProvider();
  30. _Des.IV = Encoding.UTF8.GetBytes("12345678");
  31. _Des.Key = Encoding.UTF8.GetBytes("12345678");
  32. }
  33. return _Des;
  34. }
  35. set { _Des = value; }
  36. }
  37. private static DESCryptoServiceProvider _Des;
  38. #endregion
  39. private void Start()
  40. {
  41. Inst = this;
  42. }
  43. private void Update()
  44. {
  45. if (AnyKeyUp)
  46. {
  47. if (Input.anyKey == false)
  48. {
  49. AnyKeyUp = false;
  50. }
  51. }
  52. if (Input.anyKeyDown)
  53. {
  54. AnyKeyDown = true;
  55. }
  56. if (AnyKeyDown)
  57. {
  58. if (Input.anyKey == false)
  59. {
  60. AnyKeyUp = true;
  61. AnyKeyDown = false;
  62. }
  63. }
  64. if (Input.GetKeyDown(KeyCode.P))
  65. {
  66. ManaData.Level += 10;
  67. }
  68. if (Input.GetKeyDown(KeyCode.O))
  69. {
  70. for (int i = 0; i < ManaData.SkillList.Count; i++)
  71. {
  72. ManaData.SkillList[i].ReceiveCool(1, true, true);
  73. }
  74. }
  75. if (Input.GetKeyDown(KeyCode.I))
  76. {
  77. ManaData.Coin += 1000;
  78. ManaData.Diamond += 1000;
  79. }
  80. if (Input.GetKeyDown(KeyCode.U))
  81. {
  82. Data.SavePlayerConfig();
  83. }
  84. if (Input.GetKeyDown(KeyCode.Y))
  85. {
  86. Data.ResetPlayerConfig();
  87. }
  88. if (Input.GetKeyDown(KeyCode.T))
  89. {
  90. if (Math.Abs(Time.timeScale) < 0.0005f)
  91. {
  92. Time.timeScale = 1;
  93. ManaLog.Log("<color=red>游戏已恢复</color>");
  94. }
  95. else
  96. {
  97. Time.timeScale = 0;
  98. ManaLog.Log("<color=red>游戏已暂停</color>");
  99. }
  100. }
  101. }
  102. public static byte[] Encrypt(string str)
  103. {
  104. byte[] bytes = Encoding.UTF8.GetBytes(str);
  105. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  106. return encryptBytes;
  107. }
  108. public static string Decrypt(string str)
  109. {
  110. byte[] encryptBytes = ToBytes(str);
  111. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  112. return Encoding.UTF8.GetString(decryptBytes);
  113. }
  114. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic)
  115. {
  116. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  117. for (int i = 0; i < transforms.Length; i++)
  118. {
  119. if (dic.ContainsKey(transforms[i].name))
  120. {
  121. throw new Exception(transforms[i].name);
  122. }
  123. else
  124. {
  125. dic.Add(transforms[i].name, transforms[i]);
  126. }
  127. }
  128. }
  129. public static byte[] ToBytes(string str)
  130. {
  131. string[] strings = str.Split(' ');
  132. byte[] bytes = new byte[strings.Length];
  133. for (int i = 0; i < bytes.Length; i++)
  134. {
  135. bytes[i] = byte.Parse(strings[i]);
  136. }
  137. return bytes;
  138. }
  139. public static string ToString(byte[] bytes)
  140. {
  141. StringBuilder strB = new StringBuilder();
  142. for (int i = 0; i < bytes.Length; i++)
  143. {
  144. if (i == bytes.Length - 1)
  145. {
  146. strB.Append(bytes[i]);
  147. }
  148. else
  149. {
  150. strB.Append(bytes[i] + " ");
  151. }
  152. }
  153. return strB.ToString();
  154. }
  155. public void DelayCall(UnityAction function, int frame)
  156. {
  157. StartCoroutine(IDelayCall(function, frame));
  158. }
  159. public void DelayCall(UnityAction function, float time)
  160. {
  161. StartCoroutine(IDelayCall(function, time));
  162. }
  163. private static IEnumerator IDelayCall(UnityAction function, int frame)
  164. {
  165. int count = 0;
  166. if (count++ < frame)
  167. {
  168. yield return null;
  169. }
  170. function.Invoke();
  171. }
  172. private static IEnumerator IDelayCall(UnityAction function, float time)
  173. {
  174. yield return new WaitForSeconds(time);
  175. function.Invoke();
  176. }
  177. }