/// <summary> /// 莫顿码计算 /// </summary> /// <param name="iTileIndex">地形的Tile索引</param> /// <param name="iChunkTileIndex">单个地形的拆分成chunk后的tile索引</param> /// <param name="iSlicingCount">单个地形的拆分个数。(如:2x2 则为2)</param> /// <param name="iLayerLevel">当前所属层级</param> /// <returns>莫顿码</returns> public static UINT32 Morton(Vector2 iTileIndex, Vector2 iChunkTileIndex, int iSlicingCount, int iLayerLevel) { var chunkIndexXG = (int)(iTileIndex.x * iSlicingCount + iChunkTileIndex.x); var chunkIndexZG = (int)(iTileIndex.y * iSlicingCount + iChunkTileIndex.y); return(UtilsMorton.Morton3d(chunkIndexXG, iLayerLevel, chunkIndexZG)); }
/// <summary> /// 莫顿码顺算预览(3D) /// 备注 /// x : x轴方向 /// y : z轴方向 /// </summary> /// <param name="iLevel">层级(影响到左边缩进的余白)</param> /// <param name="iMorton">莫顿码</param> private void DrawMorton3DPreView(int iLevel, ref Vector3 iMorton) { // 设定缩进 for (var i = 0; i < iLevel; ++i) { ++EditorGUI.indentLevel; } var level = iLevel; // 莫顿码输入值获取 iMorton.x = iMorton.x >= 0 ? iMorton.x : 0; iMorton.y = iMorton.y >= 0 ? iMorton.y : 0; DrawVector3Field(level + 1, "预览", ref iMorton); var morton = UtilsMorton.Morton3d(iMorton.x, iMorton.y, iMorton.z); // 莫顿码 DrawLabel(level, "莫顿码", Color.yellow, morton.ToString()); // 恢复缩进 for (var i = 0; i < iLevel; ++i) { --EditorGUI.indentLevel; } }