/// <summary> /// Interacts with this object. /// Attempts to insert a matter object held by <paramref name="interactor"/> or take a matter object from the output slot. /// If the interactor does not hold anything and the output slot is empty, this method will try take the last inserted object and give it to the interactor. /// </summary> /// <param name="interactor">The initiator of this interaction.</param> public override void Interact(Interactor interactor) { if (this.IsActivated) { return; } PickableObject heldObject = interactor.HeldObject; if (heldObject != null) { if (this.outputObjects.Count == 0) { MatterObject matterObject = heldObject.GetComponent <MatterObject>(); if (matterObject != null) { interactor.SetHeldObject(null); this.InsertMatterObject(matterObject); } } } else if (interactor.HeldObject == null) { MatterObject toTake = this.outputObjects.Count != 0 ? this.TakeOutputObject() : this.insertedObjects.Count > 0 ? this.TakeLastInsertedObject() : null; if (toTake != null) { interactor.SetHeldObject(toTake.GetComponent <PickableObject>()); } } }
/// <summary> /// Adds an output object to this equipment. /// Synchronizes it with the clients if run on the server. /// </summary> /// <param name="matterObject">The object to add to the output.</param> private void AddOutputObject(MatterObject matterObject) { this.outputObjects.Add(matterObject); this.contentsUI?.AddMatter(matterObject.Matter); matterObject.DisablePhysics(); matterObject.transform.SetParent(this.outputContainer.transform, false); matterObject.transform.localPosition = Vector3.zero; matterObject.transform.localRotation = Quaternion.identity; if (this.isServer) { this.RpcAddOutput(matterObject.GetComponent <NetworkIdentity>()); } }