using LitJson; using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; using System; using System.IO; using System.Linq; using System.Text; using System.Collections; using System.Collections.Generic; using System.Security.Cryptography; public class Auxiliary : MonoBehaviour { #region 变量 public string String; public Font Font; public GameObject Go; public List GoList; public List SrList; public static bool AnyKeyUp; public static bool AnyKeyDown; public static Auxiliary Inst; public static DESCryptoServiceProvider Des { get { if (_Des == null) { _Des = new DESCryptoServiceProvider(); _Des.IV = Encoding.UTF8.GetBytes("12345678"); _Des.Key = Encoding.UTF8.GetBytes("12345678"); } return _Des; } set { _Des = value; } } private static DESCryptoServiceProvider _Des; #endregion private void Start() { Inst = this; } private void Update() { #region 调试 if (Input.GetKeyDown(KeyCode.P)) { ManaData.Level += 20; } if (Input.GetKeyDown(KeyCode.O)) { for (int i = 0; i < ManaData.SkillList.Count; i++) { ManaData.SkillList[i].ReceiveCool(1, true, true); } } if (Input.GetKeyDown(KeyCode.I)) { ManaData.Coin += 1000; ManaData.Diamond += 1000; } if (Input.GetKeyDown(KeyCode.U)) { Data.SavePlayerConfig(); } if (Input.GetKeyDown(KeyCode.Y)) { Data.ResetPlayerConfig(); } if (Input.GetKeyDown(KeyCode.T)) { ManaData.Pause = !ManaData.Pause; } if (Input.GetKeyDown(KeyCode.Escape)) { ManaReso.Get("K_QuitGame").TweenForCG(); } #endregion #region 输入检测 if (AnyKeyUp) { if (Input.anyKey == false) { AnyKeyUp = false; } } if (Input.anyKeyDown) { AnyKeyDown = true; } if (AnyKeyDown) { if (Input.anyKey == false) { AnyKeyUp = true; AnyKeyDown = false; } } #endregion } public static byte[] Encrypt(string str) { byte[] bytes = Encoding.UTF8.GetBytes(str); byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length); return encryptBytes; } public static byte[] ToBytes(string str) { string[] strings = str.Split(' '); byte[] bytes = new byte[strings.Length]; for (int i = 0; i < bytes.Length; i++) { bytes[i] = byte.Parse(strings[i]); } return bytes; } public static string Decrypt(string str) { byte[] encryptBytes = ToBytes(str); byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length); return Encoding.UTF8.GetString(decryptBytes); } public static string ToString(byte[] bytes) { StringBuilder strB = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { if (i == bytes.Length - 1) { strB.Append(bytes[i]); } else { strB.Append(bytes[i] + " "); } } return strB.ToString(); } public static void CompileDic(Transform tra, Dictionary dic) { Transform[] transforms = tra.GetComponentsInChildren(true); for (int i = 0; i < transforms.Length; i++) { if (dic.ContainsKey(transforms[i].name)) { throw new Exception(transforms[i].name); } else { dic.Add(transforms[i].name, transforms[i]); } } } public void DelayCall(UnityAction function, int frame) { StartCoroutine(IDelayCall(function, frame)); } public void DelayCall(UnityAction function, float time) { StartCoroutine(IDelayCall(function, time)); } public static IEnumerator IDelayCall(UnityAction function, int frame) { int count = 0; if (count++ < frame) { yield return null; } function.Invoke(); } public static IEnumerator IDelayCall(UnityAction function, float time) { yield return new WaitForSeconds(time); function.Invoke(); } public static string FmlParse1(string str) { int index = 0; int openIndex = 0; bool flag = false; bool group = false; for (int i = 0; i < str.Length; i++) { if (group) { if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/') { str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1))); i = 0; group = false; } else if (i == str.Length - 1) { str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i))); break; } } else { if (str[i] == '+' || str[i] == '-') { flag = true; openIndex = i + 1; } else if (str[i] == '*' || str[i] == '/') { index = i; group = true; if (!flag) { openIndex = 0; } } } } group = false; for (int i = 0; i < str.Length; i++) { if (group) { if (str[i] == '+' || str[i] == '-') { str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1))); i = -1; group = false; } else if (i == str.Length - 1) { return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i)); } } else { if (str[i] == '+' || str[i] == '-') { index = i; group = true; } } } return str; } public static string FmlParse2(char op, string str1, string str2) { double var1 = double.Parse(str1); double var2 = double.Parse(str2); if (op == '+') { return (var1 + var2).ToString(); } else if (op == '-') { return (var1 - var2).ToString(); } else if (op == '*') { return (var1 * var2).ToString(); } else if (op == '/') { return (var1 / var2).ToString(); } else { throw new Exception(op.ToString()); } } public static double FmlParse(string str, params string[] strings) { for (int i = 0; i < strings.Length; i += 2) { str = str.Replace(strings[i], strings[i + 1]); } int openIndex = 0; for (int i = 0; i < str.Length; i++) { if (str[i] == '(') { openIndex = i; } else if (str[i] == ')') { str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1))); i = -1; } } return double.Parse(FmlParse1(str)); } }