Beispiel #1
0
        // Use this for initialization
        void Start()
        {
            cloudOptionList = CloudOptManager.GetInstance().optionList;
            plantOptionList = PlantOptManager.GetInstance().optionList;

            //cloudOptImageList = new List<RawImage>();
            //plantOptImageList = new List<RawImage>();
            EnableSubscribe();
            SetSteps();
            UpdateCloudOption();

            StartCoroutine("InitialSunshine");
        }
Beispiel #2
0
    // Use this for initialization
    void Start()
    {
        wNum        = Global.HorizonalGridNum;
        hNum        = Global.VerticalGridNum;
        planeWidth  = transform.GetComponent <Collider>().bounds.size.x;//大面片的长宽
        planeHeight = transform.GetComponent <Collider>().bounds.size.z;
        gridWidth   = planeWidth / wNum;
        gridHeight  = planeHeight / hNum;
        grids       = new GroundGrid[wNum, hNum];

        hints            = new GroundHintGrid[wNum, hNum];
        activeHints      = new List <GroundHintGrid>();
        skyHoveringGrids = new List <GroundHintGrid>();

        elimTemplate    = Global.elimTemplate;
        plantOptManager = PlantOptManager.GetInstance();
        plantList       = new List <GameObject>();

        InitGround();
        EnableSubscribe();

        //UpdatePlantOption();
    }
Beispiel #3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="i">选项左上角的对应格子数组的横坐标</param>
    /// <param name="j">选项左上角的对应格子数组的纵坐标</param>
    /// <param name="c">选项数据</param>
    /// <returns></returns>
    public void UpdatePlantOption()
    {
        //int left = i - 1 < 0 ? 0 : i - 1;
        //int right = (i + c.width+1) > wNum ? wNum : (i + c.width);
        //int bottom = j - 1 < 0 ? 0 : j - 1;
        //int top = (j + c.height+1) > hNum ? hNum : (j + c.height);
        //int[,] connectRegion=new int[wNum,hNum];
        //int regionIndex = 0;

        //int[,] horProjection = new int[wNum, Global.dMoisture];

        ////遍历一遍找出每行,每种湿度的格子有几个
        //for (int m = 0; m < hNum; m++)
        //{
        //    for (int n = 0; n < wNum; n++)
        //    {
        //        horProjection[n, grids[n,m].Moisture]++;
        //    }
        //}
        plantOptManager.optionList.Clear();

        TemplateMatch(plantOptManager.bigPlants, plantOptManager.optionList);
        TemplateMatch(plantOptManager.middlePlants, plantOptManager.optionList);
        TemplateMatch(plantOptManager.smallPlants, plantOptManager.optionList);

        PlantOptManager.optionChangeHandle(); //通知HUD更新选项
                                              //连通区域标记算法
                                              //先逐行扫描,标记行中所有团
                                              //for (int n = bottom, a = 0; n < top; n++)
                                              //{
                                              //    connectRegion[a, 0] = regionIndex;

        //    for (int m=left+1,b=1;m<right;m++)
        //    {

        //       if(m>0&&grids[n,m].Moisture==grids[n,m-1].Moisture)
        //        {
        //            connectRegion[a,b] = connectRegion[a,b-1];
        //        }
        //        else
        //        {
        //            regionIndex++;
        //            connectRegion[a, b] = regionIndex;
        //        }
        //    }
        //}
        ////再将每行的团进行合并
        //for(int n=bottom+1,a=1;n<top;n++)
        //{
        //    for(int m=left,b=0;m<right;m++)
        //    {
        //        if (grids[n,m].Moisture == grids[n-1,m].Moisture)
        //        {
        //            int moisture = grids[n, m].Moisture;
        //            int index = connectRegion[a, b];
        //            while(m<right&&grids[n,m].Moisture==moisture)
        //            {
        //                connectRegion[a, b] = index;
        //                m++;b++;
        //            }

        //        }
        //    }
        //}
    }
Beispiel #4
0
    public void EndDrag(PlantProperty p, Vector2 leftTop)
    {
        activeHints.ClearHintState();

        bool destroyOption = false;

        RaycastHit hit;

        Vector2Int pos    = new Vector2Int();
        int        left   = 0;//图片对应的最左和最右格子,用于传递给TemplateMatch(),减小遍历面积
        int        right  = 0;
        int        top    = 0;
        int        bottom = 0;

        Ray ray = Camera.main.ScreenPointToRay(leftTop);

        if (Physics.Raycast(ray, out hit, 100.0f, LayerMask.GetMask("Ground")))
        {
            //activeHints.ClearHintState();
            //debugHitPoint = hit.point;

            // 打印射线检测到的物体的名称
            //Debug.Log("射线检测到的物体名称: " + hit.transform.name);

            pos    = hit.transform.GetComponent <GroundGrid>().position;//图片左上角碰撞到的格子的坐标
            left   = pos.x;
            right  = pos.x + p.width - 1;
            top    = pos.y;
            bottom = pos.y + p.height - 1;
            //判断选项是否被完全包含在棋盘里
            //既然左上角碰撞到了就只需检查右界、下界
            //ground的格子是从上到下下标从小到大的
            if (pos.x + p.width > wNum || pos.y + p.height > hNum)
            {
                destroyOption = false;
            }
            else
            {
                destroyOption = true;
                for (int i = 0; i < p.width; i++)
                {
                    for (int j = 0; j < p.height; j++)//注意pos.y是上大下小
                    {
                        //如果这片地上有东西就不能放置
                        if (grids[pos.x + i, pos.y + j].State == 1 || grids[pos.x + i, pos.y + j].Moisture < p.moisture)
                        {
                            destroyOption = false;
                            break;
                        }
                    }
                    if (destroyOption == false)
                    {
                        break;
                    }
                }
            }
        }


        if (destroyOption)
        {
            GrowPlant(pos, p);
            UpdatePlantOption();
        }
        else
        {
            //如果没拖到云彩上,要把选项放回到原来的位置
            PlantOptManager.GetInstance().PutBackOption(p);
        }
    }
Beispiel #5
0
 private void Awake()
 {
     instance = this;
 }