/// <summary> /// Adds the given item to be rendered. /// </summary> /// <param name="color"></param> /// <param name="matrix"></param> public void AddItem(Color32 color, Matrix4x4 matrix) { int foundAtIndex = -1; // check if the color was already added to group the matrices for (int i = 0; i < batchInfos.Count; i++) { if ((Color)batchInfos[i].color == (Color)color) { foundAtIndex = i; break; } } // the color was not added yet if (foundAtIndex < 0 && batchInfos.Count >= MaxColorVariations - 1) { // we have surpassed the limit of colors supported Logger.LogWarningFormat("Can not add another color variation to the batcher, because it reached the maximum allowed: {0}. Consider increasing it.", MaxColorVariations.ToString()); return; } else if (foundAtIndex < 0 && batchInfos.Count < MaxColorVariations - 1 || foundAtIndex >= 0) { // color not added yet and still have room for another color, or color added already BatchInfo info = foundAtIndex >= 0 ? batchInfos[foundAtIndex] : new BatchInfo(color); info.AddMatrix(matrix); if (foundAtIndex < 0) { batchInfos.Add(info); } } }