Exemplo n.º 1
0
    /// <summary>
    /// Reads in the config files and sets the player start and end nodes for each round
    /// </summary>
    private void readInPlayerNodes()
    {
        // Read in config file
        string configFilepath;

        if (UnityEngine.Debug.isDebugBuild)
        {
            configFilepath = "Assets/Resources/config.ini";
        }
        else
        {
            configFilepath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"/Resources/config.ini";
        }
        var parser = new FileIniDataParser();

        configData = parser.ReadFile(configFilepath);

        // For each round
        PlayerNodeClass playerNodeObject;
        int             numRounds;

        int.TryParse(configData["Session"]["numberOfRounds"], out numRounds);
        for (int i = 1; i <= numRounds; i++)
        {
            // Read in start and end data for each player
            string filepath;
            if (UnityEngine.Debug.isDebugBuild)
            {
                filepath = "Assets/Resources/Maps/" + configData["Map"]["name"] + "/playerPaths/session" + i + ".json";
            }
            else
            {
                filepath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"/Resources/Maps/" + configData["Map"]["name"] + "/playerPaths/session" + i + ".json";
            }
            StreamReader reader = new StreamReader(filepath);
            playerNodeObject = PlayerNodeClass.CreateFromJSON(reader.ReadToEnd());

            // Add to the ID lists
            startIDs.Add(playerNodeObject.originNode);
            endIDs.Add(playerNodeObject.destinationNode);
        }
    }
    private IniData configData;    // An object holding the game config data

    /// <summary>
    /// Is called before the application starts (NOTE: This will have issues finding any dynamically created objects as they do not exist yet)
    /// </summary>
    void Awake()
    {
        // First sets up the gameworld map
        GameObject go = GameObject.Find("CitySimulatorMap");

        world = (WorldMap)go.GetComponent <WorldMap>();
        g     = GameObject.Find("Graph").GetComponent <GraphController>().graph;

        // Grab config data
        string configFilepath;

        if (UnityEngine.Debug.isDebugBuild)
        {
            configFilepath = "Assets/Resources/config.ini";
        }
        else
        {
            configFilepath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"/Resources/config.ini";
        }
        var parser = new FileIniDataParser();

        configData = parser.ReadFile(configFilepath);

        // Grab map data
        string mapAttributesPath;

        if (UnityEngine.Debug.isDebugBuild)
        {
            mapAttributesPath = "Assets/Resources/Maps/" + configData["Map"]["name"] + "/config.ini";
        }
        else
        {
            mapAttributesPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"/Resources/Maps/" + configData["Map"]["name"] + "/config.ini";
        }
        IniData mapAttributes = parser.ReadFile(mapAttributesPath);

        // Grab player path data
        takenStartingNodes = new HashSet <string>();
        PlayerNodeClass playerNodeObject;
        int             numRounds;

        int.TryParse(configData["Session"]["numberOfRounds"], out numRounds);
        for (int i = 1; i <= numRounds; i++)
        {
            // Read in start and end data for each player
            string filepath;
            if (UnityEngine.Debug.isDebugBuild)
            {
                filepath = "Assets/Resources/Maps/" + configData["Map"]["name"] + "/playerPaths/session" + i + ".json";
            }
            else
            {
                filepath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"/Resources/Maps/" + configData["Map"]["name"] + "/playerPaths/session" + i + ".json";
            }
            StreamReader reader = new StreamReader(filepath);
            playerNodeObject = PlayerNodeClass.CreateFromJSON(reader.ReadToEnd());

            // Add to the ID lists
            if (!takenStartingNodes.Contains(playerNodeObject.originNode))
            {
                takenStartingNodes.Add(playerNodeObject.originNode);
            }
        }

        // Set the random seed according to the config file
        int.TryParse(configData["Session"]["randomSeed"], out var randSeed);
        UnityEngine.Random.InitState(randSeed);
        UnityEngine.Debug.Log("randomSeed: " + randSeed);

        if (useCachedPath)
        {
            generateExistingPaths();
        }
        else
        {
            createPaths();
        }

        numSmartRemaining = smartCars.Count;
        numSmartSpawned   = 0;
        InvokeRepeating("spawnSmartTraffic", 15f, 10f); // Repeatedly spawns smart traffic
    }