Exemple #1
0
    async UniTask BeginDrag(bool isDragFromScene)//isDragFromScene是否从放好了的在拖动
    {
        this.isDragFromScene = isDragFromScene;
        //设置初始位置
        SetTilePos(true);
        Root2dSceneManager._instance.isTileDrag = true;
        TipsTileComponent._instance.SetUpAnimPos(transform);
        //显示提示
        if (isDragFromScene)
        {
            //播放抬起动画
            ctsWaitPlayUpAnim = new CancellationTokenSource();
            isUpAnimPlaying   = true;
            await TipsTileComponent._instance.PlayUpAnim(ctsWaitPlayUpAnim.Token);

            if (ctsWaitPlayUpAnim.Token.IsCancellationRequested)
            {
                return;
            }
            TipsTileComponent._instance.SetCanPlace(transform, true, this);
            isUpAnimPlaying = false;
            //从场景中拖起,设置最高层级
            SetPlantLayerMax();
        }
        else
        {
            TipsTileComponent._instance.SetCanPlace(transform, true, this);
        }

        //等动画播放再拖拽
        isDrag       = true;
        isBeginPlace = true;
        //开始拖拽的时候记录World摄像机位置
        var worldComponent = Root2dSceneManager._instance.worldCameraComponent;

        worldComponent.SetPreCameraPos();
        //拖动地块的时候关闭地块UI
        UIWorldHandleManager uiUIWorldHandleComponent = StaticData.GetUIWorldHandleComponent();

        uiUIWorldHandleComponent.SetHandleTileUIClose();
        //关闭Manor UI
        UIManorComponent uiManorComponent = UIComponent.GetComponentHaveExist <UIManorComponent>(UIType.UIManor);

        uiManorComponent.DragTileOrDecorateCloseSelfManor(true);
    }
