Example #1
0
    void CreateCell(int x, int z, int i)//在这里初始化格子的status并通过status设置格子的颜色
    {
        Vector3 positon;

        positon.x = (x + z * 0.5f - z / 2) * (HexMetrics.innerRadius * 2f);
        positon.y = 0f;
        positon.z = z * (HexMetrics.outerRadius * 1.5f);

        HexCell cell = cells[i] = Instantiate <HexCell>(cellPrefab);

        cell.transform.SetParent(transform, false);
        cell.transform.localPosition = positon;
        cell.coordinates             = HexCoordinates.FromOffsetCoordinates(x, z);
        cell.color = CellColor[0];


        //原版代码
        //Text label = Instantiate<Text>(cellLablePrefab);
        //label.rectTransform.SetParent(gridCanvas.transform, false);
        //label.rectTransform.anchoredPosition = new Vector2(positon.x, positon.z);
        //label.text = cell.coordinates.ToStringOnSeparateLines();

        //方政言加,为现实格子内容
        gridcontent.setcontent(i);
        Text label = texts[i] = Instantiate <Text>(cellLablePrefab);

        label.rectTransform.SetParent(gridCanvas.transform, false);
        label.rectTransform.anchoredPosition = new Vector2(positon.x, positon.z);
        label.text    = gridcontent.getcontent(i);
        label.enabled = false;
        //gridcontent.setcontent(i);
        //Text label = texts[i] = Instantiate<Text>(cellLablePrefab);
        //label.rectTransform.SetParent(gridCanvas.transform, false);
        //label.rectTransform.anchoredPosition = new Vector2(positon.x, positon.z);
        //label.text = gridcontent.getcontent(i);
        //if (gridcontent.contents[i].con == GridContent.Content.Portal) label.enabled = true;
        //else

        //方政言加end

        //边界和图片的实现
        Image border = Instantiate <Image>(borderPrefab);

        border.rectTransform.SetParent(gridCanvas.transform, false);
        border.rectTransform.anchoredPosition = new Vector2(positon.x, positon.z);

        Image content = images[i] = Instantiate <Image>(contentImage);

        content.rectTransform.SetParent(gridCanvas.transform, false);
        content.rectTransform.anchoredPosition = new Vector2(positon.x, positon.z);
        string con = gridcontent.ReturnContent(i);

        switch (con)
        {
        case "Nothing":
            content.color = new Color(0, 0, 0, 0);
            break;

        case "Resource":
            content.sprite = contentSprite[5];
            break;

        case "Electric":
            content.sprite = contentSprite[1];
            break;

        case "FirstAid":
            content.sprite = contentSprite[3];
            break;

        case "MResource":
            content.sprite = contentSprite[5];
            break;

        case "MElectric":
            content.sprite = contentSprite[1];
            break;

        case "MFirstAid":
            content.sprite = contentSprite[3];
            break;

        case "Chip":
            content.sprite = contentSprite[0];
            break;

        case "Incident":
            content.sprite = contentSprite[2];
            break;

        case "Portal":
            content.sprite = contentSprite[8];
            break;

        case "specialitem1":
            content.sprite = contentSprite[9];
            break;

        case "specialitem2":
            content.sprite = contentSprite[10];
            break;

        default:
            break;
        }
        content.enabled = false;
    }