本文整理汇总了C#中dfRenderData类的典型用法代码示例。如果您正苦于以下问题:C# dfRenderData类的具体用法?C# dfRenderData怎么用?C# dfRenderData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
dfRenderData类属于命名空间,在下文中一共展示了dfRenderData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public void Add( dfRenderData buffer )
{
if( Material == null && buffer.Material != null )
Material = buffer.Material;
buffers.Add( buffer );
}
示例2: Clip
public static void Clip(IList<Plane> planes, dfRenderData source, dfRenderData dest)
{
dest.EnsureCapacity(dest.Vertices.Count + source.Vertices.Count);
for (int i = 0; i < source.Triangles.Count; i = i + 3)
{
for (int j = 0; j < 3; j++)
{
int item = source.Triangles[i + j];
Matrix4x4 transform = source.Transform;
dfClippingUtil.clipSource[0].corner[j] = transform.MultiplyPoint(source.Vertices[item]);
dfClippingUtil.clipSource[0].uv[j] = source.UV[item];
dfClippingUtil.clipSource[0].color[j] = source.Colors[item];
}
int plane = 1;
for (int k = 0; k < planes.Count; k++)
{
plane = dfClippingUtil.clipToPlane(planes[k], dfClippingUtil.clipSource, dfClippingUtil.clipDest, plane);
dfClippingUtil.ClipTriangle[] clipTriangleArray = dfClippingUtil.clipSource;
dfClippingUtil.clipSource = dfClippingUtil.clipDest;
dfClippingUtil.clipDest = clipTriangleArray;
}
for (int l = 0; l < plane; l++)
{
dfClippingUtil.clipSource[l].CopyTo(dest);
}
}
}
示例3: renderSprite
internal static new void renderSprite( dfRenderData renderData, RenderOptions options )
{
#if UNITY_EDITOR
var atlas = options.atlas;
if( atlas == null )
throw new NullReferenceException( "The Texture Atlas cannot be null" );
if( atlas.Texture == null )
throw new NullReferenceException( "The Texture Altas has no texture assigned or the texture was deleted" );
if( options.spriteInfo == null )
throw new ArgumentNullException( "The Sprite cannot be null" );
#endif
options.baseIndex = renderData.Vertices.Count;
rebuildTriangles( renderData, options );
rebuildVertices( renderData, options );
rebuildUV( renderData, options );
rebuildColors( renderData, options );
if( options.fillAmount < 1f )
{
doFill( renderData, options );
}
}
示例4: renderSprite
internal static new void renderSprite(dfRenderData renderData, dfSprite.RenderOptions options)
{
options.baseIndex = renderData.Vertices.Count;
dfSlicedSprite.rebuildTriangles(renderData, options);
dfSlicedSprite.rebuildVertices(renderData, options);
dfSlicedSprite.rebuildUV(renderData, options);
dfSlicedSprite.rebuildColors(renderData, options);
if (options.fillAmount < 1f)
{
dfSlicedSprite.doFill(renderData, options);
}
}
示例5: Clip
/// <summary>
/// Clips a <see cref="dfRenderData"/> instance containing control rendering data
/// against a list of <see cref="Plane"/> objects defined by the current clipping
/// region, and outputs the clipped data into <paramref name="dest"/>
/// </summary>
/// <param name="planes">The list of planes to clip against</param>
/// <param name="source">The control rendering data to be clipped</param>
/// <param name="dest">The output buffer that will hold the resulting clipped data</param>
public static void Clip( IList<Plane> planes, dfRenderData source, dfRenderData dest )
{
dest.EnsureCapacity( dest.Vertices.Count + source.Vertices.Count );
var triangleCount = source.Triangles.Count;
var vertices = source.Vertices.Items;
var triangles = source.Triangles.Items;
var uvs = source.UV.Items;
var colors = source.Colors.Items;
var transform = source.Transform;
var planeCount = planes.Count;
for( int sourceIndex = 0; sourceIndex < triangleCount; sourceIndex += 3 )
{
for( int i = 0; i < 3; i++ )
{
var index = triangles[ sourceIndex + i ];
clipSource[ 0 ].corner[ i ] = transform.MultiplyPoint( vertices[ index ] );
clipSource[ 0 ].uv[ i ] = uvs[ index ];
clipSource[ 0 ].color[ i ] = colors[ index ];
}
var count = 1;
for( int planeIndex = 0; planeIndex < planeCount; planeIndex++ )
{
var clipPlane = planes[ planeIndex ];
count = clipToPlane( ref clipPlane, clipSource, clipDest, count );
var temp = clipSource;
clipSource = clipDest;
clipDest = temp;
}
for( int i = 0; i < count; i++ )
{
clipSource[ i ].CopyTo( dest );
}
}
}
示例6: renderText
private void renderText( dfRenderData textBuffer )
{
var p2u = PixelsToUnits();
var maxSize = new Vector2( size.x - padding.horizontal, this.size.y - padding.vertical );
var pivotOffset = pivot.TransformToUpperLeft( Size );
var origin = new Vector3(
pivotOffset.x + padding.left,
pivotOffset.y - padding.top,
0
) * p2u;
var displayText = IsPasswordField && !string.IsNullOrEmpty( this.passwordChar ) ? passwordDisplayText() : this.text;
var renderColor = IsEnabled ? TextColor : DisabledColor;
var scaleMultiplier = getTextScaleMultiplier();
using( var textRenderer = font.ObtainRenderer() )
{
textRenderer.WordWrap = false;
textRenderer.MaxSize = maxSize;
textRenderer.PixelRatio = p2u;
textRenderer.TextScale = TextScale * scaleMultiplier;
textRenderer.VectorOffset = origin;
textRenderer.MultiLine = false;
textRenderer.TextAlign = TextAlignment.Left;
textRenderer.ProcessMarkup = false;
textRenderer.DefaultColor = renderColor;
textRenderer.BottomColor = renderColor;
textRenderer.OverrideMarkupColors = false;
textRenderer.Opacity = this.CalculateOpacity();
textRenderer.Shadow = this.Shadow;
textRenderer.ShadowColor = this.ShadowColor;
textRenderer.ShadowOffset = this.ShadowOffset;
#region Manage the scroll position - Keep cursor in view at all times
cursorIndex = Mathf.Min( cursorIndex, displayText.Length );
scrollIndex = Mathf.Min( Mathf.Min( scrollIndex, cursorIndex ), displayText.Length );
charWidths = textRenderer.GetCharacterWidths( displayText );
var maxRenderSize = maxSize * p2u;
leftOffset = 0f;
if( textAlign == TextAlignment.Left )
{
// Measure everything from the current scroll position up to the cursor
var renderedWidth = 0f;
for( int i = scrollIndex; i < cursorIndex; i++ )
{
renderedWidth += charWidths[ i ];
}
// Make sure that the cursor can still be viewed
while( renderedWidth >= maxRenderSize.x && scrollIndex < cursorIndex )
{
renderedWidth -= charWidths[ scrollIndex++ ];
}
}
else
{
scrollIndex = Mathf.Max( 0, Mathf.Min( cursorIndex, displayText.Length - 1 ) );
var renderedWidth = 0f;
var slop = font.FontSize * 1.25f * p2u;
while( scrollIndex > 0 && renderedWidth < maxRenderSize.x - slop )
{
renderedWidth += charWidths[ scrollIndex-- ];
}
var textSize = ( displayText.Length > 0 ) ? textRenderer.GetCharacterWidths( displayText.Substring( scrollIndex ) ).Sum() : 0;
switch( textAlign )
{
case TextAlignment.Center:
leftOffset = Mathf.Max( 0, ( maxRenderSize.x - textSize ) * 0.5f );
break;
case TextAlignment.Right:
leftOffset = Mathf.Max( 0, maxRenderSize.x - textSize );
break;
}
origin.x += leftOffset;
textRenderer.VectorOffset = origin;
}
#endregion
if( selectionEnd != selectionStart )
{
renderSelection( scrollIndex, charWidths, leftOffset );
}
else if( cursorShown )
{
//.........这里部分代码省略.........
示例7: clipToViewport
private void clipToViewport( dfRenderData renderData )
{
//@Profiler.BeginSample( "Clip markup box to viewport" );
var planes = getViewportClippingPlanes();
var material = renderData.Material;
var matrix = renderData.Transform;
clipBuffer.Clear();
dfClippingUtil.Clip( planes, renderData, clipBuffer );
renderData.Clear();
renderData.Merge( clipBuffer, false );
renderData.Material = material;
renderData.Transform = matrix;
Profiler.EndSample();
}
示例8: renderSprite
private void renderSprite( dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination )
{
try
{
//@Profiler.BeginSample( "Render embedded sprite" );
var spriteName = token.GetAttribute( 0 ).Value.Value;
var spriteInfo = SpriteAtlas[ spriteName ];
if( spriteInfo == null )
return;
var options = new dfSprite.RenderOptions()
{
atlas = SpriteAtlas,
color = color,
fillAmount = 1,
flip = dfSpriteFlip.None,
offset = position,
pixelsToUnits = PixelRatio,
size = new Vector2( token.Width, token.Height ),
spriteInfo = spriteInfo
};
dfSprite.renderSprite( SpriteBuffer, options );
}
finally
{
//@Profiler.EndSample();
}
}
示例9: renderLine
/// <summary>
/// Renders a single line of text
/// </summary>
private void renderLine( LineRenderInfo line, Stack<Color32> colors, Vector3 position, dfRenderData destination )
{
position.x += calculateLineAlignment( line );
for( int i = line.startOffset; i <= line.endOffset; i++ )
{
var token = tokens[ i ];
var type = token.TokenType;
if( type == dfMarkupTokenType.Text )
{
renderText( token, colors.Peek(), position, destination );
}
else if( type == dfMarkupTokenType.StartTag )
{
if( token.Matches( "sprite" ) && SpriteAtlas != null && SpriteBuffer != null )
{
renderSprite( token, colors.Peek(), position, SpriteBuffer );
}
else if( token.Matches( "color" ) )
{
colors.Push( parseColor( token ) );
}
}
else if( type == dfMarkupTokenType.EndTag )
{
if( token.Matches( "color" ) && colors.Count > 1 )
{
colors.Pop();
}
}
position.x += token.Width;
}
}
示例10: clipBottom
private void clipBottom( dfRenderData destination, int startIndex )
{
if( destination == null )
return;
var limit = VectorOffset.y - MaxSize.y * PixelRatio;
var verts = destination.Vertices;
var uv = destination.UV;
var colors = destination.Colors;
for( int i = startIndex; i < verts.Count; i += 4 )
{
var ul = verts[ i + 0 ];
var ur = verts[ i + 1 ];
var br = verts[ i + 2 ];
var bl = verts[ i + 3 ];
var h = ul.y - bl.y;
if( bl.y <= limit )
{
var clip = 1f - ( Mathf.Abs( -limit + ul.y ) / h );
verts[ i + 0 ] = ul = new Vector3( ul.x, Mathf.Max( ul.y, limit ), ur.z );
verts[ i + 1 ] = ur = new Vector3( ur.x, Mathf.Max( ur.y, limit ), ur.z );
verts[ i + 2 ] = br = new Vector3( br.x, Mathf.Max( br.y, limit ), br.z );
verts[ i + 3 ] = bl = new Vector3( bl.x, Mathf.Max( bl.y, limit ), bl.z );
uv[ i + 3 ] = Vector2.Lerp( uv[ i + 3 ], uv[ i + 0 ], clip );
uv[ i + 2 ] = Vector2.Lerp( uv[ i + 2 ], uv[ i + 1 ], clip );
var color = Color.Lerp( colors[ i + 3 ], colors[ i ], clip );
colors[ i + 3 ] = color;
colors[ i + 2 ] = color;
}
}
}
示例11: Merge
/// <summary>
/// Merges another <see cref="dfRenderData"/> instance with this instance
/// </summary>
/// <param name="buffer">The render data to be appended to this instance</param>
/// <param name="transformVertices">If set to TRUE, the render data in
/// <paramref name="buffer"/> will be transformed by its <see cref="Transform"/>
/// before being merged with this instance. If set to FALSE, the data will be
/// merged without tranforming.</param>
public void Merge( dfRenderData buffer, bool transformVertices )
{
// We need the current currentIndex of vertices before adding any more so that
// we have a proper base index for our triangle indices
var baseIndex = Vertices.Count;
#region Merge vertices
Vertices.AddRange( buffer.Vertices );
if( transformVertices )
{
var rawVerts = Vertices.Items;
var count = buffer.Vertices.Count;
var transform = buffer.Transform;
for( int i = baseIndex; i < baseIndex + count; i++ )
{
rawVerts[ i ] = transform.MultiplyPoint( rawVerts[ i ] );
}
}
#endregion
#region Merge triangles
var triangleBaseIndex = Triangles.Count;
Triangles.AddRange( buffer.Triangles );
var bufferTriangleCount = buffer.Triangles.Count;
var rawTriangles = Triangles.Items;
for( int i = triangleBaseIndex; i < triangleBaseIndex + bufferTriangleCount; i++ )
{
rawTriangles[ i ] += baseIndex;
}
#endregion
UV.AddRange( buffer.UV );
Colors.AddRange( buffer.Colors );
Normals.AddRange( buffer.Normals );
Tangents.AddRange( buffer.Tangents );
}
示例12: RenderMultiple
public dfList<dfRenderData> RenderMultiple()
{
if( Atlas == null || Font == null )
return null;
if( !isVisible )
{
return null;
}
// Initialize render buffers if needed
if( renderData == null )
{
renderData = dfRenderData.Obtain();
textRenderData = dfRenderData.Obtain();
isControlInvalidated = true;
}
// If control is not dirty, update the transforms on the
// render buffers (in case control moved) and return
// pre-rendered data
if( !isControlInvalidated )
{
for( int i = 0; i < buffers.Count; i++ )
{
buffers[ i ].Transform = transform.localToWorldMatrix;
}
return buffers;
}
#region Prepare render buffers
buffers.Clear();
renderData.Clear();
renderData.Material = Atlas.Material;
renderData.Transform = this.transform.localToWorldMatrix;
buffers.Add( renderData );
textRenderData.Clear();
textRenderData.Material = Atlas.Material;
textRenderData.Transform = this.transform.localToWorldMatrix;
buffers.Add( textRenderData );
#endregion
// Render background before anything else, since we're going to
// want to keep track of where the background data ends and any
// other data begins
renderBackground();
// We want to start clipping *after* the background is rendered, so
// grab the current number of vertices before rendering other elements
var spriteClipStart = renderData.Vertices.Count;
// Render other sprites
renderHover();
renderSelection();
// Render text items
renderItems( textRenderData );
// Perform clipping
clipQuads( renderData, spriteClipStart );
clipQuads( textRenderData, 0 );
// Control is no longer in need of rendering
isControlInvalidated = false;
// Make sure that the collider size always matches the control
updateCollider();
return buffers;
}
示例13: clipToViewport
private void clipToViewport( dfRenderData renderData )
{
var planes = getViewportClippingPlanes();
var material = renderData.Material;
var matrix = renderData.Transform;
clipBuffer.Clear();
dfClippingUtil.Clip( planes, renderData, clipBuffer );
renderData.Clear();
renderData.Merge( clipBuffer, false );
renderData.Material = material;
renderData.Transform = matrix;
}
示例14: rebuildVertices
private static void rebuildVertices( dfRenderData renderData, RenderOptions options )
{
float meshLeft = 0;
float meshTop = 0;
float meshRight = Mathf.Ceil( options.size.x );
float meshBottom = Mathf.Ceil( -options.size.y );
#region Borders
var spriteInfo = options.spriteInfo;
float borderLeft = spriteInfo.border.left;
float borderTop = spriteInfo.border.top;
float borderRight = spriteInfo.border.right;
float borderBottom = spriteInfo.border.bottom;
if( options.flip.IsSet( dfSpriteFlip.FlipHorizontal ) )
{
float temp = borderRight;
borderRight = borderLeft;
borderLeft = temp;
}
if( options.flip.IsSet( dfSpriteFlip.FlipVertical ) )
{
float temp = borderBottom;
borderBottom = borderTop;
borderTop = temp;
}
#endregion
// Top left corner
verts[ 0 ] = new Vector3( meshLeft, meshTop, 0 ) + options.offset;
verts[ 1 ] = verts[ 0 ] + new Vector3( borderLeft, 0, 0 );
verts[ 2 ] = verts[ 0 ] + new Vector3( borderLeft, -borderTop, 0 );
verts[ 3 ] = verts[ 0 ] + new Vector3( 0, -borderTop, 0 );
// Top right corner
verts[ 4 ] = new Vector3( meshRight - borderRight, meshTop, 0 ) + options.offset;
verts[ 5 ] = verts[ 4 ] + new Vector3( borderRight, 0, 0 );
verts[ 6 ] = verts[ 4 ] + new Vector3( borderRight, -borderTop, 0 );
verts[ 7 ] = verts[ 4 ] + new Vector3( 0, -borderTop, 0 );
// Bottom left corner
verts[ 8 ] = new Vector3( meshLeft, meshBottom + borderBottom, 0 ) + options.offset;
verts[ 9 ] = verts[ 8 ] + new Vector3( borderLeft, 0, 0 );
verts[ 10 ] = verts[ 8 ] + new Vector3( borderLeft, -borderBottom, 0 );
verts[ 11 ] = verts[ 8 ] + new Vector3( 0, -borderBottom, 0 );
// Bottom right corner
verts[ 12 ] = new Vector3( meshRight - borderRight, meshBottom + borderBottom, 0 ) + options.offset;
verts[ 13 ] = verts[ 12 ] + new Vector3( borderRight, 0, 0 );
verts[ 14 ] = verts[ 12 ] + new Vector3( borderRight, -borderBottom, 0 );
verts[ 15 ] = verts[ 12 ] + new Vector3( 0, -borderBottom, 0 );
for( int i = 0; i < verts.Length; i++ )
{
renderData.Vertices.Add( ( verts[ i ] * options.pixelsToUnits ).Quantize( options.pixelsToUnits ) );
}
}
示例15: rebuildUV
private static void rebuildUV( dfRenderData renderData, RenderOptions options )
{
var atlas = options.atlas;
var textureSize = new Vector2( atlas.Texture.width, atlas.Texture.height );
var spriteInfo = options.spriteInfo;
float offsetTop = spriteInfo.border.top / textureSize.y;
float offsetBottom = spriteInfo.border.bottom / textureSize.y;
float offsetLeft = spriteInfo.border.left / textureSize.x;
float offsetRight = spriteInfo.border.right / textureSize.x;
var rect = spriteInfo.region;
// Top left corner
uv[ 0 ] = new Vector2( rect.x, rect.yMax );
uv[ 1 ] = new Vector2( rect.x + offsetLeft, rect.yMax );
uv[ 2 ] = new Vector2( rect.x + offsetLeft, rect.yMax - offsetTop );
uv[ 3 ] = new Vector2( rect.x, rect.yMax - offsetTop );
// Top right corner
uv[ 4 ] = new Vector2( rect.xMax - offsetRight, rect.yMax );
uv[ 5 ] = new Vector2( rect.xMax, rect.yMax );
uv[ 6 ] = new Vector2( rect.xMax, rect.yMax - offsetTop );
uv[ 7 ] = new Vector2( rect.xMax - offsetRight, rect.yMax - offsetTop );
// Bottom left corner
uv[ 8 ] = new Vector2( rect.x, rect.y + offsetBottom );
uv[ 9 ] = new Vector2( rect.x + offsetLeft, rect.y + offsetBottom );
uv[ 10 ] = new Vector2( rect.x + offsetLeft, rect.y );
uv[ 11 ] = new Vector2( rect.x, rect.y );
// Bottom right corner
uv[ 12 ] = new Vector2( rect.xMax - offsetRight, rect.y + offsetBottom );
uv[ 13 ] = new Vector2( rect.xMax, rect.y + offsetBottom );
uv[ 14 ] = new Vector2( rect.xMax, rect.y );
uv[ 15 ] = new Vector2( rect.xMax - offsetRight, rect.y );
#region Flip UV if requested
if( options.flip != dfSpriteFlip.None )
{
for( int i = 0; i < uv.Length; i += 4 )
{
Vector2 temp = Vector2.zero;
if( options.flip.IsSet( dfSpriteFlip.FlipHorizontal ) )
{
temp = uv[ i + 0 ]; uv[ i + 0 ] = uv[ i + 1 ]; uv[ i + 1 ] = temp;
temp = uv[ i + 2 ]; uv[ i + 2 ] = uv[ i + 3 ]; uv[ i + 3 ] = temp;
}
if( options.flip.IsSet( dfSpriteFlip.FlipVertical ) )
{
temp = uv[ i + 0 ]; uv[ i + 0 ] = uv[ i + 3 ]; uv[ i + 3 ] = temp;
temp = uv[ i + 1 ]; uv[ i + 1 ] = uv[ i + 2 ]; uv[ i + 2 ] = temp;
}
}
if( options.flip.IsSet( dfSpriteFlip.FlipHorizontal ) )
{
var th = new Vector2[ uv.Length ];
Array.Copy( uv, th, uv.Length );
// Swap top-left and top-right corners
Array.Copy( uv, 0, uv, 4, 4 );
Array.Copy( th, 4, uv, 0, 4 );
// Swap bottom-left and bottom-right corners
Array.Copy( uv, 8, uv, 12, 4 );
Array.Copy( th, 12, uv, 8, 4 );
}
if( options.flip.IsSet( dfSpriteFlip.FlipVertical ) )
{
var tv = new Vector2[ uv.Length ];
Array.Copy( uv, tv, uv.Length );
// Swap top-left and bottom-left corners
Array.Copy( uv, 0, uv, 8, 4 );
Array.Copy( tv, 8, uv, 0, 4 );
// Swap top-right and bottom-right corners
Array.Copy( uv, 4, uv, 12, 4 );
Array.Copy( tv, 12, uv, 4, 4 );
}
}
#endregion
for( int i = 0; i < uv.Length; i++ )
{
renderData.UV.Add( uv[ i ] );
//.........这里部分代码省略.........