void SetInventory(StateData state) { var domainObjects = new NativeList <(DomainObject, int)>(4, Allocator.TempJob); foreach (var(_, domainObjectIndex) in state.GetDomainObjects(domainObjects, k_InventoryType)) { var inventory = state.GetTraitOnObjectAtIndex <Inventory>(domainObjectIndex); if (inventory.SatisfiesNeed == NeedType.Hunger) // Apples { m_NumApples = (int)inventory.Amount; for (var i = 0; i < m_Apples.Count; i++) { m_Apples[i].enabled = i >= m_MaxApples - m_NumApples; } } else if (inventory.SatisfiesNeed == NeedType.Thirst) // Bottles { m_NumBottles = (int)inventory.Amount; for (var i = 0; i < m_Bottles.Count; i++) { m_Bottles[i].enabled = i >= m_MaxBottles - m_NumBottles; } } } domainObjects.Dispose(); }
public override void EndExecution(StateData state, ActionKey action, Otto actor) { base.EndExecution(state, action, actor); var domainObjects = new NativeList <(DomainObject, int)>(4, Allocator.TempJob); foreach (var(_, domainObjectIndex) in state.GetDomainObjects(domainObjects, typeof(Inventory))) { var inventory = state.GetTraitOnObjectAtIndex <Inventory>(domainObjectIndex); inventory.Amount -= inventory.ConsumableType == m_ConsumableType ? 1 : 0; state.SetTraitOnObjectAtIndex(inventory, domainObjectIndex); } domainObjects.Clear(); foreach (var(_, domainObjectIndex) in state.GetDomainObjects(domainObjects, typeof(Need))) { var need = state.GetTraitOnObjectAtIndex <Need>(domainObjectIndex); need.Urgency -= need.NeedType == m_NeedType ? m_NeedReduction : 0; state.SetTraitOnObjectAtIndex(need, domainObjectIndex); } domainObjects.Dispose(); }
public override void EndExecution(StateData state, ActionKey action, Otto actor) { var domainObjects = new NativeList <(DomainObject, int)>(4, Allocator.TempJob); foreach (var(_, domainObjectIndex) in state.GetDomainObjects(domainObjects, new ComponentType[] { typeof(Inventory) })) { var inventory = state.GetTraitOnObjectAtIndex <Inventory>(domainObjectIndex); inventory.Amount += inventory.ConsumableType == m_ConsumableType ? 1 : 0; state.SetTraitOnObjectAtIndex(inventory, domainObjectIndex); } domainObjects.Dispose(); base.EndExecution(state, action, actor); }
public override void BeginExecution(StateData state, ActionKey action, Otto actor) { base.BeginExecution(state, action, actor); m_Animator = actor.GetComponentInParent <Animator>(); m_Animator.SetTrigger(Animator.StringToHash("Sleep")); // Reset fatigue var domainObjects = new NativeList <(DomainObject, int)>(4, Allocator.TempJob); foreach (var(_, domainObjectIndex) in state.GetDomainObjects(domainObjects, new ComponentType[] { typeof(Need) })) { var need = state.GetTraitOnObjectAtIndex <Need>(domainObjectIndex); if (need.NeedType == NeedType.Fatigue) { need.Urgency = 0; state.SetTraitOnObjectAtIndex(need, domainObjectIndex); break; } } domainObjects.Dispose(); }
void SetNeeds(StateData state) { var domainObjects = new NativeList <(DomainObject, int)>(4, Allocator.TempJob); foreach (var(_, domainObjectIndex) in state.GetDomainObjects(domainObjects, k_NeedType)) { var need = state.GetTraitOnObjectAtIndex <Need>(domainObjectIndex); if (need.NeedType == NeedType.Hunger) { m_HungerMat.SetFloat(s_Amount, 1 - need.Urgency / 100f); } else if (need.NeedType == NeedType.Thirst) { m_ThirstMat.SetFloat(s_Amount, 1 - need.Urgency / 100f); } else if (need.NeedType == NeedType.Fatigue) { m_FatigueMat.SetFloat(s_Amount, 1 - need.Urgency / 100f); } } domainObjects.Dispose(); }