Esempio n. 1
0
 void OnEnable()
 {
     myCurrentlyInspectedThing = target as ChunkLevel;
 }
    // When we receive the order (from viewer only?) to update the map based on position
    public void UpdateChunks()
    {
        // Compute Bound
        Bounds             viewerBound = Viewer.instance.bound;
        WorldChunkSettings setting     = MapEngine.instance.worldChunkSetting;

        ChunkLevel chunkLevel = this.GetChunkLevel(Viewer.instance.scale);

        // Get the bound min/max [@TODO: Wy don't reverse TOP or RIGHT so min/max already are boundMin and boundMax !! But actually it's for dev]
        // Later (when Coord.Top/Left.. are sure uncomment min/max and stop compute them)
        Coord boundMin /*min*/ = new Coord(viewerBound.min, setting);
        Coord boundMax /*max*/ = new Coord(viewerBound.max, setting);
        // Cause Coord.Top & Coord.Right can be reverse, check min/max
        Coord min = new Coord(
            (boundMin.x < boundMax.x) ? boundMin.x : boundMax.x,
            (boundMin.y < boundMax.y) ? boundMin.y : boundMax.y
            );
        Coord max = new Coord(
            (boundMin.x > boundMax.x) ? boundMin.x : boundMax.x,
            (boundMin.y > boundMax.y) ? boundMin.y : boundMax.y
            );

        // Hide chunk you are not on bound
        if (this.worldChunksInView.Count > 0)
        {
            for (int idx = 0; idx < this.worldChunksInView.Count; idx++)
            {
                WorldChunk chunk = this.worldChunksInView [idx];
                // Not In bound, Unload
                if (chunk.coord.x < min.x || chunk.coord.y < min.y || chunk.coord.x > max.x || chunk.coord.y > max.y)
                {
                    this.worldChunksInView [idx].Unload(setting);
                }
            }
        }
        this.worldChunksInView.Clear();

        //  Regenerate new
        for (int y = min.y; y <= max.y; y++)
        {
            for (int x = min.x; x <= max.x; x++)
            {
                Coord c = new Coord(x, y);
                if (this.worldChunks.ContainsKey(c))
                {
                    // If chunk is here, but need more
                    if (this.worldChunks [c].state < this.stateInBoundChunk)
                    {
                        this.worldChunks [c].UpdateState(setting, this.stateInBoundChunk);
                    }
                    this.worldChunks [c].Load(MapDisplay.instance.displayMode);
                }
                else
                {
                    this.CreateChunk(c, this.stateInBoundChunk);
                }
                // Visible Chunk
                this.worldChunksInView.Add(this.worldChunks [c]);
            }
        }
        setting.parent.gameObject.name = "Map Chunks [" + this.worldChunksInView.Count + "/" + this.worldChunks.Count + "] [zones: " + worldZones.Count + "]";
    }