コード例 #1
0
    private void EradicatePlant()
    {
        if (seedGrowComponent != null && seedGrowComponent.currCropPeriod == SeedGrowComponent.PeriodGrow.Ripe)
        {
            StaticData.CreateToastTips($"作物已成熟,不能铲除!");
            SetHandleTileUIClose();
            return;
        }
        CSEradicate csEradicate = new CSEradicate()
        {
            SoilId = currClickComponent.SoilId
        };

        ManorProtocalHelper.ManorEradicatePlant(csEradicate, async(succ) =>
        {
            //关闭UI
            SetHandleTileUIClose();
            //铲除特效
            GoEradicateEffect.GetComponent <RectTransform>().anchoredPosition = StaticData.ManorWorldPointToUICameraAnchorPos(currClickComponent.transform.position);
            GoEradicateEffect.SetActive(true);
            isEradicating = true;
            await UniTask.Delay(500);
            GoEradicateEffect.SetActive(false);
            isEradicating = false;
            //播放音效点击
            GameSoundPlayer.Instance.PlaySoundEffect(MusicHelper.SoundEffectEradicate);
            currClickComponent.CropGoodId = 0;
            //删除
            if (seedGrowComponent != null)
            {
                Destroy(seedGrowComponent.gameObject);
            }
            currClickComponent.SetCurrGoPlant(null);
            //删除seedGrowCom
            Root2dSceneManager._instance.RemoveFromListSeedGrow(this.seedGrowComponent);
            this.seedGrowComponent = null;
        });
    }
コード例 #2
0
    private async UniTask GenerateExistPlants(RepeatedField <SCManorStruct> manorInfo, bool isFriendManor)
    {
        //进入庄园的时候 清空收获.偷取图标
        StaticData.GetUIWorldHandleComponent().ClearAllGainGo();
        StaticData.GetUIWorldHandleComponent().ClearAllStealGo();
        for (int i = 0; i < manorInfo.Count; i++)
        {
            SCManorStruct plant = manorInfo[i];
            GameObject    go;
            TileComponent tileComponent = null;
            if (plant.SoilType == ManorScene.None)
            {
                Debug.LogError($"服务器初始化庄园Plant.id:{plant.SoilId}");
            }
            if (plant.SoilType != ManorScene.None && plant.SoilType != ManorScene.Tile && plant.SoilType != ManorScene.Npc &&
                plant.CropGoodId != 0)
            {
                //装饰物(装饰物,礼盒,狗窝)
                //装饰物旋转索引
                int    rotateIdx      = plant.DecorateRotateIndex;
                var    DecorateDefine = StaticData.configExcel.GetDecorateByDecorateId((int)plant.CropGoodId);
                string modelName      = DecorateDefine.Model[rotateIdx];
                go = await GenerateDecorate(modelName, DecorateDefine.DecorateId);

                tileComponent = go.GetComponent <TileComponent>();
                go.transform.localPosition      = new Vector2(plant.Xaxle, plant.Yaxle);
                tileComponent.regionId          = plant.ParcelDivision;
                tileComponent.idxDecorateRotate = rotateIdx;
            }
            else if (plant.SoilType == ManorScene.Tile)
            {
                ////test
                //plant.CropGoodId = 400001;
                //plant.NextTime = 360000;
                ////test end
                go            = GenerateTile();
                tileComponent = go.GetComponent <TileComponent>();
                go.transform.localPosition = new Vector2(plant.Xaxle, plant.Yaxle);
                go.GetComponent <TileComponent>().regionId = plant.ParcelDivision;
                //创建地块上庄稼
                tileComponent.CropGoodId = (int)plant.CropGoodId;
                tileComponent.SoilId     = plant.SoilId;
                if (tileComponent.CropGoodId == 0)
                {
                    continue;
                }
                var prefabName  = StaticData.configExcel.GetManorCropByCropId(tileComponent.CropGoodId).Model;
                var plantPrefab = await ABManager.GetAssetAsync <GameObject>(prefabName);

                var       goPlant    = GameObject.Instantiate <GameObject>(plantPrefab);
                Transform plantTrans = goPlant.transform;
                plantTrans.parent        = tileComponent.rootPlant.transform;
                plantTrans.localPosition = Vector3.zero;
                plantTrans.localScale    = Vector3.one;
                tileComponent.SetCurrGoPlant(goPlant);
                var seedGrowComponent = plantTrans.GetComponent <SeedGrowComponent>();
                seedGrowComponent.SetCropId((int)plant.CropGoodId, tileComponent);
                seedGrowComponent.GenerateTimer();
                seedGrowComponent.SetPeriod((SeedGrowComponent.PeriodGrow)plant.SoilStatus, plant.NextTime);
                Root2dSceneManager._instance.AddListSeedGrow(seedGrowComponent);
            }
            else if (plant.SoilType == ManorScene.Npc)
            {
                //设置Npc位置
                Root2dSceneManager._instance.femaleManorManagerTileComponent.transform.localPosition = new Vector2(plant.Xaxle, plant.Yaxle);
                Root2dSceneManager._instance.femaleManorManagerTileComponent.SoilId = plant.SoilId;
            }
            if (tileComponent != null)
            {
                tileComponent.SoilId = plant.SoilId;
            }
        }

        //排序
        UpdateSortLayer(true);
        //add_by_wsf
        //检查地鼠的生成
        if (!isFriendManor)
        {
            mouseManorManager.CheckSelfMouseGenerate();
        }
        else
        {
            mouseManorManager.CheckFriendMouseGenerate();
        }
        //add_by_wsf end
    }