private void Update() { if (_input == null || _output == null || HeldItem == null) { return; } if (DesiredItem != null) { Debug.Log(_operation + " to " + DesiredItem.gameObject + " at " + DesiredItem.transform.position); } else { Debug.Log(_operation); } switch (_operation) { case InserterOperation.WaitingForItem: if (_input.TestForAvailableItems() && _output.TestForAvailableSlot()) { _operation = InserterOperation.ReachingForItem; DesiredItem = _input.GetDesiredItem(HeldItem.transform.position); } break; case InserterOperation.ReachingForItem: if (!_input.TestForAvailableItems() || DesiredItem == null) { _operation = InserterOperation.Returning; break; } HeldItem.transform.position = Vector3.MoveTowards(HeldItem.transform.position, DesiredItem.transform.position, _movementSpeed * Time.deltaTime); float distIn = Vector3.Distance(DesiredItem.transform.position, HeldItem.transform.position); if (distIn < 0.1f) { DesiredItem = _output.GetDesiredItem(HeldItem.transform.position); HeldItem.SetItem(DesiredItem.Item); DesiredItem.RemoveItem(); _operation = InserterOperation.MovingItem; } else if (distIn > 2f) { _operation = InserterOperation.Returning; } break; case InserterOperation.MovingItem: if (DesiredItem == null || DesiredItem.Item != null) { _operation = InserterOperation.Returning; break; } HeldItem.transform.position = Vector3.MoveTowards(HeldItem.transform.position, DesiredItem.transform.position, _movementSpeed * Time.deltaTime); float distOut = Vector3.Distance(DesiredItem.transform.position, HeldItem.transform.position); if (distOut < 0.1f) { DesiredItem = _output.GetDesiredItem(HeldItem.transform.position); DesiredItem.SetItem(HeldItem.Item); HeldItem.RemoveItem(); _operation = InserterOperation.Returning; } else if (distOut > 3f) { _operation = InserterOperation.Returning; } break; case InserterOperation.Returning: HeldItem.transform.position = Vector3.MoveTowards(HeldItem.transform.position, _basePosition, _movementSpeed * Time.deltaTime); break; } }
public void SetItem(ItemObject item) { Item.SetItem(item); }