Skip to content

Commit

Permalink
Merge branch 'upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Feb 9, 2020
2 parents b4a98d4 + 0f10c72 commit 23e5f65
Show file tree
Hide file tree
Showing 30 changed files with 520 additions and 277 deletions.
3 changes: 2 additions & 1 deletion Assets/Mirror/CompilerSymbols/PreprocessorDefine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static void AddDefineSymbols()
"MIRROR_6_0_OR_NEWER",
"MIRROR_7_0_OR_NEWER",
"MIRROR_8_0_OR_NEWER",
"MIRROR_9_0_OR_NEWER"
"MIRROR_9_0_OR_NEWER",
"MIRROR_10_0_OR_NEWER"
};
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, string.Join(";", defines));
}
Expand Down
4 changes: 3 additions & 1 deletion Assets/Mirror/Components/Discovery/NetworkDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class NetworkDiscovery : NetworkDiscoveryBase<ServerRequest, ServerRespon
[Tooltip("Invoked when a server is found")]
public ServerFoundUnityEvent OnServerFound;

public void Start()
public override void Start()
{
ServerId = RandomLong();

Expand All @@ -31,6 +31,8 @@ public void Start()
// Or just let the user assign it in the inspector
if (transport == null)
transport = Transport.activeTransport;

base.Start();
}

/// <summary>
Expand Down
15 changes: 13 additions & 2 deletions Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public static long RandomLong()
return value1 + ((long)value2 << 32);
}

/// <summary>
/// virtual so that inheriting classes' Start() can call base.Start() too
/// </summary>
public virtual void Start()
{
// headless mode? then start advertising
if (NetworkManager.isHeadless)
{
AdvertiseServer();
}
}

