コード例 #1
0
    private void OnPlantClick(PointerEventData eventData)
    {
        int seedCount     = StaticData.GetWareHouseItem(CropGoodId).GoodNum;
        int costCoinCount = 0;

        if (seedCount <= 0)
        {
            //判定金钱
            if (StaticData.GetWareHouseItem(currPlantSeed.coinPriceId).GoodNum < currPlantSeed.price)
            {
                ToBuyCurrency();
                return;
            }
            costCoinCount = (int)currPlantSeed.price;
        }
        UIWorldHandleManager uiUIWorldHandleComponent = StaticData.GetUIWorldHandleComponent();

        //实例化
        goPlant = GameObject.Instantiate <GameObject>(goPrefab);
        CSPlantStruct csPlantStruct = new CSPlantStruct()
        {
            SoilId     = uiUIWorldHandleComponent.currClickComponent.SoilId,
            CropGoodId = this.CropGoodId
        };

        if (uiUIWorldHandleComponent.currClickComponent != null)
        {
            uiUIWorldHandleComponent.currClickComponent.Plant(goPlant, csPlantStruct, () => {
                //设置地块上庄稼的id
                uiUIWorldHandleComponent.currClickComponent.CropGoodId = this.CropGoodId;
                AfterPlantCropSetInfo(uiUIWorldHandleComponent.currClickComponent);
            });
        }
        //种植
        ManorProtocalHelper.ManorPlant(Root2dSceneManager._instance.PlantData, (succ) => {
            StaticData.UpdateSeedMinus1(Root2dSceneManager._instance.PlantData);
            //更新货币
            if (costCoinCount > 0)
            {
                StaticData.UpdateWareHouseItem(currPlantSeed.coinPriceId, -costCoinCount);
            }
            uiUIWorldHandleComponent.SetHandleTileUIClose();
        });
    }
コード例 #2
0
    public void Plant(GameObject goPlant, CSPlantStruct csPlantStruct, Action ActionRealPlant)
    {
        if (currGoPlant != null)
        {//已经种植了东西,返回
            //实例化的删除掉
            Destroy(goPlant);
            return;
        }
        ActionRealPlant?.Invoke();
        Transform plantTrans = goPlant.transform;

        plantTrans.parent        = rootPlant.transform;
        plantTrans.localPosition = Vector3.zero;
        plantTrans.localScale    = Vector3.one;
        SetCurrGoPlant(goPlant);
        //播放音效点击
        GameSoundPlayer.Instance.PlaySoundEffect(MusicHelper.SoundEffectPlanting);
        //种植协议增加作物
        Root2dSceneManager._instance.PlantData.PlantInfo.Add(csPlantStruct);
        //更新作物层级
        Root2dSceneManager._instance.UpdateSortLayer(true);
    }
コード例 #3
0
    public void HandlePlant()
    {
        //划过的地块都种植
        var worldPoint = Root2dSceneManager._instance.worldCameraComponent.cameraWorld.ScreenToWorldPoint(Input.mousePosition);

        Collider2D[] colliders = Physics2D.OverlapPointAll(worldPoint);
        listOverlapPointCollider.Clear();
        //colliders 转list
        for (int i = 0; i < colliders.Length; i++)
        {
            listOverlapPointCollider.Add(colliders[i]);
        }

        Collider2D colliderTileCom = colliderTileCom = listOverlapPointCollider.Find(x => x.gameObject.CompareTag(TagHelper.Tile));

        if (colliderTileCom != null &&
            colliderTileCom.GetComponent <TileComponent>() != null &&
            !colliderTileCom.GetComponent <TileComponent>().isNPC &&
            colliderTileCom.GetComponent <TileComponent>().CropGoodId == 0)
        {
            StaticData.GetUIWorldHandleComponent().SetHandleTileUIClose();
            int haveSeedCount = StaticData.GetWareHouseItem(CropGoodId).GoodNum;
            //判定当前种子是否还够
            if (DragNeedSeedCount <= haveSeedCount)
            {
                DragNeedSeedCount++;
            }
            else
            {
                if (currPlantSeed.isRarity)
                {
                    //稀有种子直接移除
                    Destroy(gameObject);
                    //向服务器发消息种植,关闭拖拽的UI
                    OnDragUp();
                    Root2dSceneManager._instance.isTileDrag = false;
                    return;
                }

                //金钱加上
                DragWillCostCoin += (int)currPlantSeed.price;
                //判定金钱
                if (StaticData.GetWareHouseItem(currPlantSeed.coinPriceId).GoodNum < DragWillCostCoin)
                {
                    //减掉最后一个的钱
                    //金钱加上
                    DragWillCostCoin -= (int)currPlantSeed.price;
                    //向服务器发消息种植,关闭拖拽的UI
                    OnDragUp();
                    Root2dSceneManager._instance.isTileDrag = false;
                    return;
                }
            }
            //实例化
            goPlant = GameObject.Instantiate <GameObject>(goPrefab);
            CSPlantStruct csPlantStruct = new CSPlantStruct()
            {
                SoilId     = colliderTileCom.GetComponent <TileComponent>().SoilId,
                CropGoodId = this.CropGoodId
            };
            var tileComponent = colliderTileCom.GetComponent <TileComponent>();
            if (tileComponent.typeTile == Company.Cfg.TypeManorDecorate.Tile)
            {
                tileComponent.Plant(goPlant, csPlantStruct, () => {
                    //设置地块上庄稼的id
                    tileComponent.CropGoodId = this.CropGoodId;
                    AfterPlantCropSetInfo(tileComponent);
                });
            }
        }
    }