Exemplo n.º 1
0
 internal void OnEnterInventoryTarget(InventoryTarget target)
 {
     if (target.IsEmpty())
     {
         this.currentTargets.Add(target);
     }
 }
Exemplo n.º 2
0
 void OnObjectPlacedInInventory(ObjectPlacedOnInventoryTargetEvent evt)
 {
     if (evt.placedObject.GetInstanceID() == this.gameObject.GetInstanceID())
     {
         this.target = this.currentTargets.GetOne();
         this.PositionObjectInsideTarget(this.target);
         var collider = this.gameObject.GetComponent <Collider>();
         collider.isTrigger = true;
         EventManager.FireEvent(new ObjectAcceptedByInventoryTargetEvent(this.gameObject));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Position this GameObject so that it fits inside the given target, and is centered inside it.
        /// Also moves this GameObject to the main scene, and sets its parent to the inventory manager.
        /// </summary>
        /// <param name="aTarget">The target to position inside</param>
        internal void PositionObjectInsideTarget(InventoryTarget aTarget)
        {
            var rigidBody = this.gameObject.GetComponent <Rigidbody>();

            ScaleToFit(cubeSize);
            this.gameObject.transform.rotation = aTarget.transform.rotation;
            this.gameObject.transform.position = aTarget.transform.position;

            rigidBody.velocity               = Vector3.zero;
            rigidBody.angularVelocity        = Vector3.zero;
            rigidBody.useGravity             = false;
            this.oldScene                    = this.gameObject.scene;
            this.gameObject.transform.parent = null;
            SceneManager.MoveGameObjectToScene(this.gameObject, SceneManager.GetSceneByName(SceneName.Main));
            this.oldParent = this.gameObject.transform.parent;
            this.gameObject.transform.SetParent(this.inventoryManager.transform);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Instantiates as many InventoryTargets as there are inventory slots
        /// </summary>
        void GenerateTargets()
        {
            float totalWidth   = this.numSlots * targetWidth + (this.numSlots - 1) * targetSeparation;
            float widthPerSlot = totalWidth / this.numSlots;
            float zCoord       = -targetWidth / 2.0f;
            float yCoord       = 0;

            for (uint i = 0; i < this.numSlots; i++)
            {
                float xCoord = i * widthPerSlot;
                var   target = GameObject.Instantiate(this.targetPrefab);
                target.transform.position   = new Vector3(xCoord, yCoord, zCoord);
                target.transform.localScale = new Vector3(this.targetWidth, this.targetWidth, this.targetWidth);
                target.transform.parent     = this.gameObject.transform;
                InventoryTarget it = target.GetComponent <InventoryTarget>();
                it.index      = i;
                this.slots[i] = it;
            }
        }
Exemplo n.º 5
0
 internal void OnExitInventoryTarget(InventoryTarget target)
 {
     // We don't need to check if the target was a valid one for us, (i.e. empty when we entered)
     // because Remove will just do nothing if target isn't inside currentTargets
     this.currentTargets.Remove(target);
     if (!this.IsInsideTarget())
     {
         Debug.Log("Exited");
         var rigidBody = this.gameObject.GetComponent <Rigidbody>();
         rigidBody.useGravity = true;
         var collider = this.gameObject.GetComponent <Collider>();
         collider.isTrigger = false;
         Scene?newScene = locator.GetSceneForGameObject(this.gameObject);
         if (newScene.HasValue)
         {
             this.gameObject.transform.SetParent(null);
             SceneManager.MoveGameObjectToScene(this.gameObject, newScene.Value);
         }
         else
         {
             Debug.LogError("Couldnt locate new scene");
         }
     }
 }