Beispiel #1
0
    public void OnPointerClick(PointerEventData eventData)
    {
        switch (this.name)
        {
        case "Sell":
            int itemId = 0;
            if (Inv.currentType == "harvest")
            {
                itemId = Inv.currentHarv.ItemId;
            }
            else if (Inv.currentType == "sead")
            {
                itemId = Inv.currentSead.ItemId;
            }
            else if (Inv.currentType == "fertilizer")
            {
                itemId = Inv.currentFert.ItemId;
            }
            Money.money += Inv.items[itemId].ItemPrice;
            Inv.items[itemId].ItemCount -= 1;
            if (Inv.items[itemId].ItemCount <= 0)
            {
                Inv.DropItem(itemId);
                Inv.actionPanel.SetActive(false);
                Inv.FillInventory("current");
            }
            else
            {
                int id = Inv.currSelect;
                Inv.FillInventory("current");
                Inv.Select(id);
            }
            GameObject.Find("Sounds").GetComponent <Sounds>().PlayBuy();
            break;

        case "Plant":
            Inv.actionPanel.SetActive(false);
            Inv.inventoryPanel.SetActive(false);
            Inv.filterPanel.SetActive(false);
            if (Inv.currentType == "fertilizer")
            {
                ToolsClick.currentTool = "fertilizer";
            }
            else
            {
                ToolsClick.currentTool = "planted";
            }
            Cursor.SetCursor(Resources.Load <Texture2D>("Sprite/InstrumentsPanel/cartoon-seeds2"), Vector2.zero, CursorMode.Auto);
            Inv.lockPanelInv.SetActive(false);
            break;
        }
    }
Beispiel #2
0
    void GetMouseValue()                   // метод обработки клика мышкой по полю в зависимости от типа курсора
    {
        if (idFild < nextFild)
        {
            switch (ToolsClick.currentTool)
            {
            //==========================================================
            case "dig":
                if (!dig)
                {
                    if (plant != null)
                    {
                        if (plant.stage == "stage6")
                        {
                            sown = false;
                            GameObject.Find("Sounds").GetComponent <Sounds>().PlaySoudDiging();

                            plant.EndGrow();
                            plant = null;
                            dig   = true;
                            this.GetComponent <SpriteRenderer>().sprite = sandField;
                            ChangeWeed(false);
                            ChangeVermin(false);
                            ChangeFert(false, 0.0f);
                            ChangeWatering(true);
                            timeFactor = 1.0f;
                        }
                    }
                }
                break;

            //==========================================================
            case "watering":

                if (!watering)
                {
                    GameObject.Find("Sounds").GetComponent <Sounds>().PlaySoudWatering();
                    events.AddFildEvent(idFild, 300.0f, "watering");
                    ChangeWatering(false);
                }
                break;

            //==========================================================
            case "weed":
                if (weed)
                {
                    GameObject.Find("Sounds").GetComponent <Sounds>().PlaySoudSprey();
                    ChangeWeed(!weed);
                }
                break;

            //==========================================================
            case "fertilizer":                     // доработать
                if (!fertilizer && sown)
                {
                    Inv.items[Inv.currentFert.ItemId].ItemCount -= 1;

                    if (Inv.items[Inv.currentFert.ItemId].ItemCount <= 0)
                    {
                        ToolsClick.currentTool = "arrow";
                        Cursor.SetCursor(Resources.Load <Texture2D>("Sprite/InstrumentsPanel/arrow2"), Vector2.zero, CursorMode.Auto);
                        Inv.DropItem(Inv.currentFert.ItemId);
                    }
                    GameObject.Find("Sounds").GetComponent <Sounds>().PlayFert();
                    ChangeFert(true, Inv.currentFert.timeFactor);
                }
                break;

            //==========================================================
            case "vermin":
                if (vermin)
                {
                    GameObject.Find("Sounds").GetComponent <Sounds>().PlaySoudSprey();
                    ChangeVermin(!vermin);
                }
                break;

            //==========================================================
            case "hand":
                if (plant != null)
                {
                    GameObject.Find("Sounds").GetComponent <Sounds>().PlaySoudGet();
                    plant.DropFruit();
                }
                break;

            //==========================================================
            case "planted":
                if (plant == null)
                {
                    sown = true;
                    dig  = false;
                    Inv.items[Inv.currentSead.ItemId].ItemCount -= 1;

                    if (Inv.items[Inv.currentSead.ItemId].ItemCount <= 0)
                    {
                        ToolsClick.currentTool = "arrow";
                        Cursor.SetCursor(Resources.Load <Texture2D>("Sprite/InstrumentsPanel/arrow2"), Vector2.zero, CursorMode.Auto);
                        Inv.DropItem(Inv.currentSead.ItemId);
                    }

                    this.GetComponentInChildren <Plant>().Init(Inv.currentSead);
                    plant = this.GetComponentInChildren <Plant>();
                    plant.StartGrowing(timeFactor);
                    events.GenEvent(idFild, plant.GrowingTime, "vermin");
                    events.GenEvent(idFild, plant.GrowingTime, "weed");
                }
                break;
            }
        }
        else
        {
            if (idFild == nextFild)
            {
                Inv.buyFildPanel.SetActive(true);
                Inv.actionPanel.SetActive(false);
                Inv.filterPanel.SetActive(false);
                Inv.inventoryPanel.SetActive(false);
                Shop.shopPanel.SetActive(false);
                Inv.currFild = this;
                GameObject.Find("PriceFild").GetComponent <Text>().text = (idFild * 10 * 1.5).ToString();
                ToolsClick.currentTool = "arrow";
                Cursor.SetCursor(Resources.Load <Texture2D>("Sprite/InstrumentsPanel/arrow2"), Vector2.zero, CursorMode.Auto);
                Inv.lockPanelInv.SetActive(true);
            }
        }
    }