// Ensure the ports are cleared no matter when Game/Unity UI exits
void OnApplicationQuit()
{
Expand Down Expand Up @@ -101,7 +113,6 @@ void Shutdown()
/// <summary>
/// Advertise this server in the local network
/// </summary>
/// <param name="networkManager">Network Manager</param>
public void AdvertiseServer()
{
if (!SupportedOnThisPlatform)
Expand Down Expand Up @@ -252,7 +263,7 @@ public void StartDiscovery()
}

/// <summary>
/// Start Active Discovery
/// Stop Active Discovery
/// </summary>
public void StopDiscovery()
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Components/NetworkProximityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void Update()
/// <summary>
/// Called when a new player enters
/// </summary>
/// <param name="newObserver"></param>
/// <returns></returns>
/// <param name="newObserver">NetworkConnection of player object</param>
/// <returns>True if object is within visible range</returns>
public override bool OnCheckObserver(NetworkConnection newObserver)
{
if (ForceHidden)
Expand Down
8 changes: 7 additions & 1 deletion Assets/Mirror/Components/NetworkSceneChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public class NetworkSceneChecker : NetworkBehaviour
string currentScene;

[ServerCallback]
void Awake()
void OnEnable()
{
currentScene = gameObject.scene.name;
if (LogFilter.Debug) Debug.Log($"NetworkSceneChecker.OnEnable currentScene: {currentScene}");
}

public override void OnStartServer()
Expand Down Expand Up @@ -74,6 +75,11 @@ void RebuildSceneObservers()
networkIdentity.RebuildObservers(false);
}

/// <summary>
/// Called when a new player enters the scene
/// </summary>
/// <param name="newObserver">NetworkConnection of player object</param>
/// <returns>True if object is in the same scene</returns>
public override bool OnCheckObserver(NetworkConnection conn)
{
if (forceHidden)
Expand Down
7 changes: 3 additions & 4 deletions Assets/Mirror/Editor/EnterPlayModeSettingsCheck.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Unity 2019.3 has an experimental 'disable domain reload on play'
// Unity 2019.3 has an experimental 'disable domain reload on play'
// feature. keeping any global state between sessions will break
// Mirror and most of our user's projects. don't allow it for now.
// https://blogs.unity3d.com/2019/11/05/enter-play-mode-faster-in-unity-2019-3/
Expand Down Expand Up @@ -33,11 +33,10 @@ static void OnPlayModeStateChanged(PlayModeStateChange state)

static void CheckPlayModeOptions()
{
// enabling the checkbox is enough. it controls all the other
// settings.
// enabling the checkbox is enough. it controls all the other settings.
if (EditorSettings.enterPlayModeOptionsEnabled)
{
Debug.LogError("Enter Play Mode Options are not supported by Mirror. Please disable 'ProjectSettings->Editor->Enter Play Mode Settings (Experimental)'.");
Debug.LogError("Enter Play Mode Options are not supported by Mirror. Please disable 'ProjectSettings -> Editor -> Enter Play Mode Settings (Experimental)'.");
EditorApplication.isPlaying = false;
}
}
Expand Down
7 changes: 6 additions & 1 deletion Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public static class CompilationFinishedHook

public static bool WeaverEnabled { get; set; } // controls whether we weave any assemblies when CompilationPipeline delegates are invoked
public static bool UnityLogEnabled = true; // controls weather Weaver errors are reported direct to the Unity console (tests enable this)
public static bool WeaveFailed { get; private set; } // holds the result status of our latest Weave operation

// holds the result status of our latest Weave operation
// NOTE: WeaveFailed is critical to unit tests, but isn't used for anything else.
public static bool WeaveFailed { get; private set; }

// debug message handler that also calls OnMessageMethod delegate
static void HandleMessage(string msg)
Expand Down Expand Up @@ -153,7 +156,9 @@ static void OnCompilationFinished(string assemblyPath, CompilerMessage[] message
// passing null in the outputDirectory param will do an in-place update of the assembly
if (Program.Process(unityEngineCoreModuleDLL, mirrorRuntimeDll, null, new[] { assemblyPath }, dependencyPaths.ToArray(), HandleWarning, HandleError))
{
// NOTE: WeaveFailed is critical for unit tests but isn't used elsewhere
WeaveFailed = false;

//Debug.Log("Weaving succeeded for: " + assemblyPath);
}
else
Expand Down
25 changes: 16 additions & 9 deletions Assets/Mirror/Editor/Weaver/Readers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ public static MethodReference GetReadFunc(TypeReference variable, int recursionC
return foundFunc;
}

MethodDefinition newReaderFunc;

// Arrays are special, if we resolve them, we get teh element type,
// so the following ifs might choke on it for scriptable objects
// or other objects that require a custom serializer
// thus check if it is an array and skip all the checks.
if (variable.IsArray)
{
newReaderFunc = GenerateArrayReadFunc(variable, recursionCount);
RegisterReadFunc(variable.FullName, newReaderFunc);
return newReaderFunc;
}

TypeDefinition td = variable.Resolve();
if (td == null)
{
Expand Down Expand Up @@ -55,13 +68,7 @@ public static MethodReference GetReadFunc(TypeReference variable, int recursionC
return null;
}

MethodDefinition newReaderFunc;

if (variable.IsArray)
{
newReaderFunc = GenerateArrayReadFunc(variable, recursionCount);
}
else if (td.IsEnum)
if (td.IsEnum)
{
return GetReadFunc(td.GetEnumUnderlyingType(), recursionCount);
}
Expand All @@ -71,7 +78,7 @@ public static MethodReference GetReadFunc(TypeReference variable, int recursionC
}
else
{
newReaderFunc = GenerateStructReadFunction(variable, recursionCount);
newReaderFunc = GenerateClassOrStructReadFunction(variable, recursionCount);
}

if (newReaderFunc == null)
Expand Down Expand Up @@ -281,7 +288,7 @@ static MethodDefinition GenerateArraySegmentReadFunc(TypeReference variable, int
return readerFunc;
}

static MethodDefinition GenerateStructReadFunction(TypeReference variable, int recursionCount)
static MethodDefinition GenerateClassOrStructReadFunction(TypeReference variable, int recursionCount)
{
if (recursionCount > MaxRecursionCount)
{
Expand Down
25 changes: 16 additions & 9 deletions Assets/Mirror/Editor/Weaver/Writers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ public static MethodReference GetWriteFunc(TypeReference variable, int recursion
return foundFunc;
}

MethodDefinition newWriterFunc;

// Arrays are special, if we resolve them, we get the element type,
// so the following ifs might choke on it for scriptable objects
// or other objects that require a custom serializer
// thus check if it is an array and skip all the checks.
if (variable.IsArray)
{
newWriterFunc = GenerateArrayWriteFunc(variable, recursionCount);
RegisterWriteFunc(variable.FullName, newWriterFunc);
return newWriterFunc;
}

if (variable.IsByReference)
{
// error??
Expand Down Expand Up @@ -56,13 +69,7 @@ public static MethodReference GetWriteFunc(TypeReference variable, int recursion
return null;
}

MethodDefinition newWriterFunc;

if (variable.IsArray)
{
newWriterFunc = GenerateArrayWriteFunc(variable, recursionCount);
}
else if (variable.Resolve().IsEnum)
if (variable.Resolve().IsEnum)
{
return GetWriteFunc(variable.Resolve().GetEnumUnderlyingType(), recursionCount);
}
Expand All @@ -72,7 +79,7 @@ public static MethodReference GetWriteFunc(TypeReference variable, int recursion
}
else
{
newWriterFunc = GenerateStructWriterFunction(variable, recursionCount);
newWriterFunc = GenerateClassOrStructWriterFunction(variable, recursionCount);
}

if (newWriterFunc == null)
Expand All @@ -93,7 +100,7 @@ static void RegisterWriteFunc(string name, MethodDefinition newWriterFunc)
Weaver.WeaveLists.generateContainerClass.Methods.Add(newWriterFunc);
}

static MethodDefinition GenerateStructWriterFunction(TypeReference variable, int recursionCount)
static MethodDefinition GenerateClassOrStructWriterFunction(TypeReference variable, int recursionCount)
{
if (recursionCount > MaxRecursionCount)
{
Expand Down
12 changes: 3 additions & 9 deletions Assets/Mirror/Examples/Chat/Scripts/ChatNetworkManager.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using System;

namespace Mirror.Examples.Chat
{
[AddComponentMenu("")]
public class ChatNetworkManager : NetworkManager
{
public string playerName { get; set; }

public void SetHostname(string hostname)
{
this.networkAddress = hostname;
networkAddress = hostname;
}

public ChatWindow chatWindow;
Expand All @@ -33,10 +30,7 @@ public override void OnClientConnect(NetworkConnection conn)
base.OnClientConnect(conn);

// tell the server to create a player with this name
conn.Send(new CreatePlayerMessage
{
name = playerName
});
conn.Send(new CreatePlayerMessage { name = playerName });
}

private void OnCreatePlayer(NetworkConnection connection, CreatePlayerMessage createPlayerMessage)
Expand Down
4 changes: 0 additions & 4 deletions Assets/Mirror/Examples/Chat/Scripts/ChatWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

Expand All @@ -15,9 +13,7 @@ public class ChatWindow : MonoBehaviour

public void Awake()
{

Player.OnMessage += OnPlayerMessage;

}

private void OnPlayerMessage(Player player, string message)
Expand Down
3 changes: 0 additions & 3 deletions Assets/Mirror/Examples/Chat/Scripts/Player.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Mirror.Examples.Chat
{
Expand Down
Binary file modified Assets/Mirror/Icon/MirrorIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion Assets/Mirror/Icon/MirrorIcon.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Assets/Mirror/Runtime/ClientScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ internal static void InternalAddPlayer(NetworkIdentity identity)
// NOTE: It can be "normal" when changing scenes for the player to be destroyed and recreated.
// But, the player structures are not cleaned up, we'll just replace the old player
localPlayer = identity;

// NOTE: we DONT need to set isClient=true here, because OnStartClient
// is called before OnStartLocalPlayer, hence it's already set.
// localPlayer.isClient = true;

if (readyConnection != null)
{
readyConnection.identity = identity;
Expand Down
10 changes: 10 additions & 0 deletions Assets/Mirror/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ internal void OnStartServer()
// because we already set m_isServer=true above)
spawned[netId] = this;

// in host mode we set isClient true before calling OnStartServer,
// otherwise isClient is false in OnStartServer.
if (NetworkClient.active)
{
isClient = true;
}

foreach (NetworkBehaviour comp in NetworkBehaviours)
{
try
Expand All @@ -532,6 +539,8 @@ internal void OnStartClient()
return;
clientStarted = true;

isClient = true;

if (LogFilter.Debug) Debug.Log("OnStartClient " + gameObject + " netId:" + netId);
foreach (NetworkBehaviour comp in NetworkBehaviours)
{
Expand Down Expand Up @@ -1105,6 +1114,7 @@ internal void Reset()
return;

clientStarted = false;
isClient = false;
reset = false;

netId = 0;
Expand Down
5 changes: 5 additions & 0 deletions Assets/Mirror/Runtime/NetworkReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,5 +374,10 @@ public static Uri ReadUri(this NetworkReader reader)
{
return new Uri(reader.ReadString());
}

public static void ReadMessage<T>(this NetworkReader reader, T msg) where T : IMessageBase
{
msg.Deserialize(reader);
}
}
}
Loading

0 comments on commit 23e5f65

Please sign in to comment.