Table of Contents

Class SwitchTargetMover

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

A ISwitchTarget that slides and/or rotates a transform between a closed pose and an open pose — a door, a portcullis, a drawbridge, a moving platform.

public class SwitchTargetMover : MonoBehaviour, ITimedSwitchTarget, IClearanceSwitchTarget, ISwitchTarget, ITickPosed
Inheritance
Object
Component
Behaviour
MonoBehaviour
SwitchTargetMover
Implements
Inherited Members
MonoBehaviour.IsInvoking()
MonoBehaviour.CancelInvoke()
MonoBehaviour.StopCoroutine(Coroutine)
MonoBehaviour.StopAllCoroutines()
MonoBehaviour.destroyCancellationToken
MonoBehaviour.useGUILayout
MonoBehaviour.didStart
MonoBehaviour.didAwake
MonoBehaviour.runInEditMode
Behaviour.enabled
Behaviour.isActiveAndEnabled
Component.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.transform
Component.transformHandle
Component.gameObject
Component.tag
Object.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.ToString()
Object.name
Object.hideFlags

Remarks

The closed pose is wherever the moved transform sits when the scene loads, so a designer places the door shut and describes only the offset that opens it. Offsets are local to the moved transform's parent, so a door rotated to fit a wall opens along its own axis rather than a world one.

The motion is worked out in Update on both peers rather than replicated per-frame. Only the switch's state crosses the wire — once, when it changes — with the server tick the change began at and how far along the travel it stood then (ITimedSwitchTarget). Every peer evaluates the same pose from FishNet's synchronised tick, so the door stands in the same place on every screen and on the server, whose collider the character controller tests. It used to start on each peer when that peer heard of the change (a round trip apart), run on its own frame times, and snap a late arrival to the end pose while the server was still mid-swing.

The server moves too, and must: this transform carries the collider the character controller tests against, so a door that only opened on clients would be an invisible wall.

Properties

ChangeTick

The server tick the last change began at (0: none since the scene loaded).

public uint ChangeTick { get; }

Property Value

uint

ChangeTravel

How far along its travel it stood when that change began, 0..1.

public float ChangeTravel { get; }

Property Value

float

IsActivated

Whether this target is currently in the activated state.

public bool IsActivated { get; }

Property Value

bool

SolidTick

The server tick from which the pose it has come to rest in is solid: 0 while undecided (still moving, or held open to characters because someone stands where it came to rest), 1 for settled since before anyone watched. Only the server decides it, so every peer turns the target solid on the same tick.

public uint SolidTick { get; }

Property Value

uint

Methods

Activate(IPlayerCharacter)

Activates this target (e.g., opens a door, unlocks a chest, disarms a trap).

public void Activate(IPlayerCharacter activator)

Parameters

activator IPlayerCharacter

The player character who triggered the switch.

Deactivate(IPlayerCharacter)

Deactivates this target (e.g., closes a door, locks a chest, re-arms a trap).

public void Deactivate(IPlayerCharacter activator)

Parameters

activator IPlayerCharacter

The player character who triggered the switch.

IsObstructed(bool)

True when going to activated would leave solid colliders where a character stands now. Asked by the server before it changes the target; a pose that is never solid is never obstructed.

public bool IsObstructed(bool activated)

Parameters

activated bool

Returns

bool

Remarks

Each FishMMO.Shared.SwitchTargetMover.solidWhenClosed collider is placed where that pose puts it, and every character collider near it is tested against it there (ComputePenetration(Collider, Vector3, Quaternion, Collider, Vector3, Quaternion, out Vector3, out float) takes both poses, so the leaf is never moved to ask). The broad phase is a sphere round the posed collider with slack for transforms physics has not synced yet; the test itself reads the transforms.

PoseForTick(uint, double)

Puts this object where (and as solid as) it is at server tick syncTick. True when a transform or collider changed, so the caller syncs transforms once for all.

public bool PoseForTick(uint tick, double tickDelta)

Parameters

tick uint
tickDelta double

Returns

bool

Remarks

Blocking or not, and when blocking, in the resting pose the controller collides with. Applied by TickPoser before every live and replayed tick, at the server tick that tick runs at. Before it, a door's collider turned solid or passable on the client's FRAME estimate of the server tick, which is not the tick the owner's prediction runs at and was never rewound for a replay, so walking through a door as it opened or shut was corrected.

SetState(bool, uint, float, uint)

Adopts the server's state: activated, changed at changeTick from changeTravel, solid at rest from solidTick (0: not yet).

public void SetState(bool activated, uint tick, float fromTravel, uint solidFrom)

Parameters

activated bool
tick uint
fromTravel float
solidFrom uint

SnapTo(bool)

Puts this target into the given state with no transition.

public void SnapTo(bool activated)

Parameters

activated bool

The state to adopt immediately.

Remarks

For catching up rather than for reacting. A client that starts observing a switch reads the switch's current state out of its spawn payload, and that state describes something that happened before the player arrived — possibly hours before. Replaying it through Activate(IPlayerCharacter) would play the transition too, so walking into a room would set every door in it swinging. Nothing on the interaction path calls this.

Events

SolidDecided

Raised on the server when it decides SolidTick, for the switch to tell its observers.

public event Action<ITimedSwitchTarget> SolidDecided

Event Type

Action<ITimedSwitchTarget>