private void SetMapBlockDic(byte[] datas, eMapBlockType type, Dictionary <string, MapBlockData> dic) { int count = datas.Length / MapDefine.MapByteInterval; for (int index = 0; index < count; index++) { MapBlockData tempData = new MapBlockData(); byte[] temp = new byte[MapDefine.MapByteInterval]; Array.Copy(datas, index * MapDefine.MapByteInterval, temp, 0, MapDefine.MapByteInterval); ByteBuffer tempBuffer = new ByteBuffer(temp); tempData.row = tempBuffer.ReadInt16(); tempData.col = tempBuffer.ReadInt16(); int tempInt = tempBuffer.ReadInt16(); if (type == eMapBlockType.Hide) { float tempFloat = tempInt * 0.01f; tempInt = (int)tempFloat; tempData.paramValue = tempInt; } else//高度float,取数据时候转 { tempData.paramValue = tempInt; } tempData.type = type; dic[tempData.row + "_" + tempData.col] = tempData; } }
private static void AddColliderToDic(string key, eMapBlockType mapBlockType, string param) { if (mapBlockType == eMapBlockType.Collect) { string[] datas = key.Split('_'); int row = (int)(int.Parse(datas[0])); int col = (int)(int.Parse(datas[1])); int index = row + col * 10240; int byteRow = index / 8; int byteCol = index % 8; if (byteRow >= blockBytesData.Length) { Debug.LogError("byteRow:" + byteRow + " " + key); return; } byte curByte = blockBytesData[byteRow]; byte temp = (byte)Mathf.Pow(2, byteCol); curByte |= temp; blockBytesData[byteRow] = curByte; // Debug.LogError(row+" "+col+" "+" "); } else { string[] datas = key.Split('_'); int paramValue = string.IsNullOrEmpty(param) ? 0 : (int)(float.Parse(param) * 100); tempBlock = new MapBlockData { row = int.Parse(datas[0]), col = int.Parse(datas[1]), type = mapBlockType, paramValue = paramValue }; if (mapBlockType == eMapBlockType.Hide) { if (!MapHideBlockDataDic.ContainsKey(key)) { MapHideBlockDataDic[key] = tempBlock; } } else if (mapBlockType == eMapBlockType.Height) { if (!MapHeightBlockDataDic.ContainsKey(key)) { MapHeightBlockDataDic[key] = tempBlock; } } } //if (!MapHideBlockDataDic.ContainsKey(key)) //{ // string[] datas = key.Split('_'); // int paramValue = string.IsNullOrEmpty(param) ? 0 : (int)(float.Parse(param) * 100); // MapHideBlockDataDic[key] = new MapBlockData { row = int.Parse(datas[0]), col = int.Parse(datas[1]), type = mapBlockType, paramValue = paramValue }; //} }
private void AddCollider(int row, int col, eMapBlockType mapBlockType) { int index = _mapBlockData.FindIndex(a => a.row == row && a.col == col); if (index >= 0) { _mapBlockData[index].type = mapBlockType; } else { _mapBlockData.Add(new MapBlockData { row = row, col = col, type = mapBlockType }); } }
private void MenuInput() { if (GUI.Button(new Rect(10, 650, 50, 18), "保存")) { _mapEditHelper = MapColliderHelper.eMapEditHelper.SaveMapBlockFile; } if (GUI.Button(new Rect(100, 650, 50, 18), "填充全部")) { // Test(); } MapBlockType = (eMapBlockType)EditorGUI.EnumPopup(new Rect(0, 670, 200, 18), "事件类型选择", MapBlockType); if (isEditMapEvent) { //string labelName = string.Format("参数设置:当前坐标 => x:{0}, y:{1}", curSelectMapBlockData.row, curSelectMapBlockData.col); //GUI.Label(new Rect(0, 690, 200, 18), labelName); //curSelectMapBlockData.param = EditorGUI.TextField(new Rect(0, 710, 200, 18), curSelectMapBlockData.param); } }
private static void CreateElement(Transform go, int offsetX, int offsetY) { if (go == null) { return; } for (int index = 0; index < go.childCount; index++) { Transform element = go.GetChild(index); if (element.name.Contains("Ele_")) { Transform colliderRoots = element.Find("ColliderRoot"); if (colliderRoots == null) { continue; } List <KeyValuePair <string, CollRectange> > goInCludeRects = GetGoIncludeBlocks(element, offsetX, offsetY); for (int rootIndex = 0; rootIndex < colliderRoots.childCount; rootIndex++) { Transform root = colliderRoots.GetChild(rootIndex); string[] datas = root.name.Split('_'); if (!Enum.IsDefined(typeof(eMapBlockType), datas[0])) { continue; } eMapBlockType blockType = (eMapBlockType)Enum.Parse(typeof(eMapBlockType), datas[0]); if ((int)fileData != (int)blockType && fileData != MapByteDataType.All) { continue; } string blockParam = datas.Length > 1 ? datas[1] : ""; Renderer[] colliderRenderers = root.GetComponentsInChildren <Renderer>(true); List <CollRectange> colliderRectList = new List <CollRectange>(); for (int colliderIndex = 0; colliderIndex < colliderRenderers.Length; colliderIndex++) { Renderer tempRenderer = colliderRenderers[colliderIndex]; CollRectange tempColl = new CollRectange(tempRenderer.transform.position.x, tempRenderer.transform.position.z, tempRenderer.transform.eulerAngles.y, Mathf.Abs(tempRenderer.transform.lossyScale.x), Mathf.Abs(tempRenderer.transform.lossyScale.z)); colliderRectList.Add(tempColl); } for (int blockIndex = goInCludeRects.Count - 1; blockIndex >= 0; blockIndex--) { for (int colliderIndex = 0; colliderIndex < colliderRectList.Count; colliderIndex++) { if (ZTCollider.CheckCollision(goInCludeRects[blockIndex].Value, colliderRectList[colliderIndex])) { if (blockType == eMapBlockType.Height) { blockParam = Mathf.Abs(colliderRenderers[colliderIndex].bounds.size.y) + ""; } AddColliderToDic(goInCludeRects[blockIndex].Key, blockType, blockParam); //goInCludeRects.RemoveAt(blockIndex); break; } } } } } else { CreateElement(element, offsetX, offsetY); } } }