This commit is contained in:
muzzik 2022-07-16 04:02:04 +08:00
parent bba9915be7
commit b3de7b808d
6 changed files with 205 additions and 5620 deletions

View File

@ -65,7 +65,7 @@ export class BezierCurveAnimation extends Component {
/** 更新事件 */ /** 更新事件 */
@property({ @property({
displayName: '更新事件', displayName: '更新事件',
tooltip: '(总曲线Y_yN, 当前缓动下标_indexN, 当前缓动曲线Y_yN)', tooltip: '(当前缓动曲线Y_yN, 当前缓动下标_indexN)',
type: [cc.EventHandler] type: [cc.EventHandler]
}) })
updateEventAS: cc.EventHandler[] = []; updateEventAS: cc.EventHandler[] = [];
@ -92,11 +92,28 @@ export class BezierCurveAnimation extends Component {
* @param endIndexN_ * @param endIndexN_
* @returns * @returns
*/ */
startTween(startIndexN_?: number, endIndexN_ = (startIndexN_ ?? 0) + 1): cc.Tween<any> { startTween(startIndexN_?: number): cc.Tween<any>;
startTween(tweenNS_?: number[]): cc.Tween<any>;
startTween(args_?: number | number[]): cc.Tween<any> {
/** 缓动队列 */
let tweenUnitAs = this.tweenUnitAS; let tweenUnitAs = this.tweenUnitAS;
if (startIndexN_ !== undefined) {
tweenUnitAs = tweenUnitAs.slice(startIndexN_, endIndexN_); // 获取缓动队列
if (args_ !== undefined) {
if (typeof args_ === 'number') {
tweenUnitAs = tweenUnitAs.slice(args_, 1);
} else {
tweenUnitAs = [];
args_.forEach((vN) => {
tweenUnitAs.push(this.tweenUnitAS[vN]);
});
} }
tweenUnitAs = tweenUnitAs.filter((v) => Boolean(v));
}
if (!tweenUnitAs.length) {
return;
}
/** 总时间(秒) */ /** 总时间(秒) */
let totalTimeSN = tweenUnitAs.reduce((preValue, currValue) => preValue + currValue.timeSN, 0); let totalTimeSN = tweenUnitAs.reduce((preValue, currValue) => preValue + currValue.timeSN, 0);
/** 时间占比 */ /** 时间占比 */
@ -147,13 +164,12 @@ export class BezierCurveAnimation extends Component {
let posN = (ratioN - lastTimeRatioN) / timeRangeN; let posN = (ratioN - lastTimeRatioN) / timeRangeN;
/** 曲线位置 */ /** 曲线位置 */
let yN = curveFS[tweenIndexN](posN); let yN = curveFS[tweenIndexN](posN);
let y2N = yN * timeRangeN + lastTimeRatioN;
// 缓动切换事件触发 // 缓动切换事件触发
if (lastTweenIndexN !== tweenIndexN) { if (lastTweenIndexN !== tweenIndexN) {
this.emit('tweenSwitchEventAS', lastTweenIndexN); this.emit('tweenSwitchEventAS', lastTweenIndexN);
} }
// 更新事件触发 // 更新事件触发
this.emit('updateEventAS', y2N, tweenIndexN, yN); this.emit('updateEventAS', yN, tweenIndexN);
// 更新缓动下标 // 更新缓动下标
lastTweenIndexN = tweenIndexN; lastTweenIndexN = tweenIndexN;
} }

View File

@ -51,8 +51,6 @@ export class RollingLottery extends Component {
private _selfRect = cc.rect(); private _selfRect = cc.rect();
/** 上次曲线 Y */ /** 上次曲线 Y */
private _lastCurveYN = 0; private _lastCurveYN = 0;
/** 当前缓动下标 */
private _currTweenIndexN = 0;
/** 当前滚动配置 */ /** 当前滚动配置 */
private _scrollConfig: RollingLotteryScrollConfig; private _scrollConfig: RollingLotteryScrollConfig;
/** 父节点中心点矩形 */ /** 父节点中心点矩形 */
@ -459,11 +457,11 @@ export class RollingLottery extends Component {
// 更新移动距离 // 更新移动距离
this._updateMoveDist(indexN_); this._updateMoveDist(indexN_);
// 开始滚动 // 开始滚动
this._currTweenIndexN = this._scrollConfig.tweenIndexN; this.curveComp.startTween(this._scrollConfig.tweenIndexNS);
this.curveComp.startTween(this._currTweenIndexN);
} }
/* ------------------------------- 自定义事件 ------------------------------- */ /* ------------------------------- 自定义事件 ------------------------------- */
private _eventUpdate(yN_: number, indexN_: number, y2N_: number): void { private _eventUpdate(yN_: number, indexN_: number): void {
cc.log(yN_, yN_);
if (this.dire === RollingLotteryDirection.HORIZONTAL) { if (this.dire === RollingLotteryDirection.HORIZONTAL) {
cc.error('未实现'); cc.error('未实现');
// ... // ...
@ -476,15 +474,9 @@ export class RollingLottery extends Component {
private _eventEnd(): void { private _eventEnd(): void {
this._scrollB = false; this._scrollB = false;
// 继续缓动
if (this._scrollConfig.nextPlayB && ++this._currTweenIndexN < this.curveComp.tweenUnitAS.length) {
this.curveComp.startTween(this._currTweenIndexN);
} else {
this.scrollEndEvent.emit([]); this.scrollEndEvent.emit([]);
this._scrollConfig.endCBF?.(); this._scrollConfig.endCBF?.();
} }
}
/* ------------------------------- 节点事件 ------------------------------- */ /* ------------------------------- 节点事件 ------------------------------- */
private _nodeChildAdded(): void { private _nodeChildAdded(): void {
this.reset(); this.reset();
@ -499,10 +491,8 @@ class RollingLotteryScrollConfig {
constructor(init_?: RollingLotteryScrollConfig) { constructor(init_?: RollingLotteryScrollConfig) {
Object.assign(this, init_); Object.assign(this, init_);
} }
/** 指定缓动单元下标 */ /** 缓动队列 */
tweenIndexN? = 0; tweenIndexNS?: number[];
/** 继续下个缓动单元播放 */
nextPlayB? = false;
/** 结束回调 */ /** 结束回调 */
endCBF?: () => void; endCBF?: () => void;
} }

File diff suppressed because it is too large Load Diff

View File

@ -8,17 +8,19 @@ export class main extends Component {
/* ------------------------------- segmentation ------------------------------- */ /* ------------------------------- segmentation ------------------------------- */
start() { start() {
let comp = this.node.getComponentInChildren(RollingLottery); let comp = this.node.getComponentInChildren(RollingLottery);
// comp.loop(1500);
// let indexN = 0; // let indexN = 0;
// this.node.on( // this.node.on(
// cc.Node.EventType.TOUCH_END, // cc.Node.EventType.TOUCH_END,
// () => { // () => {
// comp['_scrollChild'](cc.v3(0, -50)); // comp.scroll(0, {});
// }, // },
// this // this
// ); // );
comp.scroll(10, {});
comp.reset(); // comp.reset();
comp.loop(-1500); // comp.loop(-1500);
// setTimeout(() => { // setTimeout(() => {
// comp.scroll(-10, { // comp.scroll(-10, {
// tweenIndexN: 3, // tweenIndexN: 3,
@ -35,11 +37,11 @@ export class main extends Component {
node_.getComponentInChildren(cc.Label).string = indexN_ + ''; node_.getComponentInChildren(cc.Label).string = indexN_ + '';
} }
centerNodeEvent(indexN_: number): void { eventCenterNode(indexN_: number): void {
cc.log('当前下标', indexN_); cc.log('当前下标', indexN_);
} }
scrollEndEvent(): void { eventScrollEnd(): void {
cc.log('滚动结束'); cc.log('滚动结束');
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +0,0 @@
{
"ver": "1.1.32",
"importer": "prefab",
"imported": true,
"uuid": "3fe6ec1e-8b71-4777-bd7f-a9a1bb2debef",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "滚动根节点"
}
}