示例#1
0
        /// <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>());
                }
            }
        }
示例#2
0
        /// <summary>
        /// Checks if interactor is server
        /// Checks if interactor is already holding an object -
        /// if it is not holding an object the respective matter object is created, <see cref="Interactor.HeldObject"/> is called
        /// and then <see cref="RpcGiveMatterObjectToInteractor(NetworkIdentity, NetworkIdentity)"/> is called
        /// with the given interactor and the created matter as parameters.
        /// If it is holding an object and the container can take this object back the matter object will be destroyed
        /// and the interactor will not hold an object anymore.
        /// </summary>
        /// <param name="interactor"></param>
        public void Interact(Interactor interactor)
        {
            if (this.isServer)
            {
                if (!interactor.IsHoldingObject)
                {
                    if (this.containedMatter != null)
                    {
                        GameObject instantiatedMatter = GameObject.Instantiate(this.containedMatter.GetPrefab(), this.transform.position, Quaternion.identity);
                        NetworkServer.Spawn(instantiatedMatter);
                        interactor.SetHeldObject(instantiatedMatter.GetComponent <PickableObject>());

                        this.RpcGiveMatterObjectToInteractor(instantiatedMatter.GetComponent <NetworkIdentity>(), interactor.GetComponent <NetworkIdentity>());
                    }
                }
                else if (this.canTakeBackItems)
                {
                    MatterObject matterObject = interactor.HeldObject.GetComponent <MatterObject>();

                    if (matterObject != null && (this.containedMatter == null || this.containedMatter.Equals(matterObject.Matter)))
                    {
                        interactor.SetHeldObject(null);
                        this.RpcGiveMatterObjectToInteractor(null, interactor.GetComponent <NetworkIdentity>());
                        NetworkServer.Destroy(matterObject.gameObject);
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Is only called by server.
        /// Checks if given iterator and matter is not null and calls <see cref="Interactor.SetHeldObject(PickableObject)"/>
        /// with given matterObject as parameter
        /// </summary>
        /// <param name="matterObject">matter object to be interacted with</param>
        /// <param name="interactor">object which is able to interact</param>
        private void RpcGiveMatterObjectToInteractor(NetworkIdentity matterObject, NetworkIdentity interactor)
        {
            if (interactor != null)
            {
                Interactor i = interactor.GetComponent <Interactor>();

                if (i != null)
                {
                    i.SetHeldObject(matterObject != null ? matterObject.GetComponent <PickableObject>() : null);
                }
            }
        }
        /// <summary>
        /// Drops this object.
        /// Resets the rotation of the object to make the orb text visible.
        /// Will only drop it if the given interactor matches <see cref="CurrentHolder"/>.
        /// </summary>
        /// <param name="interactor">The <see cref="Interactor"/> object that should drop this object.</param>
        public virtual void Drop(Interactor interactor)
        {
            if (interactor == this.currentHolder)
            {
                this.currentHolder = null;
                interactor.SetHeldObject(null);
                this.transform.SetParent(this.defaultParent);

                foreach (Rigidbody rb in this.nonKinematicRBs)
                {
                    rb.isKinematic = false;
                }

                this.OnDropped?.Invoke(this, interactor);
                this.transform.rotation = Quaternion.Euler(0, 90, 60);
            }
        }
        /// <summary>
        /// Picks up this object and attaches it to the given <see cref="Interactor"/> object.
        /// Resets the rotation of the object to make the orb text visible.
        /// </summary>
        /// <param name="interactor">The <see cref="Interactor"/> object that should pick up this object.</param>
        public virtual void Pickup(Interactor interactor)
        {
            if (interactor != this.currentHolder)
            {
                this.currentHolder = interactor;
                interactor.SetHeldObject(this);
                this.transform.SetParent(interactor.transform, true);

                foreach (Rigidbody rb in this.nonKinematicRBs)
                {
                    rb.isKinematic = true;
                }

                this.OnPickedUp?.Invoke(this, interactor);
                this.transform.rotation = Quaternion.Euler(0, 90, 60);
            }
        }