Created
January 31, 2023 07:04
-
-
Save Amitkapadi/42606483205f1492ccd7211e08faeac3 to your computer and use it in GitHub Desktop.
LayoutUtility for Unity World Space.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyUtility | |
{ | |
public static class LayoutUtility | |
{ | |
public static float[] GetXPosLayout(int totalObj, float maxWidth, float objXSize, float space, float xPedding) | |
{ | |
float maxSize = maxWidth - xPedding - xPedding; //Left and Right | |
float occupiedArea = (totalObj * objXSize); | |
float halfObjSize = objXSize * 0.5f; | |
if (totalObj >= 2) | |
occupiedArea += (totalObj - 1) * space; | |
float difference = (maxSize - occupiedArea) * 0.5f; | |
float[] xPos = new float[totalObj]; | |
float starting_x_value = maxWidth * -0.5f;// localSpace | |
starting_x_value += xPedding; | |
starting_x_value += difference; | |
starting_x_value += halfObjSize; | |
for (int i = 0; i < totalObj; i++) | |
{ | |
xPos[i] = starting_x_value; | |
starting_x_value += (objXSize + space); | |
} | |
return xPos; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment