public OpenTextureWindow(TextureCallback callback) : base(DevelopmentMenu.Instance) { this.Title = "Select Texture"; this.Resized += OnResize; this.SetPosition((int)MouseManager.GetMousePositionWindows().X, (int)MouseManager.GetMousePositionWindows().Y); Callback = callback; PackageView = new PackageTree(this); PackageView.SetPosition(10, 10); PackageView.Filter = ResourceType.Texture; PackageView.TextureOpened += ItemSelected; PackageView.RefreshPackageView(); Cancel = new Button(this); Cancel.Text = "Cancel"; Cancel.Clicked += delegate(Base item, ClickedEventArgs args) { FSTexture none = new FSTexture(); none.ID = Guid.Empty; this.ItemSelected(none); this.Close(); }; this.SetSize(340, 450); }
public void PrivateLoadTexture(string url, TextureCallback callback = null, Material mat = null, string property = null, Texture tex = null) { if (texList.ContainsKey(url) && texList[url] != null) { FinishLoad(url, callback, mat, property, tex); return; } if (!texList.ContainsKey(url)) { Texture tempTex = Resources.Load(url) as Texture; if (tempTex) { texList[url] = tempTex; FinishLoad(url, callback, mat, property, tex); } else if (File.Exists(GetCachePath(url))) { StartCoroutine(CoLoadTexture(GetCachePath(url), callback, mat, property, tex)); } else { StartCoroutine(CoLoadTexture(url, callback, mat, property, tex, cache: true)); } } else { StartCoroutine(CoLoadTexture(url, callback, mat, property, tex)); } }
public static IEnumerator GetPictureTexture(string facebookID, int width = 128, int height = 128, string type = null, bool secure = true, TextureCallback callback = null) { string url = GetPictureURL(facebookID, width, height, type, secure); WWW www = new WWW(url); yield return www; callback(www.texture); }
void FinishLoad(string url, TextureCallback callback = null, Material mat = null, string property = null, Texture tex = null) { if (texList.ContainsKey(url) && texList[url] != null) { if (mat) { if (property != null) { mat.SetTexture(property, texList[url]); } else { mat.mainTexture = texList[url]; } } if (tex) { tex = texList[url]; } if (callback != null) { callback.Invoke(texList[url]); } } }
public static void LoadTexture(string url, TextureCallback callback = null, Material mat = null, string property = null, Texture tex = null) { if (!main) { main = FindObjectOfType <TextureLoader>(); } if (main && !string.IsNullOrEmpty(url)) { main.PrivateLoadTexture(url, callback, mat, property, tex); } }
/* Take an action if/when the texture is loaded. */ public void withTexture(TextureCallback callback) { if (loadedTexture != null) { callback.Invoke(loadedTexture); } else { TextureCallback prev = loadingCallback; loadingCallback = (t2d) => { prev.Invoke(t2d); callback.Invoke(t2d); }; } }
public void applyTexture(ImageLoaderThreaded.QueuedImage tex) { if (tex.hadError) { SuperController.LogError("Error loading texture: " + tex.errorText); } else { loadedTexture = tex.tex; loadingCallback.Invoke(tex.tex); loadingCallback = BLANK; } }
/// <summary> /// Register a callback method that will be invoked once a texture /// has finished loading. Upon adding the callback, it will /// immediately be invoked with the names of all textures that /// have already been loaded in the past. /// </summary> /// <param name="callback">A callback that is safe to be invoked /// from any thread.</param> public void AddCallback(TextureCallback callback) { Debug.Assert(callback != null); lock (_loaded) { if (InvokeCallbacks(callback)) { return; } _textureCallbacks.Add(callback); } }
/** * Load (or reuse) a texture from a file to perform an action. */ public void withTexture(string textureFile, int textureType, TextureCallback action) { if (textureCache.ContainsKey(textureFile)) { textureCache[textureFile].withTexture(action); } else { // Create the texture state object TextureState newState = new TextureState(); newState.withTexture(action); textureCache[textureFile] = newState; bool createMipMaps = true; bool linear = false; bool isNormal = false; bool compress = true; switch (textureType) { case TYPE_SPECULAR: case TYPE_GLOSS: linear = true; break; case TYPE_NORMAL: linear = true; isNormal = true; compress = false; break; default: break; } // Begin loading the texture var img = new ImageLoaderThreaded.QueuedImage(); img.imgPath = textureFile; img.callback = qimg => newState.applyTexture(qimg); img.createMipMaps = createMipMaps; img.isNormalMap = isNormal; img.linear = linear; img.compress = compress; ImageLoaderThreaded.singleton.QueueImage(img); } }
IEnumerator CoLoadTexture(string url, TextureCallback callback = null, Material mat = null, string property = null, Texture tex = null, bool cache = false) { if (!texList.ContainsKey(url)) { texList[url] = null; WWW www = new WWW(url); yield return(www); //yield return new WaitForSeconds(3f); // Simulated lag if (string.IsNullOrEmpty(www.error)) { Texture2D newTex = new Texture2D(0, 0); www.LoadImageIntoTexture(newTex); texList[url] = newTex; if (cache && !File.Exists(GetCachePath(url))) { if (!Directory.Exists(Directory.GetCurrentDirectory() + "/" + CACHE_PATH)) { Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/" + CACHE_PATH); } File.WriteAllBytes(GetCachePath(url), www.bytes); } } else { texList.Remove(url); } } if (mat != null || tex != null || callback != null) { if (texList.ContainsKey(url) && texList[url] == null) { float startTime = Time.time; while (Time.time < startTime + MAX_WAIT_TIME) { yield return(new WaitForSeconds(0.05f)); if (texList.ContainsKey(url) && texList[url] != null) { break; } } } FinishLoad(url, callback, mat, property, tex); } }
public IEnumerator GetPictureFromIdCoroutine(TextureCallback callback, string fbid = "") { //To get our facebook picture we use this address which we pass our facebookId into var www = new WWW("http://graph.facebook.com/" + (string.IsNullOrEmpty(fbid) ? AccessToken.CurrentAccessToken.UserId : fbid) + "/picture?width=210&height=210"); yield return(www); Texture2D tempPic = new Texture2D(25, 25); if (!string.IsNullOrEmpty(www.error)) { Debug.LogError("Error fetching image"); } else { www.LoadImageIntoTexture(tempPic); } callback(tempPic); }
/** * Load (or reuse) a texture from a file to perform an action. */ public void withTexture(string textureFile, TextureCallback action) { if (textureCache.ContainsKey(textureFile)) { textureCache[textureFile].withTexture(action); } else { // Create the texture state object TextureState newState = new TextureState(); newState.withTexture(action); textureCache[textureFile] = newState; // Begin loading the texture var img = new ImageLoaderThreaded.QueuedImage(); img.imgPath = textureFile; img.createMipMaps = true; img.callback = qimg => newState.applyTexture(qimg); ImageLoaderThreaded.singleton.QueueImage(img); } }
private bool InvokeCallbacks(TextureCallback callback) { foreach (var s in _loaded) { if (!callback(s, _dict[s])) { return(true); } } foreach (var kv in _replacements) { if (!_loaded.Contains(kv.Value.Value)) { continue; } if (!callback(kv.Value.Key, Get(kv.Value.Value))) { return(true); } } return(false); }
/// <summary> /// Register a callback method that will be invoked every time a texture /// is being replaced. The callback is not invoked for previously /// replaced textures. /// </summary> /// <param name="callback">A callback that is safe to be invoked /// from any thread. The callback receives the previous name of /// the texture as first parameter, but the texture instance /// that is passed for the second parameter is already the /// new texture.</param> public void AddReplaceCallback(TextureCallback callback) { Debug.Assert(callback != null); _replaceCallbacks.Add(callback); }
private bool InvokeCallbacks(TextureCallback callback) { foreach (var s in _loaded) { if (!callback(s, _dict[s])) { return true; } } foreach (var kv in _replacements) { if (!_loaded.Contains(kv.Value.Value)) { continue; } if (!callback(kv.Value.Key, Get(kv.Value.Value))) { return true; } } return false; }
/// <summary> /// Register a callback method that will be invoked once a texture /// has finished loading. Upon adding the callback, it will /// immediately be invoked with the names of all textures that /// have already been loaded in the past. /// </summary> /// <param name="callback">A callback that is safe to be invoked /// from any thread.</param> public void AddCallback(TextureCallback callback) { Debug.Assert(callback != null); lock (_loaded) { if (InvokeCallbacks(callback)) return; _textureCallbacks.Add(callback); } }
IEnumerator PaintWaveformSpectrum(float[] samples, int sampleStart, int sampleSection, int width, int height, Color col, TextureCallback cb) { if (width <= 0) { yield break; } Texture2D tex = new Texture2D(width, height, TextureFormat.RGBA32, false); //Set all to clear Color32 resetColor = new Color32(255, 255, 255, 0); Color32[] resetColorArray = tex.GetPixels32(); for (int i = 0; i < resetColorArray.Length; i++) { resetColorArray[i] = resetColor; } tex.SetPixels32(resetColorArray); float sampleIncr = sampleSection / (float)width; const int PIXELS_PER_YIELD = 32; //Waits every 400,000 loop int loopCounter = 0; for (int x = 0; x < width; x++) { float maxValue = 0; float avgValue = 0; for (int s = 0; s < sampleIncr; s++) { float sampleIdx = sampleStart + x * sampleIncr + s; int idx = Math.Min((int)sampleIdx, samples.Length - 1); float sampleVal = Math.Abs(samples[idx]); avgValue += sampleVal * sampleVal; maxValue = Math.Max(maxValue, sampleVal * sampleVal); } avgValue /= sampleIncr; //For sections with huge peaks, just use avg if (maxValue > 0.5f) { maxValue = avgValue; } float paintHeight = Mathf.Sqrt(maxValue) * height; for (int y = 0; y <= paintHeight; y++) { tex.SetPixel(x, (height / 2) + y, col); tex.SetPixel(x, (height / 2) - y, col); } ++loopCounter; if (loopCounter % PIXELS_PER_YIELD == 0) { yield return(null); } } tex.Apply(); cb(tex); }
public void GetPictureFromFBID(string fbid, TextureCallback callback) { StartCoroutine(socialHandler.GetPictureFromIdCoroutine(callback, fbid)); }
public static IEnumerator GetPictureTexture(string facebookID, int width = 128, int height = 128, string type = null, bool secure = true, TextureCallback callback = null) { string url = GetPictureURL(facebookID, width, height, type, secure); WWW www = new WWW(url); yield return(www); callback(www.texture); }