Пример #1
0
        public void SaveExtraData(IWorldGenObject worldGenObject, byte data)
        {
            int id = worldGenObject.Id;

            if (id >= extraData.Length)
            {
                byte[] newEDArray = new byte[id + 1];
                Array.Copy(extraData, newEDArray, extraData.Length);
                extraData = newEDArray;
            }
            extraData[id] = data;
        }
Пример #2
0
    private void PopulateTile(MapTile mapTile, Vector2Int pos, byte saveData)
    {
        Vector2 randomOffset = new Vector2(
            Mathf.PerlinNoise(pos.x * 53.791f, pos.y * 29.314f) * Mathf.PerlinNoise((pos.y + 23.4f) * 11.172f, (pos.x + 62.6f) * 86.148f),
            Mathf.PerlinNoise(pos.x * -21.218f, pos.y * -58.057f) * Mathf.PerlinNoise((pos.y - 23.4f) * 62.127f, (pos.x - 62.6f) * 10.150f)
            ) * scale * 0.35f;
        Quaternion randomRotation = Quaternion.Euler(0, (Mathf.PerlinNoise(pos.y * 83.163f, pos.x * -65.273f) * Mathf.PerlinNoise(pos.y * 3.12f, pos.x * 7.31f)) * 360, 0);

        if (mapTile == MapTile.OreTile)
        {
            Vector3 position = new Vector3(
                pos.x * scale - randomOffset.x,
                0,
                pos.y * scale - randomOffset.y
                );

            GameObject oreObject = Instantiate(orePrefab, position, randomRotation);
            oreObject.transform.parent = chunkHandler.transform;
            IWorldGenObject worldGenObject = oreObject.GetComponent <IWorldGenObject>();
            if (worldGenObject != null)
            {
                worldGenObject.Id = (pos.x + (pos.y * mapSize));
                worldGenObject.OnWorldLoaded(saveData);
            }
        }
        else if (mapTile == MapTile.HoleTile)
        {
            Vector3 position = new Vector3(
                pos.x * scale,
                holePrefab.transform.position.y,
                pos.y * scale
                );
            GameObject holeObject = Instantiate(holePrefab, position, randomRotation);
            holeObject.transform.parent = chunkHandler.transform;
            holeObject.GetComponent <ActivatableHole>().tilePos = pos;
        }
    }