public override void Invoke() { RenderTexture.active = tex; if (buffTex.width != tex.width || buffTex.height != tex.height) { buffTex.Resize(tex.width, tex.height); } buffTex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0); buffTex.Apply(); RenderTexture.active = null; onInvoke.Invoke(buffTex); }
IEnumerator RequestTextureRoutine(System.Action <string, Texture2D> onFinish) { if (this != null) { using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(url)) { yield return(www.SendWebRequest()); if (this != null) { if (www.isNetworkError || www.isHttpError) { Clear(); Debug.Log("[ExternalTexture2D] " + url + " Failed: " + www.error); } else { if (m_Texture2D == null) { Clear(); } var bytes = www.downloadHandler.data; var isPng = www.GetResponseHeader("Content-Type").Contains("png"); if ((isPng && m_Texture2D.format != TextureFormat.ARGB32) || (!isPng && m_Texture2D.format != TextureFormat.RGB24)) { m_Texture2D.Resize(m_Texture2D.width, m_Texture2D.height, isPng? TextureFormat.ARGB32 : TextureFormat.RGB24, false); } m_Texture2D.LoadImage(bytes); m_Texture2D.hideFlags = HideFlags.NotEditable; if (hasTexture) { var size = Mathf.Max(m_Texture2D.width, m_Texture2D.height); if (size > m_MaxSize) { float mult = m_MaxSize / (float)size; int width = Mathf.Clamp((int)Mathf.Ceil(m_Texture2D.width * mult), 1, m_MaxSize); int height = Mathf.Clamp((int)Mathf.Ceil(m_Texture2D.height * mult), 1, m_MaxSize); Kyub.Extensions.Texture2DExtensions.BilinearScale(m_Texture2D, width, height); } } } } else { if (onFinish != null) { onFinish(url, null); } yield break; } } m_Texture2D.IncrementUpdateCount(); _previousDownloadedUrl = url; if (onDownload != null) { onDownload.Invoke(m_Texture2D); } } if (onFinish != null) { onFinish(url, m_Texture2D); } }
/*AUTO SCRIPT*/ /*AUTO SCRIPT*/ public override void Invoke() /*AUTO SCRIPT*/ { /*AUTO SCRIPT*/ onInvoke.Invoke(value); /*AUTO SCRIPT*/ }