diff --git a/Assets/Scenes/Test.unity b/Assets/Scenes/Test.unity index 3acacec..4015dc0 100644 --- a/Assets/Scenes/Test.unity +++ b/Assets/Scenes/Test.unity @@ -820,6 +820,74 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: ddd89e93db279184daa80d86bd4e770f, type: 3} +--- !u!1001 &606358046 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalPosition.x + value: 20 + objectReference: {fileID: 0} + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalPosition.y + value: 0.8 + objectReference: {fileID: 0} + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalPosition.z + value: -5 + objectReference: {fileID: 0} + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2356242250385391551, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6227019518059310355, guid: be07db3098b709a40a6965f50f8c9640, + type: 3} + propertyPath: m_Name + value: Lever (9) + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: be07db3098b709a40a6965f50f8c9640, type: 3} --- !u!1001 &627238400 PrefabInstance: m_ObjectHideFlags: 0 @@ -2666,6 +2734,26 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 7351527485767933101, guid: dbf59764203ca4645a295e650a306b7b, + type: 3} + propertyPath: fixedScale.x + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 7351527485767933101, guid: dbf59764203ca4645a295e650a306b7b, + type: 3} + propertyPath: fixedScale.y + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 7351527485767933101, guid: dbf59764203ca4645a295e650a306b7b, + type: 3} + propertyPath: fixedScale.z + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 7351527485767933101, guid: dbf59764203ca4645a295e650a306b7b, + type: 3} + propertyPath: overridePrefabScale + value: 1 + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] @@ -3357,6 +3445,7 @@ SceneRoots: - {fileID: 473911345} - {fileID: 865274353} - {fileID: 6350903300567888677} + - {fileID: 606358046} - {fileID: 346781470} - {fileID: 817379214} - {fileID: 439165101} diff --git a/Assets/Script/Gameplay/Facility/EmitterController.cs b/Assets/Script/Gameplay/Facility/EmitterController.cs index ddb1b36..0fdc005 100644 --- a/Assets/Script/Gameplay/Facility/EmitterController.cs +++ b/Assets/Script/Gameplay/Facility/EmitterController.cs @@ -19,6 +19,14 @@ namespace Script.Gameplay.Facility [Header("生成对象销毁时间")] [SerializeField] private float destroyDelay = 5f; // 生成对象多少秒后销毁 + // 新增:发射物缩放设置 + [Header("发射物缩放")] + [SerializeField] private bool overridePrefabScale = false; // 是否覆盖预制体原始缩放 + [SerializeField] private Vector3 fixedScale = Vector3.one; // 固定缩放 + [SerializeField] private bool randomizeScale = false; // 是否随机缩放 + [SerializeField] private Vector3 minScale = Vector3.one; // 随机最小值(每轴) + [SerializeField] private Vector3 maxScale = Vector3.one; // 随机最大值(每轴) + private Coroutine emitCoroutine; private void Start() @@ -62,6 +70,13 @@ namespace Script.Gameplay.Facility { if (prefabToEmit == null || emitPoint == null) return; var obj = Instantiate(prefabToEmit, emitPoint.position, emitPoint.rotation); + + // 应用缩放设置 + if (overridePrefabScale) + { + obj.transform.localScale = ComputeEmitScale(obj.transform.localScale); + } + var rb = obj.GetComponent(); if (rb != null) { @@ -70,5 +85,33 @@ namespace Script.Gameplay.Facility // 添加销毁逻辑 Destroy(obj, destroyDelay); } + + // 计算要应用的缩放(考虑固定/随机,并保证 min<=max) + private Vector3 ComputeEmitScale(Vector3 prefabScale) + { + if (!overridePrefabScale) + return prefabScale; + + if (!randomizeScale) + return fixedScale; + + // 确保 min <= max 各轴 + Vector3 minV = new Vector3( + Mathf.Min(minScale.x, maxScale.x), + Mathf.Min(minScale.y, maxScale.y), + Mathf.Min(minScale.z, maxScale.z) + ); + Vector3 maxV = new Vector3( + Mathf.Max(minScale.x, maxScale.x), + Mathf.Max(minScale.y, maxScale.y), + Mathf.Max(minScale.z, maxScale.z) + ); + + return new Vector3( + UnityEngine.Random.Range(minV.x, maxV.x), + UnityEngine.Random.Range(minV.y, maxV.y), + UnityEngine.Random.Range(minV.z, maxV.z) + ); + } } }