Remvoed unnecessary prefab menus from the loadup and from being cached variables. Also added notes and documentation to the SRMP.cs file and Utils file
This commit is contained in:
parent
a9885a57d5
commit
e2d711d45c
3 changed files with 67 additions and 6 deletions
|
@ -15,8 +15,9 @@ namespace SRMultiplayer
|
||||||
public static UserData UserData;
|
public static UserData UserData;
|
||||||
public static GameObject BeatrixModel;
|
public static GameObject BeatrixModel;
|
||||||
public static RuntimeAnimatorController BeatrixController;
|
public static RuntimeAnimatorController BeatrixController;
|
||||||
public static GameObject IngameMultiplayerMenuPrefab;
|
//unused prefab menus
|
||||||
public static GameObject MainMultiplayerMenuPrefab;
|
//public static GameObject IngameMultiplayerMenuPrefab;
|
||||||
|
//public static GameObject MainMultiplayerMenuPrefab;
|
||||||
public static Dictionary<byte, NetworkPlayer> Players = new Dictionary<byte, NetworkPlayer>();
|
public static Dictionary<byte, NetworkPlayer> Players = new Dictionary<byte, NetworkPlayer>();
|
||||||
public static string Username;
|
public static string Username;
|
||||||
public static string ServerCode;
|
public static string ServerCode;
|
||||||
|
|
58
SRMP/SRMP.cs
58
SRMP/SRMP.cs
|
@ -20,26 +20,41 @@ namespace SRMultiplayer
|
||||||
|
|
||||||
private float m_LastTimeSync;
|
private float m_LastTimeSync;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Acts as the initializer for the Mod
|
||||||
|
/// </summary>
|
||||||
public override void Awake()
|
public override void Awake()
|
||||||
{
|
{
|
||||||
base.Awake();
|
base.Awake();
|
||||||
|
|
||||||
|
//attach scene manager to trigger event when in a menu or loading up a game
|
||||||
SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
|
SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
|
||||||
|
//attach log messager to log all game errors and exceptions into the SRMP Logs
|
||||||
Application.logMessageReceived += Application_logMessageReceived;
|
Application.logMessageReceived += Application_logMessageReceived;
|
||||||
|
|
||||||
|
//load up mod specific resources
|
||||||
var myLoadedAssetBundle = AssetBundle.LoadFromMemory(Utils.ExtractResource("SRMultiplayer.srmultiplayer.dat"));
|
var myLoadedAssetBundle = AssetBundle.LoadFromMemory(Utils.ExtractResource("SRMultiplayer.srmultiplayer.dat"));
|
||||||
if (myLoadedAssetBundle == null)
|
if (myLoadedAssetBundle == null)
|
||||||
{
|
{
|
||||||
SRMP.Log("Failed to load AssetBundle!");
|
SRMP.Log("Failed to load AssetBundle!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//load up the Player moment animator for the Beatrix model
|
||||||
Globals.BeatrixController = myLoadedAssetBundle.LoadAsset<RuntimeAnimatorController>("Controller");
|
Globals.BeatrixController = myLoadedAssetBundle.LoadAsset<RuntimeAnimatorController>("Controller");
|
||||||
Globals.IngameMultiplayerMenuPrefab = myLoadedAssetBundle.LoadAsset<GameObject>("IngameMultiplayerMenu");
|
|
||||||
Globals.MainMultiplayerMenuPrefab = myLoadedAssetBundle.LoadAsset<GameObject>("MainMultiplayerMenu");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//unused prefab menus, these menus functions are handled in the floating gui
|
||||||
|
//Globals.IngameMultiplayerMenuPrefab = myLoadedAssetBundle.LoadAsset<GameObject>("IngameMultiplayerMenu");
|
||||||
|
//Globals.MainMultiplayerMenuPrefab = myLoadedAssetBundle.LoadAsset<GameObject>("MainMultiplayerMenu");
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Subscriber to the Applicaiton log and process it on to the Mods console
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="condition">Log condition</param>
|
||||||
|
/// <param name="stackTrace">Stack trace of log strigger (if applicable)</param>
|
||||||
|
/// <param name="type">Log Type</param>
|
||||||
private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
|
private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
|
||||||
{
|
{
|
||||||
|
//if Error or Exception hand the error of to the Mods log/console to display
|
||||||
if(type == LogType.Error || type == LogType.Exception)
|
if(type == LogType.Error || type == LogType.Exception)
|
||||||
{
|
{
|
||||||
SRMP.Log(condition);
|
SRMP.Log(condition);
|
||||||
|
@ -54,6 +69,10 @@ namespace SRMultiplayer
|
||||||
//menuObj.AddComponent<NetworkClientUI>();
|
//menuObj.AddComponent<NetworkClientUI>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// After triggering base destroy
|
||||||
|
/// trigger disconnect and shut down the server
|
||||||
|
/// </summary>
|
||||||
public override void OnDestroy()
|
public override void OnDestroy()
|
||||||
{
|
{
|
||||||
base.OnDestroy();
|
base.OnDestroy();
|
||||||
|
@ -62,18 +81,25 @@ namespace SRMultiplayer
|
||||||
NetworkServer.Instance.Disconnect();
|
NetworkServer.Instance.Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// On Game quit trigger disconnect and shut down the server
|
||||||
|
/// </summary>
|
||||||
private void OnApplicationQuit()
|
private void OnApplicationQuit()
|
||||||
{
|
{
|
||||||
NetworkClient.Instance.Disconnect();
|
NetworkClient.Instance.Disconnect();
|
||||||
NetworkServer.Instance.Disconnect();
|
NetworkServer.Instance.Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// On Update triggered sync up game time
|
||||||
|
/// </summary>
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if(Globals.GameLoaded)
|
if(Globals.GameLoaded)
|
||||||
{
|
{
|
||||||
if(Globals.IsServer)
|
if(Globals.IsServer)
|
||||||
{
|
{
|
||||||
|
//every 30 seconds send a time updater out to all clients
|
||||||
if(Time.time - m_LastTimeSync > 30)
|
if(Time.time - m_LastTimeSync > 30)
|
||||||
{
|
{
|
||||||
m_LastTimeSync = Time.time;
|
m_LastTimeSync = Time.time;
|
||||||
|
@ -98,17 +124,28 @@ namespace SRMultiplayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handle scene changed events triggered by the game
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="from">Scene previously</param>
|
||||||
|
/// <param name="to">New Scene</param>
|
||||||
private void SceneManager_activeSceneChanged(Scene from, Scene to)
|
private void SceneManager_activeSceneChanged(Scene from, Scene to)
|
||||||
{
|
{
|
||||||
|
//trigger handlers for returning or going to the main menu
|
||||||
if (to.buildIndex == 2) OnMainMenuLoaded();
|
if (to.buildIndex == 2) OnMainMenuLoaded();
|
||||||
if (to.buildIndex == 3) OnGameLoaded();
|
//trigger handlers for loading the game
|
||||||
|
else if (to.buildIndex == 3) OnGameLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handle user changing to the main menu, whether it is start up or from saving/ being kicked out of the game
|
||||||
|
/// </summary>
|
||||||
private void OnMainMenuLoaded()
|
private void OnMainMenuLoaded()
|
||||||
{
|
{
|
||||||
//var menuObj = Instantiate(Globals.MainMultiplayerMenuPrefab, null, false);
|
//var menuObj = Instantiate(Globals.MainMultiplayerMenuPrefab, null, false);
|
||||||
//menuObj.AddComponent<NetworkClientUI>();
|
//menuObj.AddComponent<NetworkClientUI>();
|
||||||
|
|
||||||
|
//innitialize all necessary global variables
|
||||||
Globals.LocalID = 0;
|
Globals.LocalID = 0;
|
||||||
Globals.DisableAchievements = false;
|
Globals.DisableAchievements = false;
|
||||||
Globals.GameLoaded = false;
|
Globals.GameLoaded = false;
|
||||||
|
@ -135,6 +172,8 @@ namespace SRMultiplayer
|
||||||
Globals.Nutcrackers.Clear();
|
Globals.Nutcrackers.Clear();
|
||||||
Globals.RaceTriggers.Clear();
|
Globals.RaceTriggers.Clear();
|
||||||
NetworkAmmo.All.Clear();
|
NetworkAmmo.All.Clear();
|
||||||
|
|
||||||
|
//clean up any lingering players in the global list
|
||||||
foreach (var player in Globals.Players.Values.ToList())
|
foreach (var player in Globals.Players.Values.ToList())
|
||||||
{
|
{
|
||||||
if(player != null && player.gameObject != null)
|
if(player != null && player.gameObject != null)
|
||||||
|
@ -144,9 +183,14 @@ namespace SRMultiplayer
|
||||||
}
|
}
|
||||||
Globals.Players.Clear();
|
Globals.Players.Clear();
|
||||||
|
|
||||||
|
|
||||||
|
//reset the chat
|
||||||
ChatUI.Instance.Clear();
|
ChatUI.Instance.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handle the user loading into the multiplayer game
|
||||||
|
/// </summary>
|
||||||
private void OnGameLoaded()
|
private void OnGameLoaded()
|
||||||
{
|
{
|
||||||
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
|
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
|
||||||
|
@ -365,6 +409,12 @@ namespace SRMultiplayer
|
||||||
|
|
||||||
private static FileStream m_LogFileStream;
|
private static FileStream m_LogFileStream;
|
||||||
private static StreamWriter m_LogWriter;
|
private static StreamWriter m_LogWriter;
|
||||||
|
/// <summary>
|
||||||
|
/// Custom message logging of a given message
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">Main message to be logged</param>
|
||||||
|
/// <param name="prefix">Prefix to be displayed before the message. Prefix will be after time marker and before the message
|
||||||
|
/// It will also be incapsulated in []</param>
|
||||||
public static void Log(string msg, string prefix = null)
|
public static void Log(string msg, string prefix = null)
|
||||||
{
|
{
|
||||||
if(m_LogFileStream == null)
|
if(m_LogFileStream == null)
|
||||||
|
|
|
@ -43,6 +43,11 @@ namespace SRMultiplayer
|
||||||
}
|
}
|
||||||
|
|
||||||
private static System.Random m_Random = new System.Random();
|
private static System.Random m_Random = new System.Random();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a new random actor id for netowkr actors
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Random integer between in Min and int max that is not in the current sessions of NetworkActors</returns>
|
||||||
public static int GetRandomActorID()
|
public static int GetRandomActorID()
|
||||||
{
|
{
|
||||||
int id = m_Random.Next(int.MinValue, int.MaxValue);
|
int id = m_Random.Next(int.MinValue, int.MaxValue);
|
||||||
|
@ -55,6 +60,11 @@ namespace SRMultiplayer
|
||||||
|
|
||||||
static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
||||||
const long byteConversion = 1000;
|
const long byteConversion = 1000;
|
||||||
|
/// <summary>
|
||||||
|
/// Takes a count of bytes and turns it into a human readable version
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">Count of Bytes as a long</param>
|
||||||
|
/// <returns>String statement of the bytes </returns>
|
||||||
public static string GetHumanReadableFileSize(long value)
|
public static string GetHumanReadableFileSize(long value)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue