internal static void DumpTexture(TextureMetadata tm) { var dir = $"{TL_DIR_SCENE}/{tm.scene}"; var di = new DirectoryInfo(dir); if (!di.Exists) { di.Create(); } var path = $"{dir}/{tm.SafeID}.png"; if (!File.Exists(path)) { TextureUtils.SaveTex(tm.texture, path); } var s = DynamicTranslator.DumpingAllToGlobal.Value ? GlobalTextureTargetName : tm.scene; var sw = SwTextureNameDump[s]; if (sw == null) { return; } //if (sw.BaseStream == null) return; sw.WriteLine("{0}={1}", tm.SafeID, path.Replace(TL_DIR_SCENE + "/", "")); sw.Flush(); }
internal static void RegisterTexture(Texture tex, string path, string s) { if (DynamicTranslator.IsDumpingEnabled.Value) { if (tex == null) { return; } if (IsSwappedTexture(tex)) { return; } if (string.IsNullOrEmpty(tex.name)) { return; } if (DynamicTranslator.DumpingAllToGlobal.Value) { s = GlobalTextureTargetName; } PrepDumper(s); var tm = new TextureMetadata(tex, path, s); if (TextureDumpTargets[s].Contains(tm)) { return; } TextureDumpTargets[s].Add(tm); DumpTexture(tm); } }
internal static void RegisterTexture(UnityEngine.UI.Image i, string path, string s) { if (DynamicTranslator.IsDumpingEnabled.Value) { var tex = i.mainTexture; if (tex == null) { return; } if (IsSwappedTexture(tex)) { return; } if (string.IsNullOrEmpty(tex.name)) { return; } if (DynamicTranslator.DumpingAllToGlobal.Value) { s = GlobalTextureTargetName; } PrepDumper(s); RegisterTexture(i.mainTexture, path, s); if (i.sprite == null) { return; } var rect = i.sprite.textureRect; if (rect == new Rect(0, 0, tex.width, tex.height)) { RegisterTexture(i.mainTexture, path, s); return; } if (!ReadableTextures.TryGetValue(tex.name, out var readable)) { ReadableTextures[tex.name] = TextureUtils.MakeReadable(tex); readable = ReadableTextures[tex.name]; } var cropped = readable.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); var nt2D = new Texture2D((int)rect.width, (int)rect.height); nt2D.SetPixels(cropped); nt2D.Apply(); nt2D.name = tex.name.ToLower().Contains("atlas") ? GetAtlasTextureName(i) : tex.name; var tm = new TextureMetadata(nt2D, path, s); if (TextureDumpTargets[s].Contains(tm)) { return; } TextureDumpTargets[s].Add(tm); DumpTexture(tm); } }