GenericCraftingStation
A class in Root.Township, Alta.Crafting.
A crafting station driven by a recipe page in its dock: it shows ghost pieces you fill with the right materials and nail, then lets you pull out the finished item. The server runs the project; clients send nail hits and piece grabs.
- Listed in Crafting and making
- Inherits or implements
NetworkEntityBehaviour,ISavable<GenericCraftingStationData>,ISavableSave<GenericCraftingStationData>,ISavableSaveBase - Derived types
GenericCraftingStationData - Nested types
ClientSideNailHitSync,PickupColliders - Documented in Crafting
Constructors
| Member | What it is |
|---|---|
GenericCraftingStation() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
25 private and internal fields
| Member | What it is |
|---|---|
private float androidMaxDistanceToRenderProjectGhostSquared | Android ghost render distance, squared. Nothing reads it. |
private float androidMaxDistanceToRenderProjectSquared | Android project render distance, squared. Nothing reads it. |
private IProject currentProject | The project being built, or null when the station is empty. |
private Interactable fakeInteractable | Interactable over the finished project that players grab to take the result. |
private BoxCollider fakeInteractableCollider | Box collider for fakeInteractable, sized to the project when complete. |
private bool isSyncingAllowed | Turned off while SetupProjectFromResult rebuilds a project, so per-piece syncs aren't sent. |
private static Logger logger | NLog logger for this class. |
private float maxDistanceToRenderProjectGhostSquared | Squared distance within which the project ghost renders, used by UpdateDistanceLOD. |
private float maxDistanceToRenderProjectSquared | Squared distance within which the project renders, used by UpdateDistanceLOD. |
private Transform piecesParent | Backing field for PiecesParent. The result spawns at its position. |
private PickupDock recipeDock | Dock that holds the recipe page. |
private MethodSyncStruct<GenericCraftingStation.ClientSideNailHitSync> syncClientNailHit | Method sync for SyncClientNailHit. |
private MethodSyncStruct<int> syncDestroyEffect | Method sync for SyncDestroyEffect. |
private MethodSync syncFull | Method sync for SyncFull. |
private MethodSyncStruct<NailIdentifier> syncNailHit | Method sync for SyncNailHit. |
private MethodSyncStruct<int> syncPiece | Method sync for SyncPiece. |
private MethodSyncStruct<int> syncPieceGrab | Method sync for SyncPieceGrab. |
private MethodSync syncProject | Method sync for SyncProject. |
private MethodSyncStruct<bool> syncProjectStatus | Method sync for SyncProjectStatus. |
private static List<Rigidbody> toRemove | Static scratch list used by TrackPickups. |
private Dictionary<Rigidbody, GenericCraftingStation.PickupColliders> trackedPickups | Crafting component pickups inside the station's trigger, by rigidbody, with the colliders seen. |
private IUnityUpdateMethod trackPickups | Update registration for TrackPickups, live while any pickup is tracked. |
private static IUnityUpdateMethod updateDistanceLOD | Static update registration for the distance LOD method. |
private static UpdateModule updateModule | Static update module that runs TrackPickups. |
private static Dictionary<GenericCraftingStation, Vector3> updatingStations | Static map of stations with a project to their positions, for distance LOD. |
Properties
| Member | What it is |
|---|---|
Transform PiecesParent { get; } | Parent transform of the project's pieces; the completed effect plays here. |
1 private and internal property
Methods
| Member | What it is |
|---|---|
void ChangedPieces() | Server: resyncs the project status, or clears the project and returns materials if no page is docked and no piece is filled. |
override void Initialize() | Sets up the station's synced messages and hooks the recipe dock filter and the finished-item grab. |
override void InitializeAsServer(SpawnData spawnData) | Server: hooks page dock and undock, and loads the recipe of a page already docked. |
override void OnConnected(Player player) | Server: sends the full project state to a new player. |
void RequestClientNailHit(int pieceHash, int nailIndex, ImpactHitWithTool impactWithTool) | Client: sends a nail hit on a piece to the server. |
void RequestDestroyEffect(int pieceHash) | Server: tells clients to play a piece's destroy effect. |
void RequestSyncNailHit(NailIdentifier nailArguments) | Server: syncs a nail hit to clients. |
void RequestSyncPiece(GenericCraftingPiece piece) | Server: syncs one piece's state to clients. |
void RequestSyncPieceGrab(GenericCraftingPiece piece) | Client: tells the server a piece was grabbed. |
void SetupProjectFromResult(GenericCraftingResult result) | Rebuilds a complete project from a finished item placed back on the station (keeping its materials) and destroys the item. |
void TriggerEnter(Collider other) | Starts tracking a crafting component pickup that enters the station area. Already crafted pickups are ignored. |
void TriggerExit(Collider other) | Stops tracking a pickup once all its colliders have left. |
void TryAddPiece(int bestPieceKey, Action<GenericCraftingPiece> callback) | Calls back with the piece for a key if it isn't filled yet. Logs an error for an unknown key. |
int TrySetClosestPiece(GenericCraftingComponent component, Vector3 position, Action<GenericCraftingPiece> callback) | Finds the nearest piece that accepts a component within animate range and calls back with it. Returns its key or -1. |
void UpdateProjectComplete(bool hasEffects = false) | Syncs whether the project is complete and turns the grab area for the finished item on or off. |
33 private and internal methods
| Member | What it is |
|---|---|
private IEnumerator AddItemOnReleaseCoroutine(Pickup pickup) (iterator) | Waits to the end of the frame after a component is let go, then adds it to the project if it's still valid. |
private void CheckFakeInteractable(bool hasEffects) | Client: turns on the grab-result collider when the project is complete, with the completion effect if asked. |
private bool CheckPageForRecipe(Pickup pagePickup, out GenericCraftingRecipe recipe) | Gets the generic crafting recipe from a page pickup, if it has one. |
private void CleanDestroy(NetworkEntity entity, bool isUnload) | Clears the project without returning materials when the scene destroys the station. |
private void ClearLOD() | Removes the station from the distance LOD list. |
private void ClearProject(bool isReturningMaterials) | Clears the current project, optionally returning materials, and the server syncs the empty project. |
private void ClearTracked() | Unhooks and forgets every tracked pickup. Called on destroy. |
private void ComponentReleased(Interactable interactable, Interactor interactor) | Server: when a tracked pickup is let go, starts AddItemOnReleaseCoroutine for it. |
private void DockingFilter(Interactor interactor, PickupDock dock, ref bool result) | Client: refuses docking for pickups inside the station's trigger. |
private void GrabResult(Interactable interactable, Interactor interactor) | Server: when the finished project is grabbed, spawns the result and swaps it into the hand. |
private void GrabResultFilter(Interactor interactor, Interactable interactable, ref bool result) | Blocks grabbing the result until the project is complete. |
private bool IsPickupValidToAdd(Pickup pickup) | False for pickups that are held, docked or already crafted. |
private void LoadRecipe(GenericCraftingRecipe recipe) | Starts a project from a recipe and syncs it to chunks. |
private void OnDestroy() | Calls ClearTracked. |
private void OnPageDocked(Interactor interactor, Pickup pickup, PickupDock dock) | Server: starts a project from the docked page unless pieces are already filled. |
private void OnPageUndocked(Interactor interactor, Pickup pickup, PickupDock dock) | Server: clears an unfinished project, returning materials, when the page is removed and no pieces are filled. |
private void PageFilter(Interactor interactor, Pickup pickup, ref bool result) | Only lets pages that hold a generic crafting recipe dock in recipeDock. |
private void SetupFakeInteractable() | Fits the grab-result collider around the bounds of all project pieces. |
private void SetupLOD() | Client: adds the station to the distance LOD list. |
private void SetupProjectFromPage() | Starts a project from the page in recipeDock, if it holds a recipe. |
private NetworkEntity SpawnResult() | Spawns the recipe's result, clears the project and starts a new one from the docked page. |
private void StopAnimating() | Stops the placement animation on every project piece. |
private void SyncClientNailHit(IPlayer player, Stream stream, GenericCraftingStation.ClientSideNailHitSync arguments) | Server: applies a nail hit reported by a client, working out damage from the tool. |
private void SyncDestroyEffect(IPlayer player, Stream stream, int pieceIndex) | Hands a piece's destroy effect sync to the project. |
private void SyncFull(IPlayer player, Stream stream) | Syncs the whole station: recipe, every piece and the project status. Sent on connect. |
private void SyncNailHit(IPlayer player, Stream stream, NailIdentifier identifier) | Syncs a nail's state and the piece's failure, playing the nail effect on clients. |
private void SyncPiece(IPlayer player, Stream stream, int pieceIndex) | Hands one piece's sync to the project. |
private void SyncPieceGrab(IPlayer player, Stream stream, int pieceIndex) | Syncs a piece being grabbed, sent by clients. |
private void SyncProject(IPlayer player, Stream stream) | Syncs which recipe is loaded; clients start or clear their project to match. |
private void SyncProjectStatus(IPlayer player, Stream stream, bool hasEffects) | Syncs whether the project is complete or its current level, and updates the grab-result collider on clients. |
private void TrackPickups() | Per-frame while pickups are in the trigger: drops docked or destroyed ones and lets held components track the station. |
private static void UpdateDistanceLOD() | Sets each project's render level by distance from the local player's head. Never registered; see UpdateDistanceLODSingleGhost. |
private static void UpdateDistanceLODSingleGhost() | Empty. This, not UpdateDistanceLOD, is what SetupLOD registers, so distance LOD does nothing. |
Used in
Members of other types that take, return or hold a GenericCraftingStation:
GenericCraftingComponent.Released, GenericCraftingComponent.Track, GenericCraftingProject.GenericCraftingProject, GenericCraftingProject.Station, GenericCraftingRecipe.InitializeProject, GenericCraftingResult.Released, GenericCraftingResult.Track, IGenericCraftingComponent.Released, IGenericCraftingComponent.Track, IProject.Station.