Exemple #2
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();
        });
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (seedGrowComponent != null)
        {
            UIWorldHandleManager uiWorldHandleManager = StaticData.GetUIWorldHandleComponent();
            if (uiWorldHandleManager != null)
            {
                //设置位置
                uiWorldHandleManager.SetWorldPos(seedGrowComponent.tileComponent, gameObject, UIWorldHandleManager.TypePointUI.FirstFertilizer);
            }
        }
        if (Root2dSceneManager._instance == null)
        {
            return;
        }
        if (Root2dSceneManager._instance.isFriendManor || seedGrowComponent == null)
        {
            if (ButtonFertilizer != null)
            {
                ButtonFertilizer.gameObject.SetActive(false);
            }

            return;
        }
        if (ButtonFertilizer != null)
        {
            ButtonFertilizer.gameObject.SetActive(true);
        }
        //var firstFertilizer=StaticData.GetFertilizerCountByWhich(0);
        //if (firstFertilizer.GoodNum > 0)
        //{
        //    TextNumNormal.gameObject.SetActive(true);
        //    TextNumNormal.text = $"{firstFertilizer.GoodNum}";
        //    TextNumZero.gameObject.SetActive(false);
        //}
        //else
        //{
        //    TextNumNormal.gameObject.SetActive(false);
        //    TextNumZero.gameObject.SetActive(true);
        //}
        TextNumNormal.gameObject.SetActive(false);
        TextNumZero.gameObject.SetActive(false);
    }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        UIManorComponent     uiManorComponent         = UIComponent.GetComponentHaveExist <UIManorComponent>(UIType.UIManor);
        UIWorldHandleManager uiUIWorldHandleComponent = StaticData.GetUIWorldHandleComponent();

        if (uiManorComponent == null)
        {
            return;                    //场景加载过程中
        }
        if (Input.GetMouseButtonUp(0)) //如果左键抬起重置
        {
            isTileDrag = false;
        }
        if (Input.GetMouseButtonDown(0))//左键按下
        {
            currHandleTile = null;
            bool isUIScrollMask   = false;
            bool isUIDecorateMask = false;
            //EventSystem.current.IsPointerOverGameObject()在android上unity2019不起作用
            var clickObj = StaticData.UI_GetCurrentSelect();
            if (clickObj != null)//表明是UI
            {
                isUIScrollMask   = clickObj.CompareTag(TagHelper.UIScrollMask);
                isUIDecorateMask = clickObj.CompareTag(TagHelper.DecorateUIMask);
            }
            if (Root2dSceneManager._instance.isTileDrag)
            {
                //地块正在拖拽的时候,相机不允许平移
                return;
            }
            //覆盖的不是UI
            if (clickObj == null || isUIScrollMask)
            {
                CloseAllTileObjSelect();
                if (uiUIWorldHandleComponent != null)
                {
                    uiUIWorldHandleComponent.SetHandleTileUIClose();
                }
                StaticData.DebugGreen("Not UI");
                Camera       cameraWorld = Root2dSceneManager._instance.worldCameraComponent.cameraWorld;
                var          worldPoint  = cameraWorld.ScreenToWorldPoint(Input.mousePosition);
                Collider2D[] colliders   = Physics2D.OverlapPointAll(worldPoint);
                //层级排序上边到下边

                /*
                 * TagHelper.CollierCanOver
                 * TagHelper.PlantRenderer//植物Render层,不能拖走的
                 * TagHelper.Tile
                 * TagHelper.Ground
                 */
                listOverlapPointCollider.Clear();
                //colliders 转list
                for (int i = 0; i < colliders.Length; i++)
                {
                    listOverlapPointCollider.Add(colliders[i]);
                }

                //add_by_wsf
                Collider2D colliderMouse = listOverlapPointCollider.Find(x => x.gameObject.CompareTag(TagHelper.MouseManor));
                if (colliderMouse != null)
                {
                    //点击地鼠
                    Debug.Log("敲打地鼠~~~");
                    mouseManorManager.CatchMouse();
                    return;
                }
                //add_by_wsf end

                Collider2D colliderTileCom = null;
                colliderTileCom = listOverlapPointCollider.Find(x => x.gameObject.CompareTag(TagHelper.CollierCanOver));
                if (colliderTileCom == null)
                {
                    colliderTileCom = listOverlapPointCollider.Find(x => x.gameObject.CompareTag(TagHelper.Tile));
                }

                var colliderGrounds = listOverlapPointCollider.FindAll(x => x.gameObject.CompareTag(TagHelper.Ground));
                if (colliderTileCom != null)
                {//点击树或者小地块
                    StaticData.DebugGreen($"{colliderTileCom.name}");

                    TileComponent tileCom = colliderTileCom.gameObject.GetComponent <TileComponent>();
                    //树需要到上一层才有组件,种植的作物要上三层
                    if (tileCom == null)
                    {
                        tileCom = colliderTileCom.transform.GetComponentInParent <TileComponent>();
                    }

                    if (tileCom != null)//别墅,仓库没有TileComponent
                    {
                        currHandleTile = tileCom.gameObject;
                        tileCom.PressInScene();
                    }
                }
                else if (colliderGrounds != null && colliderGrounds.Count > 0)
                {
                    //点击到大地块
                    //大地块点击,没解锁的地方的除了Ground其它地方碰撞器都是禁用的
                    var colliderGround = colliderGrounds.Find(x => x.gameObject.GetComponent <ManorRegionComponent>().regionId != 0);
                    if (colliderGround != null) //为null表示只有0的碰撞器
                    {                           //有限处理没解锁的
                        ManorRegionComponent manorRegion = colliderGround.gameObject.GetComponent <ManorRegionComponent>();
                        StaticData.DebugGreen($"大地块按下");
                        manorRegion.PressDownRegion();
                    }
                    else
                    {//用来处理人物点击空白的行走
                        StaticData.DebugGreen($"大地块0按下");
                        ManorRegionComponent manorRegion = colliderGrounds[0].gameObject.GetComponent <ManorRegionComponent>();
                        manorRegion.PressDownRegion();
                    }
                }
            }
            //如果点击到了装饰物的UI面板
            if (isUIDecorateMask)
            {
                ContineClickDecorate();
            }
        }
    }