Browse Source

feat:优化人物点击

zouwuqiang 2 năm trước cách đây
mục cha
commit
48cfe0fbc9

+ 1 - 1
assets/script/game/account/bll/AccountInit.ts

@@ -49,7 +49,7 @@ export class AccountInitSystem extends ecs.ComblockSystem implements ecs.IEntity
 
         // 关卡等级数据
         level.upgrade(data.lv);
-
+        
         e.checkpoint = level;
         e.addChild(level)
     }

+ 7 - 5
assets/script/game/checkpoint/view/CheckpointViewComp.ts

@@ -1,6 +1,8 @@
 import { _decorator } from "cc";
 import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
 import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
+import { Checkpoint } from "../Checkpoint";
+import { CheckpointViewController } from "./CheckpointViewController";
 
 const { ccclass, property } = _decorator;
 
@@ -13,12 +15,12 @@ export class CheckpointViewComp extends CCComp {
     // loader: RoleViewLoader = null!;
     // /** 角色动画规则管理 */
     // animator: RoleViewAnimator = null!;
-    // /** 角色控制器 */
-    // controller: RoleViewController = null!;
+    /** 关卡控制器 */
+    controller: CheckpointViewController = null!;
 
     /** 视图层逻辑代码分离演示 */
     onLoad() {
-        // var checkpoint = this.ent as Checkpoint;
+        const checkpoint = this.ent as Checkpoint;
 
         // this.loader = this.node.addComponent(RoleViewLoader);
         // this.node.emit("load", role);
@@ -26,8 +28,8 @@ export class CheckpointViewComp extends CCComp {
         // this.animator = this.spine.getComponent(RoleViewAnimator)!;
         // this.animator.role = role;
 
-        // this.controller = this.node.addComponent(RoleViewController);
-        // this.controller.role = role;
+        this.controller = this.node.addComponent(CheckpointViewController);
+        this.controller.checkpoint = checkpoint;
 
         // this.on(RoleEvent.ChangeJob, this.onHandler, this);
     }

+ 48 - 0
assets/script/game/checkpoint/view/CheckpointViewController.ts

@@ -0,0 +1,48 @@
+import { Component, _decorator, Node, EventTouch, systemEvent, input, Input, geometry, Camera, PhysicsSystem, director, v3, Vec3 } from "cc";
+import { Checkpoint } from "../Checkpoint";
+import { PuppetViewComp } from "../../puppet/view/PuppetViewComp";
+
+const { ccclass, property } = _decorator;
+
+/** 关卡点击控制 */
+@ccclass('CheckpointViewController')
+export class CheckpointViewController extends Component {
+    /** 角色对象 */
+    checkpoint: Checkpoint = null!;
+
+    @property({ type: Camera, tooltip: '主相机' })
+    public mainCamera: Camera | null = null;
+
+    // @property({ type: Node, tooltip: '待触摸物体' })
+    // public node_touch_1: Node | null = null;
+
+    private _ray: geometry.Ray = new geometry.Ray();
+
+    onLoad() {
+        const cameras = director.getScene().getComponentsInChildren(Camera);
+        this.mainCamera = cameras.find(camera => camera.node.name === 'MainCamera');
+        input.on(Input.EventType.TOUCH_END, this.onTouchStart, this);
+    }
+
+    onDestory() {
+        input.off(Input.EventType.TOUCH_END, this.onTouchStart, this);
+    }
+
+    onTouchStart(event: EventTouch) {
+        // 基于摄像机 画射线
+        this.mainCamera?.screenPointToRay(event.getLocation().x, event.getLocation().y, this._ray);
+        if (PhysicsSystem.instance.raycast(this._ray)) {
+            const r = PhysicsSystem.instance.raycastResults;
+            for (let index = 0; index < r.length; index++) {
+                const element = r[0];
+                console.log(this.node?.uuid)
+                const view = element.collider.node?.getComponent(PuppetViewComp) as PuppetViewComp
+                if (view) {
+                    view.controller.onPuppetClick()
+                }
+                break
+            }
+        }
+    }
+
+}

+ 9 - 0
assets/script/game/checkpoint/view/CheckpointViewController.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "eeb779fa-1cfd-482e-9cc8-d3d49996d1af",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 11 - 11
assets/script/game/puppet/view/PuppetViewComp.ts

@@ -39,22 +39,22 @@ export class PuppetViewComp extends CCComp {
     }
 
     protected lateUpdate(dt: number): void {
-        const on = (this.ent as Puppet).PathFind?.canReach
+        const on = (this.ent as Puppet)?.PathFind?.canReach
         this.switchOutLine(on)
     }
 
     switchOutLine(on: boolean) {
         // 获取MeshRenderer组件
-        let rendererComponet = this.node.getComponentInChildren(MeshRenderer) as RenderableComponent
-
-        if (rendererComponet) {
-            // 获取材质实例
-            let materialIns = rendererComponet.material
-            if (materialIns) {
-                materialIns.setProperty('lineWidth', on ? 20 : 5);
-                rendererComponet.material = materialIns
-            }
-        }
+        let rendererComponets = this.node.getComponentsInChildren(MeshRenderer) as RenderableComponent[]
+        rendererComponets.forEach((rendererComponet) => {
+             // 获取材质实例
+             let materialIns = rendererComponet.material
+             if (materialIns) {
+                 materialIns.setProperty('lineWidth', on ? 20 : 5);
+                 rendererComponet.material = materialIns
+             }
+        })
+       
     }
 
     changeColor(color: string) {

+ 64 - 5
assets/script/game/puppet/view/PuppetViewController.ts

@@ -25,13 +25,13 @@ export class PuppetViewController extends Component {
     private _ray: geometry.Ray = new geometry.Ray();
 
     onLoad() {
-        const cameras = director.getScene().getComponentsInChildren(Camera);
-        this.mainCamera = cameras.find(camera => camera.node.name === 'MainCamera');
-        input.on(Input.EventType.TOUCH_END, this.onTouchStart, this);
+        // const cameras = director.getScene().getComponentsInChildren(Camera);
+        // this.mainCamera = cameras.find(camera => camera.node.name === 'MainCamera');
+        // input.on(Input.EventType.TOUCH_END, this.onTouchStart, this);
     }
 
     onDestory() {
-        input.off(Input.EventType.TOUCH_END, this.onTouchStart, this);
+        // input.off(Input.EventType.TOUCH_END, this.onTouchStart, this);
     }
 
     onTouchStart(event: EventTouch) {
@@ -50,7 +50,7 @@ export class PuppetViewController extends Component {
                     oops.audio.playEffect("common/audio/click");
                     console.log('当前点击: ' + element.collider.node.uuid);
                     console.log('是否可达:', this.puppet.PathFind?.canReach)
-                    if (this.puppet.PathFind?.canReach && !this.puppet.get(MoveToPathComp)) {
+                    if (this.puppet?.PathFind?.canReach && !this.puppet.get(MoveToPathComp)) {
                         VibrationManager.getInstance().vibrateShort()
                         const checkpoint = smc.initialize.account.checkpoint
                         let end = v3(0, 0, 0)
@@ -109,4 +109,63 @@ export class PuppetViewController extends Component {
         }
     }
 
+    onPuppetClick(){
+        oops.audio.playEffect("common/audio/click");
+        // console.log('当前点击: ' + element.collider.node.uuid);
+        // console.log('是否可达:', this.puppet.PathFind?.canReach)
+        if (this.puppet?.PathFind?.canReach && !this.puppet.get(MoveToPathComp)) {
+            VibrationManager.getInstance().vibrateShort()
+            const checkpoint = smc.initialize.account.checkpoint
+            let end = v3(0, 0, 0)
+            if (checkpoint.CheckpointModel.curVehicle.VehicleModel.color === this.puppet.PuppetModel.color && !checkpoint.CheckpointModel.curVehicle.VehicleModel.isFull) {
+                // end = v3(0, 0, 0)
+                this.puppet.PuppetView.animator.onRunPathComplete = () => {
+                    checkpoint.CheckpointModel.curVehicle.VehicleView.createPuppet()
+                    checkpoint.CheckpointModel.peopleCount-=1
+                    checkpoint.removeChild(this.puppet)
+                    this.puppet.destroy()
+                }
+                checkpoint.CheckpointModel.curVehicle.VehicleModel.useSit += 1
+                
+            } else if (checkpoint.CheckpointModel.emptyStation) {
+                if (checkpoint.CheckpointModel.emptyStationCount <= 1) {
+                    console.log('游戏结束')
+                    oops.gui.open(UIID.Recovery)
+                    // checkpoint.add(CheckpointCheckFailComp)
+                }
+                end = checkpoint.CheckpointModel.emptyStation.StationView.node.position.clone()
+                checkpoint.CheckpointModel.emptyStation.StationModel.puppet = this.puppet
+
+            } else {
+                console.log('游戏结束')
+                return
+            }
+
+            this.puppet.PuppetView.animator.moveToPath(end)
+            // const moveToPath = this.puppet.add(MoveToPathComp)
+            // moveToPath.speed = 2
+            // moveToPath.paths = this.puppet.PathFind.path.concat([end])
+            // moveToPath.node = this.node
+            // moveToPath.ns = Node.NodeSpace.WORLD
+            // const forwardClone = this.puppet.PuppetView.node.forward.clone()
+            // moveToPath.onComplete = () => {
+            //     console.log('移动完成')
+            //     this.puppet.PuppetView.ske.play('idle')
+            //     this.puppet.PuppetView.node.forward = forwardClone
+            //     needDestory&&this.puppet.destroy()
+            // }
+            // this.puppet.PuppetView.ske.play('run')
+            // checkpoint.CheckpointModel.emptyStation
+            const pathGrid = checkpoint.CheckpointModel.path_grid
+            pathGrid[this.puppet.PuppetModel.x][this.puppet.PuppetModel.y].fill = null
+            const cell = checkpoint.CheckpointModel.cells
+            cell[this.puppet.PuppetModel.x][this.puppet.PuppetModel.y] = null
+            this.puppet.remove(PathFindComp)
+            // console.log('我开始动了')
+            oops.audio.playEffect("common/audio/move");
+        }else{
+            VibrationManager.getInstance().vibrateLong()
+        }
+    }
+
 }