Пример #1
0
    // Use this for initialization
    void Awake()
    {
        Main           = this;
        Cursor.visible = false;
        Player         = GameObject.FindGameObjectWithTag("Player");
        MainCamera     = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();

        GameObject TerrainObject = GameObject.FindGameObjectWithTag("Terrain");

        if (TerrainObject != null)
        {
            MainTerrain         = TerrainObject.GetComponent <Terrain>();
            terrainModification = TerrainObject.GetComponent <TerrainModification>();
        }

        if (playerMaterialOverride != null)
        {
            Player.GetComponent <Collider>().material = playerMaterialOverride;
        }
        if (playerDragOverride != -1)
        {
            Player.GetComponent <Rigidbody>().drag = playerDragOverride;
        }

        Physics.gravity = Gravity * 2;
    }
Пример #2
0
    // Use this for initialization
    void Awake()
    {
        Main        = this;
        terrain     = GetComponent <Terrain>();
        terrainData = terrain.terrainData;
        terrainPos  = terrain.transform.position;

        initialHeights  = terrainData.GetHeights(0, 0, terrainData.heightmapWidth, terrainData.heightmapHeight);
        heightmapWidth  = terrainData.heightmapWidth;
        heightmapHeight = terrainData.heightmapHeight;
    }
Пример #3
0
 public void TryPerformTerrainModification(TerrainModification mod)
 {
     if (Ready)
     {
         _PerformTerrainModification(mod, false);
     }
     else
     {
         _cachedTerrainModifications.Add(mod);
     }
 }
Пример #4
0
    private void _PerformTerrainModification(TerrainModification mod, bool immediate)
    {
        Collider[] cols = null;
        switch (mod.Type)
        {
        case TerrainAlterationType.Radial:
            cols = Utils.GetPrismsInCylinder(mod.Position, mod.RadiusOrLength);
            break;

        case TerrainAlterationType.Wall:
            cols = Utils.GetPrismsInWall(mod.Position, mod.Forward, mod.RadiusOrLength);
            break;
        }
        Utils.AlterTerrain(cols, mod.Delta, immediate);
    }
Пример #5
0
        public void ApplyModification(TerrainModification mod)
        {
            TerrainModified?.Invoke(this, mod);

            // Compute bounding box
            int tlx = (int)Math.Floor(mod.X - mod.Radius);
            int tly = (int)Math.Floor(mod.Y - mod.Radius);
            int brx = (int)Math.Ceiling(mod.X + mod.Radius);
            int bry = (int)Math.Ceiling(mod.Y + mod.Radius);

            // Clamp to world boundaries
            tlx = Math.Min(Math.Max(0, tlx), width - 1);
            tly = Math.Min(Math.Max(0, tly), height - 1);
            brx = Math.Min(Math.Max(0, brx), width - 1);
            bry = Math.Min(Math.Max(0, bry), height - 1);


            // Iterate over bounding box part of bitmap
            for (int j = tly; j < bry; ++j)
            {
                for (int i = tlx; i < brx; ++i)
                {
                    if (Distance(i, j, mod.X, mod.Y) > mod.Radius)
                    {
                        continue;
                    }

                    TerrainType cur = PublicShape.TerrainBitmap[i, j];

                    if (cur == TerrainType.Earth || cur == TerrainType.Sand)
                    {
                        if (mod.Subtract)
                        {
                            PublicShape.TerrainBitmap[i, j] = TerrainType.Air;
                        }
                        else
                        {
                            PublicShape.TerrainBitmap[i, j] = TerrainType.Earth;
                        }
                    }
                }
            }

            // Let sand "fall down" etc.
            UpdateTerrain(tly, tlx, brx);

            WorkingRevision++;
        }
Пример #6
0
        public void ApplyModification(TerrainModification mod)
        {
            TerrainModified?.Invoke(this, mod);

            // Compute bounding box
            int tlx = (int)Math.Floor(mod.X - mod.Radius);
            int tly = (int)Math.Floor(mod.Y - mod.Radius);
            int brx = (int)Math.Ceiling(mod.X + mod.Radius);
            int bry = (int)Math.Ceiling(mod.Y + mod.Radius);

            // Clamp to world boundaries
            tlx = Math.Min(Math.Max(0, tlx), width - 1);
            tly = Math.Min(Math.Max(0, tly), height - 1);
            brx = Math.Min(Math.Max(0, brx), width - 1);
            bry = Math.Min(Math.Max(0, bry), height - 1);


            // Iterate over bounding box part of bitmap
            for (int j = tly; j < bry; ++j)
            {
                for (int i = tlx; i < brx; ++i)
                {
                    if (Distance(i, j, mod.X, mod.Y) > mod.Radius)
                        continue;

                    TerrainType cur = PublicShape.TerrainBitmap[i, j];

                    if (cur == TerrainType.Earth || cur == TerrainType.Sand)
                    {
                        if (mod.Subtract)
                            PublicShape.TerrainBitmap[i, j] = TerrainType.Air;
                        else
                            PublicShape.TerrainBitmap[i, j] = TerrainType.Earth;
                    }
                }
            }

            // Let sand "fall down" etc.
            UpdateTerrain(tly, tlx, brx);

            WorkingRevision++;
        }