From adb56d3023f3014cc4a73713d03aa28ee2c25c60 Mon Sep 17 00:00:00 2001 From: CortexCore <2630229280@qq.com> Date: Fri, 27 Dec 2024 21:46:57 +0800 Subject: [PATCH] 1 --- .../Configs/Input/BITController.inputactions | 90 +++++++ Src/Unity/Materials/UX_Video.renderTexture | 2 +- Src/Unity/Scripts/Physics/PhysicsUtils.cs | 47 ++++ .../Scripts/Physics/PhysicsUtils.cs.meta | 3 + Src/Unity/Scripts/UX/ToolTips/UXToolTips.cs | 17 +- .../Shader/ShaderGraph/Fresnel.shadergraph | 250 ++++++++++++++++++ .../BITKit.Extensions.MonkeyCommand.asmdef | 3 +- .../MonkeyCommand/QuickFixBoxCollider.cs | 39 +-- .../MonkeyCommand/QuickFixFloatModel.cs | 2 +- 9 files changed, 415 insertions(+), 38 deletions(-) create mode 100644 Src/Unity/Scripts/Physics/PhysicsUtils.cs create mode 100644 Src/Unity/Scripts/Physics/PhysicsUtils.cs.meta diff --git a/Src/Unity/Configs/Input/BITController.inputactions b/Src/Unity/Configs/Input/BITController.inputactions index df780ad..8d81621 100644 --- a/Src/Unity/Configs/Input/BITController.inputactions +++ b/Src/Unity/Configs/Input/BITController.inputactions @@ -1300,6 +1300,96 @@ "isPartOfComposite": false } ] + }, + { + "name": "Editor", + "id": "0b8cb1df-3be9-4e75-acbe-3a304d61e56c", + "actions": [ + { + "name": "Vertical", + "type": "Button", + "id": "cc774816-362e-40d3-98c5-19411a7ae97a", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "PerformView", + "type": "Button", + "id": "b48069bf-ceb9-4dd3-b3d5-802fe5f8337c", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "Accelerate", + "type": "Button", + "id": "833e8df7-3a64-4c84-b90c-727ef54565e9", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + } + ], + "bindings": [ + { + "name": "1D Axis", + "id": "d78128d0-99dc-4ec8-9605-f7b3dbafd52e", + "path": "1DAxis", + "interactions": "", + "processors": "", + "groups": "", + "action": "Vertical", + "isComposite": true, + "isPartOfComposite": false + }, + { + "name": "negative", + "id": "14b328fc-701f-4164-bad3-2dd5f6383f01", + "path": "/q", + "interactions": "", + "processors": "", + "groups": "", + "action": "Vertical", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "positive", + "id": "19f974a1-37f5-439e-85d7-f09ce9596b57", + "path": "/e", + "interactions": "", + "processors": "", + "groups": "", + "action": "Vertical", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "", + "id": "6f192504-1dcc-41a9-8210-7baf63297c3a", + "path": "/rightButton", + "interactions": "", + "processors": "", + "groups": "", + "action": "PerformView", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "1c6399a5-abe1-424b-9dd2-26d27d82a9af", + "path": "/shift", + "interactions": "", + "processors": "", + "groups": "", + "action": "Accelerate", + "isComposite": false, + "isPartOfComposite": false + } + ] } ], "controlSchemes": [] diff --git a/Src/Unity/Materials/UX_Video.renderTexture b/Src/Unity/Materials/UX_Video.renderTexture index 1890244..ffab1c0 100644 --- a/Src/Unity/Materials/UX_Video.renderTexture +++ b/Src/Unity/Materials/UX_Video.renderTexture @@ -6,7 +6,7 @@ RenderTexture: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: UX_Video + m_Name: Assets/BITKit/Unity/Materials/ux_video.renderTexture m_ImageContentsHash: serializedVersion: 2 Hash: 00000000000000000000000000000000 diff --git a/Src/Unity/Scripts/Physics/PhysicsUtils.cs b/Src/Unity/Scripts/Physics/PhysicsUtils.cs new file mode 100644 index 0000000..74b1982 --- /dev/null +++ b/Src/Unity/Scripts/Physics/PhysicsUtils.cs @@ -0,0 +1,47 @@ +using UnityEngine; + +namespace BITKit.Physics +{ + public static class PhysicsUtils + { + public static void FixCollidersBound(params Transform[] transforms) + { + foreach (var transform in transforms) + { + // 获取或创建 BoxCollider 组件 + var boxCollider = transform.GetComponent(); + if (boxCollider == null) + { + continue; + } + + // 获取所有可见的 MeshRenderer 组件 + var meshRenderers = transform.GetComponentsInChildren(); + + if (meshRenderers.Length == 0) + { + Debug.LogWarning("No MeshRenderer components found in children."); + return; + } + + // 初始化包围盒,以第一个 MeshRenderer 的包围盒为基准 + Bounds bounds = new Bounds(transform.transform.InverseTransformPoint(meshRenderers[0].bounds.center), + transform.transform.InverseTransformVector(meshRenderers[0].bounds.size)); + + // 遍历所有 MeshRenderer,合并包围盒 + for (int i = 1; i < meshRenderers.Length; i++) + { + Bounds localBounds = meshRenderers[i].bounds; + Vector3 localCenter = transform.transform.InverseTransformPoint(localBounds.center); + Vector3 localSize = transform.transform.InverseTransformVector(localBounds.size); + + bounds.Encapsulate(new Bounds(localCenter, localSize)); + } + + // 设置 BoxCollider 的中心和大小 + boxCollider.center = bounds.center; + boxCollider.size = bounds.size; + } + } + } +} \ No newline at end of file diff --git a/Src/Unity/Scripts/Physics/PhysicsUtils.cs.meta b/Src/Unity/Scripts/Physics/PhysicsUtils.cs.meta new file mode 100644 index 0000000..223dab0 --- /dev/null +++ b/Src/Unity/Scripts/Physics/PhysicsUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 796081504c0e47ce93358ef36ba3adb9 +timeCreated: 1735276998 \ No newline at end of file diff --git a/Src/Unity/Scripts/UX/ToolTips/UXToolTips.cs b/Src/Unity/Scripts/UX/ToolTips/UXToolTips.cs index aea388e..74ee500 100644 --- a/Src/Unity/Scripts/UX/ToolTips/UXToolTips.cs +++ b/Src/Unity/Scripts/UX/ToolTips/UXToolTips.cs @@ -10,6 +10,8 @@ namespace BITKit.UX { public class UXToolTips:IDisposable { + public static VisualElement Hovering; + private readonly IUXService _uxService; private readonly IMainTicker _ticker; @@ -40,7 +42,12 @@ namespace BITKit.UX } - if(_label is null || _rootVisualElement is null)return; + + if (_label is null || _rootVisualElement is null) + { + Hovering = null; + return; + } var tooltip = CurrentToolTip(_rootVisualElement.panel); if (tooltip != "") { @@ -71,12 +78,18 @@ namespace BITKit.UX { // https://docs.unity3d.com/2022.2/Documentation/Manual/UIE-faq-event-and-input-system.html - if (!EventSystem.current.IsPointerOverGameObject()) return ""; + if (!EventSystem.current.IsPointerOverGameObject()) + { + Hovering = null; + return ""; + } var screenPosition = Mouse.current.position.ReadValue(); screenPosition.y = Screen.height - screenPosition.y; VisualElement ve = panel.Pick(RuntimePanelUtils.ScreenToPanel(panel, screenPosition)); + + Hovering = ve; return ve == null ? "" : ve.tooltip; } diff --git a/Src/Unity/Shader/ShaderGraph/Fresnel.shadergraph b/Src/Unity/Shader/ShaderGraph/Fresnel.shadergraph index 744b54b..7fd42bc 100644 --- a/Src/Unity/Shader/ShaderGraph/Fresnel.shadergraph +++ b/Src/Unity/Shader/ShaderGraph/Fresnel.shadergraph @@ -5,6 +5,15 @@ "m_Properties": [ { "m_Id": "ccadb1d66cf440a7b41ff9fbbad6ee48" + }, + { + "m_Id": "340c28e5d7b7473bad5b43173c9ffc74" + }, + { + "m_Id": "db4b7780fd2a42ab914eab0355797fba" + }, + { + "m_Id": "ab5e83f359174135bdda247a62e3f51c" } ], "m_Keywords": [], @@ -53,6 +62,12 @@ }, { "m_Id": "e9de460ea17f4b2ab37e30749eae2ff3" + }, + { + "m_Id": "9b675d24ae084cd198c336bb48eafa67" + }, + { + "m_Id": "cd485f7b79c24c04869e8b2bc464506e" } ], "m_GroupDatas": [], @@ -72,6 +87,34 @@ "m_SlotId": 1 } }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "9b675d24ae084cd198c336bb48eafa67" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "cfea2ba421334488af1907aac6323af7" + }, + "m_SlotId": 2 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "cd485f7b79c24c04869e8b2bc464506e" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "883b7be471df49eaa25e412b80d05a08" + }, + "m_SlotId": 0 + } + }, { "m_OutputSlot": { "m_Node": { @@ -249,6 +292,15 @@ "m_ChildObjectList": [ { "m_Id": "ccadb1d66cf440a7b41ff9fbbad6ee48" + }, + { + "m_Id": "340c28e5d7b7473bad5b43173c9ffc74" + }, + { + "m_Id": "db4b7780fd2a42ab914eab0355797fba" + }, + { + "m_Id": "ab5e83f359174135bdda247a62e3f51c" } ] } @@ -337,6 +389,49 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "3375426f46684b608adeaaf27951b6d7", + "m_Id": 0, + "m_DisplayName": "Power", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty", + "m_ObjectId": "340c28e5d7b7473bad5b43173c9ffc74", + "m_Guid": { + "m_GuidSerialized": "28008257-ad01-4138-8e47-68dbcabf2152" + }, + "m_Name": "Power", + "m_DefaultRefNameVersion": 1, + "m_RefNameGeneratedByDisplayName": "Power", + "m_DefaultReferenceName": "_Power", + "m_OverrideReferenceName": "", + "m_GeneratePropertyBlock": true, + "m_UseCustomSlotLabel": false, + "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, + "m_Precision": 0, + "overrideHLSLDeclaration": false, + "hlslDeclarationOverride": 0, + "m_Hidden": false, + "m_Value": 0.0, + "m_FloatType": 0, + "m_RangeValues": { + "x": 0.0, + "y": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", @@ -589,6 +684,31 @@ "m_Space": 2 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "7265d8a9b8af4c068033d9acb604cf13", + "m_Id": 0, + "m_DisplayName": "Emission", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", @@ -678,6 +798,42 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.PropertyNode", + "m_ObjectId": "9b675d24ae084cd198c336bb48eafa67", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Property", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -880.9999389648438, + "y": 309.9999694824219, + "width": 108.5, + "height": 34.0 + } + }, + "m_Slots": [ + { + "m_Id": "3375426f46684b608adeaaf27951b6d7" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_Property": { + "m_Id": "340c28e5d7b7473bad5b43173c9ffc74" + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.BlockNode", @@ -712,6 +868,36 @@ "m_SerializedDescriptor": "VertexDescription.Position" } +{ + "m_SGVersion": 3, + "m_Type": "UnityEditor.ShaderGraph.Internal.ColorShaderProperty", + "m_ObjectId": "ab5e83f359174135bdda247a62e3f51c", + "m_Guid": { + "m_GuidSerialized": "0e1f0246-4216-4706-975d-7da18b0a8170" + }, + "m_Name": "Emission", + "m_DefaultRefNameVersion": 1, + "m_RefNameGeneratedByDisplayName": "Emission", + "m_DefaultReferenceName": "_Emission", + "m_OverrideReferenceName": "", + "m_GeneratePropertyBlock": true, + "m_UseCustomSlotLabel": false, + "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, + "m_Precision": 0, + "overrideHLSLDeclaration": false, + "hlslDeclarationOverride": 0, + "m_Hidden": false, + "m_Value": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 + }, + "isMainColor": false, + "m_ColorMode": 0 +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot", @@ -841,6 +1027,42 @@ "m_ColorMode": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.PropertyNode", + "m_ObjectId": "cd485f7b79c24c04869e8b2bc464506e", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Property", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -260.0, + "y": 476.0, + "width": 123.0, + "height": 33.99993896484375 + } + }, + "m_Slots": [ + { + "m_Id": "7265d8a9b8af4c068033d9acb604cf13" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_Property": { + "m_Id": "ab5e83f359174135bdda247a62e3f51c" + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.BlockNode", @@ -973,6 +1195,34 @@ "m_SupportVFX": false } +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.Internal.Vector4ShaderProperty", + "m_ObjectId": "db4b7780fd2a42ab914eab0355797fba", + "m_Guid": { + "m_GuidSerialized": "7ba75dfb-6576-48ac-ac18-f3106aa7e5a8" + }, + "m_Name": "Vector4", + "m_DefaultRefNameVersion": 1, + "m_RefNameGeneratedByDisplayName": "Vector4", + "m_DefaultReferenceName": "_Vector4", + "m_OverrideReferenceName": "", + "m_GeneratePropertyBlock": true, + "m_UseCustomSlotLabel": false, + "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, + "m_Precision": 0, + "overrideHLSLDeclaration": false, + "hlslDeclarationOverride": 0, + "m_Hidden": false, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.MultiplyNode", diff --git a/Src/UnityPluginsSupport/MonkeyCommand/BITKit.Extensions.MonkeyCommand.asmdef b/Src/UnityPluginsSupport/MonkeyCommand/BITKit.Extensions.MonkeyCommand.asmdef index 60032a2..e2c7b85 100644 --- a/Src/UnityPluginsSupport/MonkeyCommand/BITKit.Extensions.MonkeyCommand.asmdef +++ b/Src/UnityPluginsSupport/MonkeyCommand/BITKit.Extensions.MonkeyCommand.asmdef @@ -3,7 +3,8 @@ "rootNamespace": "", "references": [ "GUID:14fe60d984bf9f84eac55c6ea033a8f4", - "GUID:39db31f0562d9184c92881e43adea352" + "GUID:39db31f0562d9184c92881e43adea352", + "GUID:89bd0da52dc3cc94daadea6252c6ad1b" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Src/UnityPluginsSupport/MonkeyCommand/QuickFixBoxCollider.cs b/Src/UnityPluginsSupport/MonkeyCommand/QuickFixBoxCollider.cs index af36d37..b278840 100644 --- a/Src/UnityPluginsSupport/MonkeyCommand/QuickFixBoxCollider.cs +++ b/Src/UnityPluginsSupport/MonkeyCommand/QuickFixBoxCollider.cs @@ -1,7 +1,9 @@ using System.Collections; using System.Collections.Generic; using System.Text; +using BITKit.Physics; using MonKey; +using MonKey.Editor.Commands; using UnityEditor; using UnityEngine; @@ -15,42 +17,13 @@ namespace BITKit.GameEditor { foreach (var transform in UnityEditor.Selection.transforms) { - // 获取或创建 BoxCollider 组件 - var boxCollider = transform.GetComponent(); - if (boxCollider == null) + if (transform.TryGetComponent(out BoxCollider boxCollider)) { - continue; + PhysicsUtils.FixCollidersBound(transform); + EditorUtility.SetDirty(boxCollider); } - - // 获取所有可见的 MeshRenderer 组件 - var meshRenderers = transform.GetComponentsInChildren(); - - if (meshRenderers.Length == 0) - { - Debug.LogWarning("No MeshRenderer components found in children."); - return; - } - - // 初始化包围盒,以第一个 MeshRenderer 的包围盒为基准 - Bounds bounds = new Bounds(transform.transform.InverseTransformPoint(meshRenderers[0].bounds.center), - transform.transform.InverseTransformVector(meshRenderers[0].bounds.size)); - - // 遍历所有 MeshRenderer,合并包围盒 - for (int i = 1; i < meshRenderers.Length; i++) - { - Bounds localBounds = meshRenderers[i].bounds; - Vector3 localCenter = transform.transform.InverseTransformPoint(localBounds.center); - Vector3 localSize = transform.transform.InverseTransformVector(localBounds.size); - - bounds.Encapsulate(new Bounds(localCenter, localSize)); - } - - // 设置 BoxCollider 的中心和大小 - boxCollider.center = bounds.center; - boxCollider.size = bounds.size; - - EditorUtility.SetDirty(boxCollider); } + } } } \ No newline at end of file diff --git a/Src/UnityPluginsSupport/MonkeyCommand/QuickFixFloatModel.cs b/Src/UnityPluginsSupport/MonkeyCommand/QuickFixFloatModel.cs index 5b02064..274118f 100644 --- a/Src/UnityPluginsSupport/MonkeyCommand/QuickFixFloatModel.cs +++ b/Src/UnityPluginsSupport/MonkeyCommand/QuickFixFloatModel.cs @@ -19,7 +19,7 @@ namespace BITKit.GameEditor reportBuilder.AppendLine($"已选择{transforms.Length}个物体:"); foreach (var x in transforms) { - if (Physics.Raycast(x.position, Vector3.down, out var hit, 1000) is false) continue; + if (UnityEngine.Physics.Raycast(x.position, Vector3.down, out var hit, 1000) is false) continue; x.position = hit.point; EditorUtility.SetDirty(x); reportBuilder.AppendLine($"已修复{x.name}的位置于{hit.point}");