Пример #1
0
        /// <summary>
        /// 根据格子坐标计算得到相对格子的世界平面坐标(x,y)
        /// </summary>
        /// <param name="nRow"></param>
        /// <param name="nCol"></param>
        /// <param name="space"></param>
        /// <returns></returns>
        public static Vector2 GetHexPosByIndex(int nRow, int nCol, Space space)
        {
            Vector2 zero            = Vector2.zero;
            Vector3 hex3DPosByIndex = HexagonImplement.GetHex3DPosByIndex(nRow, nCol, space);

            zero.x = hex3DPosByIndex.x;
            zero.y = hex3DPosByIndex.z;
            return(zero);
        }
Пример #2
0
        /// <summary>
        /// 根据格子坐标计算得到相对格子的世界坐标
        /// </summary>
        /// <param name="hexPos"></param>
        /// <param name="space"></param>
        /// <returns></returns>
        public static Vector3 GetHex3DPos(CVector3 hexPos, Space space)
        {
            Vector3 result;

            if (null != hexPos)
            {
                result = HexagonImplement.GetHex3DPosByIndex(hexPos.nRow, hexPos.nCol, space);
            }
            else
            {
                result = Vector3.zero;
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 根据世界坐标获取格子坐标
        /// </summary>
        /// <param name="realPos"></param>
        /// <param name="nRow"></param>
        /// <param name="nCol"></param>
        /// <returns></returns>
        public static bool GetHexIndexByPos(Vector3 realPos, out int nRow, out int nCol)
        {
            if (null != HexagonImplement.TransformBase)
            {
                realPos = HexagonImplement.TransformBase.InverseTransformPoint(realPos);
            }
            Vector2 pos            = new Vector2(realPos.x, realPos.z);
            float   num            = (pos.x - pos.y / Mathf.Sqrt(3f)) / HexagonImplement.m_fSideLength;
            int     num2           = (int)num;
            float   num3           = pos.y / (HexagonImplement.m_fSideLength * Mathf.Sqrt(3f) / 2f);
            int     num4           = (int)num3;
            int     num5           = (int)Mathf.Sign(num) * (Mathf.Abs(num2) + 1);
            int     num6           = (int)Mathf.Sign(num3) * (Mathf.Abs(num4) + 1);
            Vector2 hexPosByIndex  = HexagonImplement.GetHexPosByIndex(num4, num2);
            Vector2 hexPosByIndex2 = HexagonImplement.GetHexPosByIndex(num6, num2);
            Vector2 hexPosByIndex3 = HexagonImplement.GetHexPosByIndex(num4, num5);
            Vector2 hexPosByIndex4 = HexagonImplement.GetHexPosByIndex(num6, num5);
            float   num7           = HexagonImplement.SquareDistance(pos, hexPosByIndex);
            float   num8           = HexagonImplement.SquareDistance(pos, hexPosByIndex2);
            float   num9           = HexagonImplement.SquareDistance(pos, hexPosByIndex3);
            float   num10          = HexagonImplement.SquareDistance(pos, hexPosByIndex4);

            nCol = num2;
            nRow = num4;
            float num11 = num7;

            if (num8 < num11)
            {
                nCol  = num2;
                nRow  = num6;
                num11 = num8;
            }
            if (num9 < num11)
            {
                nCol  = num5;
                nRow  = num4;
                num11 = num9;
            }
            if (num10 < num11)
            {
                nCol = num5;
                nRow = num6;
            }
            return(true);
        }
Пример #4
0
 /// <summary>
 /// 根据格子坐标计算得到自身平面坐标(x,y)
 /// </summary>
 /// <param name="nRow"></param>
 /// <param name="nCol"></param>
 /// <returns></returns>
 public static Vector2 GetHexPosByIndex(int nRow, int nCol)
 {
     return(HexagonImplement.GetHexPosByIndex(nRow, nCol, Space.Self));
 }