feat: add builder configuration file
feat: add cocos-service configuration file feat: add device configuration file feat: add engine configuration file feat: add information configuration file feat: add program configuration file feat: add project configuration file feat: add TypeScript configuration file
This commit is contained in:
408
assets/script/QuickTween/QuickTween.ts
Normal file
408
assets/script/QuickTween/QuickTween.ts
Normal file
@@ -0,0 +1,408 @@
|
||||
|
||||
import { Component, Node, Vec3, tween, Quat, Sprite, Color, math, easing, Camera, ITweenOption, IPunchTweenOption, IShakeTweenOption, Label } from 'cc';
|
||||
import { calcPunchData, calcShakeData, quadraticCurve } from './Util';
|
||||
|
||||
//////////////////////
|
||||
// Transform
|
||||
//////////////////////
|
||||
Node.prototype.qtPosition = function (to: Vec3, duration: number, opts?: ITweenOption) {
|
||||
return tween(this).to(duration, { position: to }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtPositionX = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startPos = this.position;
|
||||
return tween(this).to(duration, { position: new Vec3(to, startPos.y, startPos.z) }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtPositionY = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startPos = this.position;
|
||||
return tween(this).to(duration, { position: new Vec3(startPos.x, to, startPos.z) }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtPositionZ = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startPos = this.position;
|
||||
return tween(this).to(duration, { position: new Vec3(startPos.x, startPos.y, to) }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtWorldPosition = function (to: Vec3, duration: number, opts?: ITweenOption) {
|
||||
return tween(this).to(duration, { worldPosition: to }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtWorldPositionX = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startPos = this.worldPosition;
|
||||
return tween(this).to(duration, { worldPosition: new Vec3(to, startPos.y, startPos.z) }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtWorldPositionY = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startPos = this.worldPosition;
|
||||
return tween(this).to(duration, { worldPosition: new Vec3(startPos.x, to, startPos.z) }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtWorldPositionZ = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startPos = this.worldPosition;
|
||||
return tween(this).to(duration, { worldPosition: new Vec3(startPos.x, startPos.y, to) }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtRotation = function (to: Vec3, duration: number, opts?: ITweenOption) {
|
||||
return tween(this).to(duration, { eulerAngles: to }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtRotationQuat = function (to: Quat, duration: number, opts?: ITweenOption) {
|
||||
return tween(this).to(duration, { rotation: to }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtScale = function (to: Vec3 | number, duration: number, opts?: ITweenOption) {
|
||||
let toScale = to;
|
||||
if (!(to instanceof Vec3)) {
|
||||
toScale = new Vec3(to, to, to);
|
||||
}
|
||||
|
||||
return tween(this).to(duration, { scale: toScale }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtScaleX = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startScale = this.scale;
|
||||
return tween(this).to(duration, { scale: new Vec3(to, startScale.y, startScale.z) }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtScaleY = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startScale = this.scale;
|
||||
return tween(this).to(duration, { scale: new Vec3(startScale.x, to, startScale.z) }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtScaleZ = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startScale = this.scale;
|
||||
return tween(this).to(duration, { scale: new Vec3(startScale.x, startScale.y, to) }, opts);
|
||||
}
|
||||
|
||||
Node.prototype.qtPunchPosition = function (punch: Vec3, duration: number, opts?: IPunchTweenOption) {
|
||||
const vibrato = opts?.vibrato ?? 3;
|
||||
const elasticity = opts?.elasticity ?? 0.5;
|
||||
const { tos, durations } = calcPunchData(this.position.clone(), punch, duration, vibrato, elasticity);
|
||||
|
||||
const punchTween = tween(this);
|
||||
tos.forEach((to, index) => {
|
||||
const d = durations[index];
|
||||
let tweenOpts: ITweenOption | undefined;
|
||||
if (index === 0) {
|
||||
tweenOpts = {
|
||||
onStart: opts.onStart
|
||||
}
|
||||
} else if (index === tos.length - 1) {
|
||||
tweenOpts = {
|
||||
onComplete: opts.onComplete
|
||||
}
|
||||
}
|
||||
punchTween.then(tween().to(d, { position: to }, tweenOpts));
|
||||
});
|
||||
|
||||
return punchTween.union();
|
||||
}
|
||||
|
||||
Node.prototype.qtPunchRotation = function (punch: Vec3, duration: number, opts?: IPunchTweenOption) {
|
||||
const vibrato = opts?.vibrato ?? 3;
|
||||
const elasticity = opts?.elasticity ?? 0.5;
|
||||
const { tos, durations } = calcPunchData(this.rotation.clone(), punch, duration, vibrato, elasticity);
|
||||
|
||||
const punchTween = tween(this);
|
||||
tos.forEach((to, index) => {
|
||||
const d = durations[index];
|
||||
let tweenOpts: ITweenOption | undefined;
|
||||
if (index === 0) {
|
||||
tweenOpts = {
|
||||
onStart: opts.onStart
|
||||
}
|
||||
} else if (index === tos.length - 1) {
|
||||
tweenOpts = {
|
||||
onComplete: opts.onComplete
|
||||
}
|
||||
}
|
||||
punchTween.then(tween().to(d, { eulerAngles: to }, tweenOpts));
|
||||
});
|
||||
|
||||
return punchTween.union();
|
||||
}
|
||||
|
||||
Node.prototype.qtPunchScale = function (punch: Vec3, duration: number, opts?: IPunchTweenOption) {
|
||||
const vibrato = opts?.vibrato ?? 3;
|
||||
const elasticity = opts?.elasticity ?? 0.5;
|
||||
const { tos, durations } = calcPunchData(this.scale.clone(), punch, duration, vibrato, elasticity);
|
||||
|
||||
const punchTween = tween(this);
|
||||
tos.forEach((to, index) => {
|
||||
const d = durations[index];
|
||||
let tweenOpts: ITweenOption | undefined;
|
||||
if (index === 0) {
|
||||
tweenOpts = {
|
||||
onStart: opts.onStart
|
||||
}
|
||||
} else if (index === tos.length - 1) {
|
||||
tweenOpts = {
|
||||
onComplete: opts.onComplete
|
||||
}
|
||||
}
|
||||
punchTween.then(tween().to(d, { scale: to }, tweenOpts));
|
||||
});
|
||||
|
||||
return punchTween.union();
|
||||
}
|
||||
|
||||
Node.prototype.qtJumpPosition = function (to: Vec3, jumpHeight: number, jumpNum: number, duration: number, opts?: ITweenOption) {
|
||||
const tweenPos = new Vec3();
|
||||
const jumpTween = tween(this);
|
||||
const totalNum = jumpNum * 2;
|
||||
|
||||
// 初始化选项对象,确保即使没有传入选项也不会出错
|
||||
const options = opts || {};
|
||||
|
||||
this.jumpY = 0;
|
||||
let startPosY = 0;
|
||||
const yUpTween = tween().to(duration / totalNum, { jumpY: jumpHeight }, {
|
||||
onStart: (target: Node) => {
|
||||
startPosY = target.position.y;
|
||||
target.jumpY = 0;
|
||||
},
|
||||
onUpdate: (target: Node, ratio) => {
|
||||
tweenPos.set(target.position);
|
||||
tweenPos.y = startPosY + target.jumpY;
|
||||
target.position = tweenPos;
|
||||
},
|
||||
onComplete: (target: Node) => {
|
||||
target.jumpY = 0;
|
||||
}, easing: 'quadOut'
|
||||
}).to(duration / totalNum, { jumpY: jumpHeight }, {
|
||||
onStart: (target: Node) => {
|
||||
startPosY = target.position.y;
|
||||
},
|
||||
onUpdate: (target: Node, ratio) => {
|
||||
tweenPos.set(target.position);
|
||||
tweenPos.y = startPosY - target.jumpY;
|
||||
target.position = tweenPos;
|
||||
},
|
||||
onComplete: (target: Node) => {
|
||||
target.jumpY = 0;
|
||||
}, easing: 'quadIn',
|
||||
}).union().repeat(jumpNum);
|
||||
|
||||
this.jumpOffsetY = 0;
|
||||
let offsetY = 0;
|
||||
const offsetYTween = tween().to(duration, { jumpOffsetY: to.y - this.position.y }, {
|
||||
onStart: (target: Node) => {
|
||||
offsetY = to.y - target.position.y;
|
||||
target.jumpOffsetY = 0;
|
||||
},
|
||||
onUpdate: (target: Node, ratio) => {
|
||||
const interpOffsetY = easing.quadOut(ratio) * offsetY;
|
||||
tweenPos.set(target.position);
|
||||
tweenPos.y += interpOffsetY;
|
||||
target.position = tweenPos;
|
||||
},
|
||||
onComplete: (target: Node) => {
|
||||
target.jumpOffsetY = 0;
|
||||
}, easing: 'quadOut'
|
||||
});
|
||||
|
||||
this.jumpX = this.position.x;
|
||||
this.jumpZ = this.position.z;
|
||||
const xzTween = tween().to(duration, { jumpX: to.x, jumpZ: to.z }, {
|
||||
// 使用可选链运算符或者默认值
|
||||
onStart: options.onStart,
|
||||
onUpdate: (target: Node, ratio) => {
|
||||
tweenPos.set(target.position);
|
||||
tweenPos.x = target.jumpX;
|
||||
tweenPos.z = target.jumpZ;
|
||||
target.position = tweenPos;
|
||||
options.onUpdate?.();
|
||||
},
|
||||
onComplete: (target: Node) => {
|
||||
// delete target.jumpX;
|
||||
// delete target.jumpY;
|
||||
// delete target.jumpZ;
|
||||
// delete target.jumpOffsetY;
|
||||
target.jumpX = target.position.x;
|
||||
target.jumpZ = target.position.z;
|
||||
options.onComplete?.();
|
||||
}
|
||||
})
|
||||
|
||||
jumpTween.parallel(yUpTween, offsetYTween, xzTween);
|
||||
return jumpTween;
|
||||
}
|
||||
|
||||
Node.prototype.qtShakePosition = function (strength: Vec3 | number, duration: number, opts?: IShakeTweenOption) {
|
||||
const options = opts || {};
|
||||
|
||||
const vibrato = options?.vibrato ?? 10;
|
||||
const randomness = options?.randomness ?? 90;
|
||||
const fadeOut = options?.fadeOut ?? true;
|
||||
let toStrength: Vec3;
|
||||
let vectorBased = false;
|
||||
if (!(strength instanceof Vec3)) {
|
||||
toStrength = new Vec3(strength, strength, strength);
|
||||
} else {
|
||||
toStrength = strength;
|
||||
vectorBased = true;
|
||||
}
|
||||
const { tos, durations } = calcShakeData(this.position.clone(), duration, toStrength, vibrato, randomness, false, vectorBased, fadeOut)
|
||||
const shakeTween = tween(this);
|
||||
tos.forEach((to, index) => {
|
||||
const d = durations[index];
|
||||
let tweenOpts: ITweenOption | undefined;
|
||||
if (index === 0) {
|
||||
tweenOpts = {
|
||||
onStart: options.onStart
|
||||
}
|
||||
} else if (index === tos.length - 1) {
|
||||
tweenOpts = {
|
||||
onComplete: options.onComplete
|
||||
}
|
||||
}
|
||||
shakeTween.then(tween().to(d, { position: to }, tweenOpts));
|
||||
});
|
||||
|
||||
return shakeTween.union();
|
||||
}
|
||||
|
||||
Node.prototype.qtShakeRotation = function (strength: Vec3 | number, duration: number, opts?: IShakeTweenOption) {
|
||||
const vibrato = opts?.vibrato ?? 10;
|
||||
const randomness = opts?.randomness ?? 90;
|
||||
const fadeOut = opts?.fadeOut ?? true;
|
||||
let toStrength: Vec3;
|
||||
let vectorBased = false;
|
||||
if (!(strength instanceof Vec3)) {
|
||||
toStrength = new Vec3(strength, strength, strength);
|
||||
} else {
|
||||
toStrength = strength;
|
||||
vectorBased = true;
|
||||
}
|
||||
const { tos, durations } = calcShakeData(this.eulerAngles.clone(), duration, toStrength, vibrato, randomness, false, vectorBased, fadeOut)
|
||||
const shakeTween = tween(this);
|
||||
tos.forEach((to, index) => {
|
||||
const d = durations[index];
|
||||
let tweenOpts: ITweenOption | undefined;
|
||||
if (index === 0) {
|
||||
tweenOpts = {
|
||||
onStart: opts.onStart
|
||||
}
|
||||
} else if (index === tos.length - 1) {
|
||||
tweenOpts = {
|
||||
onComplete: opts.onComplete
|
||||
}
|
||||
}
|
||||
shakeTween.then(tween().to(d, { eulerAngles: to }, tweenOpts));
|
||||
});
|
||||
|
||||
return shakeTween.union();
|
||||
}
|
||||
|
||||
Node.prototype.qtShakeScale = function (strength: Vec3 | number, duration: number, opts?: IShakeTweenOption) {
|
||||
const vibrato = opts?.vibrato ?? 10;
|
||||
const randomness = opts?.randomness ?? 90;
|
||||
const fadeOut = opts?.fadeOut ?? true;
|
||||
let toStrength: Vec3;
|
||||
let vectorBased = false;
|
||||
if (!(strength instanceof Vec3)) {
|
||||
toStrength = new Vec3(strength, strength, strength);
|
||||
} else {
|
||||
toStrength = strength;
|
||||
vectorBased = true;
|
||||
}
|
||||
const { tos, durations } = calcShakeData(this.scale.clone(), duration, toStrength, vibrato, randomness, false, vectorBased, fadeOut)
|
||||
const shakeTween = tween(this);
|
||||
tos.forEach((to, index) => {
|
||||
const d = durations[index];
|
||||
let tweenOpts: ITweenOption | undefined;
|
||||
if (index === 0) {
|
||||
tweenOpts = {
|
||||
onStart: opts.onStart
|
||||
}
|
||||
} else if (index === tos.length - 1) {
|
||||
tweenOpts = {
|
||||
onComplete: opts.onComplete
|
||||
}
|
||||
}
|
||||
shakeTween.then(tween().to(d, { scale: to }, tweenOpts));
|
||||
});
|
||||
|
||||
return shakeTween.union();
|
||||
}
|
||||
|
||||
Node.prototype.qtQuadraticCurve = function (p1: Vec3, cp: Vec3, p2: Vec3, duration: number, opts?: ITweenOption) {
|
||||
return tween(this).to(duration, { position: p2, easing: opts?.easing }, {
|
||||
onUpdate(target, ratio) {
|
||||
target.setPosition(quadraticCurve(ratio, p1, cp, p2));
|
||||
},
|
||||
onComplete: opts?.onComplete,
|
||||
onStart: opts?.onStart
|
||||
}).union();
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
// Sprite
|
||||
//////////////////////
|
||||
// good color lerp
|
||||
// https://www.alanzucconi.com/2016/01/06/colour-interpolation/
|
||||
Sprite.prototype.qtColor = function (to: Color, duration: number, opts?: ITweenOption) {
|
||||
return tween(this).to(duration, { color: to }, opts);
|
||||
}
|
||||
|
||||
Sprite.prototype.qtOpacity = function (to: number, duration: number, opts?: ITweenOption) {
|
||||
const startColor = this.color.clone();
|
||||
const tempColor = new Color();
|
||||
return tween(this).to(duration, { color: new Color(startColor.r, startColor.g, startColor.b, to) }, {
|
||||
onStart: opts.onStart,
|
||||
onUpdate: (target: { _val: number }, ratio: number) => {
|
||||
const lerpA = startColor.a + (to - startColor.a) * ratio
|
||||
tempColor.set(startColor.r, startColor.g, startColor.b, lerpA);
|
||||
this.color = tempColor;
|
||||
opts.onUpdate?.();
|
||||
},
|
||||
onComplete: opts.onComplete
|
||||
});
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
// Label
|
||||
//////////////////////
|
||||
Label.prototype.qtColor = function (to: Color, duration: number, opts?: ITweenOption) {
|
||||
return tween(this).to(duration, { color: to }, opts);
|
||||
}
|
||||
|
||||
Label.prototype.qtString = function (to: string, duration: number, opts?: ITweenOption) {
|
||||
return tween(this).to(duration, { string: to }, opts);
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
// Camera
|
||||
//////////////////////
|
||||
Camera.prototype.qtShakePosition = function (strength: Vec3 | number, duration: number, opts?: IShakeTweenOption) {
|
||||
const vibrato = opts?.vibrato ?? 10;
|
||||
const randomness = opts?.randomness ?? 90;
|
||||
const fadeOut = opts?.fadeOut ?? true;
|
||||
let toStrength: Vec3;
|
||||
let vectorBased = false;
|
||||
if (!(strength instanceof Vec3)) {
|
||||
toStrength = new Vec3(strength, strength, strength);
|
||||
} else {
|
||||
toStrength = strength;
|
||||
vectorBased = true;
|
||||
}
|
||||
const { tos, durations } = calcShakeData(this.node.position.clone(), duration, toStrength, vibrato, randomness, true, vectorBased, fadeOut)
|
||||
const shakeTween = tween(this.node);
|
||||
tos.forEach((to, index) => {
|
||||
const d = durations[index];
|
||||
let tweenOpts: ITweenOption | undefined;
|
||||
if (index === 0) {
|
||||
tweenOpts = {
|
||||
onStart: opts.onStart
|
||||
}
|
||||
} else if (index === tos.length - 1) {
|
||||
tweenOpts = {
|
||||
onComplete: opts.onComplete
|
||||
}
|
||||
}
|
||||
shakeTween.then(tween().to(d, { position: to }, tweenOpts));
|
||||
});
|
||||
|
||||
return shakeTween.union();
|
||||
}
|
||||
9
assets/script/QuickTween/QuickTween.ts.meta
Normal file
9
assets/script/QuickTween/QuickTween.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7068ad06-e307-495f-befa-d9239208e9f1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
160
assets/script/QuickTween/Util.ts
Normal file
160
assets/script/QuickTween/Util.ts
Normal file
@@ -0,0 +1,160 @@
|
||||
import { KeyCode, math, Quat, Vec3 } from "cc";
|
||||
|
||||
export function clampLength(vec: Vec3, maxLength: number) {
|
||||
if (vec.lengthSqr() > maxLength * maxLength) {
|
||||
const clampVec = new Vec3();
|
||||
Vec3.normalize(clampVec, vec);
|
||||
clampVec.multiplyScalar(maxLength);
|
||||
return clampVec;
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
export function vec3FromAngle(degree: number, length: number) {
|
||||
const radian = math.toRadian(degree);
|
||||
return new Vec3(length * Math.cos(radian), length * Math.sin(radian), 0);
|
||||
}
|
||||
|
||||
export function calcPunchData(start: Vec3, direction: Vec3, duration: number, vibrato: number, elasticity: number) {
|
||||
math.clamp01(elasticity);
|
||||
let strength = direction.length();
|
||||
let toIterations = Math.round(vibrato * duration);
|
||||
if (toIterations < 2) {
|
||||
toIterations = 2;
|
||||
}
|
||||
|
||||
const deltaStrength = strength / toIterations;
|
||||
|
||||
let durations = [];
|
||||
let sum = 0;
|
||||
for (let i = 0; i < toIterations; i++) {
|
||||
const iterationPercent = (i + 1) / toIterations;
|
||||
const deltaDuration = duration * iterationPercent;
|
||||
sum += deltaDuration;
|
||||
durations[i] = deltaDuration;
|
||||
}
|
||||
|
||||
const durationMultiplier = duration / sum;
|
||||
durations = durations.map((d) => d * durationMultiplier);
|
||||
|
||||
// create to vec3 array
|
||||
const tos: Vec3[] = [];
|
||||
for (let i = 0; i < toIterations; i++) {
|
||||
if (i < toIterations - 1) {
|
||||
if (i === 0) {
|
||||
tos[i] = Vec3.add(new Vec3(), start, direction);
|
||||
} else if (i % 2 !== 0) {
|
||||
const deltaVec = clampLength(direction, strength * elasticity);
|
||||
deltaVec.negative();
|
||||
tos[i] = deltaVec.add(start);
|
||||
} else {
|
||||
const deltaVec = clampLength(direction, strength);
|
||||
tos[i] = deltaVec.add(start);
|
||||
}
|
||||
} else {
|
||||
tos[i] = start;
|
||||
}
|
||||
|
||||
strength -= deltaStrength;
|
||||
}
|
||||
|
||||
return {
|
||||
tos,
|
||||
durations
|
||||
}
|
||||
}
|
||||
|
||||
export function calcShakeData(start: Vec3, duration: number, strength: Vec3, vibrato: number, randomness: number, ignoreZAxis: boolean, vectorBased: boolean,
|
||||
fadeOut: boolean) {
|
||||
KeyCode
|
||||
let shakeLength = vectorBased ? strength.length() : strength.x;
|
||||
let toIterations = Math.floor(vibrato * duration);
|
||||
if (toIterations < 2) {
|
||||
toIterations = 2;
|
||||
}
|
||||
const deltaShakeLen = shakeLength / toIterations;
|
||||
let durations = [];
|
||||
let sum = 0;
|
||||
for (let i = 0; i < toIterations; i++) {
|
||||
const iterationPercent = (i + 1) / toIterations;
|
||||
const deltaDuration = fadeOut ? duration * iterationPercent : duration / toIterations;
|
||||
sum += deltaDuration;
|
||||
durations[i] = deltaDuration;
|
||||
}
|
||||
|
||||
const durationMultiplier = duration / sum;
|
||||
durations = durations.map((d) => d * durationMultiplier);
|
||||
|
||||
let angle = math.randomRange(0, 360);
|
||||
const tos: Vec3[] = [];
|
||||
|
||||
for (let i = 0; i < toIterations; i++) {
|
||||
if (i < toIterations - 1) {
|
||||
let randQuat = new Quat();
|
||||
if (i > 0) {
|
||||
angle = angle - 180 + math.randomRange(-randomness, randomness);
|
||||
}
|
||||
// switch(randomnessMode) {
|
||||
// case ShakeRandomnessMode.Harmonic:
|
||||
// if (i > 0) {
|
||||
// angle = angle - 180 + math.randomRange(0, randomness);
|
||||
// }
|
||||
// if (vectorBased || !ignoreZAxis) {
|
||||
// Quat.fromAxisAngle(randQuat, Vec3.UP, math.randomRange(0, randomness));
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// if (i > 0) {
|
||||
// angle = angle - 180 + math.randomRange(-randomness, randomness);
|
||||
// }
|
||||
// if (vectorBased || !ignoreZAxis) {
|
||||
// Quat.fromAxisAngle(randQuat, Vec3.UP, math.randomRange(-randomness, randomness));
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
|
||||
if (vectorBased) {
|
||||
let to = vec3FromAngle(angle, shakeLength);
|
||||
Vec3.transformQuat(to, to, randQuat);
|
||||
to.x = clampLength(to, strength.x).x;
|
||||
to.y = clampLength(to, strength.y).y;
|
||||
to.z = clampLength(to, strength.z).z;
|
||||
to.normalize().multiplyScalar(shakeLength);
|
||||
tos[i] = to.add(start);
|
||||
if (fadeOut) {
|
||||
shakeLength -= deltaShakeLen;
|
||||
}
|
||||
strength = clampLength(strength, shakeLength);
|
||||
} else {
|
||||
if (ignoreZAxis) {
|
||||
tos[i] = vec3FromAngle(angle, shakeLength).add(start);
|
||||
} else {
|
||||
Quat.fromAxisAngle(randQuat, Vec3.UP, math.randomRange(-randomness, randomness));
|
||||
let to = vec3FromAngle(angle, shakeLength);
|
||||
Vec3.transformQuat(to, to, randQuat);
|
||||
tos[i] = to.add(start);
|
||||
}
|
||||
|
||||
if (fadeOut) {
|
||||
shakeLength -= deltaShakeLen;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tos[i] = start;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
tos,
|
||||
durations
|
||||
}
|
||||
}
|
||||
|
||||
export function quadraticCurve(t: number, p1: Vec3, cp: Vec3, p2: Vec3) {
|
||||
let out = new Vec3(0, 0, 0);
|
||||
out.x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
|
||||
out.y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
|
||||
out.z = (1 - t) * (1 - t) * p1.z + 2 * t * (1 - t) * cp.z + t * t * p2.z;
|
||||
return out;
|
||||
}
|
||||
9
assets/script/QuickTween/Util.ts.meta
Normal file
9
assets/script/QuickTween/Util.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9d1ed435-17ef-4b92-9fd9-391c112c8f2a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
310
assets/script/QuickTween/quick-tween.d.ts
vendored
Normal file
310
assets/script/QuickTween/quick-tween.d.ts
vendored
Normal file
@@ -0,0 +1,310 @@
|
||||
declare module 'cc' {
|
||||
|
||||
interface IPunchTweenOption extends ITweenOption {
|
||||
// How much the punch will vibrate
|
||||
vibrato?: number,
|
||||
// Represents how much (0 to 1) the vector will go beyond the starting position
|
||||
// when bouncing backwards. 1 creates a full oscillation between the punch direction and the
|
||||
// opposite direction, while 0 oscillates only between the punch and the start scale.
|
||||
elasticity?: number
|
||||
}
|
||||
|
||||
interface IShakeTweenOption extends ITweenOption {
|
||||
vibrato?: number //每秒振动次数
|
||||
randomness?: number // 随机角度值
|
||||
fadeOut?: boolean // 是否淡出
|
||||
}
|
||||
|
||||
interface Node {
|
||||
/**
|
||||
* @zh
|
||||
* 移动目标的坐标到指定位置
|
||||
* @en
|
||||
* Moves the target's position to the given value
|
||||
* @param to dest position
|
||||
* @param duration time in seconds
|
||||
* @param {ITweenOption} opts options for tween
|
||||
* @param {Function} opts.onStart start callback
|
||||
*/
|
||||
qtPosition(to: Vec3, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 移动目标的坐标到指定位置, 只移动X坐标
|
||||
* @en
|
||||
* Moves the target's position to the given value, tweening only the X axis.
|
||||
* @param to dest position
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtPositionX(to: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 移动目标的坐标到指定位置, 只移动Y坐标
|
||||
* @en
|
||||
* Moves the target's position to the given value, tweening only the Y axis.
|
||||
* @param to dest position
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtPositionY(to: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 移动目标的坐标到指定位置, 只移动Z坐标
|
||||
* @en
|
||||
* Moves the target's position to the given value, tweening only the Z axis.
|
||||
* @param to dest position
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtPositionZ(to: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 移动目标的世界坐标到指定位置
|
||||
* @en
|
||||
* Moves the target's worldPosition to the given value
|
||||
* @param to dest position
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtWorldPosition(to: Vec3, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 移动目标的世界坐标到指定位置, 只移动X坐标
|
||||
* @en
|
||||
* Moves the target's worldPosition to the given value, tweening only the X axis.
|
||||
* @param to dest position
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtWorldPositionX(to: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 移动目标的世界坐标到指定位置, 只移动Y坐标
|
||||
* @en
|
||||
* Moves the target's worldPosition to the given value, tweening only the Y axis.
|
||||
* @param to dest position
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtWorldPositionY(to: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 移动目标的世界坐标到指定位置, 只移动Z坐标
|
||||
* @en
|
||||
* Moves the target's worldPosition to the given value, tweening only the Z axis.
|
||||
* @param to dest position
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtWorldPositionZ(to: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 旋转目标到指定值
|
||||
* @en
|
||||
* Rotates the target to ghe given value
|
||||
* @param to dest rotation in eulerAngle
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtRotation(to: Vec3, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 旋转目标到指定值
|
||||
* @en
|
||||
* Rotates the target to ghe given value
|
||||
* @param to dest rotation in quaternion
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtRotationQuat(to: Quat, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 缩放目标到指定值
|
||||
* @en
|
||||
* Scales the target to ghe given value
|
||||
* @param to dest scale value
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtScale(to: Vec3 | number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 缩放目标到指定值,只影响X轴
|
||||
* @en
|
||||
* Scales the target to ghe given value, tweening only X axis
|
||||
* @param to dest scale value
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtScaleX(to: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 缩放目标到指定值,只影响Y轴
|
||||
* @en
|
||||
* Scales the target to ghe given value, tweening only Y axis
|
||||
* @param to dest scale value
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtScaleY(to: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
/**
|
||||
* @zh
|
||||
* 缩放目标到指定值,只影响Z轴
|
||||
* @en
|
||||
* Scales the target to ghe given value, tweening only Z axis
|
||||
* @param to dest scale value
|
||||
* @param duration time in seconds
|
||||
* @param opts options for tween
|
||||
*/
|
||||
qtScaleZ(to: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 击打目标位置到指定方向,然后回到初始值
|
||||
* @en
|
||||
* Punches a position towards the given direction and then
|
||||
* back to the starting one as if it was connected to the starting position
|
||||
* via an elastic.
|
||||
* @param punch The direction and strength of the punch, (added to the node's current position)
|
||||
* @param duration Time in seconds
|
||||
* @param {IPunchTweenOption} opts punch tween options
|
||||
* @param {number} opts.vibrato How much the punch will vibrate
|
||||
* @param {number} opts.elasticity Represents how much (0 to 1) the vector will go beyond the starting position
|
||||
* when bouncing backwards. 1 creates a full oscillation between the punch direction and the
|
||||
* opposite direction, while 0 oscillates only between the punch and the start position.
|
||||
*/
|
||||
qtPunchPosition(punch: Vec3, duration: number, opts?: IPunchTweenOption): Tween<Node>;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 击打目标旋转方向到指定值,然后回到初始值
|
||||
* @en
|
||||
* Punches a rotation to the given value and then back to the starting one as if it was connected
|
||||
* to the starting rotation via an elastic.
|
||||
* @param punch The strength of punch, (added to the node's current rotation)
|
||||
* @param duration Time in seconds
|
||||
* @param {IPunchTweenOption} opts punch tween options
|
||||
* @param {number} opts.vibrato How much the punch will vibrate
|
||||
* @param {number} opts.elasticity Represents how much (0 to 1) the vector will go beyond the starting position
|
||||
* when bouncing backwards. 1 creates a full oscillation between the punch direction and the
|
||||
* opposite direction, while 0 oscillates only between the punch and the start rotation.
|
||||
*/
|
||||
qtPunchRotation(punch: Vec3, duration: number, opts?: IPunchTweenOption): Tween<Node>;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 击打目标缩放到指定值,然后回到初始值
|
||||
* @en
|
||||
* Punches a scale to the given value and then back to the starting one as if it was connected
|
||||
* to the starting scale via an elastic.
|
||||
* @param punch The strength of punch, (added to the node's current scale)
|
||||
* @param duration Time in seconds
|
||||
* @param {IPunchTweenOption} opts punch tween options
|
||||
* @param {number} opts.vibrato How much the punch will vibrate
|
||||
* @param {number} opts.elasticity Represents how much (0 to 1) the vector will go beyond the starting position
|
||||
* when bouncing backwards. 1 creates a full oscillation between the punch direction and the
|
||||
* opposite direction, while 0 oscillates only between the punch and the start scale.
|
||||
*/
|
||||
qtPunchScale(punch: Vec3, duration: number, opts?: IPunchTweenOption): Tween<Node>;
|
||||
|
||||
jumpX?: number;
|
||||
jumpY?: number;
|
||||
jumpZ?: number;
|
||||
jumpOffsetY?: number;
|
||||
/**
|
||||
* @zh
|
||||
* 缓动目标的坐标到指定值,在移动过程中同时附加一个Y坐标的高度值来模拟跳跃动作
|
||||
* @en
|
||||
* Tweens the target's position to the given value, while also applying a jump effect along the Y axis.
|
||||
* @param to 目标坐标值
|
||||
* @param jumpHeight 跳跃高度
|
||||
* @param jumpNum 跳跃次数
|
||||
* @param duration 时间
|
||||
* @param opts tween options
|
||||
*/
|
||||
qtJumpPosition(to: Vec3, jumpHeight: number, jumpNum: number, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 使目标的位置在设定的参数下抖动
|
||||
* @en
|
||||
* Shakes the target's position with the given values
|
||||
* @param strength 强度
|
||||
* @param duration 时间
|
||||
* @param {IShakeTweenOption} opts shake tween options
|
||||
* @param {number} opts.vibrato 每秒振动次数
|
||||
* @param {number} opts.randomness 随机角度值
|
||||
* @param {boolean} opts.fadeOut 是否淡出
|
||||
*/
|
||||
qtShakePosition(strength: Vec3 | number, duration: number, opts?: IShakeTweenOption): Tween<Node>;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 使目标的旋转在设定的参数下抖动
|
||||
* @en
|
||||
* Shakes the target's rotation with the given values
|
||||
* @param strength 强度
|
||||
* @param duration 时间
|
||||
* @param {IShakeTweenOption} opts shake tween options
|
||||
* @param {number} opts.vibrato 每秒振动次数
|
||||
* @param {number} opts.randomness 随机角度值
|
||||
* @param {boolean} opts.fadeOut 是否淡出
|
||||
*/
|
||||
qtShakeRotation(strength: Vec3 | number, duration: number, opts?: IShakeTweenOption): Tween<Node>;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 使目标的缩放在设定的参数下抖动
|
||||
* @en
|
||||
* Shakes the target's scale with the given values
|
||||
* @param strength 强度
|
||||
* @param duration 时间
|
||||
* @param {IShakeTweenOption} opts shake tween options
|
||||
* @param {number} opts.vibrato 每秒振动次数
|
||||
* @param {number} opts.randomness 随机角度值
|
||||
* @param {boolean} opts.fadeOut 是否淡出
|
||||
*/
|
||||
qtShakeScale(strength: Vec3 | number, duration: number, opts?: IShakeTweenOption): Tween<Node>;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 缓动目标的坐标到指定值,使用二次贝塞尔曲线
|
||||
* @en
|
||||
* Tweens the target's position to the given value, using a quadratic Bezier curve.
|
||||
* @param p1 起点
|
||||
* @param cp 控制点
|
||||
* @param p2 终点
|
||||
* @param duration 时间
|
||||
* @param opts tween options
|
||||
*/
|
||||
qtQuadraticCurve(p1: Vec3, cp: Vec3, p2: Vec3, duration: number, opts?: ITweenOption): Tween<Node>;
|
||||
}
|
||||
|
||||
interface Sprite {
|
||||
qtColor(to: Color, duration: number, opts?: ITweenOption): Tween<Sprite>;
|
||||
qtOpacity(to: number, duration: number, opts?: ITweenOption): Tween<Sprite>;
|
||||
}
|
||||
|
||||
interface Label extends Omit<UIRenderer, 'spriteFrame'> {
|
||||
//@ts-expect-error
|
||||
spriteFrame: SpriteFrame | null;
|
||||
qtColor(to: Color, duration: number, opts?: ITweenOption): Tween<Label>;
|
||||
qtString(to: string, duration: number, opts?: ITweenOption): Tween<Label>;
|
||||
}
|
||||
|
||||
interface Camera {
|
||||
/**
|
||||
* @zh
|
||||
* 使目标的位置在设定的参数下抖动
|
||||
* @en
|
||||
* Shakes the target's position with the given values
|
||||
* @param strength 强度
|
||||
* @param duration 时间
|
||||
* @param {IShakeTweenOption} opts shake tween options
|
||||
* @param {number} opts.vibrato 每秒振动次数
|
||||
* @param {number} opts.randomness 随机角度值
|
||||
* @param {boolean} opts.fadeOut 是否淡出
|
||||
*/
|
||||
qtShakePosition(strength: Vec3 | number, duration: number, opts?: IShakeTweenOption): Tween<Node>;
|
||||
}
|
||||
}
|
||||
9
assets/script/QuickTween/quick-tween.d.ts.meta
Normal file
9
assets/script/QuickTween/quick-tween.d.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "af3336d7-4ce2-4d9d-a529-51281d4eaa30",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user