private void DoFairyBatching()
{
_fBatchingRequested = false;
if (_descendants == null)
_descendants = new List<DisplayObject>();
else
_descendants.Clear();
CollectChildren(this);
int cnt = _descendants.Count;
//Debug.Log("DoFairyBatching " + cnt + "," + this.cachedTransform.GetInstanceID());
int i, j, k, m;
object curMat, testMat, lastMat;
DisplayObject current, test;
Rect bound;
for (i = 0; i < cnt; i++)
{
current = _descendants[i];
bound = current._internal_bounds;
curMat = current.material;
if (curMat == null || current._skipInFairyBatching)
continue;
k = -1;
lastMat = null;
m = i;
for (j = i - 1; j >= 0; j--)
{
test = _descendants[j];
if (test._skipInFairyBatching)
break;
testMat = test.material;
if (testMat != null)
{
if (lastMat != testMat)
{
lastMat = testMat;
m = j + 1;
}
if (curMat == testMat)
k = m;
}
if (bound.Overlaps(test._internal_bounds))
{
if (k == -1)
k = m;
break;
}
}
if (k != -1 && i != k)
{
_descendants.RemoveAt(i);
_descendants.Insert(k, current);
}
}
}