(changed: ComponentChanged, count?: number)
| 127 | } |
| 128 | } |
| 129 | async add(changed: ComponentChanged, count?: number) { |
| 130 | const component = changed.component as Spine; |
| 131 | clearTimeout(component.addHandler); |
| 132 | const gameObjectId = changed.gameObject.id; |
| 133 | const asyncId = this.increaseAsyncId(gameObjectId); |
| 134 | const res = await resource.getResource(component.resource); |
| 135 | if (!this.validateAsyncId(gameObjectId, asyncId)) return; |
| 136 | const spineData = await getSpineData(res, component.scale, this.pixiSpine); |
| 137 | if (!this.validateAsyncId(gameObjectId, asyncId)) return; |
| 138 | if (!spineData) { |
| 139 | component.addHandler = setTimeout(() => { |
| 140 | if (!component.destroied) { |
| 141 | if (count === undefined) { |
| 142 | // 最大重试次数 |
| 143 | count = MaxRetryCount; |
| 144 | } |
| 145 | count--; |
| 146 | if (count > 0) { |
| 147 | this.add(changed, count); |
| 148 | } else { |
| 149 | console.log('retry exceed max times', component.resource); |
| 150 | } |
| 151 | } |
| 152 | }, 1000); |
| 153 | return; |
| 154 | } |
| 155 | this.remove(changed); |
| 156 | const container = this.renderSystem?.containerManager?.getContainer(changed.gameObject.id); |
| 157 | if (!container) { |
| 158 | // console.warn('添加spine的container不存在'); |
| 159 | return; |
| 160 | } |
| 161 | component.lastResource = component.resource; |
| 162 | // @ts-ignore |
| 163 | const armature: any = new this.pixiSpine.Spine({ |
| 164 | skeletonData: spineData, |
| 165 | autoUpdate: false, |
| 166 | }); |
| 167 | |
| 168 | this.armatures[changed.gameObject.id] = armature; |
| 169 | this._spineComponents[changed.gameObject.id] = component; |
| 170 | if (changed.gameObject && changed.gameObject.transform) { |
| 171 | const tran = changed.gameObject.transform; |
| 172 | armature.x = tran.size.width * tran.origin.x; |
| 173 | armature.y = tran.size.height * tran.origin.y; |
| 174 | } |
| 175 | |
| 176 | container.addChildAt(armature, 0); |
| 177 | /** 保证第一帧显示正常 */ |
| 178 | armature.update(); |
| 179 | component._containerManager = this.renderSystem?.containerManager; |
| 180 | component.armature = armature; |
| 181 | // @ts-ignore |
| 182 | component.emit('loaded', { resource: component.resource }); |
| 183 | armature.state.addListener({ |
| 184 | // @ts-ignore |
| 185 | start: (track, event) => { |
| 186 | component.emit('start', { track, name: track.animation.name }); |
no test coverage detected