public void CreateAndAddTextToTexture() { if (useSharedMaterial) { mat = gameObject.GetComponent <Renderer>().sharedMaterial; } else { mat = gameObject.GetComponent <Renderer>().material; } TextToTexture textToTexture = new TextToTexture(customFont, fontCountX, fontCountY, perCharacterKerning, false); int textWidthPlusTrailingBuffer = textToTexture.CalcTextWidthPlusTrailingBuffer(text, decalTextureSize, characterSize); int posX = (decalTextureSize - (textWidthPlusTrailingBuffer + 1)) - Mathf.Clamp(((maxMugTextWidth - textWidthPlusTrailingBuffer) / 2), 0, decalTextureSize); mat.SetTexture(TEXT_TEXTURE_ID, textToTexture.CreateTextToTexture(text, posX, textPlacementY, decalTextureSize, characterSize, lineSpacing)); hasTextTextureBeenSet = true; }
private static void AddWatermark(bool doWatermarkFlag, ref byte[] basePng, string wmFileName, ConfigEntry <float> times) { if (!doWatermarkFlag && !KK_PNGCaptureSizeModifier.ResolutionWaterMark.Value) { return; } Texture2D screenshot = new Texture2D(2, 2); screenshot.LoadImage(basePng); //圖片分辨率 if (KK_PNGCaptureSizeModifier.ResolutionWaterMark.Value || doWatermarkFlag) { string text = $"{screenshot.width}x{screenshot.height}"; int textureWidth = TextToTexture.CalcTextWidthPlusTrailingBuffer(text, KK_PNGCaptureSizeModifier.CharacterSize.Value); Texture2D capsize = TextToTexture.CreateTextToTexture(text, 0, 0, textureWidth, KK_PNGCaptureSizeModifier.CharacterSize.Value); capsize = Extension.Extension.Scale(capsize, (int)(capsize.width * times.Value / (float)times.DefaultValue), (int)(capsize.height * times.Value / (float)times.DefaultValue)); screenshot = Extension.Extension.OverwriteTexture( screenshot, capsize, screenshot.width * KK_PNGCaptureSizeModifier.PositionX.Value / 100 - capsize.width, screenshot.height * KK_PNGCaptureSizeModifier.PositionY.Value / 100 ); KK_PNGCaptureSizeModifier.Logger.LogDebug($"Add Resolution: {text}"); } //浮水印 if (doWatermarkFlag) { Texture2D watermark = Extension.Extension.LoadDllResource($"KK_PNGCaptureSizeModifier.Resources.{wmFileName}"); watermark = Extension.Extension.Scale(watermark, (int)(watermark.width * times.Value / (float)times.DefaultValue), (int)(watermark.height * times.Value / (float)times.DefaultValue)); screenshot = Extension.Extension.OverwriteTexture( screenshot, watermark, 0, screenshot.height - watermark.height ); KK_PNGCaptureSizeModifier.Logger.LogDebug($"Add Watermark: {wmFileName}"); } basePng = screenshot.EncodeToPNG(); }