コード例 #1
0
    private IEnumerator InitGameGlobals()
    {
        string configText = "";

        GameProperties.configurableProperties = new DynamicallyConfigurableGameProperties();


        //Assign configurable game properties from file if any
        //Application.ExternalEval("console.log('streaming assets: "+ Application.streamingAssetsPath + "')");

        string path = Application.streamingAssetsPath + "/config.cfg";

        if (path.Contains("://") || path.Contains(":///")) //url instead of path
        {
            WWW www = new WWW(path);
            yield return(www);

            configText = www.text;
        }
        else
        {
            configText = File.ReadAllText(path);
        }

        UpdateGameConfig(configText);


        GameGlobals.numberOfSpeakingPlayers = 0;
        GameGlobals.currGameId++;
        GameGlobals.currGameRoundId = 0;
        GameGlobals.albumIdCount    = 0;

        GameGlobals.gameDiceNG   = new RandomDiceNG();
        GameGlobals.audioManager = new AudioManager();


        //GameGlobals.playerIdCount = 0;
        //GameGlobals.albumIdCount = 0;

        GameGlobals.albums = new List <Album>(GameProperties.configurableProperties.numberOfAlbumsPerGame);

        //destroy UIs if any
        if (GameGlobals.players != null && GameGlobals.players.Count > 0)
        {
            UIPlayer firstUIPlayer = null;
            int      pIndex        = 0;
            while (firstUIPlayer == null && pIndex < GameGlobals.players.Count)
            {
                firstUIPlayer = (UIPlayer)GameGlobals.players[pIndex++];
                if (firstUIPlayer != null)
                {
                    firstUIPlayer.GetWarningScreenRef().DestroyPoppupPanel();
                    Destroy(firstUIPlayer.GetPlayerCanvas());
                }
            }
        }
        GameGlobals.players = new List <Player>(GameProperties.configurableProperties.numberOfPlayersPerGame);


        GameGlobals.gameLogManager = new MongoDBLogManager();
        GameGlobals.gameLogManager.InitLogs();

        //only generate session data in the first game
        if (GameGlobals.currGameId == 1)
        {
            //GameGlobals.gameLogManager = new DebugLogManager();


            string date = System.DateTime.Now.ToString("ddHHmm");

            //generate external game code from currsessionid and lock it in place
            //gamecode is in the format ddmmhhmmss<3RandomLetters>[TestGameCondition]

            string generatedCode = date; //sb.ToString();

            //generate 3 random letters
            for (int i = 0; i < 3; i++)
            {
                generatedCode += (char)('A' + Random.Range(0, 26));
            }

            GameGlobals.currSessionId = generatedCode;

            //update the gamecode UI
            //GameObject UIGameCodeDisplay = Object.Instantiate(UIGameCodeDisplayPrefab);
            //UIGameCodeDisplay.GetComponentInChildren<Text>().text = "Game Code: " + GameGlobals.currSessionId;
            //Object.DontDestroyOnLoad(UIGameCodeDisplay);
        }
        else
        {
            this.UIStartGameButton.interactable = true;
        }

        if (GameProperties.configurableProperties.isAutomaticalBriefing)                       //generate condition automatically (asynchronous)
        {
            GameGlobals.gameLogManager.GetLastSessionConditionFromLog(YieldedActionsAfterGet); //changes session code
        }
        else
        {
            //create session parameterization
            SessionParameterization mock = new SessionParameterization("mock");
            GameProperties.configurableProperties.possibleParameterizations.Add(mock);
            this.UIStartGameButton.interactable = true;

            GameProperties.configurableProperties.numSessionGames = 0; //not used
        }


        //init fatima strings
        GameGlobals.FAtiMAScenarioPath = "/Scenarios/ForTheRecord-EN.iat";

        AssetManager.Instance.Bridge = new AssetManagerBridge();
        GameGlobals.FAtiMAIat        = IntegratedAuthoringToolAsset.LoadFromFile(GameGlobals.FAtiMAScenarioPath);
    }