Skip to main content

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.

Constructors​

MemberWhat it is
RepairBox()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

62 private and internal fields
MemberWhat it is
private Vector3 animationPositionWhere building parts start their fly-in animation (the box's position).
private NetworkAnimator boxAnimationNetwork animator for the box; gets IsBuilding and IsRepeatable set on the server.
private bool btnFinishDebug inspector button.
private BuildingAnimationWrapper buildingAnimationWrapperBacking field for BuildingAnimationWrapper.
private AltaEvent buildingFinishedEvent invoked when the building animation ends and the box is done.
private bool canBeUndoneSaved flag; not read elsewhere in this class.
private GameObject checkmark1Checkmark shown when dock 1 is full on a one-off box.
private GameObject checkmark2Checkmark shown when dock 2 is full on a one-off box.
private GameObject checkmark3Checkmark shown when dock 3 is full on a one-off box.
private PickupDock cost1Display dock showing the first required item.
private PickupDock cost2Display dock showing the second required item; also a layout anchor.
private PickupDock cost3Display dock showing the third required item; also a layout anchor.
private NetworkPrefab destroyingChild object destroyed when the box acts (for example the broken version).
private PickupDock dock1Input dock for the first item.
private PickupDock dock2Input dock for the second item.
private PickupDock dock3Input dock for the third item.
private AltaEvent filledEvent invoked when the box is completed.
private DockFilter filter1Dock filter for the first input.
private DockFilter filter2Dock filter for the second input.
private DockFilter filter3Dock filter for the third input.
private float flyOutTimeSeconds for a part to fly from the peak into place.
private bool ignoreMaterialOnSimpleServer1If true, item 1's material requirement is dropped on simple servers.
private bool ignoreMaterialOnSimpleServer2If true, item 2's material requirement is dropped on simple servers.
private bool ignoreMaterialOnSimpleServer3If true, item 3's material requirement is dropped on simple servers.
private bool isDoneTrue once the box is completed. Repeatable boxes reset it after reporting.
private bool isNonAnimatedStaticBuildingTrue when the static object has no building animation, so Act spawns straight away.
private bool isRepeatableIf true, the box can be filled again and keeps its docks after completion.
private Item item1First required item; null for none.
private PhysicalMaterial item1MaterialPhysical material item 1 must have, if item1UsePhysMat is set.
private bool item1UsePhysMatIf true, item 1 must be of item1Material.
private Item item2Second required item; null for none.
private PhysicalMaterial item2MaterialPhysical material item 2 must have, if item2UsePhysMat is set.
private bool item2UsePhysMatIf true, item 2 must be of item2Material.
private Item item3Third required item; null for none.
private PhysicalMaterial item3MaterialPhysical material item 3 must have, if item3UsePhysMat is set.
private bool item3UsePhysMatIf true, item 3 must be of item3Material.
private uint itemCount1How many of item 1 are needed.
private uint itemCount2How many of item 2 are needed.
private uint itemCount3How many of item 3 are needed.
private static Logger loggerNLog logger for this class.
private Action onItemDepositedClient callback for an item deposited before completion.
private Action onRepairedBacking field for OnRepaired.
private Transform refundLocationWhere extra items are popped out.
private TextRenderer remaining1TextText showing how many of item 1 are still needed.
private TextRenderer remaining2TextText showing how many of item 2 are still needed.
private TextRenderer remaining3TextText showing how many of item 3 are still needed.
private RepairBoxVfxController repairBoxVfxControllerPlays the vortex, deposit, refund and completed effects.
private AnimationCurve shootOutCurveEasing for the shoot-up part of the build animation.
private float shootOutHeightHeight parts shoot up to before flying in.
private float shootOutMaxRadiusRandom spread of the shoot-up peak.
private float shootOutTimeSeconds for a part to shoot up.
private AltaEvent spawnFinishedEvent invoked after the result spawns, when done.
private NetworkPrefab spawningPrefab spawned when the box acts.
private SetPieceData spawningDataSet piece spawned when the box acts, if there's no prefab.
private Transform spawnPositionWhere the result spawns. Saved.
private uint staticHashHash of the static world object this box restores; 0 for none.
private MethodSync syncMethod sync for the full setup.
private MethodSyncStruct<int> syncDevQuickModifyMethod sync for dev tool commands.
private MethodSync syncDoneMethod sync for the done state.
private MethodSync syncItemDockedMethod sync that tells clients to refresh counts.
private AltaEvent undoneEvent invoked when the box is set back to unfinished.
private bool wasCompletedByDevToolTrue if a dev tool built it; IsRepairBoxDone is then false.

Properties​

MemberWhat it is
bool IsRepairBoxDone { get; }True when the box has been completed by players. A box completed through the dev tool reports false.
Action OnRepaired { get; set; }Callback run when all costs are met, and on clients when an item docks into a finished box.
1 private and internal property
MemberWhat 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​

MemberWhat 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
MemberWhat 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: