コード例 #1
0
 private void Awake()
 {
     CurrentGame = this;
 }
コード例 #2
0
    private List <List <float> > _ParseMap(IEnumerator <string> se)
    {
        InGameCommon gameController = InGameCommon.CurrentGame;
        Teams        teams          = gameController.GetComponent <Teams>();

        // game mode
        //   0 - capture the flag
        int gameMode = int.Parse(_Take(se));
        // number of teams - n
        int numTeams = int.Parse(_Take(se));

        // n team colors
        {
            List <Color> colors = new List <Color>(numTeams);
            for (int i = 0; i < numTeams; ++i)
            {
                Color color = new Color();
                color.r = float.Parse(_Take(se));
                color.g = float.Parse(_Take(se));
                color.b = float.Parse(_Take(se));
                color.a = 1.0f;
                colors.Add(color);
            }
            teams.Colors = colors;
        }
        // n team spawn spefications
        {
            List <InGameCommon.SpawnList> spawns = new List <InGameCommon.SpawnList>(numTeams);
            for (int i = 0; i < numTeams; ++i)
            {
                int numSpawns = int.Parse(_Take(se));
                InGameCommon.SpawnList teamSpawns = new InGameCommon.SpawnList {
                    Spawns = new List <SpawnPoint>(numSpawns)
                };
                for (int j = 0; j < numSpawns; ++j)
                {
                    float      x     = float.Parse(_Take(se)) * PrismScale;
                    float      y     = float.Parse(_Take(se)) * PrismScale;
                    GameObject spawn = Instantiate(
                        PlayerSpawnPrefab, new Vector3(x, 0.0f, y), Quaternion.identity
                        );
                    teamSpawns.Spawns.Add(spawn.GetComponent <SpawnPoint>());
                }
                spawns.Add(teamSpawns);
            }
            gameController.TeamSpawns = spawns;
        }
        if (gameMode == 0)
        {
            FlagController flagController = gameController.GetComponent <FlagController>();
            // flag zones
            for (int i = 0; i < numTeams; ++i)
            {
                int numFlagZones = int.Parse(_Take(se));
                for (int j = 0; j < numFlagZones; ++j)
                {
                    float     x      = float.Parse(_Take(se)) * PrismScale;
                    float     y      = float.Parse(_Take(se)) * PrismScale;
                    float     radius = float.Parse(_Take(se));
                    Transform t      =
                        Instantiate(FlagZonePrefab, new Vector3(x, 0.0f, y), Quaternion.identity).transform;
                    t.localScale = new Vector3(radius, 100.0f, radius);
                    t.GetComponent <FlagZone>().Team = i;
                }
            }
            // flag spawns
            int numFlagSpawns = int.Parse(_Take(se));
            {
                List <SpawnPoint> spawns = new List <SpawnPoint>(numFlagSpawns);
                for (int i = 0; i < numFlagSpawns; ++i)
                {
                    float      x     = float.Parse(_Take(se)) * PrismScale;
                    float      y     = float.Parse(_Take(se)) * PrismScale;
                    GameObject spawn = Instantiate(
                        FlagSpawnPrefab, new Vector3(x, 0.0f, y), Quaternion.identity
                        );
                    spawns.Add(spawn.GetComponent <SpawnPoint>());
                }
                flagController.Spawns = spawns;
            }
        }
        // map properties
        NumPrismsX = int.Parse(_Take(se));
        NumPrismsZ = int.Parse(_Take(se));
        MinHeight  = float.Parse(_Take(se));
        MaxHeight  = float.Parse(_Take(se));
        // initial tile heights
        List <List <float> > heights = new List <List <float> >(NumPrismsZ);

        for (int z = 0; z < NumPrismsZ; ++z)
        {
            List <float> row = new List <float>(NumPrismsX);
            for (int x = 0; x < NumPrismsX; ++x)
            {
                row.Add(float.Parse(_Take(se)));
            }
            heights.Add(row);
        }
        return(heights);
    }