Пример #1
0
        /// <summary>
        /// Routine to simulate server behavior.
        /// </summary>
        private IEnumerator Simulation()
        {
            // Wait for the agent to connect. A real game server does not need to wait for a connection.
            // The wait here is done for testing purposes so that the state changes in the code below will be
            // logged on a connected Arcus Agent (e.g. a connected Fake Agent). Without waiting, only the final
            // state would reach the Agent upon connection.
            yield return(new WaitUntil(() => server.Status == OneServerStatus.OneServerStatusReady));

            // Simulate the server starting up by sending the OneServerStarting status.
            LogWithTimestamp(string.Format("Sending <b>Application Instance Status</b>: {0} ({1})",
                                           OneApplicationInstanceStatus.OneServerStarting,
                                           (int)OneApplicationInstanceStatus.OneServerStarting));
            server.SetApplicationInstanceStatus(OneApplicationInstanceStatus.OneServerStarting);

            // Simulate the startup taking 1 second.
            yield return(new WaitForSeconds(1f));

            // Simulate the server started by sending OneServerOnline status.
            LogWithTimestamp(string.Format("Sending <b>Application Instance Status</b>: {0} ({1})",
                                           OneApplicationInstanceStatus.OneServerOnline,
                                           (int)OneApplicationInstanceStatus.OneServerOnline));
            server.SetApplicationInstanceStatus(OneApplicationInstanceStatus.OneServerOnline);

            // Send the test Live State data to the agent.
            SendLiveState(1, 5, "Example", "Example map", "Example mode", "v0.1");
            SendReverseMetadata("Example map", "Example mode", "Example type");

            // Regularly send Live State updates with a random number of players.
            while (true)
            {
                yield return(new WaitForSeconds(2f));

                // Send random values simulating changing active player count.
                SendLiveState(UnityEngine.Random.Range(1, 6), 5, "Example", "Example map", "Example mode", "v0.1");
                SendReverseMetadata("Example map", "Example mode", "Example type");
            }
        }
    private IEnumerator Simulation()
    {
        yield return(new WaitUntil(() => server.Status == OneServerStatus.OneServerStatusReady));

        server.SetApplicationInstanceStatus(OneApplicationInstanceStatus.OneServerOnline);

        while (true)
        {
            server.SetLiveState(UnityEngine.Random.Range(0, 101), 100, "Test", "Test", "Test", "v0.1", null);
            server.SendReverseMetadata("Example map", "Example mode", "example type");

            if (++_stateSentCount % 10000 == 0)
            {
                Debug.LogFormat("State sent messages: {0}", _stateSentCount);
            }

            yield return(null);
        }
    }