Пример #1
0
    private void OnSpawnBalls(MatchMessageSpawnElement message)
    {
        Debug.Log("Spawning Balls");

        // TODO: more details on setting orientation...can we send a transform?
        // TODO: handle destruction
        // TODO: need to keep track in a list?

        try
        {
            UnityMainThreadDispatcher.Instance().Enqueue(() => {
                Quaternion rot = Quaternion.AngleAxis(message.angle, Vector3.forward);
                Vector3 pos    = new Vector3(message.x, message.y);

                GameObject ball = Instantiate(ballObjectPrefab, pos, rot, transform);
                ball.GetComponent <BallScript>().id = message.elementId;

                activeBalls.Add(message.elementId, ball);
            });
        }
        catch (System.Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
Пример #2
0
    // Spawn Goals in sides of the field ##Needs Fixing
    private void SpawnGoals()
    {
        // Spawn Left Goal
        float horizontalPosition = -screenBounds.x + goalOffset;
        float verticalPosition   = 0;

        MatchMessageSpawnElement element = new MatchMessageSpawnElement("GoalLeft", horizontalPosition,
                                                                        verticalPosition, 0.0f);

        // tell the clients
        MatchCommunicationManager.Instance.SendMatchStateMessage(
            MatchMessageType.GoalSpawned, element);

        // tell yourself (host)
        MatchCommunicationManager.Instance.SendMatchStateMessageSelf(
            MatchMessageType.GoalSpawned, element);

        // Spawn Right Goal
        horizontalPosition = screenBounds.x - goalOffset;
        verticalPosition   = 0;

        element = new MatchMessageSpawnElement("GoalRight", horizontalPosition,
                                               verticalPosition, 180.0f);

        // tell the clients
        MatchCommunicationManager.Instance.SendMatchStateMessage(
            MatchMessageType.GoalSpawned, element);

        // tell yourself (host)
        MatchCommunicationManager.Instance.SendMatchStateMessageSelf(
            MatchMessageType.GoalSpawned, element);
    }
Пример #3
0
    private void OnSpawnAsteroid(MatchMessageSpawnElement message)
    {
        Debug.Log("Spawning asteroid");

        try
        {
            UnityMainThreadDispatcher.Instance().Enqueue(() => {
                Quaternion rot = Quaternion.AngleAxis(message.angle, Vector3.forward);
                Vector3 pos    = new Vector3(message.x, message.y);

                GameObject roid;
                if (MatchMaker.Instance.IsHost)
                {
                    roid = Instantiate(asteroid, pos, rot, transform);
                    roid.GetComponent <AsteroidScript>().id = message.elementId;
                }
                else
                {
                    roid = Instantiate(dummyAsteroid, pos, rot, transform);
                    roid.GetComponent <DummyController>().id = message.elementId;
                }

                activeAsteroids.Add(message.elementId, roid);
            });
        }
        catch (System.Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
Пример #4
0
    // Spawn Balls in sides of the field ##Needs Fixing
    private void SpawnBalls()
    {
        for (int currentBalls = 0; currentBalls < numOfBalls; currentBalls++)
        {
            float horizontalPosition = Random.Range(-screenBounds.x, screenBounds.x);
            float verticalPosition   = Random.Range(-screenBounds.y, screenBounds.y);

            MatchMessageSpawnElement element = new MatchMessageSpawnElement(currentBalls.ToString(), horizontalPosition,
                                                                            verticalPosition, 0.0f);

            // tell the clients
            MatchCommunicationManager.Instance.SendMatchStateMessage(
                MatchMessageType.BallSpawned, element);

            // tell yourself (host)
            MatchCommunicationManager.Instance.SendMatchStateMessageSelf(
                MatchMessageType.BallSpawned, element);
        }
        ;
    }