Auxiliary.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 Auxiliary Inst;
  21. public static DESCryptoServiceProvider Des
  22. {
  23. get
  24. {
  25. if (_Des == null)
  26. {
  27. _Des = new DESCryptoServiceProvider();
  28. _Des.IV = Encoding.UTF8.GetBytes("12345678");
  29. _Des.Key = Encoding.UTF8.GetBytes("12345678");
  30. }
  31. return _Des;
  32. }
  33. set { _Des = value; }
  34. }
  35. private static DESCryptoServiceProvider _Des;
  36. #endregion
  37. private void Start()
  38. {
  39. Inst = this;
  40. }
  41. private void Update()
  42. {
  43. if (Input.GetKeyDown(KeyCode.P))
  44. {
  45. ManaData.Level += 10;
  46. }
  47. if (Input.GetKeyDown(KeyCode.O))
  48. {
  49. for (int i = 0; i < ManaData.SkillList.Count; i++)
  50. {
  51. ManaData.SkillList[i].ReceiveCool(1, true, true);
  52. }
  53. }
  54. if (Input.GetKeyDown(KeyCode.I))
  55. {
  56. ManaData.Coin += 1000;
  57. ManaData.Diamond += 1000;
  58. }
  59. if (Input.GetKeyDown(KeyCode.U))
  60. {
  61. Data.SavePlayerConfig();
  62. }
  63. if (Input.GetKeyDown(KeyCode.Y))
  64. {
  65. Data.ResetPlayerConfig();
  66. }
  67. if (Input.GetKeyDown(KeyCode.T))
  68. {
  69. if (Math.Abs(Time.timeScale) < 0.0005f)
  70. {
  71. Time.timeScale = 1;
  72. ManaLog.Log("<color=red>游戏已恢复</color>");
  73. }
  74. else
  75. {
  76. Time.timeScale = 0;
  77. ManaLog.Log("<color=red>游戏已暂停</color>");
  78. }
  79. }
  80. }
  81. public static byte[] Encrypt(string str)
  82. {
  83. byte[] bytes = Encoding.UTF8.GetBytes(str);
  84. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  85. return encryptBytes;
  86. }
  87. public static string Decrypt(string str)
  88. {
  89. byte[] encryptBytes = ToBytes(str);
  90. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  91. return Encoding.UTF8.GetString(decryptBytes);
  92. }
  93. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic)
  94. {
  95. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  96. for (int i = 0; i < transforms.Length; i++)
  97. {
  98. if (dic.ContainsKey(transforms[i].name))
  99. {
  100. throw new Exception(transforms[i].name);
  101. }
  102. else
  103. {
  104. dic.Add(transforms[i].name, transforms[i]);
  105. }
  106. }
  107. }
  108. public static byte[] ToBytes(string str)
  109. {
  110. string[] strings = str.Split(' ');
  111. byte[] bytes = new byte[strings.Length];
  112. for (int i = 0; i < bytes.Length; i++)
  113. {
  114. bytes[i] = byte.Parse(strings[i]);
  115. }
  116. return bytes;
  117. }
  118. public static string ToString(byte[] bytes)
  119. {
  120. StringBuilder strB = new StringBuilder();
  121. for (int i = 0; i < bytes.Length; i++)
  122. {
  123. if (i == bytes.Length - 1)
  124. {
  125. strB.Append(bytes[i]);
  126. }
  127. else
  128. {
  129. strB.Append(bytes[i] + " ");
  130. }
  131. }
  132. return strB.ToString();
  133. }
  134. public void DelayCall(UnityAction function, int frame)
  135. {
  136. StartCoroutine(IDelayCall(function, frame));
  137. }
  138. public void DelayCall(UnityAction function, float time)
  139. {
  140. StartCoroutine(IDelayCall(function, time));
  141. }
  142. private static IEnumerator IDelayCall(UnityAction function, int frame)
  143. {
  144. int count = 0;
  145. if (count++ < frame)
  146. {
  147. yield return null;
  148. }
  149. function.Invoke();
  150. }
  151. private static IEnumerator IDelayCall(UnityAction function, float time)
  152. {
  153. yield return new WaitForSeconds(time);
  154. function.Invoke();
  155. }
  156. }