import { _decorator, Component, RigidBody, Collider, v3, MeshRenderer, Vec3 } from 'cc'; import { NewPackOpenedLayer } from '../gameui/NewPackOpenedLayer'; const { ccclass, property } = _decorator; @ccclass('TileItem') export class TileItem extends Component { static TileItem: any; //预制体的原始大小 oScale: Vec3 = new Vec3(1,1,1); isMoving: boolean = false auto_rotation = false; collider: Collider[] = []; rigid: RigidBody = null; removed:boolean=false removedPos:Vec3//消除的时候做一个向中间靠拢的动画 playRmovedEff:boolean=false private static starttime = Date.now(); private static getY() { let n = Date.now() - this.starttime; return n / 10; } start() { this.oScale = this.node.scale.clone(); this.collider = this.node.children[0].getComponents(Collider); } //禁用碰撞 _enableCollider: boolean = false; set enableCollider(b) { let worldRotation = this.node.children[0].worldRotation.clone(); this.node.worldPosition = this.node.children[0].worldPosition.clone(); this.node.children[0].position = v3(); this.node.children[0].worldRotation = worldRotation; this.rigid.useGravity = b; } get enableCollider() { return this._enableCollider; } destoryCollider() { if (!this.node || !this.node.isValid) return; if (!this.node.children[0]) return; this.node.children[0].position = v3(); this.node.children[0].eulerAngles = v3(); if (this.collider) { this.collider.forEach(a => { if (a && a.isValid) a.enabled = false; }); } if (this.rigid && this.rigid.isValid) { this.rigid.destroy(); } } addCollider(): RigidBody { let _render = this.node.children[0].getComponent(MeshRenderer); this.rigid = _render.node.addComponent(RigidBody); this.collider.map(a => a.enabled = true) return this.rigid; } update() { if(this.auto_rotation) { this.node.setRotationFromEuler(0, TileItem.getY(), 0); } } }