初次提交

This commit is contained in:
dgflash
2021-07-03 16:38:47 +08:00
parent 9fcf367e10
commit 7a405193fa
497 changed files with 55178 additions and 71 deletions

View File

@@ -0,0 +1,42 @@
import { Animation, AnimationClip, EventTouch, _decorator } from "cc";
import { resLoader } from "../../utils/ResLoader";
import ButtonSimple from "./ButtonSimple";
const { ccclass, property, menu } = _decorator;
@ccclass("ButtonEffect")
@menu('ui/button/ButtonEffect')
export default class ButtonEffect extends ButtonSimple {
@property({
tooltip: "是否开启"
})
disabledEffect: boolean = false;
private anim!: Animation;
onLoad() {
this.anim = this.node.addComponent(Animation);
var ac_start = resLoader.get("common/anim/button_scale_start", AnimationClip)!;
var ac_end = resLoader.get("common/anim/button_scale_end", AnimationClip)!;
this.anim.defaultClip = ac_start;
this.anim.createState(ac_start, ac_start?.name);
this.anim.createState(ac_end, ac_end?.name);
super.onLoad();
}
protected onTouchtStart(event: EventTouch) {
if (!this.disabledEffect) {
this.anim.play("button_scale_start");
}
}
protected onTouchEnd(event: EventTouch) {
if (!this.disabledEffect) {
this.anim.play("button_scale_end");
}
super.onTouchEnd(event);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "1be3686b-18ee-4ecf-a11a-a60eb2816d37",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,54 @@
import { Component, director, EventTouch, Node, _decorator } from "cc";
const { ccclass, property, menu } = _decorator;
@ccclass("ButtonSimple")
@menu('ui/button/ButtonSimple')
export default class ButtonSimple extends Component {
@property({
tooltip: "是否只能触发一次"
})
private once: boolean = false;
@property({
tooltip: "每次触发间隔"
})
private interval: number = 500;
private touchCount = 0;
private touchtEndTime = 0;
onLoad() {
this.node.on(Node.EventType.TOUCH_START, this.onTouchtStart, this);
this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
this.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
}
/** 触摸开始 */
protected onTouchtStart(event: EventTouch) { }
/** 触摸结束 */
protected onTouchEnd(event: EventTouch) {
if (this.once) {
if (this.touchCount > 0) {
event.propagationStopped = true;
return;
}
this.touchCount++;
}
// 防连点500毫秒出发一次事件
if (this.touchtEndTime && director.getTotalTime() - this.touchtEndTime < this.interval) {
event.propagationStopped = true;
}
else {
this.touchtEndTime = director.getTotalTime();
}
}
onDestroy() {
this.node.off(Node.EventType.TOUCH_START, this.onTouchtStart, this);
this.node.off(Node.EventType.TOUCH_END, this.onTouchEnd, this);
this.node.off(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "8d645c8e-6d7d-45bc-97e4-dac6e2d2bc69",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,61 @@
import { EventTouch, _decorator } from "cc";
import ButtonEffect from "./ButtonEffect";
const { ccclass, property, menu } = _decorator;
@ccclass("ButtonTouchLong")
@menu('ui/button/ButtonTouchLong')
export class ButtonTouchLong extends ButtonEffect {
@property({
tooltip: "长按时间(秒)"
})
time: number = 1;
protected _passTime = 0;
protected _isTouchLong: boolean = true;
protected _event: EventTouch | null = null;
public onLongTouchCallback!: Function | null;
onLoad() {
this._isTouchLong = false;
super.onLoad();
}
/** 触摸开始 */
onTouchtStart(event: EventTouch) {
this._event = event;
this._passTime = 0;
super.onTouchtStart(event);
}
/** 触摸结束 */
onTouchEnd(event: EventTouch) {
if (this._passTime > this.time) {
event.propagationStopped = true;
}
this._event = null;
this._passTime = 0;
this._isTouchLong = false;
super.onTouchEnd(event);
}
removeTouchLong() {
this._event = null;
this._isTouchLong = false;
}
/** 引擎更新事件 */
update(dt: number) {
if (this._event && !this._isTouchLong) {
this._passTime += dt;
if (this._passTime >= this.time) {
this._isTouchLong = true;
if (this.onLongTouchCallback)
this.onLongTouchCallback(this._event);
this.removeTouchLong();
}
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "da96e9fb-598a-4f4d-a3c8-90ed65fcdbb1",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}