Exemplo n.º 1
0
        public void Start()
        {
            while (layer.voxels.Count > 0)
            {
                int          maxRemovableCount = 0;
                Vector2      scaleFactor;
                List <Voxel> maxMergableVoxels = null;
                Vector2      maxScaleFactor    = Vector2.zero;
                Voxel        maxVoxel          = null;

                foreach (Voxel curVoxel in this.layer.voxels.Values)
                {
                    List <Voxel> curMergableVoxels = this.GetMergableVoxels(layer, curVoxel, vectorX, vectorY, out scaleFactor);
                    if (curMergableVoxels.Count > maxRemovableCount)
                    {
                        maxVoxel          = curVoxel;
                        maxRemovableCount = curMergableVoxels.Count;
                        maxMergableVoxels = curMergableVoxels;
                        maxScaleFactor    = scaleFactor;
#if UNITY_EDITOR
                        //                            if (EditorUtility.DisplayCancelableProgressBar("Optimization", aProgressCaption + " " + progressPercentage + "%", ((float)aLayers.IndexOf(curLayer)) / ((float)aLayers.Count)))
                        //return false;
#endif
                        if (((maxRemovableCount > this.optmalisationMinMergableVoxels) && (optmalisationMinMergableVoxels != 0)) || (maxRemovableCount == layer.voxels.Count))
                        {
                            break;
                        }
                    }
                }
                if (maxVoxel == null)
                {
                    break;
                }

                List <Voxel> mergableVoxels = maxMergableVoxels;

                ownerContainer.BuildPolygonsForFace(texture, mergableVoxels[0].color, vertices, triangles, uvs, maxVoxel.position + offset, vectorX * maxScaleFactor.x, vectorY * maxScaleFactor.y, textureWidth, textureHeight);
                foreach (Voxel curVoxel in mergableVoxels)
                {
                    layer.voxels.Remove(curVoxel.position);
                }
            }
        }