static public Texture2D GetTexture2D(this Color c) { var colorKey = c.ToInt().ToString(); if (Map == null) Map = new Dictionary<string, Texture2D>(); if (Map.ContainsKey(colorKey) && Map[colorKey] != null) return Map[colorKey]; var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false); tex.SetFlag(HideFlags.HideAndDontSave, true); tex.SetPixel(0, 0, c); tex.Apply(); Map.Add(colorKey, tex); return tex; }
static public Texture2D ToTexture2D(this string base64, string id = null) { var tex = new Texture2D(16, 16); tex.SetFlag(HideFlags.HideAndDontSave, true); tex.LoadImage(Convert.FromBase64String(base64)); if (string.IsNullOrEmpty(id)) return tex; if (Map == null) Map = new Dictionary<string, Texture2D>(); if (!Map.ContainsKey(id) || Map[id]==null) { Map.Add(id, tex); } else { Debug.Log("vlbTexture.ToTexture2D() Error :: id <" + id + "> already exist and will be replaced"); Map[id] = tex; } return tex; }