Example #1
0
    /// <summary>
    /// 创建六角地形
    /// </summary>
    /// <param name="hexagonsSize">地形大小</param>
    /// <param name="groundX">X轴范围</param>
    /// <param name="groundZ">Z轴范围</param>
    /// <param name="offsetX">X轴偏移角度</param>
    /// <param name="offsetZ">Z轴偏移角度</param>
    public List <GroundHexagonsBean> BuildGroundHexagons(float hexagonsSize, int groundX, int groundZ, float offsetX = 0, float offsetZ = 0)
    {
        itemHexagonsX = hexagonsSize * 2 * 0.75f;
        itemHexagonsZ = hexagonsSize * Mathf.Sqrt(3);

        List <GroundHexagonsBean> listGroundData = new List <GroundHexagonsBean>();

        for (int x = 0; x < groundX; x++)
        {
            for (int z = 0; z < groundZ; z++)
            {
                //偶数偏移
                float tempOffsetZ = (x % 2 == 0 ? itemHexagonsZ / 2f : 0);
                GroundHexagonsBean groundHexagonsData = new GroundHexagonsBean
                {
                    //设置偏移坐标
                    coordinatesForOffset = new Vector3(x, 0, z),
                    //设置世界坐标
                    coordinatesForWorld = new Vector3(itemHexagonsX * x + offsetX * x, 0, itemHexagonsZ * z + offsetZ * z + tempOffsetZ),
                    //设置地形为未探索
                    areaDiscoveryStatus = (int)AreaDiscoveryStatusEnum.Unexplored,
                    //设置地形类型为Null
                    areaType = (int)AreaTypeEnum.Null,
                };
                BuildItemGroundHexagons(groundHexagonsData);
                listGroundData.Add(groundHexagonsData);
            }
        }
        //扫描地形
        StartCoroutine(CoroutineForScanGround());
        return(listGroundData);
    }
Example #2
0
    /// <summary>
    /// 创建单个六角地形
    /// </summary>
    /// <param name="groundHexagonsData"></param>
    public void BuildItemGroundHexagons(GroundHexagonsBean groundHexagonsData)
    {
        //创建六角实例
        GameObject     objGroundHexagons  = Instantiate(gameObject, modelForGroundHexagons.gameObject, groundHexagonsData.coordinatesForWorld);
        GroundHexagons itemGroundHexagons = objGroundHexagons.GetComponent <GroundHexagons>();

        //设置数据
        itemGroundHexagons.SetGroundHexagonsData(groundHexagonsData);
        manager.AddGroundHexagons(itemGroundHexagons);
    }
 /// <summary>
 /// 设置地形数据
 /// </summary>
 /// <param name="groundHexagonsData"></param>
 public void SetGroundHexagonsData(GroundHexagonsBean groundHexagonsData)
 {
     this.groundHexagonsData = groundHexagonsData;
     areaTerrain.SetBelong(0, Color.white);
 }