@@ -1,5 +1,7 @@
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
using System.Collections.Generic;

@@ -9,10 +11,38 @@ public class GUIManager : MonoBehaviour, IGUIBehavior
private List<GameObject> registered = new List<GameObject>();

protected Dictionary<string, GameObject> elements = new Dictionary<string, GameObject>();
protected Dictionary<string, GameObject> panels = new Dictionary<string, GameObject>();
protected bool debug;
protected bool init;

public void Show(string item)
const string OpenTransitionName = "Open";
const string ClosedStateName = "Closed";
private int OpenParameterId;
public GameObject GameWindow;
public GameObject VideoWindow;
public GameObject AudioWindow;
private Animator Open;
private GameObject PreviouslySelected;

[ContextMenu("Enable All Children")]
public void EnableAll()
{
foreach (Transform child in transform)
{
child.gameObject.SetActive(true);
}
}

[ContextMenu("Disable All Children")]
public void DisableAll()
{
foreach (Transform child in transform)
{
child.gameObject.SetActive(false);
}
}

public virtual void Show(string item)
{
//Debug.Log("show " + item);

@@ -22,14 +52,14 @@ public void Show(string item)

elements[item].SetActive(true);



// if this derived type is the start menu manager
Animator anim = elements[item].GetComponent<Animator>();
if(anim != null)
{
CoreGUIManager.Instance.OpenPanel(anim);
OpenPanel(anim);
}
}

else
{
Debug.Log("could not show " + item);
@@ -162,7 +192,7 @@ protected virtual void OnEnable()
}

init = true;

OpenParameterId = Animator.StringToHash(OpenTransitionName);
HideAll();
}

@@ -174,6 +204,8 @@ protected virtual void OnEnable()
}
}



}

protected virtual void OnDisable()
@@ -198,5 +230,176 @@ public virtual void Unregister(GameObject ele)

}

#region MENU PANEL ACTIONS
public void OpenPanel(Animator anim)
{
if (Open == anim)
return;
anim.gameObject.SetActive(true);
var newPreviouslySelected = EventSystem.current.currentSelectedGameObject;

//anim.transform.SetAsLastSibling();

CloseCurrent();

PreviouslySelected = newPreviouslySelected;

Open = anim;
Open.SetBool(OpenParameterId, true);
}

public void OpenPanelWithoutClose(Animator anim)
{
if (Open == anim)
return;
anim.gameObject.SetActive(true);
var newPreviouslySelected = EventSystem.current.currentSelectedGameObject;

//anim.transform.SetAsLastSibling();

PreviouslySelected = newPreviouslySelected;

anim.SetBool(OpenParameterId, true);
}

public void CloseCurrent()
{
if (Open == null)
return;
Open.SetBool(OpenParameterId, false);
StartCoroutine(DisablePanelDelayed(Open));
Open = null;
}

public void CloseWindow(Animator anim)
{
if (!anim.gameObject.active)
{
return;
}
anim.SetBool(OpenParameterId, false);
StartCoroutine(DisablePanelDelayed(anim));
}

public IEnumerator DisablePanelDelayed(Animator anim)
{
bool closedStateReached = false;
bool wantToClose = true;
while (!closedStateReached && wantToClose)
{
if (!anim.IsInTransition(0))
closedStateReached = anim.GetCurrentAnimatorStateInfo(0).IsName(ClosedStateName);

wantToClose = !anim.GetBool(OpenParameterId);

yield return new WaitForEndOfFrame();
}
if (wantToClose)
{
if (anim.gameObject.tag == "Settings")
{
if (GameWindow.activeSelf)
{
GameWindow.SetActive(false);
}
else if (GameWindow.activeSelf)
{
VideoWindow.SetActive(false);
}
else if (GameWindow.activeSelf)
{
AudioWindow.SetActive(false);
}
}
anim.gameObject.SetActive(false);
}

Hide(anim.gameObject.name);

}

public void SetSelected()
{
EventSystem.current.SetSelectedGameObject(null);
}

#endregion

