diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs index 5365fa68..91da985f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs @@ -6,7 +6,6 @@ using System.Collections; using System.IO; using System.Threading.Tasks; using UnityEngine; -using UnityEngine.Networking; using static AxibugEmuOnline.Client.HttpAPI; using static AxibugEmuOnline.Client.Manager.LogManager; @@ -47,7 +46,7 @@ namespace AxibugEmuOnline.Client.ClientCore #else public static string PersistentDataPath => Application.persistentDataPath; #endif - public static void Init( bool isTest = false, string testSrvIP = "") + public static void Init(bool isTest = false, string testSrvIP = "") { log = new LogManager(OnLogOut); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs index 17e42907..7311c304 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs @@ -1,5 +1,5 @@ +using System; using System.Collections.Generic; -using System; using System.Diagnostics; using System.IO; using System.IO.Compression; @@ -13,22 +13,22 @@ using System.Text.RegularExpressions; using System.Threading; public static class PSVThread -{ - +{ + #if UNITY_PSP2 static AutoResetEvent autoEvent = new AutoResetEvent(false); static Queue qActs = new Queue(); static Queue qWork = new Queue(); #endif - - public static void DoTask(Action act) - { + + public static void DoTask(Action act) + { #if UNITY_PSP2 AddSingleTask(act); #else - ThreadPool.QueueUserWorkItem(new WaitCallback((state) => act.Invoke())); + ThreadPool.QueueUserWorkItem(new WaitCallback((state) => act.Invoke())); #endif - } + } #if UNITY_PSP2 static Thread psvThread = new Thread(Loop); @@ -75,1153 +75,1153 @@ public static class PSVThread } public static class AxiHttp -{ - public const char T = '\n'; - public const string CT = "\r\n"; - public const string CTRL = "\r\n\r\n"; - public const string Content_Length_Str = "content-length: "; - public const string Content_Length_Str_M = "Content-Length: "; - public const string Content_Length = "content-length"; - public const string Content_Encoding = "content-encoding"; - public const string Transfer_Encoding = "transfer-encoding"; - public const string Connection = "connection"; - public static long index = 0; - static int singlePkgMaxRead = 1024; - - public class WaitAxiRequest : UnityEngine.CustomYieldInstruction - { - public AxiRespInfo mReqAsync; - public WaitAxiRequest(AxiRespInfo reqAsync) - { - mReqAsync = reqAsync; - } - ~WaitAxiRequest() - { - mReqAsync = null; - } - public override bool keepWaiting - { - get { return !mReqAsync.isDone; } - } - } - - public static void Log(string log) - { - UnityEngine.Debug.Log(log); - //Console.WriteLine(log); - } - - static Dictionary dictIP2Address = new Dictionary(); - - public class AxiRespInfo - { - public bool isDone = false; - public AxiDownLoadMode downloadMode = AxiDownLoadMode.NotDownLoad; - public bool bHadErr - { - get - { - return - isDone = true - && - ( - !string.IsNullOrEmpty(ErrInfo) - || - code != 200 - ); - } - } - public string ErrInfo; - //public string Err = null; - public string host = "";//host主机头 - public string url = "";//pathAndQuery - public int port = 80; - public string requestRaw = ""; - public string encoding = ""; - public string header = ""; - public string text { get { return body; } } - public string body = ""; - public string reuqestBody = ""; - public string reuqestHeader = ""; - public Dictionary headers = new Dictionary(); - public string response = ""; - //public string gzip = ""; - public bool isGzip = false; - public int length = 0; - public int code = 0; - public int location = 0; - public int runTime = 0;//获取网页消耗时间,毫秒 - public int sleepTime = 0;//休息时间 - public string cookies = ""; - public bool bTimeOut = false; - - public int NeedloadedLenght; - public int loadedLenght; - public byte[] data { get { return bodyRaw; } } - public byte[] bodyRaw; - public string fileName; - public float DownLoadPr => - NeedloadedLenght <= 0 ? -1 : (float)loadedLenght / NeedloadedLenght; - public BinaryWriter binaryWriter; - } - - public static IPAddress GetDnsIP(string str) - { - if (!dictIP2Address.ContainsKey(str)) - { - IPHostEntry host = Dns.GetHostEntry(str); - IPAddress ip = host.AddressList[0]; - dictIP2Address[str] = ip; - } - return dictIP2Address[str]; - } - - public enum AxiDownLoadMode - { - NotDownLoad = 0, - DownLoadBytes = 1, - DownloadToBinaryWriter = 2 - } - - public static AxiRespInfo AxiRequest(string url) - { - AxiRespInfo respInfo = new AxiRespInfo(); - respInfo.downloadMode = AxiDownLoadMode.NotDownLoad; - SendAxiRequest(url, ref respInfo); - return respInfo; - } - - public static WaitAxiRequest AxiRequestAsync(string url) - { - AxiRespInfo respInfo = new AxiRespInfo(); - respInfo.downloadMode = AxiDownLoadMode.NotDownLoad; - WaitAxiRequest respAsync = new WaitAxiRequest(respInfo); - //Task task = new Task(() => SendAxiRequest(url, ref respInfo)); - //task.Start() - PSVThread.DoTask(() => SendAxiRequest(url, ref respInfo)); - return respAsync; - } - - public static AxiRespInfo AxiDownload(string url) - { - AxiRespInfo respInfo = new AxiRespInfo(); - respInfo.downloadMode = AxiDownLoadMode.DownLoadBytes; - SendAxiRequest(url, ref respInfo); - return respInfo; - } - - public static AxiRespInfo AxiDownloadAsync(string url) - { - AxiRespInfo respInfo = new AxiRespInfo(); - respInfo.downloadMode = AxiDownLoadMode.DownLoadBytes; - //Task task = new Task(() => SendAxiRequest(url, ref respInfo)); - //task.Start(); - PSVThread.DoTask(() => SendAxiRequest(url, ref respInfo)); - return respInfo; - } - - static void SendAxiRequest(string url, ref AxiRespInfo respinfo, int timeout = 1000 * 1000, string encoding = "UTF-8") - { - if (url.ToLower().StartsWith("https://")) - SendAxiRequestHttps(url, ref respinfo, timeout, encoding);// SendAxiRequestHttps(url, ref respinfo, timeout, encoding); - else - SendAxiRequestHttp(url, ref respinfo, timeout, encoding); - } - - static void SendAxiRequestHttp(string url, ref AxiRespInfo respinfo, int timeout, string encoding) - { - Log("SendAxiRequestHttp"); - respinfo.url = url; - Stopwatch sw = new Stopwatch(); - sw.Start(); - respinfo.loadedLenght = 0; - try - { - string strURI = url; - string strHost = ""; - string strIP = ""; - int port = 0; - string strRelativePath = ""; - bool bSSL = false; - bool foward_302 = true; - string ourErrMsg = ""; - - if (!ParseURI(strURI, ref bSSL, ref strHost, ref strIP, ref port, ref strRelativePath, ref ourErrMsg)) - { - Log("ParseURI False"); - respinfo.ErrInfo = ourErrMsg; - respinfo.code = 0; - respinfo.isDone = true; - return; - } - - - - var ip = GetDnsIP(strHost); - var ipEndPoint = new IPEndPoint(ip, port); - - using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - using (MemoryStream memoryStream = new MemoryStream()) - { - client.Connect(ipEndPoint); - if (!client.Connected) - { - client.Close(); - sw.Stop(); - respinfo.code = 0; - respinfo.isDone = true; - return; - } - - //string requestRaw = $"GET {strRelativePath} HTTP/1.1\r\nHost: {strHost}\r\nConnection: Close\r\n\r\n"; - string request = $"GET {strURI} HTTP/1.1\r\nHost: {strHost}\r\nConnection: Close\r\n\r\n"; - - checkContentLength(ref respinfo, ref request); - respinfo.requestRaw = request; - byte[] temp_responseBody = new byte[singlePkgMaxRead]; - - byte[] buffer = Encoding.ASCII.GetBytes(request); - client.Send(buffer); - - string tmp = ""; - int len = 0; - StringBuilder sb = new StringBuilder(); - do - { - byte[] responseHeader = new byte[1]; - len = client.Receive(responseHeader, 1, SocketFlags.None); - if (len == 1) - { - char c = (char)responseHeader[0]; - sb.Append(c); - if (c.Equals(T)) - { - tmp = String.Concat(sb[sb.Length - 4], sb[sb.Length - 3], sb[sb.Length - 2], c); - } - } - } while (!tmp.Equals(CTRL) - && sw.ElapsedMilliseconds < timeout - ); - - - respinfo.header = sb.ToString().Replace(CTRL, ""); - string[] headers = Regex.Split(respinfo.header, CT); - if (headers != null && headers.Length > 0) - { - //处理header - doHeader(ref respinfo, ref headers); - } - //自动修正编码 - if (!String.IsNullOrEmpty(respinfo.encoding)) - { - encoding = respinfo.encoding; - } - Encoding encod = Encoding.GetEncoding(encoding); - - //302 301跳转 - if ((respinfo.code == 302 || respinfo.code == 301) && foward_302) - { - StringBuilder rsb = new StringBuilder(respinfo.requestRaw); - int urlStart = respinfo.requestRaw.IndexOf(" ") + 1; - int urlEnd = respinfo.requestRaw.IndexOf(" HTTP"); - if (urlStart != -1 && urlEnd != -1) - { - url = respinfo.requestRaw.Substring(urlStart, urlEnd - urlStart); - rsb.Remove(urlStart, url.Length); - String location = respinfo.headers["location"]; - if (!respinfo.headers["location"].StartsWith("/") && !respinfo.headers["location"].StartsWith("http")) - { - location = Tools.getCurrentPath(url) + location; - } - rsb.Insert(urlStart, location); - //return sendHTTPRequest(count, host, port, payload, rsb.ToString(), timeout, encoding, false); - client.Close(); - sw.Stop(); - SendAxiRequest(url, ref respinfo, timeout, encoding); - return; - } - } - - //根据请求头解析 - if (respinfo.headers.ContainsKey(Content_Length)) - { - Log("User Head"); - int length = int.Parse(respinfo.headers[Content_Length]); - respinfo.NeedloadedLenght = length; - - // while (respinfo.loadedLenght < length - // && sw.ElapsedMilliseconds < timeout - // ) - //{ - // int readsize = length - respinfo.loadedLenght; - // len = client.Receive(temp_responseBody, respinfo.loadedLenght, readsize, SocketFlags.None); - - // if (len > 0) - // { - // respinfo.loadedLenght += len; - // } - //} - - while (respinfo.loadedLenght < length - && sw.ElapsedMilliseconds < timeout - ) - { - //len = client.Receive(temp_responseBody, respinfo.loadedLenght, readsize, SocketFlags.None); - int readsize = length - respinfo.loadedLenght; - readsize = Math.Min(readsize, singlePkgMaxRead); - len = client.Receive(temp_responseBody, 0, readsize, SocketFlags.None); - if (len > 0) - { - memoryStream.Write(temp_responseBody, 0, len); - respinfo.loadedLenght += len; - } - } - } - //解析chunked传输 - else if (respinfo.headers.ContainsKey(Transfer_Encoding)) - { - Log("User chunked"); - //读取长度 - int chunkedSize = 0; - byte[] chunkedByte = new byte[1]; - //读取总长度 - respinfo.loadedLenght = 0; - do - { - string ctmp = ""; - do - { - len = client.Receive(chunkedByte, 1, SocketFlags.None); - ctmp += Encoding.UTF8.GetString(chunkedByte); - - } while ((ctmp.IndexOf(CT) == -1) - && (sw.ElapsedMilliseconds < timeout) - ); - - chunkedSize = Tools.convertToIntBy16(ctmp.Replace(CT, "")); - //chunked的结束0\r\n\r\n是结束标志,单个chunked块\r\n结束 - if (ctmp.Equals(CT)) - { - continue; - } - if (chunkedSize == 0) - { - //结束了 - break; - } - //int onechunkLen = 0; - //while (onechunkLen < chunkedSize - // && sw.ElapsedMilliseconds < timeout - // ) - //{ - - // len = client.Receive(responseBody, respinfo.loadedLenght, chunkedSize - onechunkLen, SocketFlags.None); - // if (len > 0) - // { - // onechunkLen += len; - // respinfo.loadedLenght += len; - // } - //} - - int onechunkLen = 0; - while (onechunkLen < chunkedSize - && sw.ElapsedMilliseconds < timeout - ) - { - //len = client.Receive(responseBody, respinfo.loadedLenght, chunkedSize - onechunkLen, SocketFlags.None); - - int readsize = chunkedSize - onechunkLen; - readsize = Math.Min(readsize, singlePkgMaxRead); - len = client.Receive(temp_responseBody, 0, readsize, SocketFlags.None); - if (len > 0) - { - memoryStream.Write(temp_responseBody, 0, len); - onechunkLen += len; - respinfo.loadedLenght += len; - } - } - - //判断 - } while (sw.ElapsedMilliseconds < timeout); - } - //connection close方式或未知body长度 - else - { - Log("connection close or Unknow bodylenght"); - while (sw.ElapsedMilliseconds < timeout) - { - if (client.Poll(timeout, SelectMode.SelectRead)) - { - if (client.Available > 0) - { - //len = client.Receive(responseBody, respinfo.loadedLenght, (1024 * 200) - respinfo.loadedLenght, SocketFlags.None); - int readsize = (1024 * 200) - respinfo.loadedLenght; - readsize = Math.Min(readsize, singlePkgMaxRead); - len = client.Receive(temp_responseBody, 0, readsize, SocketFlags.None); - - if (len > 0) - { - memoryStream.Write(temp_responseBody, 0, len); - respinfo.loadedLenght += len; - } - } - else - { - break; - } - } - } - } - - - byte[] responseBody = memoryStream.ToArray(); - //如果是下载 - if (respinfo.downloadMode > AxiDownLoadMode.NotDownLoad) - { - //判断是否gzip - if (respinfo.headers.ContainsKey(Content_Encoding)) - { - respinfo.bodyRaw = unGzipBytes(responseBody, respinfo.loadedLenght); - } - else - { - respinfo.bodyRaw = responseBody; - } - - // 使用Uri类解析URL - Uri uri = new Uri(url); - respinfo.fileName = Path.GetFileName(uri.LocalPath); - } - else - { - //判断是否gzip - if (respinfo.headers.ContainsKey(Content_Encoding)) - { - respinfo.body = unGzip(responseBody, respinfo.loadedLenght, encod); - } - else - { - respinfo.body = encod.GetString(responseBody, 0, respinfo.loadedLenght); - } - } - - client.Close(); - } - - } - catch (Exception ex) - { - respinfo.ErrInfo = $"ex : {ex.ToString()}"; - } - finally - { - sw.Stop(); - respinfo.length = respinfo.loadedLenght; - respinfo.runTime = (int)sw.ElapsedMilliseconds; - respinfo.bTimeOut = sw.ElapsedMilliseconds >= timeout; - //if (socket != null) - //{ - // clientSocket.Close(); - //} - respinfo.isDone = true; - } - } - - - static void SendAxiRequestHttps(string url, ref AxiRespInfo respinfo, int timeout, string encoding) - { - respinfo.url = url; - Stopwatch sw = new Stopwatch(); - sw.Start(); - respinfo.loadedLenght = 0; - TcpClient client = null; - try - { - string strURI = url; - string strHost = ""; - string strIP = ""; - int port = 0; - string strRelativePath = ""; - bool bSSL = false; - bool foward_302 = true; - string ourErrMsg = ""; - - if (!ParseURI(strURI, ref bSSL, ref strHost, ref strIP, ref port, ref strRelativePath, ref ourErrMsg)) - { - Log("ParseURI False"); - respinfo.ErrInfo = ourErrMsg; - respinfo.code = 0; - respinfo.isDone = true; - return; - } - - //var ip = Dns.GetHostEntry(strHost).AddressList[0]; - //var ipEndPoint = new IPEndPoint(ip, port); - - //using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - //using (TcpClient tcpclient = new TcpClient()) - using (MemoryStream memoryStream = new MemoryStream()) - { - //client.Connect(ipEndPoint); - - TimeOutSocket tos = new TimeOutSocket(); - client = tos.Connect(strHost, port, timeout); - if (!client.Connected) - { - client.Close(); - sw.Stop(); - respinfo.code = 0; - respinfo.isDone = true; - return; - } - SslStream ssl = null; - - //string requestRaw = $"GET {strRelativePath} HTTP/1.1\r\nHost: {strHost}\r\nConnection: Close\r\n\r\n"; - string request = $"GET {strURI} HTTP/1.1\r\nHost: {strHost}\r\nConnection: Close\r\n\r\n"; - - ssl = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate)); - SslProtocols protocol = SslProtocols.Ssl3 | SslProtocols.Ssl2 | SslProtocols.Tls; - ssl.AuthenticateAsClient(strHost, null, protocol, false); - if (ssl.IsAuthenticated) - { - checkContentLength(ref respinfo, ref request); - respinfo.requestRaw = request; - byte[] requestByte = Encoding.UTF8.GetBytes(request); - ssl.Write(requestByte); - ssl.Flush(); - } - - - checkContentLength(ref respinfo, ref request); - respinfo.requestRaw = request; - byte[] temp_responseBody = new byte[singlePkgMaxRead]; - - //byte[] buffer = Encoding.ASCII.GetBytes(requestRaw); - //client.Send(buffer); - - string tmp = ""; - int len = 0; - StringBuilder sb = new StringBuilder(); - do - { - byte[] responseHeader = new byte[1]; - int read = ssl.ReadByte(); - - char c = (char)read; - sb.Append(c); - if (c.Equals(T)) - { - tmp = String.Concat(sb[sb.Length - 4], sb[sb.Length - 3], sb[sb.Length - 2], c); - } - - } while (!tmp.Equals(CTRL) - && sw.ElapsedMilliseconds < timeout - ); - - - respinfo.header = sb.ToString().Replace(CTRL, ""); - string[] headers = Regex.Split(respinfo.header, CT); - if (headers != null && headers.Length > 0) - { - //处理header - doHeader(ref respinfo, ref headers); - } - //自动修正编码 - if (!String.IsNullOrEmpty(respinfo.encoding)) - { - encoding = respinfo.encoding; - } - Encoding encod = Encoding.GetEncoding(encoding); - - //302 301跳转 - if ((respinfo.code == 302 || respinfo.code == 301) && foward_302) - { - int urlStart = respinfo.requestRaw.IndexOf(" "); - int urlEnd = respinfo.requestRaw.IndexOf(" HTTP"); - if (urlStart != -1 && urlEnd != -1) - { - url = respinfo.requestRaw.Substring(urlStart + 1, urlEnd - urlStart - 1); - if (!respinfo.headers["location"].StartsWith("/") && !respinfo.headers["location"].StartsWith("https")) - { - respinfo.requestRaw = respinfo.requestRaw.Replace(url, Tools.getCurrentPath(url) + respinfo.headers["location"]); - } - else - { - respinfo.requestRaw = respinfo.requestRaw.Replace(url, respinfo.headers["location"]); - } - //return sendHTTPRequest(count, host, port, payload, rsb.ToString(), timeout, encoding, false); - client.Close(); - sw.Stop(); - SendAxiRequest(url, ref respinfo, timeout, encoding); - return; - } - } - - //根据请求头解析 - if (respinfo.headers.ContainsKey(Content_Length)) - { - Log("Use Head"); - int length = int.Parse(respinfo.headers[Content_Length]); - respinfo.NeedloadedLenght = length; - while (respinfo.loadedLenght < length && sw.ElapsedMilliseconds < timeout) - { - //len = ssl.Read(responseBody, respinfo.loadedLenght, length - respinfo.loadedLenght); - int readsize = length - respinfo.loadedLenght; - readsize = Math.Min(readsize, singlePkgMaxRead); - len = ssl.Read(temp_responseBody, 0, readsize); - if (len > 0) - { - memoryStream.Write(temp_responseBody, 0, len); - respinfo.loadedLenght += len; - } - } - } - //解析chunked传输 - else if (respinfo.headers.ContainsKey(Transfer_Encoding)) - { - Log("User chunked"); - //读取长度 - int chunkedSize = 0; - byte[] chunkedByte = new byte[1]; - //读取总长度 - respinfo.loadedLenght = 0; - do - { - string ctmp = ""; - do - { - len = ssl.Read(chunkedByte, 0, 1); - ctmp += Encoding.UTF8.GetString(chunkedByte); - - } while (ctmp.IndexOf(CT) == -1 && sw.ElapsedMilliseconds < timeout); - - - chunkedSize = Tools.convertToIntBy16(ctmp.Replace(CT, "")); - - //chunked的结束0\r\n\r\n是结束标志,单个chunked块\r\n结束 - if (ctmp.Equals(CT)) - { - continue; - } - if (chunkedSize == 0) - { - //结束了 - break; - } - int onechunkLen = 0; - while (onechunkLen < chunkedSize && sw.ElapsedMilliseconds < timeout) - { - //len = ssl.Read(responseBody, respinfo.loadedLenght, chunkedSize - onechunkLen); - int readsize = chunkedSize - onechunkLen; - readsize = Math.Min(readsize, singlePkgMaxRead); - len = ssl.Read(temp_responseBody, 0, readsize); - if (len > 0) - { - memoryStream.Write(temp_responseBody, 0, len); - onechunkLen += len; - respinfo.loadedLenght += len; - } - } - - //判断 - } while (sw.ElapsedMilliseconds < timeout); - } - //connection close方式或未知body长度 - else - { - Log("connection close or Unknow bodylenght"); - while (sw.ElapsedMilliseconds < timeout) - { - while (sw.ElapsedMilliseconds < timeout) - { - if (client.Client.Poll(timeout, SelectMode.SelectRead)) - { - if (client.Available > 0) - { - //len = ssl.Read(responseBody, respinfo.loadedLenght, (1024 * 200) - respinfo.loadedLenght); - int readsize = (1024 * 200) - respinfo.loadedLenght; - readsize = Math.Min(readsize, singlePkgMaxRead); - len = ssl.Read(temp_responseBody, 0, readsize); - if (len > 0) - { - memoryStream.Write(temp_responseBody, 0, len); - respinfo.loadedLenght += len; - } - } - else - { - break; - } - } - } - } - } - - byte[] responseBody = memoryStream.ToArray(); - //如果是下载 - if (respinfo.downloadMode > AxiDownLoadMode.NotDownLoad) - { - //判断是否gzip - if (respinfo.isGzip) - { - respinfo.bodyRaw = unGzipBytes(responseBody, respinfo.loadedLenght); - } - else - { - respinfo.bodyRaw = responseBody; - } - - // 使用Uri类解析URL - Uri uri = new Uri(url); - respinfo.fileName = Path.GetFileName(uri.LocalPath); - } - else - { - //判断是否gzip - if (respinfo.isGzip) - { - respinfo.body = unGzip(responseBody, respinfo.loadedLenght, encod); - } - else - { - respinfo.body = encod.GetString(responseBody, 0, respinfo.loadedLenght); - } - } - - } - - } - catch (Exception ex) - { - respinfo.ErrInfo = $"ex : {ex.ToString()}"; - } - finally - { - client?.Close(); - sw.Stop(); - respinfo.length = respinfo.loadedLenght; - respinfo.runTime = (int)sw.ElapsedMilliseconds; - respinfo.bTimeOut = sw.ElapsedMilliseconds >= timeout; - //if (socket != null) - //{ - // clientSocket.Close(); - //} - respinfo.isDone = true; - } - - if (client != null) - client.Dispose(); - } - - - private static void doHeader(ref AxiRespInfo respinfo, ref string[] headers) - { - - for (int i = 0; i < headers.Length; i++) - { - if (i == 0) - { - respinfo.code = Tools.convertToInt(headers[i].Split(' ')[1]); - if (respinfo.code != 200 && respinfo.code != 301 && respinfo.code != 302) - respinfo.ErrInfo = "code:" + respinfo.code; - } - else - { - String[] kv = Regex.Split(headers[i], ": "); - String key = kv[0].ToLower(); - if (!respinfo.headers.ContainsKey(key)) - { - //自动识别编码 - if ("content-type".Equals(key)) - { - String hecnode = getHTMLEncoding(kv[1], ""); - if (!String.IsNullOrEmpty(hecnode)) - { - respinfo.encoding = hecnode; - } - } - if (kv.Length > 1) - { - respinfo.headers.Add(key, kv[1]); - } - else - { - respinfo.headers.Add(key, ""); - } - } - } - respinfo.isGzip = respinfo.headers.ContainsKey(Content_Encoding); - } - - } - public static string unGzip(byte[] data, int len, Encoding encoding) - { - - string str = ""; - MemoryStream ms = new MemoryStream(data, 0, len); - GZipStream gs = new GZipStream(ms, CompressionMode.Decompress); - MemoryStream outbuf = new MemoryStream(); - byte[] block = new byte[1024]; - - try - { - - while (true) - { - int bytesRead = gs.Read(block, 0, block.Length); - if (bytesRead <= 0) - { - break; - } - else - { - outbuf.Write(block, 0, bytesRead); - } - } - str = encoding.GetString(outbuf.ToArray()); - } - catch (Exception e) - { - Log("解压Gzip发生异常----" + e.Message); - } - finally - { - outbuf.Close(); - gs.Close(); - ms.Close(); - - } - return str; - - } - - public static byte[] unGzipBytes(byte[] data, int len) - { - MemoryStream ms = new MemoryStream(data, 0, len); - GZipStream gs = new GZipStream(ms, CompressionMode.Decompress); - MemoryStream outbuf = new MemoryStream(); - byte[] block = new byte[1024]; - byte[] result; - try - { - - while (true) - { - int bytesRead = gs.Read(block, 0, block.Length); - if (bytesRead <= 0) - { - break; - } - else - { - outbuf.Write(block, 0, bytesRead); - } - } - result = outbuf.ToArray(); - } - catch (Exception e) - { - Log("解压Gzip发生异常----" + e.Message); - result = new byte[0]; - } - finally - { - outbuf.Close(); - gs.Close(); - ms.Close(); - - } - return result; - - } - public static string getHTMLEncoding(string header, string body) - { - if (string.IsNullOrEmpty(header) && string.IsNullOrEmpty(body)) - { - return ""; - } - body = body.ToUpper(); - Match m = Regex.Match(header, @"charset\b\s*=\s*""?(?[^""]*)", RegexOptions.IgnoreCase); - if (m.Success) - { - return m.Groups["charset"].Value.ToUpper(); - } - else - { - if (string.IsNullOrEmpty(body)) - { - return ""; - } - m = Regex.Match(body, @"charset\b\s*=\s*""?(?[^""]*)", RegexOptions.IgnoreCase); - if (m.Success) - { - return m.Groups["charset"].Value.ToUpper(); - } - } - return ""; - } - private static void checkContentLength(ref AxiRespInfo respinfo, ref string request) - { - - //重新计算并设置Content-length - int sindex = request.IndexOf(CTRL); - respinfo.reuqestHeader = request; - if (sindex != -1) - { - respinfo.reuqestHeader = request.Substring(0, sindex); - respinfo.reuqestBody = request.Substring(sindex + 4, request.Length - sindex - 4); - int contentLength = Encoding.UTF8.GetBytes(respinfo.reuqestBody).Length; - String newContentLength = Content_Length_Str_M + contentLength; - - if (request.IndexOf(Content_Length_Str_M) != -1) - { - request = Regex.Replace(request, Content_Length_Str_M + "\\d+", newContentLength); - } - else - { - request = request.Insert(sindex, "\r\n" + newContentLength); - } - } - else - { - request = Regex.Replace(request, Content_Length_Str + "\\d+", Content_Length_Str_M + "0"); - request += CTRL; - } - - - } - private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) - { - return true; - } - public static bool ParseURI(string strURI, - ref bool bIsSSL, - ref string strHost, - ref string strIP, - ref int Port, - ref string strRelativePath, - ref string errMsg) - { - string strAddressRet; - string strPortRet; - string strRelativePathRet; - string strIPRet; - - /*string strProtocol = strURI.Substring(0, 7); +{ + public const char T = '\n'; + public const string CT = "\r\n"; + public const string CTRL = "\r\n\r\n"; + public const string Content_Length_Str = "content-length: "; + public const string Content_Length_Str_M = "Content-Length: "; + public const string Content_Length = "content-length"; + public const string Content_Encoding = "content-encoding"; + public const string Transfer_Encoding = "transfer-encoding"; + public const string Connection = "connection"; + public static long index = 0; + static int singlePkgMaxRead = 1024; + + public class WaitAxiRequest : UnityEngine.CustomYieldInstruction + { + public AxiRespInfo mReqAsync; + public WaitAxiRequest(AxiRespInfo reqAsync) + { + mReqAsync = reqAsync; + } + ~WaitAxiRequest() + { + mReqAsync = null; + } + public override bool keepWaiting + { + get { return !mReqAsync.isDone; } + } + } + + public static void Log(string log) + { + UnityEngine.Debug.Log(log); + //Console.WriteLine(log); + } + + static Dictionary dictIP2Address = new Dictionary(); + + public class AxiRespInfo + { + public bool isDone = false; + public AxiDownLoadMode downloadMode = AxiDownLoadMode.NotDownLoad; + public bool bHadErr + { + get + { + return + isDone = true + && + ( + !string.IsNullOrEmpty(ErrInfo) + || + code != 200 + ); + } + } + public string ErrInfo; + //public string Err = null; + public string host = "";//host主机头 + public string url = "";//pathAndQuery + public int port = 80; + public string requestRaw = ""; + public string encoding = ""; + public string header = ""; + public string text { get { return body; } } + public string body = ""; + public string reuqestBody = ""; + public string reuqestHeader = ""; + public Dictionary headers = new Dictionary(); + public string response = ""; + //public string gzip = ""; + public bool isGzip = false; + public int length = 0; + public int code = 0; + public int location = 0; + public int runTime = 0;//获取网页消耗时间,毫秒 + public int sleepTime = 0;//休息时间 + public string cookies = ""; + public bool bTimeOut = false; + + public int NeedloadedLenght; + public int loadedLenght; + public byte[] data { get { return bodyRaw; } } + public byte[] bodyRaw; + public string fileName; + public float DownLoadPr => + NeedloadedLenght <= 0 ? -1 : (float)loadedLenght / NeedloadedLenght; + public BinaryWriter binaryWriter; + } + + public static IPAddress GetDnsIP(string str) + { + if (!dictIP2Address.ContainsKey(str)) + { + IPHostEntry host = Dns.GetHostEntry(str); + IPAddress ip = host.AddressList[0]; + dictIP2Address[str] = ip; + } + return dictIP2Address[str]; + } + + public enum AxiDownLoadMode + { + NotDownLoad = 0, + DownLoadBytes = 1, + DownloadToBinaryWriter = 2 + } + + public static AxiRespInfo AxiRequest(string url) + { + AxiRespInfo respInfo = new AxiRespInfo(); + respInfo.downloadMode = AxiDownLoadMode.NotDownLoad; + SendAxiRequest(url, ref respInfo); + return respInfo; + } + + public static WaitAxiRequest AxiRequestAsync(string url) + { + AxiRespInfo respInfo = new AxiRespInfo(); + respInfo.downloadMode = AxiDownLoadMode.NotDownLoad; + WaitAxiRequest respAsync = new WaitAxiRequest(respInfo); + //Task task = new Task(() => SendAxiRequest(url, ref respInfo)); + //task.Start() + PSVThread.DoTask(() => SendAxiRequest(url, ref respInfo)); + return respAsync; + } + + public static AxiRespInfo AxiDownload(string url) + { + AxiRespInfo respInfo = new AxiRespInfo(); + respInfo.downloadMode = AxiDownLoadMode.DownLoadBytes; + SendAxiRequest(url, ref respInfo); + return respInfo; + } + + public static AxiRespInfo AxiDownloadAsync(string url) + { + AxiRespInfo respInfo = new AxiRespInfo(); + respInfo.downloadMode = AxiDownLoadMode.DownLoadBytes; + //Task task = new Task(() => SendAxiRequest(url, ref respInfo)); + //task.Start(); + PSVThread.DoTask(() => SendAxiRequest(url, ref respInfo)); + return respInfo; + } + + static void SendAxiRequest(string url, ref AxiRespInfo respinfo, int timeout = 1000 * 1000, string encoding = "UTF-8") + { + if (url.ToLower().StartsWith("https://")) + SendAxiRequestHttps(url, ref respinfo, timeout, encoding);// SendAxiRequestHttps(url, ref respinfo, timeout, encoding); + else + SendAxiRequestHttp(url, ref respinfo, timeout, encoding); + } + + static void SendAxiRequestHttp(string url, ref AxiRespInfo respinfo, int timeout, string encoding) + { + Log("SendAxiRequestHttp"); + respinfo.url = url; + Stopwatch sw = new Stopwatch(); + sw.Start(); + respinfo.loadedLenght = 0; + try + { + string strURI = url; + string strHost = ""; + string strIP = ""; + int port = 0; + string strRelativePath = ""; + bool bSSL = false; + bool foward_302 = true; + string ourErrMsg = ""; + + if (!ParseURI(strURI, ref bSSL, ref strHost, ref strIP, ref port, ref strRelativePath, ref ourErrMsg)) + { + Log("ParseURI False"); + respinfo.ErrInfo = ourErrMsg; + respinfo.code = 0; + respinfo.isDone = true; + return; + } + + + + var ip = GetDnsIP(strHost); + var ipEndPoint = new IPEndPoint(ip, port); + + using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + using (MemoryStream memoryStream = new MemoryStream()) + { + client.Connect(ipEndPoint); + if (!client.Connected) + { + client.Close(); + sw.Stop(); + respinfo.code = 0; + respinfo.isDone = true; + return; + } + + //string requestRaw = $"GET {strRelativePath} HTTP/1.1\r\nHost: {strHost}\r\nConnection: Close\r\n\r\n"; + string request = $"GET {strURI} HTTP/1.1\r\nHost: {strHost}\r\nConnection: Close\r\n\r\n"; + + checkContentLength(ref respinfo, ref request); + respinfo.requestRaw = request; + byte[] temp_responseBody = new byte[singlePkgMaxRead]; + + byte[] buffer = Encoding.ASCII.GetBytes(request); + client.Send(buffer); + + string tmp = ""; + int len = 0; + StringBuilder sb = new StringBuilder(); + do + { + byte[] responseHeader = new byte[1]; + len = client.Receive(responseHeader, 1, SocketFlags.None); + if (len == 1) + { + char c = (char)responseHeader[0]; + sb.Append(c); + if (c.Equals(T)) + { + tmp = String.Concat(sb[sb.Length - 4], sb[sb.Length - 3], sb[sb.Length - 2], c); + } + } + } while (!tmp.Equals(CTRL) + && sw.ElapsedMilliseconds < timeout + ); + + + respinfo.header = sb.ToString().Replace(CTRL, ""); + string[] headers = Regex.Split(respinfo.header, CT); + if (headers != null && headers.Length > 0) + { + //处理header + doHeader(ref respinfo, ref headers); + } + //自动修正编码 + if (!String.IsNullOrEmpty(respinfo.encoding)) + { + encoding = respinfo.encoding; + } + Encoding encod = Encoding.GetEncoding(encoding); + + //302 301跳转 + if ((respinfo.code == 302 || respinfo.code == 301) && foward_302) + { + StringBuilder rsb = new StringBuilder(respinfo.requestRaw); + int urlStart = respinfo.requestRaw.IndexOf(" ") + 1; + int urlEnd = respinfo.requestRaw.IndexOf(" HTTP"); + if (urlStart != -1 && urlEnd != -1) + { + url = respinfo.requestRaw.Substring(urlStart, urlEnd - urlStart); + rsb.Remove(urlStart, url.Length); + String location = respinfo.headers["location"]; + if (!respinfo.headers["location"].StartsWith("/") && !respinfo.headers["location"].StartsWith("http")) + { + location = Tools.getCurrentPath(url) + location; + } + rsb.Insert(urlStart, location); + //return sendHTTPRequest(count, host, port, payload, rsb.ToString(), timeout, encoding, false); + client.Close(); + sw.Stop(); + SendAxiRequest(url, ref respinfo, timeout, encoding); + return; + } + } + + //根据请求头解析 + if (respinfo.headers.ContainsKey(Content_Length)) + { + Log("User Head"); + int length = int.Parse(respinfo.headers[Content_Length]); + respinfo.NeedloadedLenght = length; + + // while (respinfo.loadedLenght < length + // && sw.ElapsedMilliseconds < timeout + // ) + //{ + // int readsize = length - respinfo.loadedLenght; + // len = client.Receive(temp_responseBody, respinfo.loadedLenght, readsize, SocketFlags.None); + + // if (len > 0) + // { + // respinfo.loadedLenght += len; + // } + //} + + while (respinfo.loadedLenght < length + && sw.ElapsedMilliseconds < timeout + ) + { + //len = client.Receive(temp_responseBody, respinfo.loadedLenght, readsize, SocketFlags.None); + int readsize = length - respinfo.loadedLenght; + readsize = Math.Min(readsize, singlePkgMaxRead); + len = client.Receive(temp_responseBody, 0, readsize, SocketFlags.None); + if (len > 0) + { + memoryStream.Write(temp_responseBody, 0, len); + respinfo.loadedLenght += len; + } + } + } + //解析chunked传输 + else if (respinfo.headers.ContainsKey(Transfer_Encoding)) + { + Log("User chunked"); + //读取长度 + int chunkedSize = 0; + byte[] chunkedByte = new byte[1]; + //读取总长度 + respinfo.loadedLenght = 0; + do + { + string ctmp = ""; + do + { + len = client.Receive(chunkedByte, 1, SocketFlags.None); + ctmp += Encoding.UTF8.GetString(chunkedByte); + + } while ((ctmp.IndexOf(CT) == -1) + && (sw.ElapsedMilliseconds < timeout) + ); + + chunkedSize = Tools.convertToIntBy16(ctmp.Replace(CT, "")); + //chunked的结束0\r\n\r\n是结束标志,单个chunked块\r\n结束 + if (ctmp.Equals(CT)) + { + continue; + } + if (chunkedSize == 0) + { + //结束了 + break; + } + //int onechunkLen = 0; + //while (onechunkLen < chunkedSize + // && sw.ElapsedMilliseconds < timeout + // ) + //{ + + // len = client.Receive(responseBody, respinfo.loadedLenght, chunkedSize - onechunkLen, SocketFlags.None); + // if (len > 0) + // { + // onechunkLen += len; + // respinfo.loadedLenght += len; + // } + //} + + int onechunkLen = 0; + while (onechunkLen < chunkedSize + && sw.ElapsedMilliseconds < timeout + ) + { + //len = client.Receive(responseBody, respinfo.loadedLenght, chunkedSize - onechunkLen, SocketFlags.None); + + int readsize = chunkedSize - onechunkLen; + readsize = Math.Min(readsize, singlePkgMaxRead); + len = client.Receive(temp_responseBody, 0, readsize, SocketFlags.None); + if (len > 0) + { + memoryStream.Write(temp_responseBody, 0, len); + onechunkLen += len; + respinfo.loadedLenght += len; + } + } + + //判断 + } while (sw.ElapsedMilliseconds < timeout); + } + //connection close方式或未知body长度 + else + { + Log("connection close or Unknow bodylenght"); + while (sw.ElapsedMilliseconds < timeout) + { + if (client.Poll(timeout, SelectMode.SelectRead)) + { + if (client.Available > 0) + { + //len = client.Receive(responseBody, respinfo.loadedLenght, (1024 * 200) - respinfo.loadedLenght, SocketFlags.None); + int readsize = (1024 * 200) - respinfo.loadedLenght; + readsize = Math.Min(readsize, singlePkgMaxRead); + len = client.Receive(temp_responseBody, 0, readsize, SocketFlags.None); + + if (len > 0) + { + memoryStream.Write(temp_responseBody, 0, len); + respinfo.loadedLenght += len; + } + } + else + { + break; + } + } + } + } + + + byte[] responseBody = memoryStream.ToArray(); + //如果是下载 + if (respinfo.downloadMode > AxiDownLoadMode.NotDownLoad) + { + //判断是否gzip + if (respinfo.headers.ContainsKey(Content_Encoding)) + { + respinfo.bodyRaw = unGzipBytes(responseBody, respinfo.loadedLenght); + } + else + { + respinfo.bodyRaw = responseBody; + } + + // 使用Uri类解析URL + Uri uri = new Uri(url); + respinfo.fileName = Path.GetFileName(uri.LocalPath); + } + else + { + //判断是否gzip + if (respinfo.headers.ContainsKey(Content_Encoding)) + { + respinfo.body = unGzip(responseBody, respinfo.loadedLenght, encod); + } + else + { + respinfo.body = encod.GetString(responseBody, 0, respinfo.loadedLenght); + } + } + + client.Close(); + } + + } + catch (Exception ex) + { + respinfo.ErrInfo = $"ex : {ex.ToString()}"; + } + finally + { + sw.Stop(); + respinfo.length = respinfo.loadedLenght; + respinfo.runTime = (int)sw.ElapsedMilliseconds; + respinfo.bTimeOut = sw.ElapsedMilliseconds >= timeout; + //if (socket != null) + //{ + // clientSocket.Close(); + //} + respinfo.isDone = true; + } + } + + + static void SendAxiRequestHttps(string url, ref AxiRespInfo respinfo, int timeout, string encoding) + { + respinfo.url = url; + Stopwatch sw = new Stopwatch(); + sw.Start(); + respinfo.loadedLenght = 0; + TcpClient client = null; + try + { + string strURI = url; + string strHost = ""; + string strIP = ""; + int port = 0; + string strRelativePath = ""; + bool bSSL = false; + bool foward_302 = true; + string ourErrMsg = ""; + + if (!ParseURI(strURI, ref bSSL, ref strHost, ref strIP, ref port, ref strRelativePath, ref ourErrMsg)) + { + Log("ParseURI False"); + respinfo.ErrInfo = ourErrMsg; + respinfo.code = 0; + respinfo.isDone = true; + return; + } + + //var ip = Dns.GetHostEntry(strHost).AddressList[0]; + //var ipEndPoint = new IPEndPoint(ip, port); + + //using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + //using (TcpClient tcpclient = new TcpClient()) + using (MemoryStream memoryStream = new MemoryStream()) + { + //client.Connect(ipEndPoint); + + TimeOutSocket tos = new TimeOutSocket(); + client = tos.Connect(strHost, port, timeout); + if (!client.Connected) + { + client.Close(); + sw.Stop(); + respinfo.code = 0; + respinfo.isDone = true; + return; + } + SslStream ssl = null; + + //string requestRaw = $"GET {strRelativePath} HTTP/1.1\r\nHost: {strHost}\r\nConnection: Close\r\n\r\n"; + string request = $"GET {strURI} HTTP/1.1\r\nHost: {strHost}\r\nConnection: Close\r\n\r\n"; + + ssl = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate)); + SslProtocols protocol = SslProtocols.Ssl3 | SslProtocols.Ssl2 | SslProtocols.Tls; + ssl.AuthenticateAsClient(strHost, null, protocol, false); + if (ssl.IsAuthenticated) + { + checkContentLength(ref respinfo, ref request); + respinfo.requestRaw = request; + byte[] requestByte = Encoding.UTF8.GetBytes(request); + ssl.Write(requestByte); + ssl.Flush(); + } + + + checkContentLength(ref respinfo, ref request); + respinfo.requestRaw = request; + byte[] temp_responseBody = new byte[singlePkgMaxRead]; + + //byte[] buffer = Encoding.ASCII.GetBytes(requestRaw); + //client.Send(buffer); + + string tmp = ""; + int len = 0; + StringBuilder sb = new StringBuilder(); + do + { + byte[] responseHeader = new byte[1]; + int read = ssl.ReadByte(); + + char c = (char)read; + sb.Append(c); + if (c.Equals(T)) + { + tmp = String.Concat(sb[sb.Length - 4], sb[sb.Length - 3], sb[sb.Length - 2], c); + } + + } while (!tmp.Equals(CTRL) + && sw.ElapsedMilliseconds < timeout + ); + + + respinfo.header = sb.ToString().Replace(CTRL, ""); + string[] headers = Regex.Split(respinfo.header, CT); + if (headers != null && headers.Length > 0) + { + //处理header + doHeader(ref respinfo, ref headers); + } + //自动修正编码 + if (!String.IsNullOrEmpty(respinfo.encoding)) + { + encoding = respinfo.encoding; + } + Encoding encod = Encoding.GetEncoding(encoding); + + //302 301跳转 + if ((respinfo.code == 302 || respinfo.code == 301) && foward_302) + { + int urlStart = respinfo.requestRaw.IndexOf(" "); + int urlEnd = respinfo.requestRaw.IndexOf(" HTTP"); + if (urlStart != -1 && urlEnd != -1) + { + url = respinfo.requestRaw.Substring(urlStart + 1, urlEnd - urlStart - 1); + if (!respinfo.headers["location"].StartsWith("/") && !respinfo.headers["location"].StartsWith("https")) + { + respinfo.requestRaw = respinfo.requestRaw.Replace(url, Tools.getCurrentPath(url) + respinfo.headers["location"]); + } + else + { + respinfo.requestRaw = respinfo.requestRaw.Replace(url, respinfo.headers["location"]); + } + //return sendHTTPRequest(count, host, port, payload, rsb.ToString(), timeout, encoding, false); + client.Close(); + sw.Stop(); + SendAxiRequest(url, ref respinfo, timeout, encoding); + return; + } + } + + //根据请求头解析 + if (respinfo.headers.ContainsKey(Content_Length)) + { + Log("Use Head"); + int length = int.Parse(respinfo.headers[Content_Length]); + respinfo.NeedloadedLenght = length; + while (respinfo.loadedLenght < length && sw.ElapsedMilliseconds < timeout) + { + //len = ssl.Read(responseBody, respinfo.loadedLenght, length - respinfo.loadedLenght); + int readsize = length - respinfo.loadedLenght; + readsize = Math.Min(readsize, singlePkgMaxRead); + len = ssl.Read(temp_responseBody, 0, readsize); + if (len > 0) + { + memoryStream.Write(temp_responseBody, 0, len); + respinfo.loadedLenght += len; + } + } + } + //解析chunked传输 + else if (respinfo.headers.ContainsKey(Transfer_Encoding)) + { + Log("User chunked"); + //读取长度 + int chunkedSize = 0; + byte[] chunkedByte = new byte[1]; + //读取总长度 + respinfo.loadedLenght = 0; + do + { + string ctmp = ""; + do + { + len = ssl.Read(chunkedByte, 0, 1); + ctmp += Encoding.UTF8.GetString(chunkedByte); + + } while (ctmp.IndexOf(CT) == -1 && sw.ElapsedMilliseconds < timeout); + + + chunkedSize = Tools.convertToIntBy16(ctmp.Replace(CT, "")); + + //chunked的结束0\r\n\r\n是结束标志,单个chunked块\r\n结束 + if (ctmp.Equals(CT)) + { + continue; + } + if (chunkedSize == 0) + { + //结束了 + break; + } + int onechunkLen = 0; + while (onechunkLen < chunkedSize && sw.ElapsedMilliseconds < timeout) + { + //len = ssl.Read(responseBody, respinfo.loadedLenght, chunkedSize - onechunkLen); + int readsize = chunkedSize - onechunkLen; + readsize = Math.Min(readsize, singlePkgMaxRead); + len = ssl.Read(temp_responseBody, 0, readsize); + if (len > 0) + { + memoryStream.Write(temp_responseBody, 0, len); + onechunkLen += len; + respinfo.loadedLenght += len; + } + } + + //判断 + } while (sw.ElapsedMilliseconds < timeout); + } + //connection close方式或未知body长度 + else + { + Log("connection close or Unknow bodylenght"); + while (sw.ElapsedMilliseconds < timeout) + { + while (sw.ElapsedMilliseconds < timeout) + { + if (client.Client.Poll(timeout, SelectMode.SelectRead)) + { + if (client.Available > 0) + { + //len = ssl.Read(responseBody, respinfo.loadedLenght, (1024 * 200) - respinfo.loadedLenght); + int readsize = (1024 * 200) - respinfo.loadedLenght; + readsize = Math.Min(readsize, singlePkgMaxRead); + len = ssl.Read(temp_responseBody, 0, readsize); + if (len > 0) + { + memoryStream.Write(temp_responseBody, 0, len); + respinfo.loadedLenght += len; + } + } + else + { + break; + } + } + } + } + } + + byte[] responseBody = memoryStream.ToArray(); + //如果是下载 + if (respinfo.downloadMode > AxiDownLoadMode.NotDownLoad) + { + //判断是否gzip + if (respinfo.isGzip) + { + respinfo.bodyRaw = unGzipBytes(responseBody, respinfo.loadedLenght); + } + else + { + respinfo.bodyRaw = responseBody; + } + + // 使用Uri类解析URL + Uri uri = new Uri(url); + respinfo.fileName = Path.GetFileName(uri.LocalPath); + } + else + { + //判断是否gzip + if (respinfo.isGzip) + { + respinfo.body = unGzip(responseBody, respinfo.loadedLenght, encod); + } + else + { + respinfo.body = encod.GetString(responseBody, 0, respinfo.loadedLenght); + } + } + + } + + } + catch (Exception ex) + { + respinfo.ErrInfo = $"ex : {ex.ToString()}"; + } + finally + { + client?.Close(); + sw.Stop(); + respinfo.length = respinfo.loadedLenght; + respinfo.runTime = (int)sw.ElapsedMilliseconds; + respinfo.bTimeOut = sw.ElapsedMilliseconds >= timeout; + //if (socket != null) + //{ + // clientSocket.Close(); + //} + respinfo.isDone = true; + } + + if (client != null) + client.Dispose(); + } + + + private static void doHeader(ref AxiRespInfo respinfo, ref string[] headers) + { + + for (int i = 0; i < headers.Length; i++) + { + if (i == 0) + { + respinfo.code = Tools.convertToInt(headers[i].Split(' ')[1]); + if (respinfo.code != 200 && respinfo.code != 301 && respinfo.code != 302) + respinfo.ErrInfo = "code:" + respinfo.code; + } + else + { + String[] kv = Regex.Split(headers[i], ": "); + String key = kv[0].ToLower(); + if (!respinfo.headers.ContainsKey(key)) + { + //自动识别编码 + if ("content-type".Equals(key)) + { + String hecnode = getHTMLEncoding(kv[1], ""); + if (!String.IsNullOrEmpty(hecnode)) + { + respinfo.encoding = hecnode; + } + } + if (kv.Length > 1) + { + respinfo.headers.Add(key, kv[1]); + } + else + { + respinfo.headers.Add(key, ""); + } + } + } + respinfo.isGzip = respinfo.headers.ContainsKey(Content_Encoding); + } + + } + public static string unGzip(byte[] data, int len, Encoding encoding) + { + + string str = ""; + MemoryStream ms = new MemoryStream(data, 0, len); + GZipStream gs = new GZipStream(ms, CompressionMode.Decompress); + MemoryStream outbuf = new MemoryStream(); + byte[] block = new byte[1024]; + + try + { + + while (true) + { + int bytesRead = gs.Read(block, 0, block.Length); + if (bytesRead <= 0) + { + break; + } + else + { + outbuf.Write(block, 0, bytesRead); + } + } + str = encoding.GetString(outbuf.ToArray()); + } + catch (Exception e) + { + Log("解压Gzip发生异常----" + e.Message); + } + finally + { + outbuf.Close(); + gs.Close(); + ms.Close(); + + } + return str; + + } + + public static byte[] unGzipBytes(byte[] data, int len) + { + MemoryStream ms = new MemoryStream(data, 0, len); + GZipStream gs = new GZipStream(ms, CompressionMode.Decompress); + MemoryStream outbuf = new MemoryStream(); + byte[] block = new byte[1024]; + byte[] result; + try + { + + while (true) + { + int bytesRead = gs.Read(block, 0, block.Length); + if (bytesRead <= 0) + { + break; + } + else + { + outbuf.Write(block, 0, bytesRead); + } + } + result = outbuf.ToArray(); + } + catch (Exception e) + { + Log("解压Gzip发生异常----" + e.Message); + result = new byte[0]; + } + finally + { + outbuf.Close(); + gs.Close(); + ms.Close(); + + } + return result; + + } + public static string getHTMLEncoding(string header, string body) + { + if (string.IsNullOrEmpty(header) && string.IsNullOrEmpty(body)) + { + return ""; + } + body = body.ToUpper(); + Match m = Regex.Match(header, @"charset\b\s*=\s*""?(?[^""]*)", RegexOptions.IgnoreCase); + if (m.Success) + { + return m.Groups["charset"].Value.ToUpper(); + } + else + { + if (string.IsNullOrEmpty(body)) + { + return ""; + } + m = Regex.Match(body, @"charset\b\s*=\s*""?(?[^""]*)", RegexOptions.IgnoreCase); + if (m.Success) + { + return m.Groups["charset"].Value.ToUpper(); + } + } + return ""; + } + private static void checkContentLength(ref AxiRespInfo respinfo, ref string request) + { + + //重新计算并设置Content-length + int sindex = request.IndexOf(CTRL); + respinfo.reuqestHeader = request; + if (sindex != -1) + { + respinfo.reuqestHeader = request.Substring(0, sindex); + respinfo.reuqestBody = request.Substring(sindex + 4, request.Length - sindex - 4); + int contentLength = Encoding.UTF8.GetBytes(respinfo.reuqestBody).Length; + String newContentLength = Content_Length_Str_M + contentLength; + + if (request.IndexOf(Content_Length_Str_M) != -1) + { + request = Regex.Replace(request, Content_Length_Str_M + "\\d+", newContentLength); + } + else + { + request = request.Insert(sindex, "\r\n" + newContentLength); + } + } + else + { + request = Regex.Replace(request, Content_Length_Str + "\\d+", Content_Length_Str_M + "0"); + request += CTRL; + } + + + } + private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) + { + return true; + } + public static bool ParseURI(string strURI, + ref bool bIsSSL, + ref string strHost, + ref string strIP, + ref int Port, + ref string strRelativePath, + ref string errMsg) + { + string strAddressRet; + string strPortRet; + string strRelativePathRet; + string strIPRet; + + /*string strProtocol = strURI.Substring(0, 7); if (strProtocol != "http://" || strProtocol != "https://") - return false;*/ - - if (!strURI.ToLower().StartsWith("http://") || strURI.ToLower().StartsWith("https://")) - return false; - - bIsSSL = strURI.ToLower().StartsWith("https://"); - - string strLeft = strURI.Substring(7, strURI.Length - 7); - int nIndexPort = strLeft.IndexOf(':'); - if (nIndexPort == -1) - { - if (bIsSSL) - strPortRet = "443"; - else - strPortRet = "80"; - int nIndexRelative = strLeft.IndexOf('/'); - if (nIndexRelative != -1) - { - strAddressRet = strLeft.Substring(0, nIndexRelative); - strRelativePathRet = strLeft.Substring(nIndexRelative, strLeft.Length - nIndexRelative); - } - else - { - errMsg = "Err Url"; - return false; - } - } - else - { - strAddressRet = strLeft.Substring(0, nIndexPort); - int nIndexRelative = strLeft.IndexOf('/'); - if (nIndexRelative != -1) - { - strPortRet = strLeft.Substring(nIndexPort + 1, nIndexRelative - (nIndexPort + 1)); - strRelativePathRet = strLeft.Substring(nIndexRelative, strLeft.Length - nIndexRelative); - } - else - { - errMsg = "Err Url"; - return false; - } - } - strHost = strAddressRet; - try - { - strIPRet = GetDnsIP(strAddressRet).ToString(); - } - catch (Exception ex) - { - errMsg = ex.ToString(); - return false; - } - - strIP = strIPRet; - Port = int.Parse(strPortRet); - strRelativePath = UrlEncode(strRelativePathRet); - return true; - } - - - public static string UrlEncode(string str) - { - string sb = ""; - List filter = new List() { '!', '#', '$', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '=', '?', '@', '_', '~' }; - byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //System.Text.Encoding.Default.GetBytes(str) - for (int i = 0; i < byStr.Length; i++) - { - if (filter.Contains((char)byStr[i])) - sb += (char)byStr[i]; - else if ((char)byStr[i] >= 'a' && (char)byStr[i] <= 'z') - sb += (char)byStr[i]; - else if ((char)byStr[i] >= 'A' && (char)byStr[i] <= 'Z') - sb += (char)byStr[i]; - else if ((char)byStr[i] >= '0' && (char)byStr[i] <= '9') - sb += (char)byStr[i]; - else - sb += (@"%" + Convert.ToString(byStr[i], 16)); - } - return sb; - } - - - class Tools - { - public static long currentMillis() - { - return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; - } - - /// - /// 将16进制转换成10进制 - /// - /// 16进制字符串 - /// - public static int convertToIntBy16(String str) - { - try - { - //Log($"convertToIntBy16 str- {str} lenght->{str.Length}"); - if (str.Length == 0) - return 0; - return Convert.ToInt32(str, 16); - } - catch (Exception e) - { - Log($"convertToIntBy16 - {e.ToString()}"); - } - return 0; - - } - public static String getCurrentPath(String url) - { - int index = url.LastIndexOf("/"); - - if (index != -1) - { - return url.Substring(0, index) + "/"; - } - else - { - return ""; - } - } - - - /// - /// 将字符串转换成数字,错误返回0 - /// - /// 字符串 - /// - public static int convertToInt(String str) - { - - try - { - return int.Parse(str); - } - catch (Exception e) - { - Log("info:-" + e.Message); - } - return 0; - - } - - } - class TimeOutSocket - { - private bool IsConnectionSuccessful = false; - private Exception socketexception = null; - private ManualResetEvent TimeoutObject = new ManualResetEvent(false); - public int useTime = 0; - public TcpClient Connect(string host, int port, int timeoutMSec) - { - Stopwatch sw = new Stopwatch(); - sw.Start(); - TimeoutObject.Reset(); - socketexception = null; - - TcpClient tcpclient = new TcpClient(); - - //IPHostEntry hostinfo = Dns.GetHostEntry("emu.axibug.com"); - //IPAddress[] aryIP = hostinfo.AddressList; - //host = aryIP[0].ToString(); - - Log($"BeginConnect {host}:{port} timeoutMSec=>{timeoutMSec}"); - tcpclient.BeginConnect(host, port, new AsyncCallback(CallBackMethod), tcpclient); - - if (TimeoutObject.WaitOne(timeoutMSec, false)) - { - if (IsConnectionSuccessful) - { - sw.Stop(); - useTime = (int)sw.ElapsedMilliseconds; - return tcpclient; - } - else - { - throw socketexception; - } - } - else - { - tcpclient.Close(); - throw new TimeoutException("TimeOut Exception"); - } - } - private void CallBackMethod(IAsyncResult asyncresult) - { - try - { - IsConnectionSuccessful = false; - TcpClient tcpclient = asyncresult.AsyncState as TcpClient; - - if (tcpclient.Client != null) - { - tcpclient.EndConnect(asyncresult); - IsConnectionSuccessful = true; - } - } - catch (Exception ex) - { - Log($"CallBackMethod - {ex.ToString()}"); - IsConnectionSuccessful = false; - socketexception = ex; - } - finally - { - TimeoutObject.Set(); - } - } - } + return false;*/ + + if (!strURI.ToLower().StartsWith("http://") || strURI.ToLower().StartsWith("https://")) + return false; + + bIsSSL = strURI.ToLower().StartsWith("https://"); + + string strLeft = strURI.Substring(7, strURI.Length - 7); + int nIndexPort = strLeft.IndexOf(':'); + if (nIndexPort == -1) + { + if (bIsSSL) + strPortRet = "443"; + else + strPortRet = "80"; + int nIndexRelative = strLeft.IndexOf('/'); + if (nIndexRelative != -1) + { + strAddressRet = strLeft.Substring(0, nIndexRelative); + strRelativePathRet = strLeft.Substring(nIndexRelative, strLeft.Length - nIndexRelative); + } + else + { + errMsg = "Err Url"; + return false; + } + } + else + { + strAddressRet = strLeft.Substring(0, nIndexPort); + int nIndexRelative = strLeft.IndexOf('/'); + if (nIndexRelative != -1) + { + strPortRet = strLeft.Substring(nIndexPort + 1, nIndexRelative - (nIndexPort + 1)); + strRelativePathRet = strLeft.Substring(nIndexRelative, strLeft.Length - nIndexRelative); + } + else + { + errMsg = "Err Url"; + return false; + } + } + strHost = strAddressRet; + try + { + strIPRet = GetDnsIP(strAddressRet).ToString(); + } + catch (Exception ex) + { + errMsg = ex.ToString(); + return false; + } + + strIP = strIPRet; + Port = int.Parse(strPortRet); + strRelativePath = UrlEncode(strRelativePathRet); + return true; + } + + + public static string UrlEncode(string str) + { + string sb = ""; + List filter = new List() { '!', '#', '$', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '=', '?', '@', '_', '~' }; + byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //System.Text.Encoding.Default.GetBytes(str) + for (int i = 0; i < byStr.Length; i++) + { + if (filter.Contains((char)byStr[i])) + sb += (char)byStr[i]; + else if ((char)byStr[i] >= 'a' && (char)byStr[i] <= 'z') + sb += (char)byStr[i]; + else if ((char)byStr[i] >= 'A' && (char)byStr[i] <= 'Z') + sb += (char)byStr[i]; + else if ((char)byStr[i] >= '0' && (char)byStr[i] <= '9') + sb += (char)byStr[i]; + else + sb += (@"%" + Convert.ToString(byStr[i], 16)); + } + return sb; + } + + + class Tools + { + public static long currentMillis() + { + return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; + } + + /// + /// 将16进制转换成10进制 + /// + /// 16进制字符串 + /// + public static int convertToIntBy16(String str) + { + try + { + //Log($"convertToIntBy16 str- {str} lenght->{str.Length}"); + if (str.Length == 0) + return 0; + return Convert.ToInt32(str, 16); + } + catch (Exception e) + { + Log($"convertToIntBy16 - {e.ToString()}"); + } + return 0; + + } + public static String getCurrentPath(String url) + { + int index = url.LastIndexOf("/"); + + if (index != -1) + { + return url.Substring(0, index) + "/"; + } + else + { + return ""; + } + } + + + /// + /// 将字符串转换成数字,错误返回0 + /// + /// 字符串 + /// + public static int convertToInt(String str) + { + + try + { + return int.Parse(str); + } + catch (Exception e) + { + Log("info:-" + e.Message); + } + return 0; + + } + + } + class TimeOutSocket + { + private bool IsConnectionSuccessful = false; + private Exception socketexception = null; + private ManualResetEvent TimeoutObject = new ManualResetEvent(false); + public int useTime = 0; + public TcpClient Connect(string host, int port, int timeoutMSec) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + TimeoutObject.Reset(); + socketexception = null; + + TcpClient tcpclient = new TcpClient(); + + //IPHostEntry hostinfo = Dns.GetHostEntry("emu.axibug.com"); + //IPAddress[] aryIP = hostinfo.AddressList; + //host = aryIP[0].ToString(); + + Log($"BeginConnect {host}:{port} timeoutMSec=>{timeoutMSec}"); + tcpclient.BeginConnect(host, port, new AsyncCallback(CallBackMethod), tcpclient); + + if (TimeoutObject.WaitOne(timeoutMSec, false)) + { + if (IsConnectionSuccessful) + { + sw.Stop(); + useTime = (int)sw.ElapsedMilliseconds; + return tcpclient; + } + else + { + throw socketexception; + } + } + else + { + tcpclient.Close(); + throw new TimeoutException("TimeOut Exception"); + } + } + private void CallBackMethod(IAsyncResult asyncresult) + { + try + { + IsConnectionSuccessful = false; + TcpClient tcpclient = asyncresult.AsyncState as TcpClient; + + if (tcpclient.Client != null) + { + tcpclient.EndConnect(asyncresult); + IsConnectionSuccessful = true; + } + } + catch (Exception ex) + { + Log($"CallBackMethod - {ex.ToString()}"); + IsConnectionSuccessful = false; + socketexception = ex; + } + finally + { + TimeoutObject.Set(); + } + } + } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs index 16d81d2c..a559bed8 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs @@ -1,76 +1,76 @@ -using UnityEngine; +using UnityEngine; using static AxiHttp; public static class AxiHttpProxy -{ - public static SendWebRequestProxy Get(string url) - { - return new SendWebRequestProxy(AxiRequestAsync(url)); - } - - public static SendDownLoadProxy GetDownLoad(string url) - { - return new SendDownLoadProxy(AxiDownloadAsync(url)); - } - - - public class SendWebRequestProxy - { - public WaitAxiRequest SendWebRequest; - public AxiRespInfo downloadHandler => SendWebRequest.mReqAsync; - public SendWebRequestProxy(WaitAxiRequest request) - { - SendWebRequest = request; - } - ~SendWebRequestProxy() - { - SendWebRequest = null; - } - } - - - public class SendDownLoadProxy - { - public AxiRespInfo downloadHandler; - public SendDownLoadProxy(AxiRespInfo re) - { - downloadHandler = re; - } - ~SendDownLoadProxy() - { - downloadHandler = null; - } - } - - - public static void ShowAxiHttpDebugInfo(AxiRespInfo resp) - { - +{ + public static SendWebRequestProxy Get(string url) + { + return new SendWebRequestProxy(AxiRequestAsync(url)); + } + + public static SendDownLoadProxy GetDownLoad(string url) + { + return new SendDownLoadProxy(AxiDownloadAsync(url)); + } + + + public class SendWebRequestProxy + { + public WaitAxiRequest SendWebRequest; + public AxiRespInfo downloadHandler => SendWebRequest.mReqAsync; + public SendWebRequestProxy(WaitAxiRequest request) + { + SendWebRequest = request; + } + ~SendWebRequestProxy() + { + SendWebRequest = null; + } + } + + + public class SendDownLoadProxy + { + public AxiRespInfo downloadHandler; + public SendDownLoadProxy(AxiRespInfo re) + { + downloadHandler = re; + } + ~SendDownLoadProxy() + { + downloadHandler = null; + } + } + + + public static void ShowAxiHttpDebugInfo(AxiRespInfo resp) + { + #if UNITY_EDITOR - Debug.Log($""); - Debug.Log($"==== request ===="); - Debug.Log($"url =>{resp.url}"); - Debug.Log($"Raw =>{resp.requestRaw}"); - Debug.Log($"code =>{resp.code}"); - Debug.Log($"respInfo.bTimeOut =>{resp.bTimeOut}"); - Debug.Log($""); - Debug.Log($"==== response ===="); - Debug.Log($"==== header ===="); - Debug.Log($"header =>{resp.header}"); - Debug.Log($"HeadersCount =>{resp.headers.Count}"); - foreach (var kv in resp.headers) - Debug.Log($"{kv.Key} => {kv.Value}"); - Debug.Log($""); - Debug.Log($"==== body ===="); - Debug.Log($"body_text =>{resp.body}"); - Debug.Log($"body_text.Length =>{resp.body.Length}"); - Debug.Log($"bodyRaw.Length =>{resp.bodyRaw?.Length}"); - Debug.Log($""); - Debug.Log($"==== download ===="); - Debug.Log($"downloadMode =>{resp.downloadMode}"); - Debug.Log($"respInfo.fileName =>{resp.fileName}"); - Debug.Log($"respInfo.NeedloadedLenght =>{resp.NeedloadedLenght}"); - Debug.Log($"respInfo.loadedLenght =>{resp.loadedLenght}"); + Debug.Log($""); + Debug.Log($"==== request ===="); + Debug.Log($"url =>{resp.url}"); + Debug.Log($"Raw =>{resp.requestRaw}"); + Debug.Log($"code =>{resp.code}"); + Debug.Log($"respInfo.bTimeOut =>{resp.bTimeOut}"); + Debug.Log($""); + Debug.Log($"==== response ===="); + Debug.Log($"==== header ===="); + Debug.Log($"header =>{resp.header}"); + Debug.Log($"HeadersCount =>{resp.headers.Count}"); + foreach (var kv in resp.headers) + Debug.Log($"{kv.Key} => {kv.Value}"); + Debug.Log($""); + Debug.Log($"==== body ===="); + Debug.Log($"body_text =>{resp.body}"); + Debug.Log($"body_text.Length =>{resp.body.Length}"); + Debug.Log($"bodyRaw.Length =>{resp.bodyRaw?.Length}"); + Debug.Log($""); + Debug.Log($"==== download ===="); + Debug.Log($"downloadMode =>{resp.downloadMode}"); + Debug.Log($"respInfo.fileName =>{resp.fileName}"); + Debug.Log($"respInfo.NeedloadedLenght =>{resp.NeedloadedLenght}"); + Debug.Log($"respInfo.loadedLenght =>{resp.loadedLenght}"); #else Debug.Log($"==== request url => { resp.url}"); Debug.Log($"code =>{resp.code}"); @@ -87,33 +87,33 @@ public static class AxiHttpProxy Debug.Log($"respInfo.loadedLenght =>{resp.loadedLenght}"); } #endif - - //if (resp.downloadMode == AxiDownLoadMode.DownLoadBytes) - //{ - // if (resp.bTimeOut) - // { - // Debug.Log($"DownLoad Timeout!"); - // return; - // } - // string downloadSavePath; - // if (Application.platform == RuntimePlatform.PSP2) - // { - // downloadSavePath = dataAxibugPath + "/" + resp.fileName; - // } - // else - // { - // downloadSavePath = persistentDataPath + "/" + resp.fileName; - // } - // try - // { - // File.WriteAllBytes(downloadSavePath, resp.bodyRaw); - // Debug.Log($"DownLoad OK"); - // } - // catch (Exception ex) - // { - // Debug.Log($"DownLoad Err {ex.ToString()}"); - // } - //} - } + + //if (resp.downloadMode == AxiDownLoadMode.DownLoadBytes) + //{ + // if (resp.bTimeOut) + // { + // Debug.Log($"DownLoad Timeout!"); + // return; + // } + // string downloadSavePath; + // if (Application.platform == RuntimePlatform.PSP2) + // { + // downloadSavePath = dataAxibugPath + "/" + resp.fileName; + // } + // else + // { + // downloadSavePath = persistentDataPath + "/" + resp.fileName; + // } + // try + // { + // File.WriteAllBytes(downloadSavePath, resp.bodyRaw); + // Debug.Log($"DownLoad OK"); + // } + // catch (Exception ex) + // { + // Debug.Log($"DownLoad Err {ex.ToString()}"); + // } + //} + } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Initer.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Initer.cs index 894cc90a..f4ab415a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Initer.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Initer.cs @@ -12,10 +12,10 @@ namespace AxibugEmuOnline.Client public static string dev_UUID; [SerializeField] - GameObject IMPORTENT; - - - + GameObject IMPORTENT; + + + #if UNITY_EDITOR public bool bTest = false; public string mTestSrvIP = "192.168.0.47"; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs index efc85db7..85bc5f92 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs @@ -432,7 +432,7 @@ namespace AxibugEmuOnline.Client.Manager /// 发送修改玩家槽位,全量 /// /// 玩家占用房间GamePlaySlot和LocalJoyIdx字典 - public void SendChangePlaySlotIdxWithJoyIdx(Dictionary> dictSlotIdx2LocalJoyIdx) + public void SendChangePlaySlotIdxWithJoyIdx(Dictionary> dictSlotIdx2LocalJoyIdx) { if (!InRoom) return; @@ -617,7 +617,7 @@ namespace AxibugEmuOnline.Client.Manager public static bool GetPlayerGamePadTypeByPlayerIdx(this Protobuf_Room_MiniInfo roomMiniInfo, uint GameSlotIdx, out GamePadType gamePadType) { if (roomMiniInfo.GamePlaySlotList[(int)GameSlotIdx].PlayerUID > 0) - { + { gamePadType = roomMiniInfo.GamePlaySlotList[(int)GameSlotIdx].PlayerLocalGamePadType; return true; } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/1990-esque/Filter1990_esque.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/1990-esque/Filter1990_esque.cs index 89d05f62..66806c4c 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/1990-esque/Filter1990_esque.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/1990-esque/Filter1990_esque.cs @@ -1,6 +1,5 @@ -using AxibugEmuOnline.Client; +using AxibugEmuOnline.Client; using UnityEngine; -using UnityEngine.Rendering; public class Filter1990_esque : FilterEffect { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterChainEffect.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterChainEffect.cs index d089c7a8..6508fad7 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterChainEffect.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterChainEffect.cs @@ -1,6 +1,5 @@ using Assets.Script.AppMain.Filter; using AxibugEmuOnline.Client; -using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Experimental.Rendering; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterParamerter.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterParamerter.cs index bd0f51d4..b155f072 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterParamerter.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterParamerter.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using UnityEngine; namespace Assets.Script.AppMain.Filter diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs index ff39204f..bb1cba26 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs @@ -1,10 +1,9 @@ -using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.ClientCore; using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; -using UnityEngine.Networking; namespace AxibugEmuOnline.Client { @@ -26,8 +25,8 @@ namespace AxibugEmuOnline.Client } IEnumerator DownloadFromURL(string url, string path, Action callback) - { - AxiHttpProxy.SendDownLoadProxy request = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{url}"); + { + AxiHttpProxy.SendDownLoadProxy request = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{url}"); while (!request.downloadHandler.isDone) { @@ -61,14 +60,14 @@ namespace AxibugEmuOnline.Client } private Dictionary cachesInMemory = new Dictionary(); - void GetCacheData(string url, string path, Action callback) where T : class - { - object cacheObj; - - if (cachesInMemory.TryGetValue(url, out cacheObj) && cacheObj is T) + void GetCacheData(string url, string path, Action callback) where T : class + { + object cacheObj; + + if (cachesInMemory.TryGetValue(url, out cacheObj) && cacheObj is T) { - T obj = (T)cacheObj; - callback.Invoke(obj, url); + T obj = (T)cacheObj; + callback.Invoke(obj, url); return; } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs index 078a16db..d3e3bbc2 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs @@ -1,9 +1,7 @@ using AxibugEmuOnline.Client.ClientCore; -using AxibugProtobuf; using System; using System.Collections; using System.Collections.Generic; -using System.Text; using UnityEngine; namespace AxibugEmuOnline.Client @@ -18,14 +16,14 @@ namespace AxibugEmuOnline.Client public void GetNesRomList(Action callback, AxibugProtobuf.RomPlatformType platform, int page, int pageSize = 10) { - App.StartCoroutine(GetRomListFlow(platform,page, pageSize, callback)); + App.StartCoroutine(GetRomListFlow(platform, page, pageSize, callback)); } public void SearchNesRomList(Action callback, AxibugProtobuf.RomPlatformType platform, string searchKey, int page, int pageSize = 10) { - App.StartCoroutine(SearchNesRomListFlow(platform,searchKey, page, pageSize, callback)); + App.StartCoroutine(SearchNesRomListFlow(platform, searchKey, page, pageSize, callback)); } - private IEnumerator SearchNesRomListFlow(AxibugProtobuf.RomPlatformType platform,string searchKey, int page, int pageSize, Action callback) + private IEnumerator SearchNesRomListFlow(AxibugProtobuf.RomPlatformType platform, string searchKey, int page, int pageSize, Action callback) { if (!string.IsNullOrEmpty(searchKey)) { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/UserDataManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/UserDataManager.cs index da91a8de..e25de19a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/UserDataManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/UserDataManager.cs @@ -154,18 +154,18 @@ namespace AxibugEmuOnline.Client.Manager for (int i = 0; i < msg.UserList.Count; i++) { UserMiniInfo mi = msg.UserList[i]; - bool isNewUser; - UpdateOrAddUser(mi, out isNewUser); + bool isNewUser; + UpdateOrAddUser(mi, out isNewUser); } Eventer.Instance.PostEvent(EEvent.OnUserListAllUpdate); } public void RecvCmdUserJoin(byte[] reqData) { Protobuf_UserJoin_RESP msg = ProtoBufHelper.DeSerizlize(reqData); - bool isNewUser; - UpdateOrAddUser(msg.UserInfo, out isNewUser); + bool isNewUser; + UpdateOrAddUser(msg.UserInfo, out isNewUser); if (isNewUser) - { + { Eventer.Instance.PostEvent(EEvent.OnUserLogin, msg.UserInfo.UID, msg.UserInfo.NickName); OverlayManager.PopTip($"玩家[{msg.UserInfo.NickName}]上线了"); } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/MsgBool.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/MsgBool.cs index b151d79f..e81f0987 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/MsgBool.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/MsgBool.cs @@ -1,15 +1,15 @@ -/// -/// StringBoolķϹ +/// +/// String和Bool的缝合怪 /// public struct MsgBool { public string ErrorMsg; - public bool Value; - - //low C# readonly - //public override readonly string ToString() - - public override string ToString() + public bool Value; + + //low C# readonly + //public override readonly string ToString() + + public override string ToString() { if (Value) { @@ -34,15 +34,15 @@ public struct MsgBool public static implicit operator bool(MsgBool msgBool) { return msgBool.Value; - } - - //low C# - //public static implicit operator (bool, string)(MsgBool msgBool) - //{ - // return (msgBool.Value, msgBool.ErrorMsg); - //} - - public static implicit operator string(MsgBool msgBool) + } + + //low C# + //public static implicit operator (bool, string)(MsgBool msgBool) + //{ + // return (msgBool.Value, msgBool.ErrorMsg); + //} + + public static implicit operator string(MsgBool msgBool) { return msgBool.ToString(); } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs index ad326776..f3b0cc93 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs @@ -106,10 +106,10 @@ namespace AxibugEmuOnline.Client uint LastTestInput = 0; public void SampleInput(uint frameIndex) { - if (InGameUI.Instance.IsNetPlay) - { - int targetFrame; ReplayStep replayData; int frameDiff; bool inputDiff; - if (App.roomMgr.netReplay.TryGetNextFrame((int)frameIndex, out replayData, out frameDiff, out inputDiff)) + if (InGameUI.Instance.IsNetPlay) + { + int targetFrame; ReplayStep replayData; int frameDiff; bool inputDiff; + if (App.roomMgr.netReplay.TryGetNextFrame((int)frameIndex, out replayData, out frameDiff, out inputDiff)) { if (inputDiff) { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs index ec7024cf..f656e589 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs @@ -1,5 +1,4 @@ -using AxibugEmuOnline.Client.ClientCore; -using AxibugEmuOnline.Client.Common; +using AxibugEmuOnline.Client.Common; using AxibugEmuOnline.Client.Event; using System.Collections.Generic; using System.Linq; @@ -91,7 +90,7 @@ namespace AxibugEmuOnline.Client Controller targetController; switch (conIndex) { - case 0: targetController = Controller0;break; + case 0: targetController = Controller0; break; case 1: targetController = Controller1; break; case 2: targetController = Controller2; break; case 3: targetController = Controller3; break; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs index d7d40b9f..c6455ae4 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs @@ -1,10 +1,10 @@ -using System; +using AxibugEmuOnline.Client.ClientCore; +using AxibugProtobuf; +using System; using System.Diagnostics; using System.Globalization; using System.IO; using System.Xml.Linq; -using AxibugEmuOnline.Client.ClientCore; -using AxibugProtobuf; using UnityEditor; using UnityEngine; using VirtualNes.Core; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/PaletteDefine.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/PaletteDefine.cs index bd1c78a2..ce44b66b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/PaletteDefine.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/PaletteDefine.cs @@ -1,6 +1,4 @@ -using VirtualNes.Core; - -namespace AxibugEmuOnline.Client +namespace AxibugEmuOnline.Client { public static class PaletteDefine { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetMsg.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetMsg.cs index b4087dd0..ddad8ec7 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetMsg.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetMsg.cs @@ -66,7 +66,7 @@ namespace AxibugEmuOnline.Client.Network { lock (lockQueueObj) { - queueNetMsg.Enqueue(new ValueTuple(cmd, ERRCODE, arg)); + queueNetMsg.Enqueue(new ValueTuple(cmd, ERRCODE, arg)); } } @@ -75,9 +75,9 @@ namespace AxibugEmuOnline.Client.Network lock (lockQueueObj) { while (queueNetMsg.Count > 0) - { - - var msgData = queueNetMsg.Dequeue(); + { + + var msgData = queueNetMsg.Dequeue(); PostNetMsgEvent(msgData.Item1, msgData.Item2, msgData.Item3); } } @@ -88,7 +88,7 @@ namespace AxibugEmuOnline.Client.Network ErrorCode err = ((ErrorCode)ERRCODE); if (err != ErrorCode.ErrorOk) { - OverlayManager.PopTip("错误:"+err.ToString()); + OverlayManager.PopTip("错误:" + err.ToString()); } List eventList = GetNetEventDicList(cmd); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/BackgroundListMenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/BackgroundListMenuItem.cs index b0a55925..4dfae4b4 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/BackgroundListMenuItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/BackgroundListMenuItem.cs @@ -1,5 +1,4 @@ using AxibugEmuOnline.Client.ClientCore; -using System; using System.Collections.Generic; namespace AxibugEmuOnline.Client diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/GlobalFilterListMenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/GlobalFilterListMenuItem.cs index 2205ef6b..5f682ab5 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/GlobalFilterListMenuItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/GlobalFilterListMenuItem.cs @@ -1,5 +1,4 @@ using AxibugEmuOnline.Client.ClientCore; -using System; using System.Collections.Generic; using System.Linq; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/UI_FilterItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/UI_FilterItem.cs index 3be94c99..548702f9 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/UI_FilterItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/UI_FilterItem.cs @@ -8,191 +8,191 @@ using static AxibugEmuOnline.Client.FilterManager; namespace AxibugEmuOnline.Client { - /// - /// 滤镜预览UI - /// - public class UI_FilterItem : MenuItem, IVirtualItem - { - public int Index { get; set; } - public Filter Datacontext { get; private set; } + /// + /// 滤镜预览UI + /// + public class UI_FilterItem : MenuItem, IVirtualItem + { + public int Index { get; set; } + public Filter Datacontext { get; private set; } - public void SetData(object data) - { - Datacontext = data as Filter; + public void SetData(object data) + { + Datacontext = data as Filter; - UpdateView(); - } + UpdateView(); + } - private void UpdateView() - { - if (Datacontext == null) - SetBaseInfo("无", null, null); - else - SetBaseInfo(Datacontext.Name, $"参数数量:{Datacontext.Paramerters.Count}", null); - } + private void UpdateView() + { + if (Datacontext == null) + SetBaseInfo("无", null, null); + else + SetBaseInfo(Datacontext.Name, $"参数数量:{Datacontext.Paramerters.Count}", null); + } - public void SetDependencyProperty(object data) - { - SetSelectState(data is ThirdMenuRoot && ((ThirdMenuRoot)data).SelectIndex == Index); + public void SetDependencyProperty(object data) + { + SetSelectState(data is ThirdMenuRoot && ((ThirdMenuRoot)data).SelectIndex == Index); - if (m_select) - { - App.settings.Filter.EnableFilterPreview(); - if (App.settings.Filter != null) - App.settings.Filter.EnableFilter(Datacontext); - else - App.settings.Filter.ShutDownFilter(); - } - } + if (m_select) + { + App.settings.Filter.EnableFilterPreview(); + if (App.settings.Filter != null) + App.settings.Filter.EnableFilter(Datacontext); + else + App.settings.Filter.ShutDownFilter(); + } + } - public void Release() { } + public void Release() { } - public override bool OnEnterItem() - { - if (Datacontext != null && Datacontext.Paramerters.Count > 0) - { - var opts = new List(); - opts.Add(new Opt_CreatePreset(Datacontext)); - opts.AddRange(Datacontext.Presets.Select(p => new Opt_Presets(Datacontext, p))); + public override bool OnEnterItem() + { + if (Datacontext != null && Datacontext.Paramerters.Count > 0) + { + var opts = new List(); + opts.Add(new Opt_CreatePreset(Datacontext)); + opts.AddRange(Datacontext.Presets.Select(p => new Opt_Presets(Datacontext, p))); - OverlayManager.PopSideBar(opts, onClose: () => - { - App.settings.Filter.EnableFilterPreview(); - Datacontext.ResetPreset(); - App.settings.Filter.EnableFilter(Datacontext); - }); - } - return false; - } + OverlayManager.PopSideBar(opts, onClose: () => + { + App.settings.Filter.EnableFilterPreview(); + Datacontext.ResetPreset(); + App.settings.Filter.EnableFilter(Datacontext); + }); + } + return false; + } - public class Opt_CreatePreset : ExecuteMenu - { - private Filter m_filter; + public class Opt_CreatePreset : ExecuteMenu + { + private Filter m_filter; - public Opt_CreatePreset(Filter filter) : base("创建滤镜预设", Resources.LoadAll("Icons/XMB-Icons/misc")[0]) - { - m_filter = filter; - } + public Opt_CreatePreset(Filter filter) : base("创建滤镜预设", Resources.LoadAll("Icons/XMB-Icons/misc")[0]) + { + m_filter = filter; + } - public override void OnFocus() - { - m_filter.ResetPreset(); - App.settings.Filter.EnableFilter(m_filter); - } + public override void OnFocus() + { + m_filter.ResetPreset(); + App.settings.Filter.EnableFilter(m_filter); + } - public override void OnExcute(OptionUI optionUI, ref bool cancelHide) - { - cancelHide = true; + public override void OnExcute(OptionUI optionUI, ref bool cancelHide) + { + cancelHide = true; - OverlayManager.Input((presetName) => - { - FilterPreset newPreset; - var result = m_filter.CreatePreset(presetName, out newPreset); - if (!result) OverlayManager.PopTip(result); - else optionUI.AddOptionMenuWhenPoping(new Opt_Presets(m_filter, newPreset)); - }, "为预设设置一个名称", string.Empty); - } - } - public class Opt_Presets : ExpandMenu - { - private Filter m_filter; - private FilterPreset m_preset; - private OptionUI_MenuItem m_ui; - private List m_menu; + OverlayManager.Input((presetName) => + { + FilterPreset newPreset; + var result = m_filter.CreatePreset(presetName, out newPreset); + if (!result) OverlayManager.PopTip(result); + else optionUI.AddOptionMenuWhenPoping(new Opt_Presets(m_filter, newPreset)); + }, "为预设设置一个名称", string.Empty); + } + } + public class Opt_Presets : ExpandMenu + { + private Filter m_filter; + private FilterPreset m_preset; + private OptionUI_MenuItem m_ui; + private List m_menu; - public Opt_Presets(Filter filter, FilterPreset preset) : base(preset.Name, null) - { - m_filter = filter; - m_preset = preset; + public Opt_Presets(Filter filter, FilterPreset preset) : base(preset.Name, null) + { + m_filter = filter; + m_preset = preset; - m_menu = new List(); - m_menu.Add(new Opt_Delete(m_filter, m_preset)); - foreach (var p in m_filter.Paramerters) - { - m_menu.Add(new Opt_ParamEditor(m_filter, p, m_preset)); - } - } + m_menu = new List(); + m_menu.Add(new Opt_Delete(m_filter, m_preset)); + foreach (var p in m_filter.Paramerters) + { + m_menu.Add(new Opt_ParamEditor(m_filter, p, m_preset)); + } + } - public override void OnShow(OptionUI_MenuItem ui) - { - EventInvoker.OnFilterPresetRemoved += EventInvoker_OnFilterPresetRemoved; - m_ui = ui; - base.OnShow(ui); - } + public override void OnShow(OptionUI_MenuItem ui) + { + EventInvoker.OnFilterPresetRemoved += EventInvoker_OnFilterPresetRemoved; + m_ui = ui; + base.OnShow(ui); + } - public override void OnHide() - { - EventInvoker.OnFilterPresetRemoved -= EventInvoker_OnFilterPresetRemoved; - } + public override void OnHide() + { + EventInvoker.OnFilterPresetRemoved -= EventInvoker_OnFilterPresetRemoved; + } - private void EventInvoker_OnFilterPresetRemoved(Filter filter, FilterPreset removedPreset) - { - if (filter != m_filter || m_preset != removedPreset) return; - m_ui.OptionUI.RemoveItem(m_ui); - } + private void EventInvoker_OnFilterPresetRemoved(Filter filter, FilterPreset removedPreset) + { + if (filter != m_filter || m_preset != removedPreset) return; + m_ui.OptionUI.RemoveItem(m_ui); + } - public override void OnFocus() - { - m_filter.ApplyPreset(m_preset); - App.settings.Filter.EnableFilter(m_filter); - } + public override void OnFocus() + { + m_filter.ApplyPreset(m_preset); + App.settings.Filter.EnableFilter(m_filter); + } - protected override List GetOptionMenus() - { - return m_menu; - } + protected override List GetOptionMenus() + { + return m_menu; + } - public class Opt_ParamEditor : ValueSetMenu - { - private Filter m_filter; - private FilterEffect.EditableParamerter m_param; - private FilterPreset m_preset; + public class Opt_ParamEditor : ValueSetMenu + { + private Filter m_filter; + private FilterEffect.EditableParamerter m_param; + private FilterPreset m_preset; - public override bool Visible => m_param.ValueType.IsEnum || m_param.ValueType == typeof(float); + public override bool Visible => m_param.ValueType.IsEnum || m_param.ValueType == typeof(float); - public Opt_ParamEditor(Filter filter, FilterEffect.EditableParamerter editParam, FilterPreset preset) - : base(editParam.Name) - { - m_filter = filter; - m_param = editParam; - m_preset = preset; - } + public Opt_ParamEditor(Filter filter, FilterEffect.EditableParamerter editParam, FilterPreset preset) + : base(editParam.Name) + { + m_filter = filter; + m_param = editParam; + m_preset = preset; + } - public override Type ValueType => m_param.ValueType; + public override Type ValueType => m_param.ValueType; - public override object ValueRaw => m_preset.GetParamValue(m_param.Name, ValueType) ?? m_param.Value; + public override object ValueRaw => m_preset.GetParamValue(m_param.Name, ValueType) ?? m_param.Value; - public override void OnValueChanged(object newValue) - { - m_preset.SetParamValue(m_param.Name, ValueType, newValue); - m_filter.SavePresets(); - m_param.Apply(newValue); - } + public override void OnValueChanged(object newValue) + { + m_preset.SetParamValue(m_param.Name, ValueType, newValue); + m_filter.SavePresets(); + m_param.Apply(newValue); + } - public override object Min => m_param.MinValue; + public override object Min => m_param.MinValue; - public override object Max => m_param.MaxValue; - } + public override object Max => m_param.MaxValue; + } - public class Opt_Delete : ExecuteMenu - { - private Filter m_filter; - private FilterPreset m_preset; + public class Opt_Delete : ExecuteMenu + { + private Filter m_filter; + private FilterPreset m_preset; - public Opt_Delete(Filter filter, FilterPreset preset) : base("删除预设", null) - { - m_filter = filter; - m_preset = preset; - } + public Opt_Delete(Filter filter, FilterPreset preset) : base("删除预设", null) + { + m_filter = filter; + m_preset = preset; + } - public override void OnExcute(OptionUI optionUI, ref bool cancelHide) - { - m_filter.RemovePreset(m_preset); - } - } + public override void OnExcute(OptionUI optionUI, ref bool cancelHide) + { + m_filter.RemovePreset(m_preset); + } + } - } - } + } + } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI_Scaler.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI_Scaler.cs index 012a0bab..2fc9d92c 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI_Scaler.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI_Scaler.cs @@ -1,7 +1,6 @@ using AxibugEmuOnline.Client.ClientCore; using System; using System.Collections.Generic; -using UnityEngine; using static AxibugEmuOnline.Client.ScreenScaler; namespace AxibugEmuOnline.Client diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/GameObjectPool.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/GameObjectPool.cs index f0ee729b..0d7e4cb2 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/GameObjectPool.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/GameObjectPool.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using UnityEngine; public static class GameObjectPool @@ -40,8 +40,8 @@ public static class GameObjectPool public static void Release(GameObject instance) { GameObject src; - Queue pool; - s_instanceToSrc.TryGetValue(instance, out src); + Queue pool; + s_instanceToSrc.TryGetValue(instance, out src); if (src != null && s_poolMap.TryGetValue(src, out pool)) { pool.Enqueue(instance); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/ItemPresent.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/ItemPresent.cs index a4b4cb53..87febc95 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/ItemPresent.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/ItemPresent.cs @@ -482,8 +482,8 @@ public class ItemPresent : GridLayoutGroup, IVirtualLayout } else if (dataList is IEnumerable) { - var ienumrable = (IEnumerable)dataList; - List temp = new List(); + var ienumrable = (IEnumerable)dataList; + List temp = new List(); foreach (var item in ienumrable) { temp.Add(item); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/ItemProxy.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/ItemProxy.cs index 36416433..489d2af5 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/ItemProxy.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/ItemPresent/ItemProxy.cs @@ -6,246 +6,246 @@ using UnityEngine.UI; public interface IVirtualLayout -{ - Dictionary CacheItemScripts { get; } - List DataList { get; } - object DependencyProperty { get; } - RectTransform RectTransform { get; } - RectTransform GetTemplate(object data); - Vector2 GetItemAnchorePos(int index); - RectTransform GetItemUIIfExist(int index); - - void UpdateProxyVisualState(); - void UpdateDependencyProperty(object dp); - void SetData(IEnumerable dataList); - void MoveToScrollViewCenter(ScrollRect scrollRect, int dataIndex); +{ + Dictionary CacheItemScripts { get; } + List DataList { get; } + object DependencyProperty { get; } + RectTransform RectTransform { get; } + RectTransform GetTemplate(object data); + Vector2 GetItemAnchorePos(int index); + RectTransform GetItemUIIfExist(int index); + + void UpdateProxyVisualState(); + void UpdateDependencyProperty(object dp); + void SetData(IEnumerable dataList); + void MoveToScrollViewCenter(ScrollRect scrollRect, int dataIndex); } public class ItemProxy -{ - public bool IsDestroyed; - public bool Visible = true; - public int Index; - public bool IsInViewRect; - - public Vector2 Pivot => _template.pivot; - public Vector2 AnchoredPosition; - - public float Width; - public float Height; - - private IVirtualLayout _parent; - - private RectTransform _template => _parent.GetTemplate(_parent.DataList[Index]); - private RectTransform _runtimeInstance; - private LayoutGroup _layoutElement; - - public RectTransform RuntimeItemUI => _runtimeInstance; - public bool firstShow { get; private set; } = true; - - public float PreferredWidth - { - get - { - if (_layoutElement == null) return 0; - - return _layoutElement.preferredWidth; - } - } - public float PreferredHeight - { - get - { - if (_layoutElement == null) return 0; - - return _layoutElement.preferredHeight; - } - } - - public ScripteInterface GetLuaObj() - { - if (_runtimeInstance == null) return null; - - ScripteInterface lfi; - - _parent.CacheItemScripts.TryGetValue(_runtimeInstance.gameObject, out lfi); - - return lfi; - } - - public ItemProxy(IVirtualLayout parent) - { - _parent = parent; - } - - public void Dispose() - { - if (_runtimeInstance != null) - { - if (Application.isPlaying) - { - GameObjectPool.Release(_runtimeInstance.gameObject); - } - else - GameObject.DestroyImmediate(_runtimeInstance.gameObject); - } - } - - public bool NeedShow - { - get - { - if (IsInViewRect && _runtimeInstance == null) return true; - else - { - if (_runtimeInstance != null && IsInViewRect && _runtimeInstance.anchoredPosition != AnchoredPosition) - return true; - else - return false; - } - } - - } - public bool NeedHide => !IsInViewRect && _runtimeInstance != null; - - public void UpdateView(bool force = false) - { - if (IsInViewRect) - { - if (_runtimeInstance == null) - { - _runtimeInstance = GetInstance(); - _layoutElement = _runtimeInstance.GetComponent(); - UpdateViewData(); - } - else if (force) - { - UpdateViewData(); - } - - UpdateLayout(); - } - else - { - ReleaseInstance(); - } - } - - public void UpdateLayout() - { - if (_runtimeInstance != null) - { - _runtimeInstance.gameObject.SetActive(true); - _runtimeInstance.anchorMax = Vector2.up; - _runtimeInstance.anchorMin = Vector2.up; - _runtimeInstance.anchoredPosition = AnchoredPosition; - _runtimeInstance.sizeDelta = new Vector2(Width, Height); - } - if (_layoutElement != null) - { - _layoutElement.CalculateLayoutInputHorizontal(); - _layoutElement.CalculateLayoutInputVertical(); - _layoutElement.SetLayoutHorizontal(); - _layoutElement.SetLayoutVertical(); - } - - } - - private void UpdateViewData() - { - if (Application.isPlaying) - { - if (!_parent.CacheItemScripts.ContainsKey(_runtimeInstance.gameObject)) - { - var vItem = _runtimeInstance.gameObject.GetComponent(); - ScripteInterface newSI = new ScripteInterface(vItem); - _parent.CacheItemScripts[_runtimeInstance.gameObject] = newSI; - } - - ScripteInterface si; - - _parent.CacheItemScripts.TryGetValue(_runtimeInstance.gameObject, out si); - si.SetDataList(_parent.DataList[Index], Index); - if (_parent.DependencyProperty != null) - si.SetDependencyProperty(_parent.DependencyProperty); - } - } - - public void UpdateDP() - { - if (_runtimeInstance == null) return; - ScripteInterface luaInterface; - _parent.CacheItemScripts.TryGetValue(_runtimeInstance.gameObject, out luaInterface); - if (luaInterface == null) return; - - if (_parent.DependencyProperty != null) - luaInterface.SetDependencyProperty(_parent.DependencyProperty); - } - - private RectTransform GetInstance() - { - var res = GameObjectPool.GetInstance(_template.gameObject, _parent.RectTransform).GetComponent(); - return res; - } - - private void ReleaseInstance() - { - if (_runtimeInstance == null) return; - - _layoutElement = null; - - if (Application.isPlaying) - { - ScripteInterface si; - _parent.CacheItemScripts.TryGetValue(_runtimeInstance.gameObject, out si); - if (si != null) si.Release(); - GameObjectPool.Release(_runtimeInstance.gameObject); - _runtimeInstance = null; - } - else - { - GameObject.DestroyImmediate(_runtimeInstance.gameObject); - _runtimeInstance = null; - } - } +{ + public bool IsDestroyed; + public bool Visible = true; + public int Index; + public bool IsInViewRect; + + public Vector2 Pivot => _template.pivot; + public Vector2 AnchoredPosition; + + public float Width; + public float Height; + + private IVirtualLayout _parent; + + private RectTransform _template => _parent.GetTemplate(_parent.DataList[Index]); + private RectTransform _runtimeInstance; + private LayoutGroup _layoutElement; + + public RectTransform RuntimeItemUI => _runtimeInstance; + public bool firstShow { get; private set; } = true; + + public float PreferredWidth + { + get + { + if (_layoutElement == null) return 0; + + return _layoutElement.preferredWidth; + } + } + public float PreferredHeight + { + get + { + if (_layoutElement == null) return 0; + + return _layoutElement.preferredHeight; + } + } + + public ScripteInterface GetLuaObj() + { + if (_runtimeInstance == null) return null; + + ScripteInterface lfi; + + _parent.CacheItemScripts.TryGetValue(_runtimeInstance.gameObject, out lfi); + + return lfi; + } + + public ItemProxy(IVirtualLayout parent) + { + _parent = parent; + } + + public void Dispose() + { + if (_runtimeInstance != null) + { + if (Application.isPlaying) + { + GameObjectPool.Release(_runtimeInstance.gameObject); + } + else + GameObject.DestroyImmediate(_runtimeInstance.gameObject); + } + } + + public bool NeedShow + { + get + { + if (IsInViewRect && _runtimeInstance == null) return true; + else + { + if (_runtimeInstance != null && IsInViewRect && _runtimeInstance.anchoredPosition != AnchoredPosition) + return true; + else + return false; + } + } + + } + public bool NeedHide => !IsInViewRect && _runtimeInstance != null; + + public void UpdateView(bool force = false) + { + if (IsInViewRect) + { + if (_runtimeInstance == null) + { + _runtimeInstance = GetInstance(); + _layoutElement = _runtimeInstance.GetComponent(); + UpdateViewData(); + } + else if (force) + { + UpdateViewData(); + } + + UpdateLayout(); + } + else + { + ReleaseInstance(); + } + } + + public void UpdateLayout() + { + if (_runtimeInstance != null) + { + _runtimeInstance.gameObject.SetActive(true); + _runtimeInstance.anchorMax = Vector2.up; + _runtimeInstance.anchorMin = Vector2.up; + _runtimeInstance.anchoredPosition = AnchoredPosition; + _runtimeInstance.sizeDelta = new Vector2(Width, Height); + } + if (_layoutElement != null) + { + _layoutElement.CalculateLayoutInputHorizontal(); + _layoutElement.CalculateLayoutInputVertical(); + _layoutElement.SetLayoutHorizontal(); + _layoutElement.SetLayoutVertical(); + } + + } + + private void UpdateViewData() + { + if (Application.isPlaying) + { + if (!_parent.CacheItemScripts.ContainsKey(_runtimeInstance.gameObject)) + { + var vItem = _runtimeInstance.gameObject.GetComponent(); + ScripteInterface newSI = new ScripteInterface(vItem); + _parent.CacheItemScripts[_runtimeInstance.gameObject] = newSI; + } + + ScripteInterface si; + + _parent.CacheItemScripts.TryGetValue(_runtimeInstance.gameObject, out si); + si.SetDataList(_parent.DataList[Index], Index); + if (_parent.DependencyProperty != null) + si.SetDependencyProperty(_parent.DependencyProperty); + } + } + + public void UpdateDP() + { + if (_runtimeInstance == null) return; + ScripteInterface luaInterface; + _parent.CacheItemScripts.TryGetValue(_runtimeInstance.gameObject, out luaInterface); + if (luaInterface == null) return; + + if (_parent.DependencyProperty != null) + luaInterface.SetDependencyProperty(_parent.DependencyProperty); + } + + private RectTransform GetInstance() + { + var res = GameObjectPool.GetInstance(_template.gameObject, _parent.RectTransform).GetComponent(); + return res; + } + + private void ReleaseInstance() + { + if (_runtimeInstance == null) return; + + _layoutElement = null; + + if (Application.isPlaying) + { + ScripteInterface si; + _parent.CacheItemScripts.TryGetValue(_runtimeInstance.gameObject, out si); + if (si != null) si.Release(); + GameObjectPool.Release(_runtimeInstance.gameObject); + _runtimeInstance = null; + } + else + { + GameObject.DestroyImmediate(_runtimeInstance.gameObject); + _runtimeInstance = null; + } + } } public class ScripteInterface -{ - private IVirtualItem _itemInstance; - public IVirtualItem ItemInstance => _itemInstance; - - public ScripteInterface(IVirtualItem lc) - { - _itemInstance = lc; - } - - public void SetDataList(object dataItem, int index) - { - if (_itemInstance == null) return; - _itemInstance.Index = index; - _itemInstance.SetData(dataItem); - } - public void Release() - { - if (_itemInstance == null) return; - _itemInstance.Release(); - } - - public void SetDependencyProperty(object dependencyProperty) - { - if (_itemInstance == null) return; - - _itemInstance.SetDependencyProperty(dependencyProperty); - } +{ + private IVirtualItem _itemInstance; + public IVirtualItem ItemInstance => _itemInstance; + + public ScripteInterface(IVirtualItem lc) + { + _itemInstance = lc; + } + + public void SetDataList(object dataItem, int index) + { + if (_itemInstance == null) return; + _itemInstance.Index = index; + _itemInstance.SetData(dataItem); + } + public void Release() + { + if (_itemInstance == null) return; + _itemInstance.Release(); + } + + public void SetDependencyProperty(object dependencyProperty) + { + if (_itemInstance == null) return; + + _itemInstance.SetDependencyProperty(dependencyProperty); + } } public interface IVirtualItem -{ - GameObject gameObject { get; } - int Index { get; set; } - void SetData(object data); - void SetDependencyProperty(object data); - void Release(); +{ + GameObject gameObject { get; } + int Index { get; set; } + void SetData(object data); + void SetDependencyProperty(object data); + void Release(); } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OptionUI/OptionUI_ValueEditItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OptionUI/OptionUI_ValueEditItem.cs index fce4e73d..1581768c 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OptionUI/OptionUI_ValueEditItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OptionUI/OptionUI_ValueEditItem.cs @@ -1,4 +1,4 @@ -using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.ClientCore; using UnityEngine; namespace AxibugEmuOnline.Client @@ -19,8 +19,8 @@ namespace AxibugEmuOnline.Client if (menuData is ValueSetMenu) { - var valueMenu = (ValueSetMenu)menuData; - if (valueMenu.ValueType == typeof(float)) + var valueMenu = (ValueSetMenu)menuData; + if (valueMenu.ValueType == typeof(float)) { m_currentCom = com_floatEdit; } @@ -30,7 +30,7 @@ namespace AxibugEmuOnline.Client } else { - App.log.Warning($"δֵ֧:{valueMenu.ValueType}"); + App.log.Warning($"尚未支持的数据类型:{valueMenu.ValueType}"); return; } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OptionUI/OptionUI_ValueEditItem_FloatEdit.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OptionUI/OptionUI_ValueEditItem_FloatEdit.cs index 29e8477c..a7fbb3ba 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OptionUI/OptionUI_ValueEditItem_FloatEdit.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OptionUI/OptionUI_ValueEditItem_FloatEdit.cs @@ -1,5 +1,4 @@ -using System; -using UnityEngine; +using UnityEngine; using UnityEngine.UI; namespace AxibugEmuOnline.Client diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs index 8ea6da94..ea08663b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs @@ -1,5 +1,4 @@ -using AxibugEmuOnline.Client.ClientCore; -using System; +using System; using System.Collections.Generic; using UnityEngine; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/PopTipsItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/PopTipsItem.cs index f24d2b33..8cf11289 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/PopTipsItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/PopTipsItem.cs @@ -1,4 +1,4 @@ -using DG.Tweening; +using DG.Tweening; using UnityEngine; using UnityEngine.UI; @@ -22,7 +22,7 @@ namespace AxibugEmuOnline.Client m_msgText.text = msg; Canvas.ForceUpdateCanvases(); - var targetPos = new Vector2(-RectTransform.rect.width - 20 , RectTransform.anchoredPosition.y); + var targetPos = new Vector2(-RectTransform.rect.width - 20, RectTransform.anchoredPosition.y); DOTween.To( () => RectTransform.anchoredPosition, (value) => RectTransform.anchoredPosition = value, diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/PopTipsUI.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/PopTipsUI.cs index 743cc28c..7ac441f5 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/PopTipsUI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/PopTipsUI.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using UnityEngine; namespace AxibugEmuOnline.Client diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/RoomUI/RoomListMenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/RoomUI/RoomListMenuItem.cs index 3d506775..a893cb59 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/RoomUI/RoomListMenuItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/RoomUI/RoomListMenuItem.cs @@ -1,6 +1,5 @@ using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.Event; -using System; namespace AxibugEmuOnline.Client { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/SubMenuItemGroup.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/SubMenuItemGroup.cs index fa62a938..526ad352 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/SubMenuItemGroup.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/SubMenuItemGroup.cs @@ -1,4 +1,4 @@ -using AxibugEmuOnline.Client.UI; +using AxibugEmuOnline.Client.UI; using DG.Tweening; using DG.Tweening.Core; using DG.Tweening.Plugins.Options; @@ -182,12 +182,12 @@ namespace AxibugEmuOnline.Client } private MenuItem Clone(MenuItem template, Transform parent) - { + { #if UNITY_EDITOR - - //========================޺======================== -#if UNITY_2019_1_OR_NEWER //°UnityUNITY2018.2ò༭Ҳ - + + //========================套娃宏======================== +#if UNITY_2019_1_OR_NEWER //新版Unity,因UNITY2018.2用不了这玩意儿,编辑器也罢 + if (Application.isPlaying) { var item = GameObject.Instantiate(template.gameObject, parent).GetComponent(); @@ -199,19 +199,19 @@ namespace AxibugEmuOnline.Client var clone = UnityEditor.PrefabUtility.InstantiatePrefab(template.gameObject, parent) as GameObject; clone.transform.localPosition = Vector3.zero; return clone.GetComponent(); - } + } #else var item = GameObject.Instantiate(template.gameObject, parent).GetComponent(); item.transform.localPosition = Vector3.zero; return item; #endif - //========================޺ End======================== - - - + //========================套娃宏 End======================== + + + #else return GameObject.Instantiate(SubMenuItemTemplate.gameObject, parent).GetComponent(); #endif - } - } + } + } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/UITool.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/UITool.cs index 813659ad..61c8f337 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/UITool.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/UITool.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; @@ -9,8 +9,8 @@ namespace AxibugEmuOnline.Client private static Dictionary _caches = new Dictionary(); public static Material GetMaterial(this Graphic graphic) { - Material material; - if (_caches.TryGetValue(graphic, out material)) + Material material; + if (_caches.TryGetValue(graphic, out material)) { return material; } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/VirtualSubMenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/VirtualSubMenuItem.cs index c16ecccf..96e6bc0e 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/VirtualSubMenuItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/VirtualSubMenuItem.cs @@ -2,7 +2,6 @@ using DG.Tweening; using DG.Tweening.Core; using DG.Tweening.Plugins.Options; -using System; using System.Collections; using UnityEngine; @@ -13,7 +12,6 @@ namespace AxibugEmuOnline.Client [SerializeField] protected CanvasGroup RomGroupRoot; - private TweenerCore m_showTween; protected override void Awake() diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs index f8b1c771..261b64f5 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs @@ -2,10 +2,8 @@ using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.Event; using DG.Tweening; -using System; using UnityEngine; using UnityEngine.UI; -using VirtualNes.Core; public class ControllerInfo : MonoBehaviour { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs index fd93e767..02d800d1 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs @@ -3,10 +3,8 @@ using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.Event; using AxibugEmuOnline.Client.Manager; using AxibugProtobuf; -using System; using System.Collections.Generic; using UnityEngine; -using VirtualNes.Core; public class ControllerInfoPanel : MonoBehaviour {