mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
periodic rebuilds
This commit is contained in:
parent
a14d094bc5
commit
d09f5ef008
@ -13,6 +13,10 @@ public class FastSpatialInterestManagement : InterestManagementBase
|
|||||||
[Tooltip("The maximum range that objects will be visible at.")]
|
[Tooltip("The maximum range that objects will be visible at.")]
|
||||||
public int visRange = 30;
|
public int visRange = 30;
|
||||||
|
|
||||||
|
[Tooltip("Rebuild all every 'rebuildInterval' seconds.")]
|
||||||
|
public float rebuildInterval = 1;
|
||||||
|
double lastRebuildTime;
|
||||||
|
|
||||||
// we use a 9 neighbour grid.
|
// we use a 9 neighbour grid.
|
||||||
// so we always see in a distance of 2 grids.
|
// so we always see in a distance of 2 grids.
|
||||||
// for example, our own grid and then one on top / below / left / right.
|
// for example, our own grid and then one on top / below / left / right.
|
||||||
@ -62,7 +66,14 @@ internal void LateUpdate()
|
|||||||
// only on server
|
// only on server
|
||||||
if (!NetworkServer.active) return;
|
if (!NetworkServer.active) return;
|
||||||
|
|
||||||
|
// rebuild all spawned entities' observers every 'interval'
|
||||||
|
// this will call OnRebuildObservers which then returns the
|
||||||
|
// observers at grid[position] for each entity.
|
||||||
|
if (NetworkTime.localTime >= lastRebuildTime + rebuildInterval)
|
||||||
|
{
|
||||||
RebuildAll();
|
RebuildAll();
|
||||||
|
lastRebuildTime = NetworkTime.localTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a new identity is spawned
|
// When a new identity is spawned
|
||||||
|
@ -41,6 +41,7 @@ public override void SetUp()
|
|||||||
|
|
||||||
aoi = holder.AddComponent<FastSpatialInterestManagement>();
|
aoi = holder.AddComponent<FastSpatialInterestManagement>();
|
||||||
aoi.visRange = 10;
|
aoi.visRange = 10;
|
||||||
|
aoi.rebuildInterval = -1; // rebuild every call :)
|
||||||
// setup server aoi since InterestManagement Awake isn't called
|
// setup server aoi since InterestManagement Awake isn't called
|
||||||
NetworkServer.aoi = aoi;
|
NetworkServer.aoi = aoi;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user