Beispiel #1
0
    public void RemoveFeature(int id, bool buffer = true)
    {
        Destroy(objects[id].gameObject);
        objects.Remove(id);

        if (buffer)
        {
            ChunkMod result = new ChunkMod(ChunkMod.ChunkModType.Remove, transform.position, id, -1);
            Server.bufferedChunkmods.Add(result);
            ServerSend.ChunkMod(result);
        }
    }
Beispiel #2
0
    public static void ChunkMod(ChunkMod c, int to)
    {
        using (Packet _packet = new Packet((int)ServerPackets.chunkMod))
        {
            _packet.Write((int)c.type);
            _packet.Write(c.chunk);
            _packet.Write(c.objectId);
            _packet.Write(c.modelId);

            SendTCPData(to, _packet);
        }
    }
Beispiel #3
0
    public void AddFeature(GameObject go, bool buffer = true)
    {
        ChunkObject c = go.GetComponent <ChunkObject>(); //to get it to work, assign every ChunkObject prefab the script and add an id.

        c.myId  = objects.Count;
        c.chunk = this;
        objects.Add(nid, c);
        nid++;
        if (buffer)
        {
            ChunkMod result = new ChunkMod(ChunkMod.ChunkModType.Add, go.transform.position, c.myId, c.model);
            Server.bufferedChunkmods.Add(result);
            ServerSend.ChunkMod(result);
        }
    }
Beispiel #4
0
    /// <summary>
    /// Mods a chunk.
    /// </summary>
    /// <param name="mod">Chunk to mod</param>
    public void ModChunk(ChunkMod mod)
    {
        ChunkManager.V2Int chunkPosition = ChunkManager.ChunkAt(mod.chunk.x, mod.chunk.z);
        GameObject         targetChunk   = ChunkManager.instance.chunks[chunkPosition.x, chunkPosition.y];

        ChunkManager.bufferedChunkMods[chunkPosition.x, chunkPosition.y].Add(mod);
        /// Creates a new GameObject and parents it to a corresponding chunk, obtained by checking the chunk array.
        if (mod.type == ChunkMod.ChunkModType.Add)
        {
            GameObject newObject = Instantiate(terrainObjectPrefabs[mod.modelId], mod.chunk, Quaternion.identity, targetChunk.transform);
            targetChunk.GetComponent <TerrainGenerator>().AddFeature(newObject);
        }
        /// Destroys a GameObject found by id on a chunk obtained from the chunk array.
        else if (mod.type == ChunkMod.ChunkModType.Remove)
        {
            targetChunk.GetComponent <TerrainGenerator>().RemoveFeature(mod.objectId);
        }
    }