InterestManagement fake static

This commit is contained in:
vis2k 2022-09-30 15:46:52 +07:00
parent c4d4e42d92
commit 7d841790f1

View File

@ -1,5 +1,6 @@
// interest management component for custom solutions like // interest management component for custom solutions like
// distance based, spatial hashing, raycast based, etc. // distance based, spatial hashing, raycast based, etc.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -9,12 +10,19 @@ 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 InterestManagement : MonoBehaviour public abstract class InterestManagement : MonoBehaviour
{ {
// "fake statics"
protected NetClient NetworkClient;
// Awake configures InterestManagement in NetworkServer/Client // Awake configures InterestManagement in NetworkServer/Client
// Do NOT check for active server or client here. // Do NOT check for active server or client here.
// Awake must always set the static aoi references. // Awake must always set the static aoi references.
// make sure to call base.Awake when overwriting! // make sure to call base.Awake when overwriting!
protected virtual void Awake() protected virtual void Awake()
{ {
// get components
NetworkClient = GetComponent<NetClient>();
if (NetworkClient == null) throw new Exception($"InterestManagement is missing a NetClient component on {name}. Please add one.");
if (NetworkServer.aoi == null) if (NetworkServer.aoi == null)
{ {
NetworkServer.aoi = this; NetworkServer.aoi = this;