Forráskód Böngészése

解决先移动后加载皮服问题

181404010226 2 hete
szülő
commit
fe4e737c44

+ 1 - 1
assets/Data/测试关卡1.json

@@ -28,7 +28,7 @@
       "characterId": 3,
       "characterName": "角色3",
       "skinId": 1,
-      "skinName": "3",
+      "skinName": "girl4",
       "qaPairs": [
         {
           "question": "你是谁?",

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
assets/resources/03/3.json


+ 28 - 4
assets/scripts/CharacterManager.ts

@@ -61,8 +61,9 @@ export class CharacterManager extends Component {
      * 设置角色外观
      * @param characterId 角色ID
      * @param skinName 皮肤名称
+     * @param onComplete 外观设置完成后的回调函数
      */
-    public setupCharacterAppearance(characterId: number, skinName: string): void {
+    public setupCharacterAppearance(characterId: number, skinName: string, onComplete?: () => void): void {
         if (!this.characterNode) {
             console.error('人物节点未设置');
             return;
@@ -90,6 +91,11 @@ export class CharacterManager extends Component {
                 skeletonComponent.setAnimation(0, 'loop', true);
               
                 console.log(`设置角色: ${characterId}, 皮肤: ${skinName}`);
+                
+                // 如果有回调函数,则在设置完成后调用
+                if (onComplete) {
+                    onComplete();
+                }
             } else {
                 console.error('人物节点上没有sp.Skeleton组件');
             }
@@ -98,8 +104,9 @@ export class CharacterManager extends Component {
 
     /**
      * 人物移动到右侧(放行)
+     * @param onComplete 移动完成后的回调函数
      */
-    public moveCharacterRight(): void {
+    public moveCharacterRight(onComplete?: () => void): void {
         if (!this.characterNode || !this.initialPosition) return;
 
         // 隐藏对话框
@@ -125,14 +132,20 @@ export class CharacterManager extends Component {
             .call(() => {
                 // 动画完成回调
                 this.currentAnimation = null;
+                
+                // 如果有完成回调则执行
+                if (onComplete) {
+                    onComplete();
+                }
             })
             .start();
     }
 
     /**
      * 人物移动到左侧(赶走)
+     * @param onComplete 移动完成后的回调函数
      */
-    public moveCharacterLeft(): void {
+    public moveCharacterLeft(onComplete?: () => void): void {
         if (!this.characterNode || !this.initialPosition) return;
 
         // 隐藏对话框
@@ -158,14 +171,20 @@ export class CharacterManager extends Component {
             .call(() => {
                 // 动画完成回调
                 this.currentAnimation = null;
+                
+                // 如果有完成回调则执行
+                if (onComplete) {
+                    onComplete();
+                }
             })
             .start();
     }
 
     /**
      * 新人物从左向右进入
+     * @param onComplete 移动完成后的回调函数
      */
-    public characterEnter(): void {
+    public characterEnter(onComplete?: () => void): void {
         console.log('characterEnter');
         if (!this.characterNode) return;
 
@@ -193,6 +212,11 @@ export class CharacterManager extends Component {
             .call(() => {
                 // 动画完成回调
                 this.currentAnimation = null;
+                
+                // 如果有完成回调则执行
+                if (onComplete) {
+                    onComplete();
+                }
             })
             .start();
     }

+ 14 - 20
assets/scripts/GameFlowManager.ts

@@ -110,17 +110,17 @@ export class GameFlowManager extends Component {
         // 获取当前NPC数据
         const npc = this.currentNpcs[this.currentNpcIndex];
         
-        // 配置角色外观
-        this.characterManager.setupCharacterAppearance(npc.characterId, npc.skinName);
-        
         // 配置问答对
         this.setupQuestionAnswers(npc.qaPairs);
         
-        // 让角色入场
-        this.characterManager.characterEnter();
-        
-        // 启用按钮
-        this.enableButtons();
+        // 配置角色外观,并在完成后让角色入场
+        this.characterManager.setupCharacterAppearance(npc.characterId, npc.skinName, () => {
+            // 让角色入场(只有在外观设置完成后才执行)
+            this.characterManager.characterEnter();
+            
+            // 启用按钮
+            this.enableButtons();
+        });
     }
 
     /**
@@ -170,13 +170,10 @@ export class GameFlowManager extends Component {
         // 禁用按钮,防止连续点击
         this.disableButtons();
         
-        // 让角色向右移动
-        this.characterManager.moveCharacterRight();
-        
-        // 延迟显示下一个NPC
-        this.scheduleOnce(() => {
+        // 让角色向右移动,动画完成后显示下一个NPC
+        this.characterManager.moveCharacterRight(() => {
             this.showNextNpc();
-        }, this.characterManager.moveDuration + 0.5);
+        });
     }
 
     /**
@@ -186,13 +183,10 @@ export class GameFlowManager extends Component {
         // 禁用按钮,防止连续点击
         this.disableButtons();
         
-        // 让角色向左移动
-        this.characterManager.moveCharacterLeft();
-        
-        // 延迟显示下一个NPC
-        this.scheduleOnce(() => {
+        // 让角色向左移动,动画完成后显示下一个NPC
+        this.characterManager.moveCharacterLeft(() => {
             this.showNextNpc();
-        }, this.characterManager.moveDuration + 0.5);
+        });
     }
 
     /**

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott