diff --git a/Assets/Prefab/Gameplay/Transport.prefab b/Assets/Prefab/Gameplay/Transport.prefab new file mode 100644 index 0000000..0a5476a --- /dev/null +++ b/Assets/Prefab/Gameplay/Transport.prefab @@ -0,0 +1,213 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4586191190057152116 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2431062606015710943} + m_Layer: 0 + m_Name: EmitPoint + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2431062606015710943 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4586191190057152116} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 1.31} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 8254182874643487870} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &6116921146274042770 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8009085288281141996} + m_Layer: 0 + m_Name: Destination + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &8009085288281141996 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6116921146274042770} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 8254182874643487870} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &6314903437700050095 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8254182874643487870} + - component: {fileID: 4974785209253217424} + - component: {fileID: 6341273798996869822} + - component: {fileID: 4491785711269447504} + - component: {fileID: 1364031631549404635} + - component: {fileID: 1226289750762660579} + m_Layer: 0 + m_Name: Transport + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &8254182874643487870 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6314903437700050095} + serializedVersion: 2 + 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: 0 + m_Children: + - {fileID: 2431062606015710943} + - {fileID: 8009085288281141996} + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &4974785209253217424 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6314903437700050095} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &6341273798996869822 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6314903437700050095} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!65 &4491785711269447504 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6314903437700050095} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!114 &1364031631549404635 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6314903437700050095} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2791e039b8344f45ad6dc86f5188d82d, type: 3} + m_Name: + m_EditorClassIdentifier: + isEnableEdit: 1 + isOpenInEditor: 1 +--- !u!114 &1226289750762660579 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6314903437700050095} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b50e39be24c44a0fb72155c7f797dbca, type: 3} + m_Name: + m_EditorClassIdentifier: + isEnableInteract: 0 + isEnableEdit: 1 + isEnableConnect: 1 + componentName: + needSignalCount: 1 + isOpenInEditor: 1 + destinationPoint: {fileID: 8009085288281141996} + playerTag: Player + transportDelay: 0.1 + detectRadius: 1 + detectHeight: 2 + playerLayer: + serializedVersion: 2 + m_Bits: 256 diff --git a/Assets/Prefab/Gameplay/Transport.prefab.meta b/Assets/Prefab/Gameplay/Transport.prefab.meta new file mode 100644 index 0000000..f0fbd55 --- /dev/null +++ b/Assets/Prefab/Gameplay/Transport.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5b168380fd354a64f83433e049b95706 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Test.unity b/Assets/Scenes/Test.unity index d6cce81..288054b 100644 --- a/Assets/Scenes/Test.unity +++ b/Assets/Scenes/Test.unity @@ -204,6 +204,18 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3bdc5380046d4cacb0dd579877f320eb, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &279470472 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 7403824303730881351, guid: 5ee760c56bad73f48a453ce5657e05b8, + type: 3} + m_PrefabInstance: {fileID: 2578337202726380610} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 115d4e847c444833bc8dce4a03a78e55, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &410087039 GameObject: m_ObjectHideFlags: 0 @@ -1423,6 +1435,11 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 3535959014221630543, guid: 85652dd0e36597644aa5b3bc9603797b, + type: 3} + propertyPath: controlTarget.Array.data[0] + value: + objectReference: {fileID: 279470472} - target: {fileID: 6268190613584218029, guid: 85652dd0e36597644aa5b3bc9603797b, type: 3} propertyPath: m_Name @@ -1977,6 +1994,74 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: be07db3098b709a40a6965f50f8c9640, type: 3} +--- !u!1001 &6865129841946316189 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 6314903437700050095, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_Name + value: Transport + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalPosition.x + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalPosition.y + value: 0.18 + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8254182874643487870, guid: 5b168380fd354a64f83433e049b95706, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 5b168380fd354a64f83433e049b95706, type: 3} --- !u!1001 &7020889523296792185 PrefabInstance: m_ObjectHideFlags: 0 @@ -1990,6 +2075,11 @@ PrefabInstance: propertyPath: m_Name value: Player objectReference: {fileID: 0} + - target: {fileID: 3550102669167288263, guid: 667aedb0d3f8c9d469819c9ff2b4472b, + type: 3} + propertyPath: m_Layer + value: 8 + objectReference: {fileID: 0} - target: {fileID: 7437893023972897012, guid: 667aedb0d3f8c9d469819c9ff2b4472b, type: 3} propertyPath: m_LocalPosition.x @@ -2147,6 +2237,7 @@ SceneRoots: - {fileID: 993640446} - {fileID: 2032802597} - {fileID: 4550639332017178188} + - {fileID: 6865129841946316189} - {fileID: 2578337202726380610} - {fileID: 1781028406820323425} - {fileID: 1035971231385273297} diff --git a/Assets/Script/Gameplay/Facility/PressurePlateController.cs b/Assets/Script/Gameplay/Facility/PressurePlateController.cs index 1fca97d..740c547 100644 --- a/Assets/Script/Gameplay/Facility/PressurePlateController.cs +++ b/Assets/Script/Gameplay/Facility/PressurePlateController.cs @@ -14,7 +14,7 @@ namespace Script.Gameplay.Facility private void FixedUpdate() { - if (!isEnableInteract) return; + if (!isOpenInEditor) return; bool hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity, detectLayer); if (hasObject != lastState) { diff --git a/Assets/Script/Gameplay/Facility/TransportController.cs b/Assets/Script/Gameplay/Facility/TransportController.cs new file mode 100644 index 0000000..7a66bc9 --- /dev/null +++ b/Assets/Script/Gameplay/Facility/TransportController.cs @@ -0,0 +1,83 @@ +using System; +using UnityEngine; + +namespace Script.Gameplay.Facility +{ + public class TransportController : BaseFacilityController + { + [Header("传送器设置")] + [SerializeField] private Transform destinationPoint; + [SerializeField] private string playerTag = "Player"; + [SerializeField] private float transportDelay = 0.1f; + + [Header("检测区域参数")] + [SerializeField] private float detectRadius = 1.0f; + [SerializeField] private float detectHeight = 2.0f; + [SerializeField] private LayerMask playerLayer; + + private bool canTransport = false; + private bool isTransporting = false; + private Collider[] hits; + + // 接收信号,决定是否允许传送 + public override void OnSignalReceived(bool active, GameObject sender) + { + base.OnSignalReceived(active, sender); + canTransport = active; + } + + // Update is called once per frame + private void FixedUpdate() + { + if (!isOpenInEditor || !canTransport || destinationPoint == null) return; + hits = Physics.OverlapCapsule( + GetCapsuleStart(), GetCapsuleEnd(), detectRadius, playerLayer); + } + + private void Update() + { + if (!isOpenInEditor || !canTransport || destinationPoint == null || hits == null) return; + foreach (var hit in hits) + { + if (hit.CompareTag(playerTag) && !isTransporting) + { + StartCoroutine(TransportPlayer(hit.gameObject)); + break; + } + } + } + + private Vector3 GetCapsuleStart() + { + return transform.position + Vector3.up * 0.1f; + } + + private Vector3 GetCapsuleEnd() + { + return transform.position + Vector3.up * detectHeight; + } + + private System.Collections.IEnumerator TransportPlayer(GameObject player) + { + isTransporting = true; + yield return new WaitForSeconds(transportDelay); + player.transform.position = destinationPoint.position; + isTransporting = false; + } + +#if UNITY_EDITOR + private void OnDrawGizmosSelected() + { + Gizmos.color = Color.cyan; + Vector3 start = GetCapsuleStart(); + Vector3 end = GetCapsuleEnd(); + Gizmos.DrawWireSphere(start, detectRadius); + Gizmos.DrawWireSphere(end, detectRadius); + Gizmos.DrawLine(start + Vector3.forward * detectRadius, end + Vector3.forward * detectRadius); + Gizmos.DrawLine(start - Vector3.forward * detectRadius, end - Vector3.forward * detectRadius); + Gizmos.DrawLine(start + Vector3.right * detectRadius, end + Vector3.right * detectRadius); + Gizmos.DrawLine(start - Vector3.right * detectRadius, end - Vector3.right * detectRadius); + } +#endif + } +} \ No newline at end of file diff --git a/Assets/Script/Gameplay/Facility/TransportController.cs.meta b/Assets/Script/Gameplay/Facility/TransportController.cs.meta new file mode 100644 index 0000000..dfca900 --- /dev/null +++ b/Assets/Script/Gameplay/Facility/TransportController.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b50e39be24c44a0fb72155c7f797dbca +timeCreated: 1761181787 \ No newline at end of file