Detailed Description

A dynamic texture renders it's pixels in a custom way. This can be considered similar to a canvas element. This allows for some very dynamic graphics on the UI (for example, a curved health bar).

Inheritance diagram for PowerUI.DynamicTexture:
HealthBar PowerBar

Public Member Functions

 DynamicTexture (int width, int height, string name)
 Creates a new dynamic texture of the given dimensions. More...
 
 DynamicTexture ()
 Creates an empty dynamic texture. Note that this is used internally by canvas. If used, you must call Resize to set it up. More...
 
void ResizeX (int width)
 Resize this texture on the X axis. More...
 
void ResizeY (int height)
 Resize this texture on the Y axis. More...
 
void Resize (int width, int height)
 Resize this texture on the X and Y axis. More...
 
void Resize (int width, int height, bool createIfZero)
 Resize this texture on the X and Y axis, optionally only doing so if dimensions aren't zero. More...
 
Texture2D GetTexture ()
 Gets the texture. More...
 
Texture2D GetTextureHolder ()
 Gets the placeholder texture. More...
 
void DrawPixel (int x, int y, Color32 colour)
 Draws a pixel at the given x/y coordinates to the atlas. More...
 
void DrawLine (int x, int y, int x2, int y2, Color32 colour)
 Draws a line on the atlas from one point to another. More...
 
void DrawCircle (int x0, int y0, int radius, Color32 colour)
 Draws a filled circle on the atlas. More...
 
void Clear ()
 Wipes the graphic clean using transparent black. More...
 
void Clear (Color32 clearColour)
 Wipes the graphic clean. More...
 
void SetPixel (int index, Color32 colour)
 Sets a the colour of a particular global pixel on the atlas. More...
 
void Refresh ()
 Called to refresh the texture. More...
 
virtual void Flush ()
 Override this to write to the pixels. Should internally use SetPixel for this. More...
 
void FlushDirect ()
 Internally used only. Flushes the pixel array to the texture right now. More...
 

Static Public Member Functions

static DynamicTexture Get (string byName)
 Gets a dynamic texture by name from the global lookup. More...
 
static void RemoveAll ()
 Removes all dynamic textures. More...
 
static void Update ()
 Redraw requests are buffered and done in one go by this method. More...
 

Public Attributes

int Width
 The width of the dynamic texture. More...
 
int Height
 The height of the dynamic texture. More...
 
string Name
 The name for this texture. More...
 
bool Refreshing
 True if this texture needs a refresh this frame. More...
 
Color32[] Pixels
 The pixels of this texture. More...
 
int ResizedWidth
 The resized height of the texture (internal). Only used if this texture is resized and it gets shrunk. More...
 
int ResizedHeight
 The resized height of the texture (internal). Only used if this texture is resized and it gets shrunk. More...
 

Static Public Attributes

static bool SomethingToUpdate
 True if at least one dynamic texture must be flushed this frame. More...
 
static Dictionary< string,
DynamicTexture
Instances
 A global lookup of available dynamic textures used for mapping a URL to an object. E.g. background:url("dynamic://healthbar"); More...
 

Properties

FilterMode FilterMode [get, set]
 The filter mode of this dynamic texture. The default filtering is point. More...
 

Private Member Functions

void Redraw ()
 Called by the update system to redraw this texture, only if it requires it. More...
 

Private Attributes

Texture2D Texture
 A placeholder texture which is only used by the atlas. More...
 

Constructor & Destructor Documentation

PowerUI.DynamicTexture.DynamicTexture ( int  width,
int  height,
string  name 
)
inline

Creates a new dynamic texture of the given dimensions.

