Example #1
0
    private void ContineClickDecorate()
    {
        StaticData.DebugGreen("继续点击装饰物");
        Camera cameraWorld = Root2dSceneManager._instance.worldCameraComponent.cameraWorld;
        var    worldPoint  = 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 = null;

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

            TileComponent tileCom = colliderTileCom.gameObject.GetComponent <TileComponent>();
            //树需要到上一层才有组件,种植的作物要上三层
            if (tileCom == null)
            {
                tileCom = colliderTileCom.transform.GetComponentInParent <TileComponent>();
            }
            //是装饰物
            if (tileCom != null && tileCom.typeTile == TypeManorDecorate.Decorate)
            {
                currHandleTile = tileCom.gameObject;
                tileCom.PressInScene();
            }
        }
    }
Example #2
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();
            }
        }
    }