Beispiel #1
0
    void EditorLoadBattlefield(string path)
    {
        foreach (GameObject sp in spawnpoints)
        {
            Destroy(sp);
        }
        spawnpoints.Clear();

        Game.BattlefieldData data = Game.game.LoadBattlefieldData(path, true);

        Game.game.battlefieldWidth  = data.width;
        Game.game.battlefieldHeight = data.height;
        Game.isWalled = data.walls;

        foreach (EnemySpawnPoint point in data.spawns)
        {
            GameObject            newSpawn   = (GameObject)Instantiate(spawnpointPrefab, point.worldPosition, Quaternion.identity);
            EditorEnemySpawnPoint spawnPoint = newSpawn.GetComponent <EditorEnemySpawnPoint> ();

            spawnPoint.endPlaced = false;
            spawnPoint.endPoint  = point.endPoint.worldPosition;
            spawnPoint.endPlaced = true;
        }

        Game.game.SetBackgoundGraphic();
        Game.game.GenerateWallMesh();
    }
    public void LoadDataToGame()
    {
        if (loadedBattlefields.Length > 0)
        {
            Debug.Log("Loading battlefield data..");
            Game game = Game.game;
            Game.BattlefieldData data = loadedBattlefields[index];

            game.battlefieldWidth  = data.width;
            game.battlefieldHeight = data.height;
            game.enemySpawnPoints  = data.spawns;
            game.battlefieldName   = data.name;

            Game.isWalled = (Game.WallType[, ])data.walls.Clone();
        }
    }
    Texture2D GenerateTexture(Game.BattlefieldData data)
    {
        int width  = data.walls.GetLength(0);
        int height = data.walls.GetLength(1);

        Texture2D tex = new Texture2D(width, height);

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                switch ((Game.WallType)data.walls[x, y])
                {
                case Game.WallType.Level:
                    tex.SetPixel(x, y, Color.red);
                    break;

                case Game.WallType.None:
                    tex.SetPixel(x, y, new Color(0f, 0.04f, 0f));
                    break;
                }
            }
        }

        for (int i = 0; i < data.spawns.Count; i++)
        {
            EnemySpawnPoint sp  = data.spawns[i];
            Vector3         wsp = sp.worldPosition + new Vector3(data.width, data.height) / 2f;
            int             sx  = Mathf.RoundToInt(wsp.x);
            int             sy  = Mathf.RoundToInt(wsp.y) - 1;

            Vector3 wep = sp.endPoint.worldPosition + new Vector3(data.width, data.height) / 2f;
            int     ex  = Mathf.RoundToInt(wep.x);
            int     ey  = Mathf.RoundToInt(wep.y);

            tex.SetPixel(sx, sy, Color.red);
            tex.SetPixel(ex, ey, Color.green);
        }

        tex.filterMode = FilterMode.Point;
        tex.Apply();

        return(tex);
    }