//const int maxAllowedCharsIfBlankPermitted = 255; // Rebuild character lists........ public void Populate(bool alsoUpdateMaterials = true) { parsedCatalogs = TexCharPresets.CharsFromString(importCatalog); switch (type) { case TexFontType.Font: PopulateCharacter(); break; case TexFontType.Sprite: PopulateSprite(); break; #if TEXDRAW_TMP case TexFontType.Font_SDF: PopulateSDFFontAsset(); break; #endif } PopulateCatalogs(); if (alsoUpdateMaterials) { TEXPreference.main.RebuildMaterial(); TEXPreference.main.PushToDictionaries(); } EditorUtility.SetDirty(this); }
public void ImportCharacters(string newcatalog) { // map from old (existing catalog) to newer one. // preserve data from each characterindex ImportDictionary(); catalogRaw = newcatalog; catalog = TexCharPresets.CharsFromString(newcatalog); var old = chars; chars = new TexChar[catalog.Length]; for (int i = 0; i < chars.Length; i++) { var cc = catalog[i]; (chars[i] = (old.FirstOrDefault(x => x.characterIndex == cc) ?? new TexChar() { characterIndex = cc, fontIndex = index, })).index = i; } }
public void ImportCatalog(string raw) { catalogRaw = string.IsNullOrEmpty(raw) ? TexCharPresets.legacyChars : raw; catalog = TexCharPresets.CharsFromString(catalogRaw); }
public void RebuildMaterial() { EditorUtility.DisplayProgressBar("Updating...", "Updating TEXDraw materials", 0); if (!defaultMaterial) { defaultMaterial = AssetDatabase.LoadAssetAtPath <Material>(MainFolderPath + "/Resources/TEX-Default.mat"); if (!defaultMaterial) { Debug.LogError("TEXDraw default Material Asset didn't found! please assign it manually."); } } if (!watchedMaterial.Contains(defaultMaterial)) { ArrayUtility.Insert(ref watchedMaterial, 0, defaultMaterial); } // Validate our lists first (no null and duplicates) watchedMaterial = watchedMaterial.Distinct().Where(x => x).ToArray(); var texCount = fonts.Length; var count = watchedMaterial.Length; for (int i = 0; i < count; i++) { // Cosmetic EditorUtility.DisplayProgressBar("Updating...", "Updating TEXDraw materials (" + i + "/" + count + ")", i / (float)count); // Find best match sampler count in 'samples' shaders var mat = watchedMaterial[i]; var type = mat.GetTag("TexMaterialType", false, "Null"); var alts = mat.GetTag("TexMaterialAlts", false, ""); if (type == "Null") { Debug.LogWarningFormat("Material {0} is not using TEXDraw shaders. Removing it from Material Stacks", mat); ArrayUtility.RemoveAt(ref watchedMaterial, i--); continue; } if (alts.Length > 1 && alts[0] == '@') { mat.shader = Shader.Find(alts.Substring(1)) ?? Shader.Find(alts.Substring(1) + "/Full"); alts = mat.GetTag("TexMaterialAlts", false, ""); } if (alts.Length >= 1 && alts[0] != '@') { var variants = TexCharPresets.CharsFromString(alts); if (variants.Any(x => x >= texCount)) { var target = (int)(variants.Where(x => x >= texCount).Min()); var name = mat.shader.name; if (name.LastIndexOf("/Full") == name.Length - 5) { name = name.Substring(0, name.Length - 5); } var shaderTarget = string.Format("{0}/x{1:X} Samples", name, target); var newShader = Shader.Find(shaderTarget); if (newShader) { mat.shader = newShader; } else { Debug.LogWarningFormat("Shader {0} wasn't found, have you double check TexMaterialAlts?", shaderTarget); } } } // Now plug it on each data textures for (int j = 0; j < fonts.Length; j++) { var propName = string.Format("_Font{0:X}", j); var font = fonts[j]; if (!mat.HasProperty(propName)) { Debug.LogWarningFormat("The shader {0} doesn't plug {1} or not declaring full fallback on TexMaterialAlts", mat.shader.name, propName); break; } mat.SetTexture(propName, font.Texture()); } // Now plug it on each data textures for (int j = fonts.Length; j < 31; j++) { var propName = string.Format("_Font{0:X}", j); if (mat.HasProperty(propName)) { mat.SetTexture(propName, null); } } } EditorUtility.ClearProgressBar(); }
public void RebuildMaterial() { EditorUtility.DisplayProgressBar("Updating...", "Updating TEXDraw materials", 0); if (!defaultMaterial) { defaultMaterial = AssetDatabase.LoadAssetAtPath <Material>(MainFolderPath + "/Resources/TEX-Default.mat"); if (!defaultMaterial) { Debug.LogError("TEXDraw default Material Asset didn't found! please assign it manually."); } } if (!watchedMaterial.Contains(defaultMaterial)) { ArrayUtility.Insert(ref watchedMaterial, 0, defaultMaterial); } // Validate our lists first (no null and duplicates) watchedMaterial = watchedMaterial.Distinct().Where(x => x).ToArray(); //var shaderLists = System.Array.ConvertAll<string, Shader>(AssetDatabase.FindAssets("t:Shader"), x => AssetDatabase.LoadAssetAtPath<Shader>(AssetDatabase.GUIDToAssetPath(x))); //var shaderNames = System.Array.ConvertAll<Shader, string>(shaderLists, x => x.name); var texCount = fontData.Length; for (int i = 0; i < watchedMaterial.Length; i++) { // Find best match sampler count in 'samples' shaders var mat = watchedMaterial[i]; var type = mat.GetTag("TexMaterialType", false, "Null"); var alts = mat.GetTag("TexMaterialAlts", false, ""); if (type == "Null") { Debug.LogWarningFormat("Material {0} is not using TEXDraw shaders. Removing it from Material Stacks", mat); ArrayUtility.RemoveAt(ref watchedMaterial, i--); continue; } if (alts.Length > 1 && alts[0] == '@') { // if (texCount > int.Parse(Regex.Match(mat.shader.name, @"([A-F0-9]+)(?= Samples)").Value, System.Globalization.NumberStyles.HexNumber)) { mat.shader = Shader.Find(alts.Substring(1)) ?? Shader.Find(alts.Substring(1) + "/Full"); alts = mat.GetTag("TexMaterialAlts", false, ""); // } } if (alts.Length >= 1 && alts[0] != '@') { var variants = TexCharPresets.CharsFromString(alts); if (variants.Any(x => x >= texCount)) { var target = (int)(variants.Where(x => x >= texCount).Min()); var name = mat.shader.name; /// Debug.LogFormat("{0} : {1}", shaderTarget, shaderTarget.LastIndexOf("/Full")); if (name.LastIndexOf("/Full") == name.Length - 5) { name = name.Substring(0, name.Length - 5); } var shaderTarget = string.Format("{0}/x{1:X} Samples", name, target); var newShader = Shader.Find(shaderTarget); if (newShader) { mat.shader = newShader; } else { Debug.LogWarningFormat("Shader {0} wasn't found, have you double check TexMaterialAlts?", shaderTarget); } } } // Now plug it on each data textures for (int j = 0; j < fontData.Length; j++) { var propName = string.Format("_Font{0:X}", j); var font = fontData[j]; if (!mat.HasProperty(propName)) { Debug.LogWarningFormat("The shader {0} doesn't plug {1} or not declaring full fallback on TexMaterialAlts", mat.shader.name, propName); break; } if (font.type == TexFontType.Font) { mat.SetTexture(propName, font.Font_Asset ? font.Font_Asset.material.mainTexture : null); } else { mat.SetTexture(propName, font.Sprite_Asset); } } } EditorUtility.ClearProgressBar(); }