Skip to main content

EdibleObject

A class in Root.Township, the global namespace.

Makes a pickup edible: bites over time at the mouth, then the server applies its effects and destroys it unless it's docked. Eating also adds the item to the edible pages.

Constructors​

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

Fields​

10 private and internal fields
MemberWhat it is
private EdibleObject.EatenStage biteEffectsBite count, duration per bite and bite effect for this food.
private AnimationCurve biteHapticHaptic curve played on each bite.
private Dictionary<ConsumptionManager, Coroutine> consumersEating coroutines running, one per ConsumptionManager.
private EffectDefinitionApplication[] consumptionEffectsBacking field for ConsumptionEffects.
private int currentBitesBites taken so far by the current holder.
private EdibleEvent finishedEatingBacking field for FinishedEating.
private NetworkEntity holdingEntityThe entity holding the food, so bites carry over while the same one holds it.
private static Logger loggerNLog logger for this class.
private Pickup pickupThe food's pickup.
private Coroutine resetingBitesThe pending bite-reset coroutine, if any.

Properties​

MemberWhat it is
EffectDefinitionApplication[] ConsumptionEffects { get; }Effects applied to whoever finishes eating it.
EdibleEvent FinishedEating { get; }Raised on both sides when the last bite is done.

Methods​

MemberWhat it is
bool StartEat(ConsumptionManager consumer, Transform mouth)Starts the biting coroutine for a consumer. False if disabled or that consumer is already eating.
void StopEat(ConsumptionManager consumer)Stops a consumer's biting. Bite count is kept until the item is let go.
6 private and internal methods
MemberWhat it is
private void Awake()Hooks the pickup's grab and release events to track who is eating.
private void BiteEffects()Client: plays the bite sound and haptics on every hand holding the food.
private void ResetBites(Interactable interactable, Interactor interactor)On release, resets the bite count after half a second (straight away if inactive).
private IEnumerator ResetBites() (iterator)On release, resets the bite count after half a second (straight away if inactive).
private IEnumerator StartEating(ConsumptionManager consumer, Transform mouth) (iterator)Coroutine for one eat: plays bite effects each bite, then applies effects (server), fires FinishedEating, unlocks the food page and destroys the food if not docked.
private void StartHolding(Interactable interactable, Interactor interactor)On grab, cancels a pending bite reset and starts the count again if a different entity picked it up.

Used in​

Members of other types that take, return or hold a EdibleObject: