public static void Register(AreaExt areaExt)
        {
#if DEBUG
            Log.Message(string.Format("new area registerd: {0}", areaExt.GetUniqueLoadID()));
#endif
            allAreaExts.Add(new WeakReference <AreaExt>(areaExt));
        }
        public static AreaExt OnLoadingVars(string id)
        {
            AreaExtID areaExtID = new AreaExtID(id);
            if (!cache.ContainsKey(areaExtID.MapID))
            {
                cache[areaExtID.MapID] = new List<WeakReference<AreaExt>>();
            }

            AreaExt areaExt;
            WeakReference<AreaExt> refAreaExt = cache[areaExtID.MapID].Find(x => x.IsAlive && x.Target.GetUniqueLoadID() == id);
            if (refAreaExt != null)
            {
                areaExt = refAreaExt.Target;
            }
            else
            {
                areaExt = new AreaExt(areaExtID);
                cache[areaExtID.MapID].Add(new WeakReference<AreaExt>(areaExt));
            }

            return areaExt;
        }
예제 #3
0
        public void RegenerateMesh()
        {
            foreach (var m in meshes)
            {
                m.Clear();
            }
            meshes.Clear();

            float y = AltitudeLayer.MapDataOverlay.AltitudeFor();

            int            cells  = 0;
            List <Vector3> verts  = new List <Vector3>();
            List <Color>   colors = new List <Color>();
            List <int>     tris   = new List <int>();
            Mesh           mesh   = new Mesh();

            var mapSize = parentAreaExt.Map.Size;

            BitArray exclusionBA         = null;
            bool     needToCalcExclusion = true;

            var innerAreas = parentAreaExt.InnerAreas;

            for (int i = 0; i < innerAreas.Count; ++i)
            {
                Area            area = innerAreas[i].Key;
                AreaExtOperator op   = innerAreas[i].Value;

                if (op == AreaExtOperator.Inclusion)
                {
                    if (needToCalcExclusion)
                    {
                        exclusionBA = new BitArray(mapSize.x * mapSize.z);
                        exclusionBA.SetAll(false);

                        for (int j = i + 1; j < innerAreas.Count; ++j)
                        {
                            if (innerAreas[j].Value != AreaExtOperator.Exclusion)
                            {
                                continue;
                            }

                            exclusionBA = exclusionBA.Or(AreaExt.GetAreaBitArray(innerAreas[j].Key));
                        }

                        exclusionBA = exclusionBA.Not();
                    }

                    CellRect cellRect = new CellRect(0, 0, mapSize.x, mapSize.z);
                    for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                    {
                        for (int k = cellRect.minZ; k <= cellRect.maxZ; k++)
                        {
                            int index = CellIndicesUtility.CellToIndex(j, k, mapSize.x);
                            if (area[index] && exclusionBA[index])
                            {
                                verts.Add(new Vector3((float)j, y, (float)k));
                                verts.Add(new Vector3((float)j, y, (float)(k + 1)));
                                verts.Add(new Vector3((float)(j + 1), y, (float)(k + 1)));
                                verts.Add(new Vector3((float)(j + 1), y, (float)k));
                                colors.Add(area.Color);
                                colors.Add(area.Color);
                                colors.Add(area.Color);
                                colors.Add(area.Color);

                                int count = verts.Count;
                                tris.Add(count - 4);
                                tris.Add(count - 3);
                                tris.Add(count - 2);
                                tris.Add(count - 4);
                                tris.Add(count - 2);
                                tris.Add(count - 1);

                                cells++;
                                if (cells >= 16383)
                                {
                                    mesh.SetVertices(verts);
                                    mesh.SetColors(colors);
                                    mesh.SetTriangles(tris, 0);

                                    verts.Clear();
                                    colors.Clear();
                                    tris.Clear();

                                    meshes.Add(mesh);
                                    mesh = new Mesh();

                                    cells = 0;
                                }
                            }
                        }
                    }
                }
                else
                {
                    needToCalcExclusion = true;
                }
            }

            if (verts.Count > 0)
            {
#if DEBUG
                Log.Message(string.Format("Vertices: {0}", verts.Count));
#endif
                mesh.SetVertices(verts);
                mesh.SetColors(colors);
                mesh.SetTriangles(tris, 0);
                meshes.Add(mesh);
            }

            if (material == null)
            {
                material             = SolidColorMaterials.SimpleSolidColorMaterial(new Color(1f, 1f, 1f, opacity), true);
                material.renderQueue = 3600;
            }

            dirty = false;
        }
예제 #4
0
 public AreaExtCellDrawer(AreaExt areaExt)
 {
     this.parentAreaExt = areaExt;
 }