Ejemplo n.º 1
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);
            }
        }
    }
Ejemplo n.º 2
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;
        }
    }