子发射器
This commit is contained in:
1 parent
d4ebb18777
commit
d224939efd
33 files changed
+5690
-1355
No files matched your search
@@ -232,6 +232,8 @@ export function defaultConfig(): EmitterConfig {
|
||||
collision: false,
|
||||
collisionColliderIds: [],
|
||||
pathFollow: false,
|
||||
eventEnabled: false,
|
||||
events: [],
|
||||
emitterFollow: false,
|
||||
emitterFollowMode: 'none',
|
||||
emitterFollowPathId: 0,
|
||||
@@ -306,6 +308,38 @@ export function ensureEmitterConfig(config: EmitterConfig): EmitterConfig {
|
||||
if (typeof config.renderLayerSlotName !== 'string') config.renderLayerSlotName = ''
|
||||
if (config.renderLayerSlotPosition !== 'above' && config.renderLayerSlotPosition !== 'below') config.renderLayerSlotPosition = 'above'
|
||||
if (typeof config.renderLayerFollowAttachment !== 'boolean') config.renderLayerFollowAttachment = false
|
||||
if (typeof config.eventEnabled !== 'boolean') config.eventEnabled = false
|
||||
if (!Array.isArray(config.events)) config.events = []
|
||||
for (const rule of config.events) {
|
||||
rule.id = Math.max(1, Math.round(Number(rule.id) || 1))
|
||||
if (rule.event !== 'birth' && rule.event !== 'death' && rule.event !== 'collision') rule.event = 'birth'
|
||||
rule.targetSystemId = Math.max(0, Math.round(Number(rule.targetSystemId) || 0))
|
||||
const probability = Number(rule.probability)
|
||||
rule.probability = Math.min(1, Math.max(0, Number.isFinite(probability) ? probability : 1))
|
||||
const collisionLimit = Math.round(Number(rule.collisionLimit))
|
||||
rule.collisionLimit = Math.min(4, Math.max(1, Number.isFinite(collisionLimit) ? collisionLimit : 1))
|
||||
// 旧版本 inherit 是单字符串;统一迁移为可多选的属性数组。
|
||||
const legacyInherit = rule.inherit as unknown
|
||||
const allowedInherit = ['color', 'scale', 'rotation', 'life']
|
||||
const inheritList = Array.isArray(legacyInherit)
|
||||
? legacyInherit
|
||||
: legacyInherit === 'all'
|
||||
? [...allowedInherit]
|
||||
: allowedInherit.includes(String(legacyInherit))
|
||||
? [String(legacyInherit)]
|
||||
: []
|
||||
const normalizedInherit = [...new Set(inheritList.filter((name) => allowedInherit.includes(String(name))))] as typeof rule.inherit
|
||||
// 只有值确实变化时才写回;ensureEmitterConfig 每帧都会调用,重复赋新数组会触发无限响应式更新。
|
||||
const currentInherit = Array.isArray(legacyInherit) ? legacyInherit : null
|
||||
if (
|
||||
!currentInherit
|
||||
|| currentInherit.length !== normalizedInherit.length
|
||||
|| normalizedInherit.some((name, index) => name !== currentInherit[index])
|
||||
) {
|
||||
rule.inherit = normalizedInherit
|
||||
}
|
||||
if (rule.colorInheritMode !== 'add' && rule.colorInheritMode !== 'replace') rule.colorInheritMode = 'add'
|
||||
}
|
||||
config.innerRadius = Math.max(0, Number(config.innerRadius) || 0)
|
||||
config.outerRadius = Math.max(config.innerRadius, Number(config.outerRadius) || 0)
|
||||
config.innerRectW = Math.max(0, Number(config.innerRectW) || 0)
|
||||
|
||||
Reference in new issue
Block a user