From c7001ae3d011d049fae2b1b8f0c7a55eec33276c Mon Sep 17 00:00:00 2001 From: "DESKTOP-DDTRVOR\\asus" <1162187704@qq.com> Date: Tue, 14 Jan 2025 10:33:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=95=B0=E6=8D=AE=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/Battle/BattleManager.cs.rej | 24 ------- .../Script/Battle/BattleManager.cs.rej.meta | 7 -- Blacksmith/Assets/Script/VoxelizationTool.cs | 65 +++++++++++++++++++ .../Assets/Script/VoxelizationTool.cs.meta | 11 ++++ sever/test/server2.go | 51 +++++++++------ 5 files changed, 108 insertions(+), 50 deletions(-) delete mode 100644 Blacksmith/Assets/Script/Battle/BattleManager.cs.rej delete mode 100644 Blacksmith/Assets/Script/Battle/BattleManager.cs.rej.meta create mode 100644 Blacksmith/Assets/Script/VoxelizationTool.cs create mode 100644 Blacksmith/Assets/Script/VoxelizationTool.cs.meta diff --git a/Blacksmith/Assets/Script/Battle/BattleManager.cs.rej b/Blacksmith/Assets/Script/Battle/BattleManager.cs.rej deleted file mode 100644 index c3901b81..00000000 --- a/Blacksmith/Assets/Script/Battle/BattleManager.cs.rej +++ /dev/null @@ -1,24 +0,0 @@ -diff a/Blacksmith/Assets/Script/Battle/BattleManager.cs b/Blacksmith/Assets/Script/Battle/BattleManager.cs (rejected hunks) -@@ -295,15 +295,15 @@ - var index = i; - if (BattleEquipments[i].EquipmentLock) - { -- PrefabPool.ins.LoadObj("Prefab/player/player", (GameObject obj) => -+ PrefabPool.ins.LoadObj("Prefab/player/player",index, (GameObject obj,int idex) => - { -- obj.transform.parent = playerParent[index]; -+ obj.transform.parent = playerParent[idex]; - obj.transform.localPosition=Vector3.zero; -- playerItems[index] = new PlayerRunState(); -- playerItems[index].player = obj.GetComponent(); -- playerItems[index].equipent = BattleEquipments[index]; -- playerItems[index].RestState(); -- -+ playerItems[idex] = new PlayerRunState(); -+ playerItems[idex].player = obj.GetComponent(); -+ playerItems[idex].equipent = BattleEquipments[idex]; -+ playerItems[idex].RestState(); -+ playerItems[idex].player.SetModel(idex+1); - }); - } - } diff --git a/Blacksmith/Assets/Script/Battle/BattleManager.cs.rej.meta b/Blacksmith/Assets/Script/Battle/BattleManager.cs.rej.meta deleted file mode 100644 index 63041640..00000000 --- a/Blacksmith/Assets/Script/Battle/BattleManager.cs.rej.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 97b74a549b99c204480a3dffcd22dc98 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Blacksmith/Assets/Script/VoxelizationTool.cs b/Blacksmith/Assets/Script/VoxelizationTool.cs new file mode 100644 index 00000000..a16139ad --- /dev/null +++ b/Blacksmith/Assets/Script/VoxelizationTool.cs @@ -0,0 +1,65 @@ +using UnityEngine; +using UnityEditor; + +[ExecuteInEditMode] +public class VoxelizationTool : MonoBehaviour +{ + public Vector3 gridSize = new Vector3(10, 10, 10); // 体素化区域的尺寸 + public float voxelSize = 1.0f; // 每个体素的大小 + public Color gridColor = Color.cyan; // 网格颜色 + public bool showGrid = true; // 是否显示网格 + public bool onlyShowMeshVoxels = true; // 是否仅显示包含 Mesh 的体素 + + private Bounds gridBounds; // 网格的总体包围盒 + + private void OnDrawGizmos() + { + if (!showGrid) return; + + Gizmos.color = gridColor; + + // 定义整个体素网格的包围盒 + gridBounds = new Bounds(transform.position + gridSize * voxelSize / 2, gridSize * voxelSize); + + // 获取场景中的所有 MeshFilter + MeshFilter[] meshFilters = FindObjectsOfType(); + + foreach (MeshFilter meshFilter in meshFilters) + { + Bounds meshBounds = meshFilter.sharedMesh.bounds; + meshBounds = TransformBounds(meshBounds, meshFilter.transform); + + // 遍历体素,检查是否与当前 Mesh 的 Bounds 相交 + for (int x = 0; x < gridSize.x; x++) + { + for (int y = 0; y < gridSize.y; y++) + { + for (int z = 0; z < gridSize.z; z++) + { + Vector3 voxelCenter = transform.position + new Vector3(x, y, z) * voxelSize + Vector3.one * voxelSize / 2; + + // 跳过不在包围盒内的体素 + if (!gridBounds.Contains(voxelCenter)) continue; + + // 检查体素是否与 Mesh 的 Bounds 相交 + Bounds voxelBounds = new Bounds(voxelCenter, Vector3.one * voxelSize); + if (meshBounds.Intersects(voxelBounds)) + { + Gizmos.DrawWireCube(voxelCenter, Vector3.one * voxelSize); + } + } + } + } + } + } + + /// + /// 将本地 Bounds 转换为世界空间的 Bounds + /// + private Bounds TransformBounds(Bounds localBounds, Transform transform) + { + Vector3 worldCenter = transform.TransformPoint(localBounds.center); + Vector3 worldExtents = Vector3.Scale(localBounds.extents, transform.lossyScale); + return new Bounds(worldCenter, worldExtents * 2); + } +} diff --git a/Blacksmith/Assets/Script/VoxelizationTool.cs.meta b/Blacksmith/Assets/Script/VoxelizationTool.cs.meta new file mode 100644 index 00000000..11dfb57e --- /dev/null +++ b/Blacksmith/Assets/Script/VoxelizationTool.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7ed37701935d86d418ebb34d139e67d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sever/test/server2.go b/sever/test/server2.go index 1d35a404..4c22dd65 100644 --- a/sever/test/server2.go +++ b/sever/test/server2.go @@ -81,14 +81,18 @@ func main() { // 检查是否缺少必要参数 if mpID == "" || dateHour == "" { - http.Error(w, "缺少必要的参数 mp_id 或 date_hour", http.StatusBadRequest) + errorMessage := "缺少必要的参数 mp_id 或 date_hour" + fmt.Println(errorMessage) + http.Error(w, errorMessage, http.StatusBadRequest) return } // 获取动态的 access_token accessToken, err := GetAccessToken() if err != nil { - http.Error(w, fmt.Sprintf("获取 access_token 失败: %v", err), http.StatusInternalServerError) + errorMessage := fmt.Sprintf("获取 access_token 失败: %v", err) + fmt.Println(errorMessage) + http.Error(w, errorMessage, http.StatusInternalServerError) return } @@ -107,7 +111,9 @@ func main() { // 调用抖音 API resp, err := http.Get(fullURL) if err != nil { - http.Error(w, "调用抖音 API 失败", http.StatusInternalServerError) + errorMessage := "调用抖音 API 失败" + fmt.Println(errorMessage, err) + http.Error(w, errorMessage, http.StatusInternalServerError) return } defer resp.Body.Close() @@ -115,7 +121,9 @@ func main() { // 读取抖音 API 响应数据 responseBody, err := ioutil.ReadAll(resp.Body) if err != nil { - http.Error(w, "读取抖音 API 响应失败", http.StatusInternalServerError) + errorMessage := "读取抖音 API 响应失败" + fmt.Println(errorMessage, err) + http.Error(w, errorMessage, http.StatusInternalServerError) return } @@ -123,13 +131,17 @@ func main() { var apiResponse APIResponse err = json.Unmarshal(responseBody, &apiResponse) if err != nil { - http.Error(w, "解析 API 响应数据失败", http.StatusInternalServerError) + errorMessage := "解析 API 响应数据失败" + fmt.Println(errorMessage, err) + http.Error(w, errorMessage, http.StatusInternalServerError) return } // 检查 API 是否返回错误 if apiResponse.ErrNo != 0 { - http.Error(w, fmt.Sprintf("抖音 API 返回错误: %s (错误码: %d)", apiResponse.ErrMsg, apiResponse.ErrNo), http.StatusInternalServerError) + errorMessage := fmt.Sprintf("抖音 API 返回错误: %s (错误码: %d)", apiResponse.ErrMsg, apiResponse.ErrNo) + fmt.Println(errorMessage) + http.Error(w, errorMessage, http.StatusInternalServerError) return } @@ -143,28 +155,29 @@ func main() { // 如果没有记录,则返回错误 if totalRecords == 0 { - http.Error(w, "未找到记录,无法计算 ECPM", http.StatusOK) + errorMessage := "未找到记录,无法计算 ECPM" + fmt.Println(errorMessage) + http.Error(w, errorMessage, http.StatusOK) return } ecpm := float64(totalCost) / 100000 * 1000 / float64(totalRecords) - // 构造返回的 JSON 数据 - result := map[string]interface{}{ - "total_cost": float64(totalCost) / 100000, - "total_records": totalRecords, - "ecpm": ecpm, - } - resultJSON, err := json.Marshal(result) - if err != nil { - http.Error(w, "生成返回 JSON 数据失败", http.StatusInternalServerError) - return + // 根据 ECPM 值判断并返回 "true" 或 "false" + var result string + if ecpm > 300 && totalRecords > 2 { + result = "true" + } else { + result = "false" } - // 返回 JSON 格式的 ECPM 数据 + // 打印日志 + fmt.Printf("ECPM: %.2f, Result: %s\n", ecpm, result) + + // 返回结果 w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - w.Write(resultJSON) + w.Write([]byte(result)) }) // 启动 HTTP 服务器