123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import { _decorator, Component, RigidBody, Collider, v3, MeshRenderer, MeshCollider, CCObject, Vec2, Vec3, ERigidBodyType } from 'cc';
- import { GameNode } from './GameNode';
- import { Main } from './Main';
- const { ccclass, property } = _decorator;
- @ccclass('TileItem')
- export class TileItem extends Component {
- static TileItem: any;
- 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.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);
- }
- }
- }
|