Parameters
widthThe width of the texture.
heightThe height of the texture.
nameThe name of the texture. This is used in urls to locate it (e.g. dynamic://theName).
PowerUI.DynamicTexture.DynamicTexture ( )
inline

Creates an empty dynamic texture. Note that this is used internally by canvas. If used, you must call Resize to set it up.

Member Function Documentation

void PowerUI.DynamicTexture.Clear ( )
inline

Wipes the graphic clean using transparent black.

void PowerUI.DynamicTexture.Clear ( Color32  clearColour)
inline

Wipes the graphic clean.

Parameters
clearColourThe colour to set the whole graphic to.
void PowerUI.DynamicTexture.DrawCircle ( int  x0,
int  y0,
int  radius,
Color32  colour 
)
inline

Draws a filled circle on the atlas.

Parameters
x0The x coordinate of the circles center in pixels from the left.
y0The y coordinate of the circles center in pixels from the bottom.
radiusThe radius of the circle, in pixels.
colourThe colour of the circle.
void PowerUI.DynamicTexture.DrawLine ( int  x,
int  y,
int  x2,
int  y2,
Color32  colour 
)
inline

Draws a line on the atlas from one point to another.

Parameters
xThe x coordinate in pixels from the left of the start of the line.
yThe y coordinate in pixels from the left of the start of the line.
x2The x coordinate in pixels from the left of the end of the line.
y2The y coordinate in pixels from the left of the end of the line.
colourThe colour of the line.
void PowerUI.DynamicTexture.DrawPixel ( int  x,
int  y,
Color32  colour 
)
inline

Draws a pixel at the given x/y coordinates to the atlas.

Parameters
xThe x coordinate in pixels from the left of the texture.
yThe y coordinate in pixels from the bottom of the texture.
colourThe colour of the pixel to draw.
virtual void PowerUI.DynamicTexture.Flush ( )
inlinevirtual

Override this to write to the pixels. Should internally use SetPixel for this.

Reimplemented in HealthBar, and PowerBar.

void PowerUI.DynamicTexture.FlushDirect ( )
inline

Internally used only. Flushes the pixel array to the texture right now.

static DynamicTexture PowerUI.DynamicTexture.Get ( string  byName)
inlinestatic

Gets a dynamic texture by name from the global lookup.

Parameters
byNameThe name of the dynamic texture.
Returns
The dynamic texture if found; null otherwise.
Texture2D PowerUI.DynamicTexture.GetTexture ( )
inline

Gets the texture.

Texture2D PowerUI.DynamicTexture.GetTextureHolder ( )
inline

Gets the placeholder texture.

void PowerUI.DynamicTexture.Redraw ( )
inlineprivate

Called by the update system to redraw this texture, only if it requires it.

void PowerUI.DynamicTexture.Refresh ( )
inline

Called to refresh the texture.

static void PowerUI.DynamicTexture.RemoveAll ( )
inlinestatic

Removes all dynamic textures.

void PowerUI.DynamicTexture.Resize ( int  width,
int  height 
)
inline

Resize this texture on the X and Y axis.

Parameters
widthThe new width.
heightThe new height.
void PowerUI.DynamicTexture.Resize ( int  width,
int  height,
bool  createIfZero 
)
inline

Resize this texture on the X and Y axis, optionally only doing so if dimensions aren't zero.

Parameters
widthThe new width.
heightThe new height.
createIfZeroOnly do the resize if the dimensions are non-zero.
void PowerUI.DynamicTexture.ResizeX ( int  width)
inline

Resize this texture on the X axis.

Parameters
widthThe new width.
void PowerUI.DynamicTexture.ResizeY ( int  height)
inline

Resize this texture on the Y axis.

Parameters
heightThe new height.
void PowerUI.DynamicTexture.SetPixel ( int  index,
Color32  colour 
)
inline

Sets a the colour of a particular global pixel on the atlas.

Parameters
indexThe global index of the pixel on the atlas.
colourThe colour of the pixel to set.
static void PowerUI.DynamicTexture.Update ( )
inlinestatic

Redraw requests are buffered and done in one go by this method.

Member Data Documentation

int PowerUI.DynamicTexture.Height

The height of the dynamic texture.

Dictionary<string,DynamicTexture> PowerUI.DynamicTexture.Instances
static

A global lookup of available dynamic textures used for mapping a URL to an object. E.g. background:url("dynamic://healthbar");

string PowerUI.DynamicTexture.Name

The name for this texture.

Color32 [] PowerUI.DynamicTexture.Pixels

The pixels of this texture.

bool PowerUI.DynamicTexture.Refreshing

True if this texture needs a refresh this frame.

int PowerUI.DynamicTexture.ResizedHeight

The resized height of the texture (internal). Only used if this texture is resized and it gets shrunk.

int PowerUI.DynamicTexture.ResizedWidth

The resized height of the texture (internal). Only used if this texture is resized and it gets shrunk.

bool PowerUI.DynamicTexture.SomethingToUpdate
static

True if at least one dynamic texture must be flushed this frame.

Texture2D PowerUI.DynamicTexture.Texture
private

A placeholder texture which is only used by the atlas.

int PowerUI.DynamicTexture.Width

The width of the dynamic texture.

Property Documentation

FilterMode PowerUI.DynamicTexture.FilterMode
getset

The filter mode of this dynamic texture. The default filtering is point.