public void run(K key, System.Action <V> callback) { if (!awaitingCallbacks.ContainsKey(key)) { awaitingCallbacks [key] = new List <System.Action <V> > (); awaitingCallbacks [key].Add(callback); } else { awaitingCallbacks [key].Add(callback); } if (!activeDownloads.Contains(key)) //don't download again, wait for previous download to finish and execute callback { if (cache.contains(key)) { executeQueuedCallbacks(key, cache.get(key)); } else { activeDownloads.Add(key); owner.StartCoroutine(download(key, result => { cache.add(key, result); activeDownloads.Remove(key); executeQueuedCallbacks(key, cache.get(key)); })); } } }
public IEnumerator downloadAndCreateTexture(string imagePath, System.Action <Texture2D> callback) { if (textureCache.contains(imagePath)) { Debug.LogFormat("Cache contains {0}", imagePath); callback(textureCache.get(imagePath)); yield return(null); } else { Debug.LogFormat("Cache does not contain {0}", imagePath); yield return(API.downloadAndCreateTexture(imagePath, texture => { textureCache.add(imagePath, texture); callback(texture); })); } }
void SelectActiveGlows() { m_NumActiveGlows = 0; if (Camera.main == null) { return; } Camera cam = Camera.main; Vector3 camPos = cam.transform.position; S_CacheRec visRec = new S_CacheRec(); float currTime = Time.time; foreach (ScreenSpaceGlowEmitter curr in ScreenSpaceGlowEmitter.ms_Instances) { Vector3 glowPos = curr.transform.position; if (Vector3.Distance(camPos, glowPos) > curr.m_MaxVisDist) { continue; } Vector3 viewportPos = cam.WorldToViewportPoint(glowPos); if (viewportPos.z < 0) { continue; } if (viewportPos.x < 0 || viewportPos.x > 1 || viewportPos.y < 0 || viewportPos.y > 1) { continue; } if (m_NumActiveGlows >= MAX_GLOWS) { return; } bool isBlocked = false; bool updateVisState = true; if (m_GlowsVisCache.get(curr.m_InstanceID, ref visRec)) { float age = currTime - visRec.m_QueryTime; MFDebugUtils.Assert(age >= 0.0f); if (age <= m_MaxVisQueryResultAge) { isBlocked = visRec.m_IsBlocked; updateVisState = false; } } if (updateVisState) { Vector3 dir = glowPos - camPos; isBlocked = Physics.Raycast(camPos, dir, 1, curr.m_ColLayerMask); visRec.m_IsBlocked = isBlocked; visRec.m_QueryTime = currTime; m_GlowsVisCache.add(curr.m_InstanceID, visRec); } if (!isBlocked) { Vector3 toViewer = camPos - glowPos; Vector3 ldir = curr.transform.forward; float dist = toViewer.magnitude; toViewer.Normalize(); float dirFadeout = RemapValue(Mathf.Clamp01(Vector3.Dot(toViewer, ldir)), Mathf.Cos(curr.m_ConeAngle * Mathf.Deg2Rad / 2), 1, 0, 1); float ndist = Mathf.Clamp01(dist / curr.m_MaxVisDist); float intensityMod = dirFadeout * (1 - ndist * ndist); //Debug.Log(intensityMod); if (intensityMod > 0.001f) { m_ActiveGlows[m_NumActiveGlows++] = curr; } } } }