2019-04-23 20:19:26 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using SanAndreasUnity.Utilities;
|
|
|
|
|
using SanAndreasUnity.Net;
|
|
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.UI
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public class StartGameWindow : PauseMenuWindow
|
|
|
|
|
{
|
|
|
|
|
string m_port = NetManager.defaultListenPortNumber.ToString();
|
|
|
|
|
bool m_dontListen = false;
|
|
|
|
|
bool m_dedicatedServer = false;
|
|
|
|
|
[SerializeField] string[] m_availableScenes = new string[]{"Main", "ModelViewer"};
|
|
|
|
|
int m_selectedSceneIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StartGameWindow()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// set default parameters
|
|
|
|
|
|
|
|
|
|
this.windowName = "Start Game";
|
|
|
|
|
this.useScrollView = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Start ()
|
|
|
|
|
{
|
|
|
|
|
// adjust rect
|
|
|
|
|
this.windowRect = GUIUtils.GetCenteredRect(new Vector2(550, 300));
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:31:23 +00:00
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
if (PauseMenu.IsOpened)
|
|
|
|
|
this.IsOpened = false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 20:19:26 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnWindowGUI ()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
GUILayout.Label ("Port:");
|
2019-04-23 21:21:41 +00:00
|
|
|
|
m_port = GUILayout.TextField(m_port, GUILayout.Width(100));
|
2019-04-23 20:19:26 +00:00
|
|
|
|
|
2019-04-23 21:21:41 +00:00
|
|
|
|
m_dontListen = GUILayout.Toggle(m_dontListen, "Don't listen");
|
2019-04-23 20:19:26 +00:00
|
|
|
|
|
2019-04-23 21:21:41 +00:00
|
|
|
|
m_dedicatedServer = GUILayout.Toggle(m_dedicatedServer, "Dedicated server");
|
2019-04-23 20:19:26 +00:00
|
|
|
|
|
|
|
|
|
GUILayout.Label("Map:");
|
|
|
|
|
m_selectedSceneIndex = GUILayout.SelectionGrid(m_selectedSceneIndex, m_availableScenes, 4);
|
|
|
|
|
|
|
|
|
|
GUILayout.Space(40);
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("Start", GUILayout.Width(80), GUILayout.Height(30)))
|
|
|
|
|
StartGame();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGame()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int port = int.Parse(m_port);
|
|
|
|
|
string scene = m_availableScenes[m_selectedSceneIndex];
|
|
|
|
|
|
|
|
|
|
// first start a server, and then change scene
|
|
|
|
|
|
2019-04-24 19:18:06 +00:00
|
|
|
|
NetManager.onlineScene = scene;
|
2019-04-23 21:21:41 +00:00
|
|
|
|
NetManager.dontListen = m_dontListen;
|
2019-04-23 20:19:26 +00:00
|
|
|
|
if (m_dedicatedServer)
|
|
|
|
|
NetManager.StartServer(port);
|
|
|
|
|
else
|
|
|
|
|
NetManager.StartHost(port);
|
|
|
|
|
|
2019-04-24 19:18:06 +00:00
|
|
|
|
//NetManager.ChangeScene(scene);
|
2019-04-23 20:19:26 +00:00
|
|
|
|
}
|
|
|
|
|
catch (System.Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Error", ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|