Class WeatherExposureController
Turns the weather a character is standing in into buffs — wet, chilled, wind-burnt — and does it inside the prediction replicate, so the owner sees the state change at the moment it earns it rather than a round trip later.
[DisallowMultipleComponent]
public class WeatherExposureController : CharacterBehaviour, ICharacterBehaviour, IPredictableController
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourNetworkBehaviourWeatherExposureController
- Implements
- Inherited Members
-
NetworkBehaviour.IsSpawnedNetworkBehaviour.ComponentIndexNetworkBehaviour.NetworkObjectNetworkBehaviour.MAXIMUM_NETWORKBEHAVIOURSNetworkBehaviour.UNSET_NETWORKBEHAVIOUR_IDNetworkBehaviour.ToString()NetworkBehaviour.Reset()NetworkBehaviour.OnValidate()NetworkBehaviour.IsBehaviourReconcilingNetworkBehaviour.ClearReplicateCache()NetworkBehaviour.RequestReconcileSends()NetworkBehaviour.CreateReconcile()NetworkBehaviour.Reconcile_Reader_Remote<T>(PooledReader, ref T)NetworkBehaviour.ClearBuffedRpcs()NetworkBehaviour.IsClientOnlyNetworkBehaviour.IsServerOnlyNetworkBehaviour.IsHostNetworkBehaviour.IsClientNetworkBehaviour.IsServerNetworkBehaviour.IsDeinitializingNetworkBehaviour.NetworkManagerNetworkBehaviour.ServerManagerNetworkBehaviour.ClientManagerNetworkBehaviour.ObserverManagerNetworkBehaviour.TransportManagerNetworkBehaviour.TimeManagerNetworkBehaviour.SceneManagerNetworkBehaviour.PredictionManagerNetworkBehaviour.RollbackManagerNetworkBehaviour.NetworkObserverNetworkBehaviour.IsClientInitializedNetworkBehaviour.IsClientStartedNetworkBehaviour.IsClientOnlyInitializedNetworkBehaviour.IsClientOnlyStartedNetworkBehaviour.IsServerInitializedNetworkBehaviour.IsServerStartedNetworkBehaviour.IsServerOnlyInitializedNetworkBehaviour.IsServerOnlyStartedNetworkBehaviour.IsHostInitializedNetworkBehaviour.IsHostStartedNetworkBehaviour.IsOfflineNetworkBehaviour.IsNetworkedNetworkBehaviour.GetIsNetworked()NetworkBehaviour.IsManagerReconcilingNetworkBehaviour.ObserversNetworkBehaviour.IsOwnerNetworkBehaviour.IsControllerNetworkBehaviour.HasAuthorityNetworkBehaviour.OwnerNetworkBehaviour.OwnerIdNetworkBehaviour.ObjectIdNetworkBehaviour.LocalConnectionNetworkBehaviour.OwnerMatches(NetworkConnection)NetworkBehaviour.Despawn(GameObject, DespawnType?)NetworkBehaviour.Despawn(NetworkObject, DespawnType?)NetworkBehaviour.Despawn(DespawnType?)NetworkBehaviour.Spawn(GameObject, NetworkConnection, Scene)NetworkBehaviour.Spawn(NetworkObject, NetworkConnection, Scene)NetworkBehaviour.RemoveOwnership()NetworkBehaviour.GiveOwnership(NetworkConnection)NetworkBehaviour.GetInstance<T>()NetworkBehaviour.TryRegisterInstance<T>(T)NetworkBehaviour.UnregisterInstance<T>()NetworkBehaviour.CanLog(LoggingType)NetworkBehaviour.OnStartServerCalledNetworkBehaviour.OnStartClientCalledNetworkBehaviour.WritePayload(NetworkConnection, Writer)NetworkBehaviour.ReadPayload(NetworkConnection, Reader)NetworkBehaviour.OnStartNetwork()NetworkBehaviour.OnStopNetwork()NetworkBehaviour.OnStartServer()NetworkBehaviour.OnStopServer()NetworkBehaviour.OnOwnershipServer(NetworkConnection)NetworkBehaviour.OnSpawnServer(NetworkConnection)NetworkBehaviour.OnDespawnServer(NetworkConnection)NetworkBehaviour.OnStartClient()NetworkBehaviour.OnStopClient()NetworkBehaviour.OnOwnershipClient(NetworkConnection)MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.MemberwiseClone()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.nameObject.hideFlags
Remarks
Who simulates. The server and the owning client, driven from
CharacterPredictionController's single [Replicate] like every other
controller. An observer never runs it: state forwarding is off on every prefab, and the buffs
it applies reach observers the way all buffs do.
Why it can be predicted at all. Everything it reads is a pure function of the tick and
the position. The weather timeline is deterministic from its seed and clock anchor, both of
which the client already holds; shelter is a point-in-collider test
(WeatherVolume.Contains, and so RegionGeometry.ContainsPoint) rather than
a physics trigger, which matters because triggers poll in OnPostPhysicsSimulation,
outside the replicate, are not rolled back, and re-fire their Enter/Exit on every replay
(N12). So the owner can work out the same answer the server will, and a replay of the same
tick gives the same answer again.
Which clock. The weather is evaluated at a SYNCHRONISED tick, and the replicate's tick is the owner's unsynchronised counter: see WeatherExposureTick, which is where that conversion lives and is tested.
No new field in the input. Nothing is sent up from the client; the whole step is derived from the tick, the character's own position and the timeline both sides already have (N12). What does ride the reconcile is the levels, because they are timers — see Exposure.
Fields
Recipes
[Tooltip("States that exist only where two or more of the above do at once: soaked AND chilled is frozen. Evaluated from the levels, so they cost nothing on the wire.")]
public List<WeatherExposureRecipe> Recipes
Field Value
SampleSeconds
[Tooltip("How often the weather is sampled, in seconds. The level is stepped by exactly this much each time, so a slower sample is cheaper without changing how fast a state builds.")]
[Range(0.1, 5)]
public float SampleSeconds
Field Value
States
[Header("Exposure")]
[Tooltip("The states this character can be put into by the weather. Empty: the controller does nothing.")]
public List<WeatherExposureTemplate> States
Field Value
VerboseLogging
[Tooltip("Log every level change. Very noisy; for working on exposure only.")]
public bool VerboseLogging
Field Value
Properties
Order
After movement (KCCPlayer, 80) so the position is this tick's, and before buffs (BuffController, 85) so a buff applied here is ticked in the same step rather than the next one.
public int Order { get; }
Property Value
OrderedRecipes
Every recipe this controller can satisfy, nulls and duplicates removed.
public IReadOnlyList<WeatherExposureRecipe> OrderedRecipes { get; }
Property Value
OrderedStates
Every state this controller can enter, in reconcile order.
public IReadOnlyList<WeatherExposureTemplate> OrderedStates { get; }
Property Value
Methods
CreateReconcileSnapshot()
The levels as they go on the wire, sorted by template ID and quantised.
public ExposureReconcileEntry[] CreateReconcileSnapshot()
Returns
Remarks
The cached array is returned unchanged when nothing moved, so the delta serializer's
ReferenceEquals shortcut skips the comparison entirely — the same trick the buff
and attribute snapshots use.
IsHolding(WeatherExposureRecipe)
True while the recipe is satisfied and holding its buff.
public bool IsHolding(WeatherExposureRecipe recipe)
Parameters
recipeWeatherExposureRecipe
Returns
IsHolding(WeatherExposureTemplate)
True while the state's buff is held.
public bool IsHolding(WeatherExposureTemplate state)
Parameters
stateWeatherExposureTemplate
Returns
IsSuppressed(WeatherExposureTemplate)
True while a recipe is holding this state's buff in its place.
public bool IsSuppressed(WeatherExposureTemplate state)
Parameters
stateWeatherExposureTemplate
Returns
LevelOf(WeatherExposureTemplate)
The level of one state, 0..1. For the recipes, the UI and tests.
public float LevelOf(WeatherExposureTemplate state)
Parameters
stateWeatherExposureTemplate
Returns
OnCreateReconcile(ref CharacterReconcileData)
Writes this controller's authoritative state into the reconcile data (server only). Called once per tick after OnReplicate(ref CharacterReplicateData, ReplicateState, Channel).
public void OnCreateReconcile(ref CharacterReconcileData reconcileData)
Parameters
reconcileDataCharacterReconcileData
OnReconcile(CharacterReconcileData, Channel)
Restores this controller's state from the server's authoritative reconcile data.
public void OnReconcile(CharacterReconcileData rd, Channel channel)
Parameters
rdCharacterReconcileDatachannelChannel
OnReplicate(ref CharacterReplicateData, ReplicateState, Channel)
Executes this controller's simulation for the current tick.
May modify input for observer prediction.
public void OnReplicate(ref CharacterReplicateData input, ReplicateState state, Channel channel)
Parameters
inputCharacterReplicateDatastateReplicateStatechannelChannel
PopulateInput(ref CharacterReplicateData)
Populates this controller's portion of the unified input data (owner only). Called once per tick before OnReplicate(ref CharacterReplicateData, ReplicateState, Channel).
public void PopulateInput(ref CharacterReplicateData input)
Parameters
inputCharacterReplicateData
ResetState(bool)
Resets this NetworkBehaviour so that it may be added to an object pool.
public override void ResetState(bool asServer)
Parameters
asServerbool
RestoreFromReconcile(ExposureReconcileEntry[])
Takes the server's levels as the truth, and re-derives which buffs are held.
public void RestoreFromReconcile(ExposureReconcileEntry[] entries)
Parameters
entriesExposureReconcileEntry[]
Remarks
The held set is rebuilt from the restored levels rather than carried across the reconcile, because the levels have just been overwritten: a buff whose level the server says never reached the threshold must not still be marked as held, or it would never be applied again. Dequantising here — the same function the server quantised with — leaves both peers on bit-identical levels, so the replay that follows starts from the server's state exactly.
RestoreFromReconcile(ExposureReconcileEntry[], BuffReconcileEntry[])
RestoreFromReconcile(ExposureReconcileEntry[]), with the server's buffs for the same tick: they say which side of a hysteresis band a state or a recipe was on, which the levels alone cannot.
public void RestoreFromReconcile(ExposureReconcileEntry[] entries, BuffReconcileEntry[] serverBuffs)
Parameters
entriesExposureReconcileEntry[]serverBuffsBuffReconcileEntry[]
Remarks
Inside the band (between release and apply) "held" depends on which way the level was travelling. The server's answer is in the same correction: the buff is on its list or it is not. Without it a state in the band kept whatever this client last believed, and every recipe was read as NOT held, so a buff the server was holding by its release margin was taken off by the owner at its next sample, put back by the next correction, and taken off again by the replay: an icon and an effect flickering once a second.