mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix(InterestManagement): calling OnEnable multiple times doesn't show an error anymore
This commit is contained in:
parent
be6c6c7c64
commit
0cc4726728
@ -9,24 +9,17 @@ namespace Mirror
|
|||||||
[HelpURL("https://mirror-networking.gitbook.io/docs/guides/interest-management")]
|
[HelpURL("https://mirror-networking.gitbook.io/docs/guides/interest-management")]
|
||||||
public abstract class InterestManagementBase : MonoBehaviour
|
public abstract class InterestManagementBase : MonoBehaviour
|
||||||
{
|
{
|
||||||
// Configures InterestManagementBase in NetworkServer/Client
|
// initialize NetworkServer/Client .aoi.
|
||||||
// Do NOT check for active server or client here.
|
// previously we did this in Awake(), but that's called for disabled
|
||||||
// OnEnable must always set the static aoi references.
|
// components too. if we do it OnEnable(), then it's not set for
|
||||||
// make sure to call base.OnEnable when overwriting!
|
// disabled components.
|
||||||
// Previously used Awake()
|
|
||||||
protected virtual void OnEnable()
|
protected virtual void OnEnable()
|
||||||
{
|
{
|
||||||
if (NetworkServer.aoi == null)
|
// do not check if == null or error if already set.
|
||||||
{
|
// users may enabled/disable components randomly,
|
||||||
NetworkServer.aoi = this;
|
// causing this to be called multiple times.
|
||||||
}
|
NetworkServer.aoi = this;
|
||||||
else Debug.LogError($"Only one InterestManagement component allowed. {NetworkServer.aoi.GetType()} has been set up already.");
|
NetworkClient.aoi = this;
|
||||||
|
|
||||||
if (NetworkClient.aoi == null)
|
|
||||||
{
|
|
||||||
NetworkClient.aoi = this;
|
|
||||||
}
|
|
||||||
else Debug.LogError($"Only one InterestManagement component allowed. {NetworkClient.aoi.GetType()} has been set up already.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ServerCallback]
|
[ServerCallback]
|
||||||
|
Loading…
Reference in New Issue
Block a user