#pragma strict
//script of connect to Photon with used many levels
//free to use
public var scroll : Vector2;
public var photonView:PhotonView;
public var windowWidth: int = 600;
public var windowHeight: int = 500;
public var windowRect : Rect;
public var windowRect2 : Rect;
public var windowRect3 : Rect = Rect (50, 50, 800, 600);
public var textures : Texture[];
public var RoomNames : String[];
public var scenes : boolean = false;
public var rooms : boolean = false;
public var num: int;
public var showPic : boolean;
function Start () {
photonView = GetComponent(PhotonView);
//PhotonNetwork.ConnectUsingSettings ("0.1");
PhotonNetwork.ConnectUsingSettings("v2.4");
windowRect = Rect((Screen.width - windowWidth)/2, (Screen.height - windowHeight)/2, windowWidth, windowHeight);
windowRect2 = Rect ((Screen.width - windowWidth)/2, (Screen.height - windowHeight)/2, windowWidth, windowHeight);
}
function OnGUI () {
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
if (GUI.Button (Rect (Screen.width - 150,50,100,30), "Create Room"))//(window run throw update)
{
scenes = true;
rooms = false;
}
if (scenes)
windowRect2 = GUI.Window (1, windowRect2, CreateRoom, "List of Scenes");
if (GUI.Button (Rect (Screen.width - 150,100,100,30), "Join Room"))
{
rooms = true;
scenes = false;
}
if (rooms)
windowRect = GUI.Window (0, windowRect, ListRoom, "List of Rooms");
//show big pic of the level
if (showPic)
{
windowRect3 = GUI.Window (2, windowRect3, PicsLevel, "Pics of Level");
}
}
// Make the contents of the window
function ListRoom (windowID : int) {
scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(windowWidth-15), GUILayout.Height(400));
var i : int;
i=0;
for (var game : RoomInfo in PhotonNetwork.GetRoomList())
{
GUILayout.BeginHorizontal();
GUILayout.Label(game.name);
GUILayout.FlexibleSpace();
GUILayout.Label(game.playerCount + "/" + game.maxPlayers);
GUILayout.Space (100);
if(GUILayout.Button("Join Room", GUILayout.Width(100), GUILayout.Height(40)))
PhotonNetwork.JoinRoom(game.name);
GUILayout.Space (10);
//find index of texture
for(var n:int = 0; n < RoomNames.length; n++ ) {
if (game.name == RoomNames[n])
num = n;
}
if (GUILayout.Button(textures[num], GUILayout.Width(100), GUILayout.Height(100)))
{
showPic = true;
rooms = false;
}
GUILayout.EndHorizontal();
i++;
}
GUILayout.EndScrollView();
GUI.DragWindow (Rect (0,0, 10000, 20));
}
function CreateRoom (windowID : int) {
var h : int = 0;
var i : int;
var butonCreate : String = "Create Room"; //name of button "Create Room"
scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(windowWidth-15), GUILayout.Height(400));
for(i = 0; i < RoomNames.length; i ++ ) {
GUI.enabled = true;
h = h + 100;
GUILayout.BeginHorizontal();
var Rname : String = " " + RoomNames[i] + ".......";
//turn of the games wich have run
for (var game : RoomInfo in PhotonNetwork.GetRoomList()){
if (RoomNames[i]==game.name)
{
GUI.enabled = false;
butonCreate = "Room already Run";
}
else butonCreate = "Create Room";
}
GUILayout.Button(GUIContent(Rname, textures[i], "Resize"), GUILayout.Width(windowWidth - 200), GUILayout.Height(100));
//showPic = true;
GUI.Label (Rect (50, h - 100/2, 100, 40), GUI.tooltip);
GUILayout.FlexibleSpace();
if (GUI.Button(Rect(windowWidth-180, h - 100/2, 140,50), butonCreate)){
PhotonNetwork.CreateRoom(RoomNames[i], true, true, 20);
}
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
GUI.DragWindow (Rect (0,0, 10000, 20));
}
function PicsLevel (windowID : int) {
GUI.Box (Rect (50,50,500,500), textures[num]);
if (GUI.Button(Rect(400,500,100,30), "Close"))
{
showPic = false;
rooms = true;
}
GUI.DragWindow (Rect (0,0, 10000, 20));
}