#region ENABLE/DISABLE INTERACTION
// Keep a list of pointer input modules that we have disabled so that we can re-enable them
List<PointerInputModule> disabled = new List<PointerInputModule>();

int disableCount = 0; // How many times has disable been called?

public void Disable()
{
if (disableCount++ == 0)
{
UpdateState(false);
}
}

public void Enable(bool enable)
{
if (!enable)
{
Disable();
return;
}
if (--disableCount == 0)
{
UpdateState(true);
if (disableCount > 0)
{
Debug.LogWarning("Warning UIDisableInput.Enable called more than Disable");
}
}
}


void UpdateState(bool enabled)
{
// First re-enable all systems
for (int i = 0; i < disabled.Count; i++)
{
if (disabled[i])
{
disabled[i].enabled = true;
}
}

disabled.Clear();

EventSystem es = EventSystem.current;

if (es == null) return;

es.sendNavigationEvents = enabled;

if (!enabled)
{
// Find all PointerInputModules and disable them
PointerInputModule[] pointerInput = es.GetComponents<PointerInputModule>();
if (pointerInput != null)
{
for (int i = 0; i < pointerInput.Length; i++)
{
PointerInputModule pim = pointerInput[i];
if (pim.enabled)
{
pim.enabled = false;
// Keep a list of disabled ones
disabled.Add(pim);
}
}
}

// Cause EventSystem to update it's list of modules
es.enabled = false;
es.enabled = true;
}
}
#endregion


}
@@ -3,8 +3,8 @@

public class GameManager : MonoBehaviour
{
public GameObject ServerManagerGO;
public GameObject ClientManagerGO;
public GameObject ServerManagerPrefab;
public GameObject ClientManagerPrefab;

private static GameManager _instance;

@@ -36,5 +36,27 @@ private void Awake()
}
}

private void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
Debug.Log(Network.player.externalIP.ToString());
StartMenuGUIManager.Instance.Show("Login_Menu");
}
}

