Ошибка в TileRule Unity выход за пределы массива
'''
private static void RuleMatrixOnGUI(Rect rect, RuleTile.TilingRule tilingRule)
{
Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f);
int index = 0;
float w = rect.width / 3f;
float h = rect.height / 3f;
for (int y = 0; y <= 3; y++)
{
float top = rect.yMin + y * h;
Handles.DrawLine(new Vector3(rect.xMin, top), new Vector3(rect.xMax, top));
}
for (int x = 0; x <= 3; x++)
{
float left = rect.xMin + x * w;
Handles.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax));
}
Handles.color = Color.white;
for (int y = 0; y <= 2; y++)
{
for (int x = 0; x <= 2; x++)
{
Rect r = new Rect(rect.xMin + x * w, rect.yMin + y * h, w - 1, h - 1);
if (x != 1 || y != 1)
{
switch (tilingRule.m_Neighbors[index])
{
case RuleTile.TilingRule.Neighbor.This:
GUI.DrawTexture(r, arrows[y*3 + x]);
break;
case RuleTile.TilingRule.Neighbor.NotThis:
GUI.DrawTexture(r, arrows[9]);
break;
}
if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition))
{
int change = 1;
if (Event.current.button == 1)
change = -1;
//if (index < tilingRule.m_Neighbors.Count)
//{
tilingRule.m_Neighbors[index] = (((int)tilingRule.m_Neighbors[index] + change) % 3);
//}
//Debug.Log(tilingRule.m_Neighbors[index]);
GUI.changed = true;
Event.current.Use();
}
//(RuleTile.TilingRule.m_Neighbors)
index++;
}
else
{
switch (tilingRule.m_RuleTransform)
{
case RuleTile.TilingRule.Transform.Rotated:
GUI.DrawTexture(r, autoTransforms[0]);
break;
case RuleTile.TilingRule.Transform.MirrorX:
GUI.DrawTexture(r, autoTransforms[1]);
break;
case RuleTile.TilingRule.Transform.MirrorY:
GUI.DrawTexture(r, autoTransforms[2]);
break;
}
if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition))
{
tilingRule.m_RuleTransform = (RuleTile.TilingRule.Transform)(((int)tilingRule.m_RuleTransform + 1) % 4);
GUI.changed = true;
Event.current.Use();
}
}
}
}
}
'''
00000000000000000000000 tilingRule.m_Neighbors[index] = (((int)tilingRule.m_Neighbors[index] + change) % 3); на эту строку выдаёт 5 ошибок ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. как от них избавиться