void HandleMouseMoveForPlant()
    {
        if (selectedPlant)
        {
            Vector3 pos      = Utility.GetMouseWorldPos();
            Vector3 plantPos = pos;
            plantPos.y -= 0.3f;
            selectedPlant.transform.position = plantPos;

            if (StageMap.IsPointInMap(pos))
            {
                StageMap.GetRowAndCol(pos, out row, out col);
                if (tempPlant.GetComponent <PlantGrow>().canGrowInMap(row, col))
                {
                    tempPlant.transform.position = StageMap.GetPlantPos(row, col);
                    tempPlant.GetComponent <SpriteDisplay>().SetOrderByRow(row);
                }
                else
                {
                    col = row = -1;
                    tempPlant.transform.position = new Vector3(1000, 1000, 0);
                }
            }
            else
            {
                col = row = -1;
                tempPlant.transform.position = new Vector3(1000, 1000, 0);
            }
        }
    }
    void HandleMouseMoveForShovel()
    {
        if (shovel)
        {
            Vector3 pos       = Utility.GetMouseWorldPos();
            Vector3 shovelPos = pos;
            shovelPos.x += 0.1f;
            shovelPos.y += 0.1f;
            shovel.transform.position = shovelPos;

            if (StageMap.IsPointInMap(pos))
            {
                int row, col;
                StageMap.GetRowAndCol(pos, out row, out col);
                GameObject plant = GameModel.GetInstance().map[row, col];
                if (selectedPlant != plant)
                {
                    if (selectedPlant)
                    {
                        selectedPlant.GetComponent <SpriteDisplay>().SetAlpha(1f);
                    }

                    if (plant && plant.tag != "UnableSell")
                    {
                        selectedPlant = plant;
                        selectedPlant.GetComponent <SpriteDisplay>().SetAlpha(0.6f);
                    }
                    else
                    {
                        selectedPlant = null;
                    }
                }
            }
        }
    }
Exemple #3
0
    void handleMouseMotion()
    {
        if (_underMousePlant)
        {
            Vector3 pos      = Utility.GetMouseWorldPos();
            Vector3 plantPos = pos /*+(Vector3.up*0.3f)*/;
            plantPos.y -= 0.3f;
            _underMousePlant.transform.position = plantPos;
            if (StageMap.IsPointInMap(plantPos))
            {
                StageMap.GetRowCol(plantPos, out _row, out _col);

                if (_underMousePlantGrow.CanGrowInMap(_row, _col))
                {
                    _transparentPlant.transform.position = StageMap.PlantPosByRowCol(_row, _col);
                }
                else
                {
                    _col = _row = -1;
                    _transparentPlant.transform.position = new Vector3(1000, 1000, 0);
                }
            }
            else
            {
                _col = _row = -1;
                _transparentPlant.transform.position = new Vector3(1000, 1000, 0);
            }
        }
    }
    void handleMouseMoveForShovel()
    {
        if (!shovel)
        {
            return;
        }

        Vector3 pos       = Utility.GetMouseWorldPos();
        Vector3 shovelPos = pos;

        shovelPos.x += 0.1f;
        shovelPos.y += 0.1f;
        Vector2 localPos;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(shovelBg.transform as RectTransform, Input.mousePosition, Camera.main, out localPos);
        shovel.transform.localPosition = localPos;

        if (!StageMap.IsPointInMap(pos))
        {
            return;
        }

        int row, col;

        StageMap.GetRowCol(pos, out row, out col);
        GameObject plant = GameModel.GetInstance().PlantsInMap[row, col];

        if (selectedPlant == plant)
        {
            return;        //铁铲从当前指向的植物 到了其他地方(有植物或没植物)
        }
        if (selectedPlant) //如果原来有指向的植物
        {
            selectedPlant.GetComponent <PlantSpriteDisplay>().SetAlpha(1f);
        }
        if (plant)//如果指向了新植物
        {
            selectedPlant = plant;
            selectedPlant.GetComponent <PlantSpriteDisplay>().SetAlpha(0.6f);
        }
        else
        {
            selectedPlant = null;
        }
    }