Toybox Trouble

Toybox Trouble ist eines meiner ersten Multiplayer versuche, bei dem der Spieler mit anderen in einer Reihe von Minispielen gegeneinander antritt um so viele Titel wie nur möglich zu gewinnen!
Wir haben hier mit dem Plugin von Photon gearbeitet, dabei habe ich mich in das Plugin eingearbeitet um entsprechende Scripts zu erstellen.

Meine Aufgaben:

-Gameplay Programmer: Player Controller für die verschiedenen Spiele. -System Programmer: Implementierung des Multiplayer Systems in die verschiedene Spiele.

Download-Link: Toybox Trouble
oder
Direkt auf dieser Website spielen: Toybox Trouble



using UnityEngine;
using Photon.Pun;
using UnityEngine.UI;

public class Login : MonoBehaviourPunCallbacks
{
	[SerializeField] GameObject lobbyConnectButton;
	[SerializeField] InputField nameInput;

	public override void OnConnectedToMaster()
	{
		PhotonNetwork.AutomaticallySyncScene = true;
		lobbyConnectButton.SetActive(true);

		if (PlayerPrefs.HasKey("NickName"))
		{
			if (PlayerPrefs.GetString("NickName") == "")
			{
				PhotonNetwork.NickName = "Player" + Random.Range(1, 1000);
			}
			else
			{
				PhotonNetwork.NickName = PlayerPrefs.GetString("NickName");
			}
		}
		else
		{
			PhotonNetwork.NickName = "Player" + Random.Range(1, 1000);
		}
		nameInput.text = PhotonNetwork.NickName;
		Debug.Log(nameInput.ToString());
	}

	public void PlayerNameInput(string nameInput)
	{
		PhotonNetwork.NickName = nameInput;
		PlayerPrefs.SetString("NickName", nameInput);
	}

	public void ExitGame()
	{
		GamesState.TryToChange(States.Quit);
	}

	public void LobbyJoin()
	{
		GamesState.TryToChange(States.Menu);
	}
}

using Photon.Pun;
using Photon.Realtime;
using System.Collections.Generic;
using UnityEngine;

public class LobbyController : MonoBehaviourPunCallbacks
{
    [SerializeField] GameObject lobbyPanel;

    private string roomName;
    private int roomSize = 4;

    private List roomListing;
    [SerializeField] Transform container;
    [SerializeField] GameObject roomListingPrefab;

    private void Start()
    {
        roomListing = new List();
    }

    public override void OnRoomListUpdate(List roomList)
    {
        int index;
        foreach (RoomInfo room in roomList)
        {
            if (roomListing != null)
            {
                index = roomListing.FindIndex(ByName(room.Name));
            }
            else
            {
                index = -1;
            }
            if (index != -1)
            {
                roomListing.RemoveAt(index);
                Destroy(container.GetChild(index).gameObject);
            }
            if (room.PlayerCount > 0)
            {
                roomListing.Add(room);
                ListRoom(room);
            }
        }
    }

    static System.Predicate ByName(string name)
    {
        return delegate (RoomInfo room)
        {
            return room.Name == name;
        };
    }

    private void ListRoom(RoomInfo room)
    {
        if (room.IsOpen && room.IsVisible)
        {
            GameObject tempListing = Instantiate(roomListingPrefab, container);
            RoomButton tempButton = tempListing.GetComponent();
            tempButton.SetRoom(room.Name, room.MaxPlayers, room.PlayerCount);
        }
    }

    public void OnRoomNameChange(string nameIn)
    {
        roomName = nameIn;
    }

    public void CreateRoom()
    {
        Debug.Log("Create room");
        gameObject.GetComponent().ChooseRandomButthurt();
        RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)roomSize };
        PhotonNetwork.CreateRoom(roomName, roomOps);
    }

    public override void OnCreateRoomFailed(short returnCode, string message)
    {
        Debug.Log("There must be a room with the same name");
    }

    public void ExitGame()
    {
        GamesState.TryToChange(States.Quit);
    }
}

using UnityEngine;
using Photon.Pun;

public class NetworkController : MonoBehaviourPunCallbacks
{
    void Start()
    {
        PhotonNetwork.ConnectUsingSettings();
    }

    public override void OnConnectedToMaster()
    {
        Debug.Log("We are now connected to the " + PhotonNetwork.CloudRegion + "server");
    }
}