Skip to Main Content

BTD_Mod_Helper​.Extensions​.Texture2DExt


BloonsTD6 Mod Helper

BTD_Mod_Helper.Extensions

Texture2DExt Class

Extensions for Texture2Ds

public static class Texture2DExt

Inheritance System.Object  Texture2DExt

Methods

Texture2DExt.AdjustHSV(this Texture, float, float, float, Nullable, float) Method

Applies a HSV adjustment, shifting its Hue/Saturation/Value(light)

public static RenderTexture AdjustHSV(this Texture texture, float hueAdjust, float saturationAdjust, float valueAdjust, System.Nullable<Color> targetColor=null, float threshold=0.05f);

Parameters

texture UnityEngine.Texture

this

hueAdjust System.Single

Amount between -180 and 180 to add to Hue

saturationAdjust System.Single

Amount between -1 and 1 to add to the saturation

valueAdjust System.Single

Amount between -1 and 1 to add to the value (light)

targetColor System.Nullable<UnityEngine.Color>

If specified, only affect this color within the image

threshold System.Single

If specified, only match the color within this threshold, 0 is exact, 1 will match anything

Returns

UnityEngine.RenderTexture

Texture2DExt.ApplyCustomShader(this Texture, CustomShader, Action) Method

Applies a custom Mod Helper shader, creating a new Texture with its effects baked in

public static RenderTexture ApplyCustomShader(this Texture texture, BTD_Mod_Helper.Api.Enums.CustomShader customShader, System.Action<Material> modifyMaterial=null);

Parameters

texture UnityEngine.Texture

this

customShader CustomShader

Mod Helper custom shader

modifyMaterial System.Action<UnityEngine.Material>

changes to make to the material

Returns

UnityEngine.RenderTexture

Texture2DExt.CreateFromColor(this Texture2D, Color) Method

Create Texture2D from a unity Color. Texture will only be this color

public static Texture2D CreateFromColor(this Texture2D texture2D, Color color);

Parameters

texture2D UnityEngine.Texture2D

color UnityEngine.Color

Color to make new texture

Returns

UnityEngine.Texture2D

Texture2DExt.CreateSpriteFromTexture(this Texture2D, float) Method

Create a Sprite from this Texture2D

public static Sprite CreateSpriteFromTexture(this Texture2D texture2D, float pixelsPerUnit);

Parameters

texture2D UnityEngine.Texture2D

pixelsPerUnit System.Single

Number of pixels you want in each unit. More pixels means bigger sprite in game

Returns

UnityEngine.Sprite

Texture2DExt.CreateSpriteFromTexture(this Texture2D, float, Vector2) Method

Create a Sprite from this Texture2D

public static Sprite CreateSpriteFromTexture(this Texture2D texture2D, float pixelsPerUnit, Vector2 pivot);

Parameters

texture2D UnityEngine.Texture2D

pixelsPerUnit System.Single

Number of pixels you want in each unit. More pixels means bigger sprite in game

pivot UnityEngine.Vector2

Returns

UnityEngine.Sprite

Texture2DExt.LoadFromFile(this Texture2D, string) Method

Create Texture2D from a file on local PC

public static Texture2D LoadFromFile(this Texture2D texture, string filePath);

Parameters

texture UnityEngine.Texture2D

filePath System.String

path of file on PC

Returns

UnityEngine.Texture2D

Texture2DExt.ReplaceColor(this Texture, Color, Color, float) Method

Replaces all the usage of a target color (within a certain threshold) with a replacement color

public static RenderTexture ReplaceColor(this Texture texture, Color targetColor, Color replacementColor, float threshold=0.05f);

Parameters

texture UnityEngine.Texture

this

targetColor UnityEngine.Color

The color to find

replacementColor UnityEngine.Color

The new color

threshold System.Single

The threshold for matching the target color, 0 is exact, 1 will match anything

Returns

UnityEngine.RenderTexture

Texture2DExt.SaveToPNG(this Texture2D, string) Method

Save Texture2D as a png to file.

public static void SaveToPNG(this Texture2D texture, string filePath);

Parameters

texture UnityEngine.Texture2D

filePath System.String

File path to save texture to

Texture2DExt.TrySaveToPNG(this Texture, string) Method

Attempts to save a Texture to a png at the given filePath, even if it isn't marked as readable

public static void TrySaveToPNG(this Texture texture, string filePath);

Parameters

texture UnityEngine.Texture

filePath System.String

To learn how to download BTD Mod Helper and install mods, click here