feat(Emit): 为发射器添加缩放配置
This commit is contained in:
@@ -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<Rigidbody>();
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user