Assets/Lib.Spine/spine-unity/SkeletonExtensions.cs
/// <summary>Fills a Vector2 buffer with local vertices.</summary>
/// <param name="va">The VertexAttachment</param>
/// <param name="slot">Slot where the attachment belongs.</param>
/// <param name="buffer">Correctly-sized buffer. Use attachment's .WorldVerticesLength to get the correct size. If null, a new Vector2[] of the correct size will be allocated.</param>
Fills a Vector2 buffer with local vertices.
Fills a Vector2 buffer with local vertices .
public static Vector2[] GetLocalVertices (this VertexAttachment va, Slot slot, Vector2[] buffer) {
			int floatsCount = va.worldVerticesLength;
			int bufferTargetSize = floatsCount >> 1;
			buffer = buffer ?? new Vector2[bufferTargetSize];
			if (buffer.Length < bufferTargetSize) throw new System.ArgumentException(string.Format("Vector2 buffer too small. {0} requires an array of size {1}. Use the attachment's .WorldVerticesLength to get the correct size.", va.Name, floatsCount), "buffer");
			if (va.bones == null) {
				var localVerts = va.vertices;
				for (int i = 0; i < bufferTargetSize; i++) {
					int j = i * 2;
					buffer[i] = new Vector2(localVerts[j], localVerts[j+1]);
				}
			} else {
				var floats = new float[floatsCount];
				va.ComputeWorldVertices(slot, floats);
				Bone sb = slot.bone;
				float ia, ib, ic, id, bwx = sb.worldX, bwy = sb.worldY;
				sb.GetWorldToLocalMatrix(out ia, out ib, out ic, out id);
				for (int i = 0; i < bufferTargetSize; i++) {
					int j = i * 2;
					float x = floats[j] - bwx, y = floats[j+1] - bwy;
					buffer[i] = new Vector2(x * ia + y * ib, x * ic + y * id);
				}
			}
			return buffer;
		}
public static Vector2 [ ] GetLocalVertices ( this VertexAttachment va , Slot slot , Vector2 [ ] buffer ) { int floatsCount = va . worldVerticesLength ; int bufferTargetSize = floatsCount >> 1 ; buffer = buffer ?? new Vector2 [ bufferTargetSize ] ; if ( buffer . Length < bufferTargetSize ) throw new System . ArgumentException ( string . Format ( " " , va . Name , floatsCount ) , " " ) ; if ( va . bones == null ) { var localVerts = va . vertices ; for ( int i = 0 ; i < bufferTargetSize ; i ++ ) { int j = i * 2 ; buffer [ i ] = new Vector2 ( localVerts [ j ] , localVerts [ j + 1 ] ) ; } } else { var floats = new float [ floatsCount ] ; va . ComputeWorldVertices ( slot , floats ) ; Bone sb = slot . bone ; float ia , ib , ic , id , bwx = sb . worldX , bwy = sb . worldY ; sb . GetWorldToLocalMatrix ( out ia , out ib , out ic , out id ) ; for ( int i = 0 ; i < bufferTargetSize ; i ++ ) { int j = i * 2 ; float x = floats [ j ] - bwx , y = floats [ j + 1 ] - bwy ; buffer [ i ] = new Vector2 ( x * ia + y * ib , x * ic + y * id ) ; } } return buffer ; }
Fills a Vector2 buffer with local vertices.
Fills a Vector2 buffer with local vertices .
VertexAttachment
this
slot
Slot
Slot where the attachment belongs.
Slot where the attachment belongs .
buffer
Vector2[]
Correctly-sized buffer. Use attachment's .WorldVerticesLength to get the correct size. If null, a new Vector2[] of the correct size will be allocated.
Correctly - sized buffer . Use attachment ' s . WorldVerticesLength to get the correct size . If null a new Vector2 [] of the correct size will be allocated .
va
None