ServerSelectionDisplay
A class in Root.Township, the global namespace.
Main menu server list laid out along a spline. Scrolling moves the elements along it; the one nearest the selection point is selected. Client only.
- Listed in Global namespace: S
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
ServerSelectionDisplay() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
14 private and internal fields
| Member | What it is |
|---|---|
private AltaEvent elementSelected | Event raised whenever a new element becomes selected. |
private bool isSelectingFirst | Inspector button that runs Setup and SelectFirst in the editor. |
private float maximumEnabledTime | Elements past this spline position are hidden. Default 0.7. |
private float maxSelectionDelta | How close (in spline position) an element must be to selectedTime to be selected. Default 0.15. |
private float minimumEnabledTime | Elements before this spline position are hidden. Default 0.2. |
private float moveToTimeAnimationDuration | Seconds a non-instant SelectElement slide takes. Default 2. |
private Coroutine moveToTimeCoroutine | The running MoveToTime slide, if any. |
private float selectedTime | Spline position (0 to 1) of the selection point. Default 0.55. |
private Transform selector | Transform placed at the selection point on the spline. |
private List<ServerElement> serverElements | The elements on the display in order. Filled by AddServerElement. |
private float spacing | Spline distance between neighbouring elements. Default 0.05. |
private BezierSpline spline | The Bezier spline the elements are laid along. |
private float startValue | Lowest allowed scroll value, set by CalculateStartValue. |
private float time | Current scroll position along the spline. Backing field for Value. |
Properties
| Member | What it is |
|---|---|
ServerElement CurrentSelection { get; private set; } | The element at the selection point, or null. |
List<ServerElement> ServerElements { get; } | The elements in display order. |
float Value { get; set; } | Scroll position along the spline, clamped to the list's range. Setting it stops any scroll animation. |
Events
| Member | What it is |
|---|---|
event SelectedElementChanged SelectedChanged | Raised with the old and new selection. |
Methods
| Member | What it is |
|---|---|
void AddServerElement(ServerElement serverElement) | Adds an element to the end of the list. |
void RemoveServerElement(ServerElement serverElement) | Removes an element, clearing the selection first if it was selected. |
void SelectElement(ServerElement serverElement, bool isInstant) | Scrolls so an element sits at the selection point, instantly or animated. |
void SelectFirst() | Scrolls to the first element. |
11 private and internal methods
| Member | What it is |
|---|---|
private void CalculateStartValue() | Sets the lowest scroll value from the element count and spacing, so the last element can reach the selection point. |
private IEnumerator MoveToTime(float targetTime, float moveToTimeAnimationDuration) (iterator) | Coroutine that slides the scroll value to a target over a duration. Started by SelectElement when not instant. |
private void OnDrawGizmos() | Editor: draws red spheres on the spline at the edges of the selection window. |
private void OnSelectionChanged(ServerElement oldSelected) | In play mode, raises SelectedChanged and, when something is selected, the elementSelected event. |
private void OnValidate() | Editor: clamps the scroll value and handles the Select First inspector button. |
private void PositionTransformAtTime(float targetTime, Transform target) | Places a transform on the spline at a position, facing along it, or hides it outside the enabled range. |
private void Setup() | Recalculates the start value and puts the selector at the selection point on the spline. |
private void Start() | Calls Setup. |
private void StopCurrentMoveToTimeAnimation() | Stops a running MoveToTime slide. |
private void Update() | Calls UpdateTargets every frame. |
private void UpdateTargets() | Positions every element along the spline, sets which are interactable, and selects the one closest to the selection point. |
Used in
Members of other types that take, return or hold a ServerSelectionDisplay: