Exemplo n.º 1
0
    private void InitTemplet()
    {
        //read from xml

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(Resources.Load("Config/CloudOptionTemplet").ToString());
        if (xmlDoc != null)
        {
            XmlNodeList cloudList = xmlDoc.SelectSingleNode("main").ChildNodes;
            foreach (XmlNode xn in cloudList)
            {
                int              width  = int.Parse(xn.SelectSingleNode("width").InnerText);
                int              height = int.Parse(xn.SelectSingleNode("height").InnerText);
                string           data   = xn.SelectSingleNode("data").InnerText;
                string           tex    = xn.SelectSingleNode("textureName").InnerText;
                Global.CloudType type   = (Global.CloudType)System.Enum.Parse(typeof(Global.CloudType), xn.SelectSingleNode("type").InnerText);

                CloudProperty cloudProperty = null;
                switch (type)
                {
                case Global.CloudType.SPECIAL_3_3:
                    cloudProperty = new CloudProperty_Special_3_3();
                    break;

                default:
                    cloudProperty = new CloudProperty();
                    break;
                }

                cloudProperty.width   = width;
                cloudProperty.height  = height;
                cloudProperty.data    = new int[width, height];
                cloudProperty.texture = Resources.Load("Textures/" + tex) as Texture2D;
                cloudProperty.type    = type;
                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        cloudProperty.data[i, j] = data[i * height + j] - '0';
                    }
                }

                if (type == Global.CloudType.NORMAL)
                {
                    options.Add(cloudProperty);
                }
                else
                {
                    specialOptions.Add(type, cloudProperty);
                }
            }
        }
    }
Exemplo n.º 2
0
    public static void RemoveAndNotify(this List <CloudProperty> options, CloudProperty cloud)
    {
        if (cloud == null)
        {
            Debug.Log("cloudProperty in <CloudOptManager>.RemoveAndNotify is NULL");
            return;
        }
        // index = options.FindIndex((CloudProperty s) => s == cloud);
        options.Remove(cloud);

        CloudOptManager.optionChangeHandle();
    }
Exemplo n.º 3
0
    /// <summary>
    /// 扩展方法:自定义的List的Add和Remove
    /// </summary>
    /// <param name="cl">表示调用这个方法的类型是List<CloudProperty></param>
    /// <param name="cloud">真正的参数,要添加到list中的item</param>
    public static void AddAndNotify(this List <CloudProperty> options, CloudProperty cloud)
    {
        options.Add(cloud);

        //CloudOptManager.optionChangeHandle.Method;
        if (CloudOptManager.optionChangeHandle == null)
        {
            Debug.Log("CloudOptManager.optionChangeHandle in <CloudOptManager> is NULL");
            return;
        }
        CloudOptManager.optionChangeHandle();
    }
Exemplo n.º 4
0
    protected override void InitSeletedItem()
    {
        int index = HUDManager.GetInstance().cloudOptImageList.FindIndex((RawImage s) => s == image);

        if (index < 0)
        {
            Debug.Log("cloudProperty in <Option> is NULL");
        }
        cloudProperty = CloudOptManager.GetInstance().optionList[index];

        //imgReduceScale = (256f/imgRect.rect.width);
        //imgNormalScale = (256f/imgRect.rect.width);

        imageOffset = new Vector2(-image.rectTransform.rect.width * 0.5f * image.rectTransform.localScale.x,
                                  image.rectTransform.rect.height * 0.5f * image.rectTransform.localScale.y);
    }
