예제 #1
0
파일: Salt.cs 프로젝트: daners88/SALT-eYe
    private void OnTriggerEnter(Collider other)
    {
        FoodSlot temp = other.gameObject.GetComponent <FoodSlot>();

        if (temp != null)
        {
            temp.saltLevel += 10;
            GameManager.Instance.DecrementSlot(slotNum);
            Destroy(this.gameObject);
        }
    }
예제 #2
0
        public void Give(string id, int amount = 1)
        {
            var item  = ItemManager.Instance[id];
            var stack = new ItemStack(id, amount);

            if (item == null)
            {
                throw new ArgumentException($"Invalid Item ID '{id}'");
            }

            //重複してるところに入れてみる
            foreach (var i in this)
            {
                if (i.Id == id)
                {
                    i.Add(amount);
                    return;
                }
            }
            //なければ空いているところに入れてみる
            if (item is IItemKey)
            {
                KeyItemSlot.Add(stack);
                return;
            }

            if (item is IFoodItem)
            {
                var index = FoodSlot.Select((x, i) => new { x, i })
                            .FirstOrDefault(o => o.x == default(ItemStack));
                if (index != null)
                {
                    FoodSlot[index.i] = stack;
                }
            }

            // otherwise
            {
                var index = CommonSlot.Select((x, i) => new { x, i })
                            .FirstOrDefault(o => o.x == default(ItemStack));
                if (index != null)
                {
                    CommonSlot[index.i] = stack;
                }
            }

            //それでもダメならエラー投げる
            throw new InventoryIsFullException();
        }
예제 #3
0
    void Update()
    {
        if (!isInput)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            isHold = true;

            SoundManager.Instance.PlaySFX(SoundManager.SFX_SOUND.CATCH);

            UpdateMousePosition();
            RaycastHit2D hit = Physics2D.Raycast(mainCamera.ScreenToWorldPoint(mouseScreenPosition)
                                                 , Vector3.forward
                                                 , Mathf.Infinity);

            if (hit)
            {
                if (isGive && hit.collider.gameObject.CompareTag("NPC"))
                {
                    //TODO :: NPC에게 줌
                    SetInput(false);
                    SetGive(false);
                    cookingManager.FinalCook();
                }
                else if (!isGive && hit.collider.gameObject.CompareTag("FoodSlot"))
                {
                    FoodSlot slot = hit.collider.gameObject.GetComponent <FoodSlot>();

                    GameObject g = Instantiate(foodPrefab, transform);
                    g.transform.localPosition = Vector3.zero;

                    SetTarget(g.transform);
                    g.GetComponent <Collider2D>().enabled         = false;
                    target.GetComponent <Rigidbody2D>().simulated = false;
                    FoodBehaviour food = g.GetComponent <FoodBehaviour>();
                    food.SetFood(slot.FoodID);
                    food.startMoveStick += RemoveTarget;
                }
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            isHold = false;

            if (target == null)
            {
                return;
            }

            target.GetComponent <Collider2D>().enabled    = true;
            target.GetComponent <Rigidbody2D>().simulated = true;
            target.SetParent(null);
            RemoveTarget();
        }

        if (isHold)
        {
            UpdateMousePosition();
            transform.position = mouseWorldPosition;
        }
    }