RepairBox
A class in Root.Township, the global namespace.
A build or repair box that takes up to three item costs in docks and, when filled, repairs a static building, destroys an old object or spawns a prefab. The server runs the logic and saves it; clients show counts and effects.
- Listed in Global namespace: Q to R
- Inherits or implements
NetworkEntityBehaviour,ISavableFull<RepairBoxSaveData>,ISavable<RepairBoxSaveData>,ISavableSave<RepairBoxSaveData>,ISavableSaveBase,ISavableFull - Derived types
RepairBoxSaveData - Documented in Other systems
Constructors
| Member | What it is |
|---|---|
RepairBox() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
62 private and internal fields
| Member | What it is |
|---|---|
private Vector3 animationPosition | Where building parts start their fly-in animation (the box's position). |
private NetworkAnimator boxAnimation | Network animator for the box; gets IsBuilding and IsRepeatable set on the server. |
private bool btnFinish | Debug inspector button. |
private BuildingAnimationWrapper buildingAnimationWrapper | Backing field for BuildingAnimationWrapper. |
private AltaEvent buildingFinished | Event invoked when the building animation ends and the box is done. |
private bool canBeUndone | Saved flag; not read elsewhere in this class. |
private GameObject checkmark1 | Checkmark shown when dock 1 is full on a one-off box. |
private GameObject checkmark2 | Checkmark shown when dock 2 is full on a one-off box. |
private GameObject checkmark3 | Checkmark shown when dock 3 is full on a one-off box. |
private PickupDock cost1 | Display dock showing the first required item. |
private PickupDock cost2 | Display dock showing the second required item; also a layout anchor. |
private PickupDock cost3 | Display dock showing the third required item; also a layout anchor. |
private NetworkPrefab destroying | Child object destroyed when the box acts (for example the broken version). |
private PickupDock dock1 | Input dock for the first item. |
private PickupDock dock2 | Input dock for the second item. |
private PickupDock dock3 | Input dock for the third item. |
private AltaEvent filled | Event invoked when the box is completed. |
private DockFilter filter1 | Dock filter for the first input. |
private DockFilter filter2 | Dock filter for the second input. |
private DockFilter filter3 | Dock filter for the third input. |
private float flyOutTime | Seconds for a part to fly from the peak into place. |
private bool ignoreMaterialOnSimpleServer1 | If true, item 1's material requirement is dropped on simple servers. |
private bool ignoreMaterialOnSimpleServer2 | If true, item 2's material requirement is dropped on simple servers. |
private bool ignoreMaterialOnSimpleServer3 | If true, item 3's material requirement is dropped on simple servers. |
private bool isDone | True once the box is completed. Repeatable boxes reset it after reporting. |
private bool isNonAnimatedStaticBuilding | True when the static object has no building animation, so Act spawns straight away. |
private bool isRepeatable | If true, the box can be filled again and keeps its docks after completion. |
private Item item1 | First required item; null for none. |
private PhysicalMaterial item1Material | Physical material item 1 must have, if item1UsePhysMat is set. |
private bool item1UsePhysMat | If true, item 1 must be of item1Material. |
private Item item2 | Second required item; null for none. |
private PhysicalMaterial item2Material | Physical material item 2 must have, if item2UsePhysMat is set. |
private bool item2UsePhysMat | If true, item 2 must be of item2Material. |
private Item item3 | Third required item; null for none. |
private PhysicalMaterial item3Material | Physical material item 3 must have, if item3UsePhysMat is set. |
private bool item3UsePhysMat | If true, item 3 must be of item3Material. |
private uint itemCount1 | How many of item 1 are needed. |
private uint itemCount2 | How many of item 2 are needed. |
private uint itemCount3 | How many of item 3 are needed. |
private static Logger logger | NLog logger for this class. |
private Action onItemDeposited | Client callback for an item deposited before completion. |
private Action onRepaired | Backing field for OnRepaired. |
private Transform refundLocation | Where extra items are popped out. |
private TextRenderer remaining1Text | Text showing how many of item 1 are still needed. |
private TextRenderer remaining2Text | Text showing how many of item 2 are still needed. |
private TextRenderer remaining3Text | Text showing how many of item 3 are still needed. |
private RepairBoxVfxController repairBoxVfxController | Plays the vortex, deposit, refund and completed effects. |
private AnimationCurve shootOutCurve | Easing for the shoot-up part of the build animation. |
private float shootOutHeight | Height parts shoot up to before flying in. |
private float shootOutMaxRadius | Random spread of the shoot-up peak. |
private float shootOutTime | Seconds for a part to shoot up. |
private AltaEvent spawnFinished | Event invoked after the result spawns, when done. |
private NetworkPrefab spawning | Prefab spawned when the box acts. |
private SetPieceData spawningData | Set piece spawned when the box acts, if there's no prefab. |
private Transform spawnPosition | Where the result spawns. Saved. |
private uint staticHash | Hash of the static world object this box restores; 0 for none. |
private MethodSync sync | Method sync for the full setup. |
private MethodSyncStruct<int> syncDevQuickModify | Method sync for dev tool commands. |
private MethodSync syncDone | Method sync for the done state. |
private MethodSync syncItemDocked | Method sync that tells clients to refresh counts. |
private AltaEvent undone | Event invoked when the box is set back to unfinished. |
private bool wasCompletedByDevTool | True if a dev tool built it; IsRepairBoxDone is then false. |
Properties
1 private and internal property
| Member | What it is |
|---|---|
private BuildingAnimationWrapper BuildingAnimationWrapper { get; set; } | The building animation on the static object with staticHash, looked up the first time it's needed. |
Methods
| Member | What it is |
|---|---|
void Act() | Server: applies the result. Destroys the linked object, marks the static building modified, and spawns the output. |
void CheckFinished() | If every dock holds its full cost, fires OnRepaired and finishes the repair. |
override void Initialize() | Sets up the network syncs for state, completion, docked items and dev tool commands. |
override void InitializeAsServer(SpawnData spawnData) | Prepares the cost docks and animator, and destroys the box if its static building is already built. |
override void OnConnected(Player player) | Sends the box state to a joining player. |
void SendDevToolCommandToServer(RepairBoxDevCommand devCommand) | Sends a dev panel build or destroy command, which skips the build animation or undoes the building. |
void SetupInput(Item item1, uint count1, Item item2 = null, uint count2 = 0, Item item3 = null, uint count3 = 0) | Sets up to three required items and counts. |
void SetupOutput(NetworkPrefab spawning, Vector3 spawnPosition = null, bool isRepeatable = true) | Sets the prefab to spawn, where to spawn it and whether the box can be used again. |
32 private and internal methods
| Member | What it is |
|---|---|
private void CheckForStaticContentAlreadyCompleted() | Server: destroys a finished box that only restores a static building (spawns nothing) once that building is already restored. |
private void CheckSpawn() | Server: spawns the spawning prefab or the spawningData set piece at the spawn point, then invokes spawnFinished if done. |
private void ConsumeAllDockContents() | Destroys the required amount from each input dock and undocks the rest. |
private static void ConsumeDockContents(PickupDock dock, int consumeQuantity) | Destroys up to an amount of a dock's stored items, then undocks whatever is left. |
private void DevToolRepair() | Dev tool: builds without the animation (the server runs Act, clients play the skipped animation). |
private void DevToolUnrepair() | Dev tool: marks the static object unmodified on the server and resets the building animation. |
private void Finish() | Marks the box done, consumes the docked items next frame and, if not repeatable, stops the box from being saved. Inspector button too. |
private void Alta.Chunks.ISavableFull.LoadSetup() | Save load setup: takes the first child NetworkPrefab as the destroying object. |
private void OnDisable() | Unhooks from static object changes. |
private void OnDrawGizmosSelected() | Draws the refund location in the editor. |
private void OnItemDocked(Interactor interactor, Pickup pickup, PickupDock dock) | Server: plays the deposit effect, refunds extras, checks for completion and syncs the remaining counts. Pouches are ignored. |
private void OnItemDockedLocal(Interactor interactor, Pickup pickup, PickupDock dock) | Client: invokes the deposited or repaired callback and refreshes the counts. Pouches are ignored. |
private void OnPreparedLocal() | Client: refreshes the remaining counts. |
private void OnResourcesChanged(Pickup pickup) | Checks for completion; when done, reports the project as finished for the last player who docked an item. |
private void OnValidate() | Editor: makes the destroying prefab a saved child of this box. |
private bool PopulateStaticObjectAnimation() | Finds the static object's building animation and hooks the fly-in animation. Returns false if the object isn't found. |
private IEnumerator PreInsertAnimation(AnimationPart part, float speed, bool isLast, IEnumerator insertAnimation) (iterator) | Animates each building part shooting up from the box and flying into place; after the last part, invokes buildingFinished and spawns on the server. |
private void Prepare() | Lays out the cost and input docks for the set items, adds dock filters and, on the server, spawns the cost display items. |
private void Prepare(Item item, ref uint count, PickupDock costDock, PickupDock dock, int dockCount, bool usePhysMat, PhysicalMaterial physMat, ref int index, out DockFilter filter) | Lays out the cost and input docks for the set items, adds dock filters and, on the server, spawns the cost display items. |
private void RefreshRemainingText() | Updates the remaining-count text and checkmarks for all three docks. |
private void RefreshText(uint cost, PickupDock inputDock, TextRenderer remainingText, GameObject checkMark) | Shows how many items a dock still needs; for one-off boxes swaps to a checkmark when full. |
private void RefundExtraItems(PickupDock dock, int requiredQuantity) | Pops items beyond the required amount out of a dock at the refund location. |
private void RejectDock(Interactor interactor, Pickup pickup, ref bool result) | Dock filter that refuses everything. |
private void Repair() | Sets the box done, starts the building animation and invokes filled. One-off boxes then refuse more items. The server syncs it. |
private void RestartVortexVfx() | Restarts the swirling effect shown while the box is unfinished. |
private void StaticUndo(uint hash, bool isModified) | Un-repairs the box when its static object is set back to unmodified. |
private void Sync(IPlayer player, Stream stream) | Sends the full setup to clients (items, counts, done state, static hash). Refused from clients. |
private void SyncDevToolCommand(IPlayer player, Stream stream, int devCommandIndex) | Runs a dev build or destroy command; the server relays it to the chunk. |
private void SyncDone(IPlayer player, Stream stream) | Syncs the done flags; clients update the docks and run the filled or undone event. |
private void SyncItemDocked(IPlayer player, Stream stream) | Refreshes the remaining counts on clients. |
private void UnRepair() | Sets the box back to unfinished, invokes undone, re-enables the docks and filters, and syncs on the server. |
private void ValidateIsDoneOnClient(bool isRunningEvent) | Client: shows or hides the docks for the done state, optionally running the filled or undone event. |
Used in
Members of other types that take, return or hold a RepairBox: