コード例 #1
0
    public void OnEvent(EventData photonEvent)
    {
        if (photonEvent.Code == RemoteEventNames.RegularStep)
        {
            StartCoroutine(MakeStepSafe((Direction[])photonEvent.CustomData));
        }

        if (photonEvent.Code == RemoteEventNames.SnakeDeadAndRespawn)
        {
            Object[]   readData       = (Object[])photonEvent.CustomData;
            int        actorID        = (int)readData[0];
            Vector2Int spawnPoint     = (Vector2Int)readData[1];
            Direction  spawnDirection = (Direction)readData[2];
            (Vector2Int, Direction)spawnPosition;
            spawnPosition.Item1 = spawnPoint;
            spawnPosition.Item2 = spawnDirection;
            Snakes[actorID - 1].Respawn(spawnPosition);
        }

        if (photonEvent.Code == RemoteEventNames.SnakeDead)
        {
            Snakes[(int)photonEvent.CustomData - 1].Clear();
        }

        if (photonEvent.Code == RemoteEventNames.FruitCollected)
        {
            Object[]   readData         = (Object[])photonEvent.CustomData;
            int        actorID          = (int)readData[0];
            Vector2Int newFruitPosition = (Vector2Int)readData[1];
            Fruit.ChangeGameFieldPosition(newFruitPosition);
            Snakes[actorID - 1].AddNode();
            rating.AddScore(PointsForFruit, actorID);
        }
    }