From ab403fac4b0fe78795e3834a6eedaced0a9a5996 Mon Sep 17 00:00:00 2001 From: GanX <2423855310@qq.com> Date: Sat, 18 Oct 2025 11:56:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(Rigidbody=20Collider):=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=8F=AF=E7=BC=96=E8=BE=91=E7=9A=84Rigidbody=20?= =?UTF-8?q?=E5=92=8C=20Collider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Prefab/Gameplay/Facility.prefab | 173 ++---------------- Assets/Scenes/Level1.unity | 45 +---- .../Facility/ColliderEditableController.cs | 44 +++++ .../ColliderEditableController.cs.meta | 3 + .../Facility/RigidbodyEditableController.cs | 42 +++++ .../RigidbodyEditableController.cs.meta | 3 + 6 files changed, 109 insertions(+), 201 deletions(-) create mode 100644 Assets/Script/Gameplay/Facility/ColliderEditableController.cs create mode 100644 Assets/Script/Gameplay/Facility/ColliderEditableController.cs.meta create mode 100644 Assets/Script/Gameplay/Facility/RigidbodyEditableController.cs create mode 100644 Assets/Script/Gameplay/Facility/RigidbodyEditableController.cs.meta diff --git a/Assets/Prefab/Gameplay/Facility.prefab b/Assets/Prefab/Gameplay/Facility.prefab index 7c41279..45bf3d3 100644 --- a/Assets/Prefab/Gameplay/Facility.prefab +++ b/Assets/Prefab/Gameplay/Facility.prefab @@ -1,80 +1,5 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &1285331887159970702 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 7491258034527094893} - - component: {fileID: 6262235791141659756} - - component: {fileID: 2577312867888845904} - m_Layer: 8 - m_Name: Panel - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &7491258034527094893 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1285331887159970702} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 1 - m_Children: [] - m_Father: {fileID: 6937855010132688348} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!222 &6262235791141659756 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1285331887159970702} - m_CullTransparentMesh: 1 ---- !u!114 &2577312867888845904 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1285331887159970702} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 0.392} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0} - m_Type: 1 - m_PreserveAspect: 0 - m_FillCenter: 1 - m_FillMethod: 4 - m_FillAmount: 1 - m_FillClockwise: 1 - m_FillOrigin: 0 - m_UseSpriteMesh: 0 - m_PixelsPerUnitMultiplier: 1 --- !u!1 &2729643726423589850 GameObject: m_ObjectHideFlags: 0 @@ -88,6 +13,8 @@ GameObject: - component: {fileID: 1791426126632920350} - component: {fileID: 6559594074799131378} - component: {fileID: 2740601845815088892} + - component: {fileID: 605469399670797709} + - component: {fileID: 6634784627554641663} m_Layer: 0 m_Name: Facility m_TagString: Untagged @@ -105,11 +32,10 @@ Transform: serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0.71, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalScale: {x: 1.9314, y: 2.3882, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1088716417574490523} - - {fileID: 6937855010132688348} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!33 &1966939443082034528 @@ -195,108 +121,33 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7986c88b8e1d4944832af56e23188597, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!1 &7518175844631896712 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 6937855010132688348} - - component: {fileID: 5901253883046461237} - - component: {fileID: 6141736885575726030} - - component: {fileID: 4792260559798747556} - m_Layer: 8 - m_Name: Canvas - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &6937855010132688348 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7518175844631896712} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0.001, y: 0.001, z: 0.001} - m_ConstrainProportionsScale: 1 - m_Children: - - {fileID: 7491258034527094893} - m_Father: {fileID: 77361986880837193} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 1000, y: 1000} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!223 &5901253883046461237 -Canvas: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7518175844631896712} - m_Enabled: 1 - serializedVersion: 3 - m_RenderMode: 2 - m_Camera: {fileID: 0} - m_PlaneDistance: 100 - m_PixelPerfect: 0 - m_ReceivesEvents: 1 - m_OverrideSorting: 0 - m_OverridePixelPerfect: 0 - m_SortingBucketNormalizedSize: 0 - m_VertexColorAlwaysGammaSpace: 0 - m_AdditionalShaderChannelsFlag: 0 - m_UpdateRectTransformForStandalone: 0 - m_SortingLayerID: 0 - m_SortingOrder: 0 - m_TargetDisplay: 0 ---- !u!114 &6141736885575726030 +--- !u!114 &605469399670797709 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7518175844631896712} + m_GameObject: {fileID: 2729643726423589850} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} + m_Script: {fileID: 11500000, guid: 3bdc5380046d4cacb0dd579877f320eb, type: 3} m_Name: m_EditorClassIdentifier: - m_UiScaleMode: 0 - m_ReferencePixelsPerUnit: 100 - m_ScaleFactor: 1 - m_ReferenceResolution: {x: 800, y: 600} - m_ScreenMatchMode: 0 - m_MatchWidthOrHeight: 0 - m_PhysicalUnit: 3 - m_FallbackScreenDPI: 96 - m_DefaultSpriteDPI: 96 - m_DynamicPixelsPerUnit: 10 - m_PresetInfoIsWorld: 1 ---- !u!114 &4792260559798747556 + Interactable: 1 + isActive: 1 +--- !u!114 &6634784627554641663 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7518175844631896712} + m_GameObject: {fileID: 2729643726423589850} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} + m_Script: {fileID: 11500000, guid: 2791e039b8344f45ad6dc86f5188d82d, type: 3} m_Name: m_EditorClassIdentifier: - m_IgnoreReversedGraphics: 1 - m_BlockingObjects: 0 - m_BlockingMask: - serializedVersion: 2 - m_Bits: 4294967295 + isActive: 1 --- !u!1 &8100744246927696703 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Level1.unity b/Assets/Scenes/Level1.unity index 46f7e52..7442d3f 100644 --- a/Assets/Scenes/Level1.unity +++ b/Assets/Scenes/Level1.unity @@ -347,26 +347,6 @@ MonoBehaviour: m_LightCookieSize: {x: 1, y: 1} m_LightCookieOffset: {x: 0, y: 0} m_SoftShadowQuality: 1 ---- !u!1 &431100842 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 2729643726423589850, guid: b3e24e2df98d14e4ebc08cc68c071afa, - type: 3} - m_PrefabInstance: {fileID: 2088331975902746738} - m_PrefabAsset: {fileID: 0} ---- !u!114 &431100848 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 431100842} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3bdc5380046d4cacb0dd579877f320eb, type: 3} - m_Name: - m_EditorClassIdentifier: - Interactable: 1 - lockLevel: 0 --- !u!1001 &769057572 PrefabInstance: m_ObjectHideFlags: 0 @@ -1250,12 +1230,12 @@ PrefabInstance: - target: {fileID: 77361986880837193, guid: b3e24e2df98d14e4ebc08cc68c071afa, type: 3} propertyPath: m_LocalPosition.x - value: 0 + value: -0.4657 objectReference: {fileID: 0} - target: {fileID: 77361986880837193, guid: b3e24e2df98d14e4ebc08cc68c071afa, type: 3} propertyPath: m_LocalPosition.y - value: 0.71 + value: 1.4041 objectReference: {fileID: 0} - target: {fileID: 77361986880837193, guid: b3e24e2df98d14e4ebc08cc68c071afa, type: 3} @@ -1297,30 +1277,15 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 1285331887159970702, guid: b3e24e2df98d14e4ebc08cc68c071afa, - type: 3} - propertyPath: m_Layer - value: 8 - objectReference: {fileID: 0} - target: {fileID: 2729643726423589850, guid: b3e24e2df98d14e4ebc08cc68c071afa, type: 3} propertyPath: m_Name - value: Facility - objectReference: {fileID: 0} - - target: {fileID: 7518175844631896712, guid: b3e24e2df98d14e4ebc08cc68c071afa, - type: 3} - propertyPath: m_Layer - value: 8 + value: Door objectReference: {fileID: 0} m_RemovedComponents: [] - m_RemovedGameObjects: - - {fileID: 7518175844631896712, guid: b3e24e2df98d14e4ebc08cc68c071afa, type: 3} + m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 2729643726423589850, guid: b3e24e2df98d14e4ebc08cc68c071afa, - type: 3} - insertIndex: -1 - addedObject: {fileID: 431100848} + m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: b3e24e2df98d14e4ebc08cc68c071afa, type: 3} --- !u!1001 &7020889523296792185 PrefabInstance: diff --git a/Assets/Script/Gameplay/Facility/ColliderEditableController.cs b/Assets/Script/Gameplay/Facility/ColliderEditableController.cs new file mode 100644 index 0000000..d1799bd --- /dev/null +++ b/Assets/Script/Gameplay/Facility/ColliderEditableController.cs @@ -0,0 +1,44 @@ +using UnityEngine; + +namespace Script.Gameplay.Facility +{ + [RequireComponent(typeof(Collider))] + public class ColliderEditableController : MonoBehaviour, IEditableComponent + { + [SerializeField] private bool isActive = true; + + public bool IsActive + { + get => isActive; + set + { + isActive = value; + // 具体被编辑的逻辑:开启或关闭碰撞体 + if (_collider != null) + _collider.enabled = isActive; + } + } + + public string ComponentName { get; set; } = "Collider"; + public LockLevel LockLevel { get; } = LockLevel.Red; + + private Collider _collider; + + private void Awake() + { + _collider = GetComponent(); + // 应用序列化的初始状态 + _collider.enabled = isActive; + } + +#if UNITY_EDITOR + private void OnValidate() + { + // 在编辑器中即时生效 + _collider = _collider == null ? GetComponent() : _collider; + if (_collider != null) + _collider.enabled = isActive; + } +#endif + } +} \ No newline at end of file diff --git a/Assets/Script/Gameplay/Facility/ColliderEditableController.cs.meta b/Assets/Script/Gameplay/Facility/ColliderEditableController.cs.meta new file mode 100644 index 0000000..8671256 --- /dev/null +++ b/Assets/Script/Gameplay/Facility/ColliderEditableController.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2791e039b8344f45ad6dc86f5188d82d +timeCreated: 1760758233 \ No newline at end of file diff --git a/Assets/Script/Gameplay/Facility/RigidbodyEditableController.cs b/Assets/Script/Gameplay/Facility/RigidbodyEditableController.cs new file mode 100644 index 0000000..dfae632 --- /dev/null +++ b/Assets/Script/Gameplay/Facility/RigidbodyEditableController.cs @@ -0,0 +1,42 @@ +using UnityEngine; + +namespace Script.Gameplay.Facility +{ + [RequireComponent(typeof(Rigidbody))] + public class RigidbodyEditableController : MonoBehaviour, IEditableComponent + { + [SerializeField] private bool isActive = true; + + public bool IsActive + { + get => isActive; + set + { + isActive = value; + //具体被编辑的逻辑 + _rigidbody.isKinematic = isActive; + } + } + + public string ComponentName { get; set; } = "Rigidbody"; + public LockLevel LockLevel { get; } = LockLevel.Red; + private Rigidbody _rigidbody; + + private void Awake() + { + _rigidbody = GetComponent(); + //应用序列化的初始状态 + _rigidbody.isKinematic = isActive; + } + +#if UNITY_EDITOR + private void OnValidate() + { + //在编辑器中即时生效 + _rigidbody = _rigidbody == null ? GetComponent() : _rigidbody; + if (_rigidbody != null) + _rigidbody.isKinematic = isActive; + } +#endif + } +} \ No newline at end of file diff --git a/Assets/Script/Gameplay/Facility/RigidbodyEditableController.cs.meta b/Assets/Script/Gameplay/Facility/RigidbodyEditableController.cs.meta new file mode 100644 index 0000000..55cd6e6 --- /dev/null +++ b/Assets/Script/Gameplay/Facility/RigidbodyEditableController.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 06015834a0da4561ba47d104b73171a4 +timeCreated: 1760757148 \ No newline at end of file