public void SetAnimationFrameByFloat(HumanAnimation ani, float progress, float step) { float percent = Mathf.Clamp01(RXMath.Mod(progress, step) / step); int frame = Mathf.RoundToInt(percent * (float)(ani.numFrames - 1)); SetAnimationFrame(ani, frame); }
public void UpdateMesh() { float offsetX = -_anchorX * width; float offsetY = -_anchorY * height; float ewidth = _element.sourceSize.x; float eheight = _element.sourceSize.y; float leftRemaining = RXMath.Mod(_scrollX, ewidth); float bottomRemaining = RXMath.Mod(_scrollY, eheight); float leftX = leftRemaining; float rightX = leftX + width; int leftCol = 0; int rightCol = Mathf.FloorToInt(rightX / ewidth); if (rightX % ewidth == 0) { rightCol--; //if it fits exactly, we don't need the last column } float bottomY = bottomRemaining; float topY = bottomY + height; int bottomRow = 0; int topRow = Mathf.FloorToInt(topY / eheight); if (topY % eheight == 0) { topRow--; //if it fits exactly, we don't need the last row } int numCols = (rightCol - leftCol) + 1; int numRows = (topRow - bottomRow) + 1; _meshData.SetFacetCount(numCols * numRows); List <FMeshFacet> quads = _meshData.facets; float rightRemaining = ((rightCol + 1) * ewidth - rightX); float topRemaining = ((topRow + 1) * eheight - topY); int q = 0; for (int r = 0; r < numRows; r++) { float quadBottom = offsetY + r * eheight - bottomRemaining; float quadTop = quadBottom + eheight; float uvBottom = 0; float uvTop = 1.0f; if (r == 0) //bottomRow { quadBottom += bottomRemaining; uvBottom += bottomRemaining / eheight; } if (r == numRows - 1) //topRow { quadTop -= topRemaining; uvTop -= topRemaining / eheight; } for (int c = 0; c < numCols; c++) { FMeshQuad quad = (FMeshQuad)quads[q]; q++; float quadLeft = offsetX + c * ewidth - leftRemaining; float quadRight = quadLeft + ewidth; float uvLeft = 0; float uvRight = 1.0f; if (c == 0) //leftCol { quadLeft += leftRemaining; uvLeft += leftRemaining / ewidth; } if (c == numCols - 1) //rightCol { quadRight -= rightRemaining; uvRight -= rightRemaining / ewidth; } quad.SetPosExtents(quadLeft, quadRight, quadBottom, quadTop); quad.SetUVExtents(uvLeft, uvRight, uvBottom, uvTop); } } _meshData.MarkChanged(); }