public static bool Exists() { if (Current == null) { DebugLog.Warning("{0} unique object's Awake() method has not been called. Attempting to find in scene.", typeof(T).Name); current = GameObject.FindObjectOfType <T>(); if (current == null) { DebugLog.Warning("Unable to find '{0}' in scene.", typeof(T).Name); return(false); } } return(true); }
/// <summary> /// Map status code to enum. Unfortunately, Unity 3D's WWW class returns the wrong status code /// if there is more than one. Only the first code is recorded in www.responseHeaders. /// </summary> void ParseStatusCode(WWW www) { Contract.PropertyNotNull("ResponseHeadersProperty", ResponseHeadersProperty); string rawHeaders = null; try { rawHeaders = ResponseHeadersProperty.GetValue(www, null) as String; /// In this example (see raw headers below), www.responseHeaders["STATUS"] returns "HTTP/1.1 100 Continue" /// HTTP/1.1 100 Continue /// /// HTTP/1.1 200 OK /// /// Content-Type: application/xml; charset=UTF-8 /// /// Date: Thu, 11 Dec 2014 05:04:56 GMT /// /// Accept-Ranges: bytes /// /// Server: Development/1.0 /// /// Cache-Control: no-cache /// /// Expires: Fri, 01 Jan 1990 00:00:00 GMT /// /// Content-Length: 3905 } catch (Exception e) { DebugLog.Warning("Unable to access private WWW response headers. {0}", e.Message); // Fallback to use public headers www.responseHeaders.TryGetValue("STATUS", out rawHeaders); } if (string.IsNullOrEmpty(rawHeaders)) { StatusCode = HttpStatusCode.InternalServerError; StatusDescription = "HTTP status code is missing"; return; } Regex statusRegex = new Regex(httpStatusCodeRegexPattern, RegexOptions.None); MatchCollection matches = statusRegex.Matches(rawHeaders); // Get the last HTTP status in the raw headers that matches the regex if (matches.Count > 0 && matches[matches.Count - 1].Success) { int status = 500; int.TryParse(matches[matches.Count - 1].Groups["code"].Value, out status); SetStatusCode(status); StatusDescription = matches[0].Groups["reason"].Value; } else { StatusCode = HttpStatusCode.InternalServerError; StatusDescription = String.Format("Unable to parse status: {0}", rawHeaders); } }