public void StartServer()
{
Instantiate(GameManager.Instance.ServerManagerPrefab);
//BoltLauncher.StartServer(UdpKit.UdpEndPoint.Parse("127.0.0.1:27000"));
BoltLauncher.StartServer(UdpKit.UdpEndPoint.Any);

BoltNetwork.SetHostInfo("Here You Go", null);
//BoltNetwork.LoadScene("Tutorial1");

// go to lobby
CoreGUIManager.Instance.Show("GameLobby");
}


}
@@ -29,7 +29,7 @@ void SelectPeer()
{
if (GUILayout.Button("Start Server", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
{
Instantiate(GameManager.Instance.ServerManagerGO);
Instantiate(GameManager.Instance.ServerManagerPrefab);
//BoltLauncher.StartServer(UdpKit.UdpEndPoint.Parse("127.0.0.1:27000"));
BoltLauncher.StartServer(UdpKit.UdpEndPoint.Any);

@@ -39,7 +39,7 @@ void SelectPeer()

if (GUILayout.Button("Start Client", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
{
Instantiate(GameManager.Instance.ClientManagerGO);
//Instantiate(GameManager.Instance.ClientManagerPrefab);
BoltLauncher.StartClient();
state = State.ServerBrowser;
}
@@ -0,0 +1,63 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using Bolt;

public class PopulateServerBrowser : MonoBehaviour
{
[SerializeField]
private GameObject ServerList;

[SerializeField]
private GameObject ServerPrefab;

public void Populate()
{
foreach (var session in BoltNetwork.SessionList)
{
/*
GUILayout.BeginHorizontal();
GUILayout.Label(session.Value.HostName + " " + session.Value.WanEndPoint);
if (GUILayout.Button("Join"))
{
// transition to "log in" gui state
selectedSession = session.Value;
state = State.SelectCredentials;
// build a credentials token to connect to the server with
//BoltNetwork.Connect(session.Value, token);
//BoltNetwork.Connect(session.Value);
}
GUILayout.EndHorizontal();
*/

GameObject server = (GameObject)Instantiate(ServerPrefab, Vector3.zero, Quaternion.identity);

server.transform.parent = ServerList.transform;

server.transform.GetChild(0).GetComponent<Text>().text = session.Value.HostName + " " + session.Value.WanEndPoint;

server.transform.GetChild(1).GetComponent<Button>().onClick.AddListener(Connect);
}
}

void Connect()
{
// get credential token from clientmanager
CredentialToken token = ClientManager.Instance.GetToken();
Debug.Log("connecting with token: ");
Debug.Log(token.LoginName);
Debug.Log(token.DisplayName);
Debug.Log(token.Password);
Debug.Log(token.IP);
Debug.Log(token.AuthLevel);
// connect to selected server
}
}
@@ -15,15 +15,28 @@ public override void Connected(BoltConnection connection, IProtocolToken acceptT
// connected to server
CredentialToken token = (CredentialToken)connectToken;

log.Message += "connected: " + token.LoginName + " " + token.Password + " " + token.IP;
log.Message += "connected: " + token.LoginName;
log.Send();

Debug.Log("token connected: " + token.LoginName);

// if not added to server's lobby, add to lobby
Messenger.Broadcast("UserAddedToLobby", token);

}

public override void Disconnected(BoltConnection connection, IProtocolToken token)
{
var log = LogEvent.Create();
log.Message = string.Format("{0} disconnected", connection.RemoteEndPoint);
log.Send();

CredentialToken currentToken = ClientManager.Instance.GetToken();

Debug.Log("token disconnected: " + currentToken.LoginName);

Messenger.Broadcast("UserRemovedFromLobby", currentToken);

// if added to server's lobby, remove from lobby
}
}
@@ -6,6 +6,16 @@ public class ServerManager: MonoBehaviour
{
private static ServerManager _instance;

private HashSet<CredentialToken> connectedUsers = new HashSet<CredentialToken>();

public HashSet<CredentialToken> ConnectedUsers
{
get
{
return connectedUsers;
}
}

private void Awake()
{
if (_instance == null)
@@ -18,6 +28,9 @@ private void Awake()
{
Destroy(this.gameObject);
}

Messenger.AddListener<CredentialToken>("UserAddedToLobby", AddToLobby);
Messenger.AddListener<CredentialToken>("UserRemovedFromLobby", AddToLobby);
}

public static ServerManager Instance
@@ -34,4 +47,19 @@ public static ServerManager Instance
}
}

public void AddToLobby(CredentialToken user)
{
if(connectedUsers.Contains(user) == false)
{
connectedUsers.Add(user);
}
}
public void RemoveFromLobby(CredentialToken user)
{
if (connectedUsers.Contains(user) == true)
{
connectedUsers.Remove(user);
}
}

}
@@ -0,0 +1,99 @@
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
using System.Collections.Generic;

public class StartMenuGUIManager : GUIManager, IGUIBehavior
{
[SerializeField]
private Camera guiCamera;

public Camera GUICamera
{
get
{
return guiCamera;
}
}

public enum PanelState
{
Login,
CreateAccount,
StartMenu,
ServerBrowser,
Lobby
}

public PanelState CurrentPanelState;

private static StartMenuGUIManager _instance;

public static StartMenuGUIManager Instance
{
get
{
if (_instance == null)
{
_instance = GameObject.FindObjectOfType<StartMenuGUIManager>();
DontDestroyOnLoad(_instance.gameObject);
}

return _instance;
}
}

private void Awake()
{
if (_instance == null)
{
//If I am the first instance, make me the Singleton
_instance = this;
DontDestroyOnLoad(this);
}
else
{
Destroy(this.gameObject);
}

base.Awake();

Messenger.AddListener("UserAddedToLobby", UpdateLobby);
Messenger.AddListener("UserRemovedFromLobby", UpdateLobby);
}

protected override void OnEnable()
{
base.OnEnable();
}

void Update()
{

}

public override void Show(string item)
{

base.Show(item);
}

public void SetActiveButton(string name)
{
//print("setactivebutton " + name);
if (elements.ContainsKey(name))
{
// set active object

//UICamera.selectedObject = _elements[name];
}
}

public void UpdateLobby()
{

}

}
BIN +88 Bytes (100%) ProjectSettings/TagManager.asset
Binary file not shown.