Skip to content

Commit

Permalink
#5 minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hani-sayegh committed Feb 27, 2017
1 parent a02d331 commit 2e6f73a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 48 deletions.
28 changes: 0 additions & 28 deletions Assets/Scene/Test Scenes/Lobby.unity
Original file line number Diff line number Diff line change
Expand Up @@ -247,33 +247,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &231447362 stripped
GameObject:
m_PrefabParentObject: {fileID: 1376183412921818, guid: 943bfba2f2daf2849a5648a5bdbd03a4,
type: 2}
m_PrefabInternal: {fileID: 536910353}
--- !u!114 &231447363
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 231447362}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 822f40b9225d36048b6f61480c9febb6, type: 3}
m_Name:
m_EditorClassIdentifier:
m_BroadcastPort: 47777
m_BroadcastKey: 2222
m_BroadcastVersion: 1
m_BroadcastSubVersion: 1
m_BroadcastInterval: 1000
m_UseNetworkManager: 1
m_BroadcastData: HELLO
m_ShowGUI: 1
m_OffsetX: 0
m_OffsetY: 0
networkDiscovery: {fileID: 0}
--- !u!1001 &536910353
Prefab:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -499,7 +472,6 @@ MonoBehaviour:
m_ShowGUI: 1
m_OffsetX: 0
m_OffsetY: 0
networkDiscovery: {fileID: 0}
--- !u!4 &1348270208
Transform:
m_ObjectHideFlags: 0
Expand Down
38 changes: 18 additions & 20 deletions Assets/hanisstuff/CreateGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,47 @@
public class CreateGame : NetworkDiscovery
{
private NetworkManager networkManager;
//public NetworkDiscovery networkDiscovery;
private float timeOut = 2f;

void Start()
{
Initialize();
networkManager = NetworkManager.singleton;
//why this works?????? new does not work if part of monobeha??
//networkDiscovery = this;
//networkDiscovery.Initialize();
//networkDiscovery.StartAsClient();
//networkDiscovery.StartAsServer();
StartAsClient();
}

bool noMoreUpdate = false;
//YOU NEED LATEUPDATE HERE, OFCOURSE UNITY DOCUMENTATION DOESNT SAY THAT:
//http://answers.unity3d.com/questions/1214729/onreceivedbroadcast-not-being-called-with-network.html
void LateUpdate()
{
if (noMoreUpdate)
return;
timeOut -= Time.deltaTime;
if (timeOut < 0)
{
//networkDiscovery.StopBroadcast();
StopBroadcast();
networkManager.StartHost();
//networkDiscovery.Initialize();
Initialize();
//networkDiscovery.broadcastData = "WORKKKK";
//networkDiscovery.StartAsServer();
StartAsServer();
noMoreUpdate = true;
BecomeHost();
}
}

public override void OnReceivedBroadcast(string fromAddress, string data)
{
base.OnReceivedBroadcast(fromAddress, data);
Debug.Log("sfdesdf");
//if (noMoreUpdate)
// return;
networkManager.networkAddress = fromAddress;
BecomeClient();
}

private void BecomeHost()
{
StopBroadcast();
networkManager.StartHost();
Initialize();
StartAsServer();
gameObject.SetActive(false);
}

private void BecomeClient()
{
networkManager.StartClient();
noMoreUpdate = true;
gameObject.SetActive(false);
}
}
2 changes: 2 additions & 0 deletions ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ EditorBuildSettings:
path: Assets/hanisstuff/Overlord - Ground test.unity
- enabled: 0
path: Assets/hanisstuff/scene/Overlord - Ground test 1.unity
- enabled: 1
path: Assets/Scene/Test Scenes/Lobby.unity
- enabled: 1
path: Assets/Scene/Test Scenes/Networking Test.unity

0 comments on commit 2e6f73a

Please sign in to comment.