- Home /
In the EditorWindow, what is the best way to click on a rect?
I am designing a custom editor for a Pachinko game and trying to build a level editor around it.
However, I need to click on the rectangles that represent the spaces on the game board in order to change them. I've got most of the code laid out, but I'm hung up on this. What is the best way to detect mouse clicks on EditorGUI.DrawRect?
for (int y = 0; y < PachinkoLevels.gridYSize; y++)
{
EditorGUILayout.BeginVertical();
for (int x = 0; x < PachinkoLevels.gridXSize; x++)
{
int index = y * PachinkoLevels.gridYSize + x;
float num = activeLevel.allLevels[0].board[index];
switch(num)
{
}
float boxSize = 35;
float rectSpacing = boxSize + 4;
Rect Position = new Rect(x * rectSpacing, y * rectSpacing, boxSize, boxSize);
EditorGUI.DrawRect(Position, Color.green);
if (Input.GetMouseButtonDown(0))
{
if (Position.Contains(Input.mousePosition))
{
Debug.Log(index);
}
}
}
Comment