Exemplo n.º 5
0
    private void EndDrag(CloudProperty c, Vector2 leftTop)
    {
        //消除提示
        hoveringGrids.ClearHintState();
        Ground.GetInstance().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("Sky")))
        {
            // 打印射线检测到的物体的名称
            //Debug.Log("射线检测到的物体名称: " + hit.transform.name);

            pos    = hit.transform.GetComponent <SkyGrid>().position;//图片左上角碰撞到的格子的坐标
            left   = pos.x;
            right  = pos.x + c.width - 1;
            top    = pos.y;
            bottom = pos.y - c.height + 1;
            //判断选项是否被完全包含在天空里
            //既然左上角碰撞到了就只需检查右界、下界
            if (pos.x + c.width > wNum || pos.y - c.height + 1 < 0)
            {
                destroyOption = false;
            }
            else
            {
                destroyOption = true;
                for (int i = 0; i < c.width; i++)
                {
                    for (int j = 0; j < c.height; j++)//注意pos.y是上大下小
                    {
                        if (c.data[i, j] == 1)
                        {
                            if (grids[pos.x + i, pos.y - j].State == 1)
                            {
                                destroyOption = false;
                                break;
                            }
                        }
                    }
                    if (destroyOption == false)
                    {
                        break;
                    }
                }
            }
        }


        if (destroyOption)
        {
            c.EnableSubscribe();
            //拖动成功,消除原来的选项
            CloudOptManager.GetInstance().RemoveOption(c);

            if (UseSkill == null)
            {
                //Normal skill
                for (int i = 0; i < c.width; i++)
                {
                    for (int j = 0; j < c.height; j++)//注意pos.y是上大下小
                    {
                        if (c.data[i, j] == 1)
                        {
                            grids[pos.x + i, pos.y - j].State = 1;
                        }
                    }
                }
                TemplateMatch(left, right, top, bottom);
            }
            else
            {
                //Special skill
                UseSkill(pos.x, pos.y);
            }
            c.DisableSubscribe();
        }
        else
        {
            //如果没拖到云彩上,要把选项放回到原来的位置
            CloudOptManager.GetInstance().PutBackOption(c);
        }
    }
Exemplo n.º 6
0
    private void DragingOption(CloudProperty c, Vector2 leftTop)
    {
        Ray ray = Camera.main.ScreenPointToRay(leftTop);

        debugDir = ray.direction;
        RaycastHit hit;

        Vector2Int pos;

        hintAble = -1;
        hoveringGrids.ClearHintState();
        Ground.GetInstance().ClearHintState();

        if (Physics.Raycast(ray, out hit, 100.0f, LayerMask.GetMask("SkyHint")))
        {
            // 打印射线检测到的物体的名称
            //Debug.Log("射线检测到的物体名称: " + hit.transform.name);
            debugHitPoint = hit.point;

            pos = hit.transform.GetComponent <SkyHintGrid>().position;//图片左上角碰撞到的格子的坐标

            //如果块没有全部包含在棋盘里,一定提示异常
            if (pos.x + c.width > wNum || pos.y - c.height + 1 < 0)
            {
                int right  = pos.x + c.width > wNum ? wNum : pos.x + c.width;
                int bottom = pos.y - c.height + 1 < 0 ? 0 : pos.y - c.height + 1;
                hintAble = 0;
                for (int i = pos.x; i < right; i++)
                {
                    for (int j = pos.y; j >= bottom; j--)
                    {
                        if (grids[i, j].State == 0 && c.data[i - pos.x, pos.y - j] == 1)
                        {
                            hoveringGrids.Add(hints[i, j]);
                            Ground.GetInstance().AddHintGrid(i, j);
                        }
                    }
                }
            }
            else
            {
                hintAble = 1;
                for (int i = 0; i < c.width; i++)
                {
                    for (int j = 0; j < c.height; j++)//注意pos.y是上大下小
                    {
                        if (c.data[i, j] == 1)
                        {
                            //如果范围内没有别的云彩块,就是绿色提示,否则也要提示异常
                            if (grids[pos.x + i, pos.y - j].State == 0)
                            {
                                hoveringGrids.Add(hints[pos.x + i, pos.y - j]);
                                Ground.GetInstance().AddHintGrid(pos.x + i, pos.y - j);
                            }
                            else
                            {
                                hintAble = 0;
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 7
0
 public Cloud(CloudProperty property)
 {
     cloudProperty = property;
 }
Exemplo n.º 8
0
 public void PutBackOption(CloudProperty cloudProperty)
 {
     //int index = optionList.FindIndex(s => s == cloudProperty);
     //HUDManager.GetInstance().PutBackOption(index);
     HUDManager.GetInstance().PutBackOption();
 }
Exemplo n.º 9
0
 public void RemoveOption(CloudProperty cloudProperty)
 {
     LevelManager.GetInstance().Steps--;
     optionList.RemoveAndNotify(cloudProperty);
 }