Commit 93f145c7 authored by haiyoucuv's avatar haiyoucuv

整理代码1

parent 3e04d3a4

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

[InternetShortcut]
URL=https://docs.cocos.com/creator/manual/en/scripting/setup.html#custom-script-template
\ No newline at end of file
{
"image": {
"type": "sprite-frame"
}
}
#///////////////////////////
# Cocos Creator 3D Project
#///////////////////////////
library/
temp/
local/
build/web-desktop/
build/web-mobile/cocos-js
build/web-mobile/remote
build/web-mobile/src
build/web-mobile/*.js
build/web-mobile/*.css
build/web-mobile-001/cocos-js
build/web-mobile-001/remote
build/web-mobile-001/src
build/web-mobile-001/*.js
build/web-mobile-001/*.css
profiles/
native
#//////////////////////////
# NPM
#//////////////////////////
node_modules/
#//////////////////////////
# VSCode
#//////////////////////////
#.vscode/
#//////////////////////////
# WebStorm
#//////////////////////////
#.idea/
.DS_Store
tmp.txt
\ No newline at end of file
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# GitHub Copilot persisted chat sessions
/copilot/chatSessions
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/library" />
<excludeFolder url="file://$MODULE_DIR$/profiles" />
<excludeFolder url="file://$MODULE_DIR$/extensions/prefab-tab/node_modules" />
<excludeFolder url="file://$MODULE_DIR$/extensions" />
</content>
<content url="file://$MODULE_DIR$/extensions/prefab-tab/node_modules" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="luna-object-viewer" level="application" />
<orderEntry type="library" name="luna-data-grid" level="application" />
<orderEntry type="library" name="luna-dom-viewer" level="application" />
<orderEntry type="library" name="luna-console" level="application" />
</component>
</module>
\ No newline at end of file
<component name="CopyrightManager">
<settings default="haiyoucuv">
<LanguageOptions name="ActionScript">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="CSS">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="ECMAScript 6">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="JSX Harmony">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="JavaScript">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="Less">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="Rust">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="SCSS">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="Stylus">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="TypeScript">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
<LanguageOptions name="TypeScript JSX">
<option name="fileTypeOverride" value="3" />
<option name="separateBefore" value="true" />
<option name="lenBefore" value="1" />
</LanguageOptions>
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectDictionaryState">
<dictionary name="qiuxu" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/../../../../../Cocos/editors/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/@types/cc.d.ts" charset="GBK" />
<file url="file://$PROJECT_DIR$/assets/AppTool.ts" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/assets/Component/Svga" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/assets/Module/hooks" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/assets/Scripts/Utils/Crypto.ts" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/assets/Scripts/Utils/Crypto.ts.meta" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/assets/plugin/SVGA.Lite.v2.1.1.js" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/assets/plugin/SVGA.Lite.v2.1.1.js.meta" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/assets/plugin/declare-process.js" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/assets/plugin/declare-process.js.meta" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/assets/store" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/preview-template/mock/loop/changeDetails.do.json" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/preview-template/mock/loop/prizeRecord.do.json" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/限流页面.html" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/../../批量压缩资源/点我开始处理资源压缩.bat" charset="GBK" />
<file url="PROJECT" charset="GBK" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxBlameSettings">
<option name="version" value="2" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxProjectSettings">
<option name="commitMessageIssueKeyValidationOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
<option name="commitMessageValidationEnabledOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JSNonASCIINames" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Default" />
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<includedPredefinedLibrary name="Node.js Core" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RustProjectSettings">
<option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/cocos-template-3d.iml" filepath="$PROJECT_DIR$/.idea/cocos-template-3d.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VagrantProjectSettings">
<option name="instanceFolder" value="" />
<option name="provider" value="" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectTasksOptions">
<TaskOptions isEnabled="false">
<option name="arguments" value="http://localhost:7456/asset-db/refresh" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="ts" />
<option name="immediateSync" value="true" />
<option name="name" value="Cocos3保存自动刷新" />
<option name="output" value="" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="curl" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="" />
<envs />
</TaskOptions>
</component>
</project>
\ No newline at end of file
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Cocos Creator Launch Chrome against localhost",
"url": "http://localhost:7456",
"webRoot": "${workspaceFolder}"
}
]
}
\ No newline at end of file
{
"version": "2.0.0",
"tasks": [
{
"label": "Cocos Creator compile",
"command": "curl",
"args": [
"http://localhost:7456/asset-db/refresh"
],
"type": "shell",
"isBackground": true,
"group": "build",
"presentation": {
"reveal": "always"
}
}
]
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "e20e0c55-d47d-462a-be6b-9fbbb71b55ec",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a2093526-9e54-49b7-be30-87d01601a00e",
"files": [],
"subMetas": {},
"userData": {
"bundleFilterConfig": [],
"isBundle": true
}
}
This diff is collapsed.
{
"ver": "1.1.50",
"importer": "scene",
"imported": true,
"uuid": "53947ca7-3484-4b53-800d-509405063d68",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "e76e702d-2e63-4483-975a-35d6f429f7a2",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "e64b34f1-7f36-4e07-8412-90f3f022f678",
"files": [],
"subMetas": {},
"userData": {}
}
{
"__type__": "cc.SpriteAtlas"
}
{
"ver": "1.0.8",
"importer": "auto-atlas",
"imported": true,
"uuid": "cbb680bf-a0cb-4362-91cd-0eecf6f971c0",
"files": [
".json"
],
"subMetas": {},
"userData": {
"maxWidth": 2048,
"maxHeight": 2048,
"padding": 2,
"allowRotation": true,
"forceSquared": false,
"powerOfTwo": false,
"algorithm": "MaxRects",
"format": "png",
"quality": 80,
"contourBleed": true,
"paddingBleed": true,
"filterUnused": false,
"removeTextureInBundle": false,
"removeImageInBundle": false,
"removeSpriteAtlasInBundle": false,
"compressSettings": {
"useCompressTexture": false,
"presetId": "2etBRk4AVAJpyEha/NLaL+"
},
"textureSetting": {
"wrapModeS": "repeat",
"wrapModeT": "repeat",
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
}
}
}
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "851d4e4c-7317-4904-9f5f-cbc80c70701c",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "851d4e4c-7317-4904-9f5f-cbc80c70701c@6c48a",
"displayName": "得分_bg",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "851d4e4c-7317-4904-9f5f-cbc80c70701c",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "851d4e4c-7317-4904-9f5f-cbc80c70701c@f9941",
"displayName": "得分_bg",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 287,
"height": 72,
"rawWidth": 287,
"rawHeight": 72,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-143.5,
-36,
0,
143.5,
-36,
0,
-143.5,
36,
0,
143.5,
36,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
72,
287,
72,
0,
0,
287,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-143.5,
-36,
0
],
"maxPos": [
143.5,
36,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "851d4e4c-7317-4904-9f5f-cbc80c70701c@6c48a",
"atlasUuid": ""
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"hasAlpha": true,
"fixAlphaTransparencyArtifacts": false,
"redirect": "851d4e4c-7317-4904-9f5f-cbc80c70701c@6c48a"
}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "78e6d446-0a8f-41a2-bc28-81f9ba2aea6f",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "095e2667-4a7b-497b-8e49-a5cd3ee55e68",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "d12c8f84-9336-4371-bd42-2c837b1d0138",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, CCBoolean, PageView, Vec2 } from 'cc';
const {icon, ccclass, property, disallowMultiple, menu} = _decorator;
@ccclass('CirculatePageView')
@disallowMultiple
@menu('自定义组件/CirculatePageView')
export class CirculatePageView extends PageView {
@property({
displayName: '循环滚动',
tooltip: "是否循环"
})
public circulate = true;
protected _autoScrollToPage(): void {
const bounceBackStarted = this._startBounceBackIfNeeded();
if (!this.circulate && bounceBackStarted) {
const bounceBackAmount = this._getHowMuchOutOfBoundary();
this._clampDelta(bounceBackAmount);
if (bounceBackAmount.x > 0 || bounceBackAmount.y < 0) {
this._curPageIdx = this._pages.length === 0 ? 0 : this._pages.length - 1;
}
if (bounceBackAmount.x < 0 || bounceBackAmount.y > 0) {
this._curPageIdx = 0;
}
if (this.indicator) {
this.indicator._changedState();
}
} else {
const moveOffset = new Vec2();
Vec2.subtract(moveOffset, this._touchBeganPosition, this._touchEndPosition);
const index = this._curPageIdx;
const nextIndex = index + this._getDragDirection(moveOffset);
const timeInSecond = this.pageTurningSpeed * Math.abs(index - nextIndex);
if (this.circulate) {
if (nextIndex >= this._pages.length) {
this.scrollToPage(0, timeInSecond);
return;
}
if (nextIndex < 0) {
this.scrollToPage(this._pages.length - 1, timeInSecond);
return;
}
}
if (nextIndex < this._pages.length) {
if (this._isScrollable(moveOffset, index, nextIndex)) {
this.scrollToPage(nextIndex, timeInSecond);
return;
} else {
const touchMoveVelocity = this._calculateTouchMoveVelocity();
if (this._isQuicklyScrollable(touchMoveVelocity)) {
this.scrollToPage(nextIndex, timeInSecond);
return;
}
}
}
this.scrollToPage(index, timeInSecond);
}
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "1563e9d8-1994-463c-bdbb-15b00d1f998e",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "98c4763d-a6a0-42dc-b228-4fe79200b423",
"files": [],
"subMetas": {},
"userData": {}
}
import {SvgaTrack} from "./SvgaTrack";
import {createImageAsync, createSpriteFrameAsync} from "./loadSvga";
import {
_decorator,
Asset,
Component,
ImageAsset,
Layers,
Node,
Sprite,
SpriteFrame,
Texture2D,
UITransform,
v3
} from "cc";
const {ccclass, property} = _decorator;
import menu = _decorator.menu;
import disallowMultiple = _decorator.disallowMultiple;
import executeInEditMode = _decorator.executeInEditMode;
import playOnFocus = _decorator.playOnFocus;
@ccclass
@executeInEditMode
@disallowMultiple
@playOnFocus
@menu('自定义组件/Svga')
export default class Svga extends Component {
static EventType = {
END_FRAME: "SVGA_END_FRAME",
}
/************************ on Editor ************************/
private edit_update: boolean = false;
onFocusInEditor() {
this.edit_update = true;
this.play(0);
}
onLostFocusInEditor() {
this.edit_update = false;
}
async resetInEditor() {
await this._load();
this.edit_update = true;
this.play(0);
}
onEnable() {
CC_EDITOR && this.play(0);
}
/************************ on Editor ************************/
/************************ ************************/
private aniNode: Node = null;
@property(Asset)
private _svga: Asset = null;
@property(Asset)
get svga() {
return this._svga;
}
set svga(svga) {
if (svga !== this._svga) {
this._svga = svga;
this._load().then(() => {
this.play(0);
});
}
}
private tracks: SvgaTrack[] = [];
isPlaying: boolean = false;
vmData: SVGA.Video = null;
async onLoad() {
this.aniNode = this.node.getChildByName("aniNode");
if (!this.aniNode) {
this.aniNode = new Node("aniNode");
this.aniNode.layer = Layers.Enum.UI_2D;
this.aniNode.setScale(v3(1, -1, 1));
this.node.addChild(this.aniNode);
}
await this._load();
(this.autoPlay || CC_EDITOR) && this.play(0);
}
start() {
}
play(frame = 0) {
this.curFrame = frame;
this.isPlaying = true;
return this;
}
stop(isReset: boolean = false) {
if (isReset) this.curFrame = 0;
this.isPlaying = false;
return this;
}
// 初始化就播放
@property({tooltip: "是否自动播放"})
private autoPlay: boolean = true;
// 是否循环
@property
private _loop: boolean = false;
@property({tooltip: "是否循环"})
get loop() {
return this._loop;
}
set loop(loop) {
this._loop = loop;
CC_EDITOR && this.play();
}
// 总时间,秒计
get totalTime(): number {
return this._totalFrames * (1 / this.fps) || 0;
};
// 总帧数
private _totalFrames: number = 0;
get totalFrames() {
return this._totalFrames;
}
// 帧时间
private _frameTime = 0;
// fps 没设置就会用vmData里的帧率
@property
private _fps: number = 0;
@property
get fps() {
return this._fps || this.vmData?.fps || 0;
}
set fps(fps) {
this._fps = fps;
this._frameTime = 1 / fps;
}
// 当前时间
private _curTime = 0;
get curTime() {
return this._curTime;
}
set curTime(time) {
this._curTime = time;
this._curFrame = time * this.fps;
}
// 当前帧
private _curFrame = 0;
get curFrame() {
return this._curFrame;
}
set curFrame(frame) {
this._curFrame = frame;
this._curTime = frame / this.fps;
}
update(dt) {
if (
(CC_EDITOR && !this.edit_update)
|| !this.isPlaying
) return;
this.curTime += dt;
if (this._curFrame > this.totalFrames) {
this.node.emit(Svga.EventType.END_FRAME);
if (this.loop) {
this.curTime = (this._curFrame - this.totalFrames) * this._frameTime;
} else {
this.stop(false);
}
}
this.tracks.forEach((v) => {
v.setValue(this._curFrame);
});
}
protected onDestroy() {
const tracks = this.tracks;
const len = tracks.length;
for (let i = 0; i < len; i++) {
tracks[i].destroy();
}
this.tracks.length = 0;
}
async _load() {
if (!this.aniNode || !this.svga) {
console.log(!!this.aniNode, !!this.svga);
return;
}
this.aniNode.removeAllChildren();
const vm = this.svga["_file"] as SVGA.Video;
vm["textures"] = {};
this.vmData = vm;
const {fps, size, images, sprites, frames,} = vm;
if (!this.fps) this.fps = fps;
this._totalFrames = frames;
this.getComponent(UITransform).setContentSize(size.width, size.height);
this.aniNode.setPosition(-size.width / 2, size.height / 2);
const ps = [];
for (let key in images) {
let src = images[key];
if (typeof src === "string") {
if (src.indexOf("iVBO") === 0 || src.indexOf("/9j/2w") === 0) {
src = 'data:image/png;base64,' + src;
}
ps.push(
createSpriteFrameAsync(src).then((sp) => {
vm["textures"][key] = sp;
})
// createImageAsync(src).then((img) => {
// const texture = new Texture2D();
// texture.image = new ImageAsset(img);
// const spr = new SpriteFrame();
// spr.texture = texture;
// vm["textures"][key] = spr;
// })
);
} else {
const texture = new Texture2D();
texture.image = new ImageAsset(src);
const spr = new SpriteFrame();
spr.texture = texture;
vm["textures"][key] = spr;
}
}
await Promise.all(ps);
const len = sprites.length;
for (let i = 0; i < len; i++) {
const {imageKey, frames} = sprites[i];
if (!imageKey) return;
const node = new Node(imageKey);
node.layer = Layers.Enum.UI_2D;
node.addComponent(UITransform).setAnchorPoint(0, 1);
this.aniNode.addChild(node);
const sp = node.addComponent(Sprite);
sp.spriteFrame = vm["textures"][imageKey];
const track = new SvgaTrack(node, frames);
track.resetValue();
this.tracks.push(track);
}
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "7c5ff865-1c3a-41a6-80d0-f307ca37ba6e",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
import { _decorator, Asset, Component, Sprite, SpriteFrame, Texture2D, } from "cc";
const {ccclass, property, requireComponent} = _decorator;
import menu = _decorator.menu;
import disallowMultiple = _decorator.disallowMultiple;
import executeInEditMode = _decorator.executeInEditMode;
import playOnFocus = _decorator.playOnFocus;
const wran = "⚠️实验组件,性能很差,不建议使用";
@ccclass("SvgaOffScreen")
@executeInEditMode
@disallowMultiple
@playOnFocus
@requireComponent(Sprite)
@menu('自定义组件/Svga离屏渲染器(⚠️实验)(⚠️性能很差)')
export default class SvgaOffScreen extends Component {
@property({tooltip: wran, displayName: wran})
tips: boolean = true;
isPlaying: boolean = false;
canvas: HTMLCanvasElement = null;
sf: SpriteFrame;
player: SVGA.Player;
/************************ on Editor ************************/
private edit_update: boolean = false;
/************************ on Editor ************************/
// 初始化就播放
@property({tooltip: "是否自动播放"})
private autoPlay: boolean = true;
/************************ ************************/
@property(Asset)
private _svga: Asset = null;
@property(Asset)
get svga() {
return this._svga;
}
set svga(svga) {
this._svga = svga;
this.mount();
}
// 是否循环
@property
private _loop: boolean = false;
@property({tooltip: "是否循环"})
get loop() {
return this._loop;
}
set loop(loop) {
this._loop = loop;
this.player.config.loop = loop ? 0 : 1;
this.player.animator.loop = loop ? Infinity : 1;
CC_EDITOR && this.play();
}
// 总时间,秒计
get totalTime(): number {
return this.player.animator?.duration / 1000;
};
// 总帧数
get totalFrames() {
return this.player.totalFrames;
}
// fps
@property
private _fps: number = 0;
@property
get fps() {
return this._fps || this.player?.videoEntity?.fps || 0;
}
set fps(fps) {
this._fps = fps;
if (this.player.videoEntity) {
this.player.videoEntity.fps = fps;
this.player.animator.duration = this.player.videoEntity.frames * (1.0 / fps) * 1000;
}
}
// 当前帧
get curFrame() {
return this.player.currentFrame;
}
set curFrame(frame) {
this.player.currentFrame = frame;
this.player.animator && (this.player.animator.startValue = frame);
}
onFocusInEditor() {
this.edit_update = true;
this.play(0);
}
onLostFocusInEditor() {
this.edit_update = false;
}
async resetInEditor() {
await this.mount();
this.edit_update = true;
this.play(0);
}
onEnable() {
CC_EDITOR && this.play(0);
}
async onLoad() {
console.warn(`[${this.name}] -> ${wran}`);
this.canvas = document.createElement("canvas");
;
this.player = new SVGA.Player({
container: this.canvas,
isUseIntersectionObserver: false,
isCacheFrames: false,
loop: this.loop ? 0 : 1,
});
await this.mount();
this.sf = SpriteFrame.createWithImage(this.canvas);
this.getComponent(Sprite).spriteFrame = this.sf;
}
start() {
}
async mount() {
if (!this.svga) return;
this.canvas.width = this.svga["_file"].size.width;
this.canvas.height = this.svga["_file"].size.height;
await this.player.mount(this.svga["_file"]);
this.fps = this.fps;
if (this.autoPlay) this.play(0);
}
update(dt) {
(this.sf?.texture as Texture2D).updateImage();
}
onDestroy() {
this.player.destroy();
}
play(frame = 0) {
if (!this.player) return;
this.player.start();
this.curFrame = frame;
this.isPlaying = true;
return this;
}
stop(isReset: boolean = false) {
if (!this.player) return;
if (isReset) this.curFrame = 0;
this.player.stop();
this.isPlaying = false;
return this;
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "da2fa8b4-30b6-459d-ae5a-9c7fa86f5b2c",
"files": [],
"subMetas": {},
"userData": {}
}
import { color, mat4, misc, Node, Sprite } from "cc";
export class SvgaTrack {
constructor(
private node: Node,
private frames: SVGA.VideoFrame[],
) {
}
tempMat = mat4();
tempColor = color(255, 255, 255, 255);
/**
* 这里用的帧数
* @param time 帧小数
*/
setValue(time: number) {
const {node, frames, tempColor, tempMat} = this;
// time = time % this.frames.length;
//处理time
time = Math.round(misc.clampf(time, 0, frames.length - 1));
//找对应数据
const {alpha, transform, maskPath} = frames[time];
// layout不晓得干嘛用,暂不管
if (alpha < 0.05) {
tempColor.a = 0;
node.getComponent(Sprite).color = tempColor;
} else {
tempColor.a = alpha * 255;
node.getComponent(Sprite).color = tempColor;
const {a, b, c, d, tx, ty} = transform;
tempMat.m00 = a;
tempMat.m01 = b;
tempMat.m04 = -c;
tempMat.m05 = -d;
tempMat.m12 = tx;
tempMat.m13 = ty;
node.matrix = tempMat;
}
}
resetValue() {
// @ts-ignore
// 2.x 重置计算本地矩阵的标记,让渲染器不计算本地矩阵,不重置的话,会在刚开始的时候计算一次
// this.node._renderFlag &= ~cc.RenderFlow.FLAG_LOCAL_TRANSFORM;
this.setValue(0);
}
destroy() {
this.node = null;
// this.frames.length = 0; // 不能加!!!
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "5eefef5b-f769-4053-8198-fa7070f661b8",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
import { SpriteFrame } from "cc";
/**
* 导出只是当作类型接口用
*/
export interface IVideoEntity {
/**
* SVGA 文件版本
*/
version: string;
/**
* 影片尺寸
*/
videoSize: {
width: number;
height: number;
};
/**
* 影片尺寸
*/
size: {
width: number;
height: number;
};
/**
* 帧率,60,30等每秒
*/
FPS: number;
/**
* 帧率,60,30等每秒
*/
fps: number;
/**
* 总帧数
*/
frames: number;
/**
* base64图片数据记录
*/
images: { [key: string]: string };
/**
* 缓存的纹理
*/
textures: { [key: string]: SpriteFrame };
// textures: { [key: string]: cc.Node };
/**
* 图片是否已被缓存,缓存全局,注意名字覆盖
*/
hasBeenCached: boolean;
/**
* sprite对象数据
*/
sprites: ISpriteEntity[];
}
export interface ISpriteEntity {
/**
* 暂时没用
*/
matteKey: string;
/**
* 图片key值
*/
imageKey: string;
/**
* 帧数据数组
*/
frames: IFrameEntity[];
}
/**
* 还有很多其他数据,暂不需要,比如矢量路径和遮罩路径暂时都无
*/
export interface IFrameEntity {
/**
* 透明度
*/
alpha: number;
/**
* 2维矩阵数据
*/
transform: {
a: number,
b: number,
c: number,
d: number,
tx: number,
ty: number,
};
/**
* 遮罩数据
*/
maskPath?: { _d: string, _styles: any, _transform: any }
}
/**
* 就是个时间轴,setValue和resetValue方法自行实现
*/
export interface IAnimationTrack {
setValue: (time: number) => void
resetValue: () => void
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "dbeb7c7f-ca46-42d7-8b41-ab1396f60b69",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
import {assetManager, ImageAsset, SpriteFrame, Texture2D} from "cc";
const loadCache = {};
assetManager.downloader.register('.svga', async (path, options, onComplete) => {
// // @ts-ignore
// assetManager.downloader.downloadFile(path, {responseType: 'arraybuffer'}, onComplete);
if (!loadCache[path]) {
loadCache[path] = new Promise(async (resolve) => {
const svgaParser = new SVGA.Parser({
// 是否取消使用 WebWorker,默认值 false
isDisableWebWorker: CC_EDITOR,
// 是否取消使用 ImageBitmap 垫片,默认值 false
isDisableImageBitmapShim: true, // 傻逼来的,会把半透明的变成黑底
});
const videoItem = await svgaParser.load(path);
resolve(videoItem);
});
}
const videoItem = await loadCache[path];
onComplete(null, videoItem);
});
export const ImgCache: { [key in string]: HTMLImageElement } = {}
export function createImageAsync(src) {
return new Promise<HTMLImageElement>((resolve) => {
if (ImgCache[src]) {
resolve(ImgCache[src]);
} else {
const img = new Image();
img.onload = () => {
ImgCache[src] = img;
resolve(img);
}
img.src = src;
}
});
}
export const SpCache: { [key in string]: SpriteFrame } = {}
export async function createSpriteFrameAsync(src) {
if (SpCache[src]) {
return SpCache[src];
}
const img = await createImageAsync(src);
const texture = new Texture2D();
texture.image = new ImageAsset(img);
const sp = new SpriteFrame();
sp.texture = texture;
SpCache[src] = sp;
return sp;
}
export function createImage(src) {
if (ImgCache[src]) return ImgCache[src];
const img = new Image();
ImgCache[src] = img; // 不在onload之后应该没事吧
img.src = src;
return img;
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "d0e08115-3ffa-4584-95dd-529ce75ef0fe",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "766c3224-4709-4c9c-b7f0-dc623dac918a",
"files": [],
"subMetas": {},
"userData": {}
}
import { EventTarget } from "cc";
export const eventTarget = new EventTarget();
export enum MEvent {
ADD_SCORE = "addScore",
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "2f8ee846-7d66-47dc-8291-cb022d4b0125",
"files": [],
"subMetas": {},
"userData": {}
}
import { Button, Component, Node } from "cc";
export default class Module extends Component {
static bundle: string = "";
static skin: string = "";
static group: string | string[] = null;
static data: any = {};
btnEnable(btn: Node | Button, enable) {
if (btn instanceof Node) {
btn = btn.getComponent(Button);
}
if (!btn) return;
btn.interactable = enable;
}
btnDelay(btn: Node | Button, time) {
if (btn instanceof Node) {
btn = btn.getComponent(Button);
}
if (!btn) return;
this.scheduleOnce(() => {
(btn as Button).interactable = true;
}, time);
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "5c11d8ea-3186-4038-a03a-8f4948941787",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, easing, Node, tween, v3 } from "cc";
import Module from "db://assets/Module/Module";
import { hidePanel } from "db://assets/Module/UIFast";
import { loadAllObject } from "db://assets/Scripts/Utils/Utils";
import { UIMgr } from "./UIMgr";
const {ccclass, property} = _decorator;
@ccclass()
export default class Panel extends Module {
view: { [key in string]: Node } = {};
data: any = {};
onLoad() {
this.view = loadAllObject(this.node);
}
onShow() {
if (this.data.panelType == "scrollTop") {
this.node.setPosition(v3(0, -812, 0));
tween(this.node)
.to(0.188, { position: v3(0, 0, 0)}, { easing: easing.quadInOut })
.start();
} else if (this.data.panelType == "topNoScale") {
// 居顶适配 且不需要缩放动效
this.node.setPosition(v3(0, 0, 0));
} else {
this.node.setScale(v3(0, 0, 1));
tween(this.node)
.to(0.188, { scale: v3(1, 1, 1) }, { easing: easing.quadInOut })
.start();
}
}
hidePanel() {
this.node.emit('close-panel');
// PanelCtrl.ins.hide();
const parent = this.node.parent;
hidePanel();
// parent.getComponent(PanelCtrl)?.hide();
// parent.getComponent(TopCtrl)?.hide();
}
hideAllPanel() {
this.node.emit('close-panel');
UIMgr.ins.hideAllPanel();
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "301c4cbf-df88-4525-9de0-2af0d020fb8e",
"files": [],
"subMetas": {},
"userData": {}
}
import { Asset, assetManager, AssetManager, ImageAsset, resources, SpriteFrame, Texture2D } from "cc";
namespace RES {
export const bundles: { [key in string]: AssetManager.Bundle } = {};
export function loadBundle(name: string) {
const url = window["__remoteAssets__"] || "";
return new Promise((resolve, reject) => {
assetManager.loadBundle(url + name, (err, bundle) => {
if (err !== null) {
console.log("[RES]:Load AssetsBundle Error: " + name);
bundles[name] = null;
reject(err);
} else {
console.log("[RES]:Load AssetsBundle Success: " + name);
bundles[name] = bundle;
resolve(true);
}
});
});
}
export const getRes = resources.get.bind(resources);
export function loadRes<T extends Asset>(path: string, type?: typeof Asset): Promise<T | null> {
return new Promise((resolve) => {
resources.load(path, type, (err, asset: T) => {
if (err) {
console.warn(`资源 ${path} 加载失败:`, err);
resolve(null);
} else if (!asset) {
resolve(null);
} else {
resolve(asset);
}
});
});
}
export function loadRemote<T extends Asset>(url: string): Promise<T | null> {
return new Promise(resolve => {
assetManager.loadRemote(url, (err, asset: T) => {
if (err || !asset) {
console.warn(`资源 ${url} 加载失败:`, err);
resolve(null);
} else {
resolve(asset)
}
})
})
}
export async function loadRemoteImg(url: string): Promise<Texture2D> {
return await RES.loadRemote<Texture2D>(url);
}
export async function loadLocalImg(url: string): Promise<SpriteFrame> {
return new Promise(resolve => {
resources.load<ImageAsset>(url, (err, asset) => {
if (err || !asset) {
console.warn(`资源 ${url} 加载失败:`, err);
resolve(null);
} else {
resolve(SpriteFrame.createWithImage(asset));
}
})
})
}
export function loadDir<T extends Asset>(path: string, onProgress: (finish: number, total: number) => void = () => 0): Promise<boolean> {
// const bundle = bundles["resources"];
// if (!bundle) {
// console.warn("resources 未初始化");
// }
return new Promise((resolve) => {
resources.loadDir(path, onProgress, (err, assets: Array<T>) => {
if (err) {
console.warn(`资源 ${path} 加载失败:`, err);
resolve(false);
} else {
resolve(true);
}
});
});
}
}
export default RES;
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "1e208e5d-4a22-47d7-8697-56db871f7acd",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator } from "cc";
import Module from "db://assets/Module/Module";
import { UILayer } from "db://assets/Module/UILayer";
const {ccclass, property} = _decorator;
@ccclass()
export default class Scene extends Module {
@property(UILayer)
uiLayer: UILayer = null;
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "61b51d14-2b50-4002-b840-19f29a1ced2f",
"files": [],
"subMetas": {},
"userData": {}
}
import { UIMgr } from "db://assets/Module/UIMgr";
import Scene from "db://assets/Module/Scene";
export async function changeScene(cls: typeof Scene, data?: any) {
await UIMgr.ins.changeScene(cls, data);
}
export async function showPanel(cls: any, data: any = {}, showMask: boolean = true) {
await UIMgr.ins.showPanel(cls, data, showMask);
}
export function hidePanel() {
UIMgr.ins.hidePanel();
}
export async function hideAllPanel() {
UIMgr.ins.hideAllPanel();
}
export function showWaiting(mask: boolean = true) {
UIMgr.ins.showWaiting(mask);
}
export function hideWaiting() {
UIMgr.ins.hideWaiting();
}
export function showToast(content: string, mask: boolean = false) {
UIMgr.ins.showToast(content, mask);
}
export function hideToast() {
UIMgr.ins.hideToast();
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "42c74a6b-b3d9-4236-b2ef-ed4140d8b4d8",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component, Node } from 'cc';
import { loadAllObject } from "db://assets/Scripts/Utils/Utils";
const {ccclass, property} = _decorator;
@ccclass('UILayer')
export class UILayer extends Component {
view: { [key in string]: Node } = {};
onLoad() {
this.view = loadAllObject(this.node);
}
start() {
}
update(deltaTime: number) {
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "a032bd13-cba3-48db-be3e-c41780ce390f",
"files": [],
"subMetas": {},
"userData": {}
}
import {
assetManager,
director,
error,
instantiate,
Label,
Node,
Prefab,
tween,
UIOpacity,
UITransform,
Widget
} from "cc";
import Scene from "db://assets/Module/Scene";
import Panel from "db://assets/Module/Panel";
import RES from "db://assets/Module/RES";
export class UIMgr {
private static _ins: UIMgr = null;
static get ins() {
if (!UIMgr._ins) UIMgr._ins = new UIMgr();
return UIMgr._ins;
}
uiCanvas: Node;
private createFullScreenNode() {
let canvas = this.uiCanvas.getComponent(UITransform);
let node = new Node();
node.layer = this.uiCanvas.layer;
let uiTransform = node.addComponent(UITransform);
uiTransform.width = canvas.width;
uiTransform.height = canvas.height;
let widget = node.addComponent(Widget);
widget.isAlignBottom = true;
widget.isAlignTop = true;
widget.isAlignLeft = true;
widget.isAlignRight = true;
widget.left = 0;
widget.right = 0;
widget.top = 0;
widget.bottom = 0;
return node;
}
setup(uiPrefab: Node | Prefab, layerNames?: Array<string>) {
if (this.uiCanvas) {
return;
}
if (!uiPrefab) {
throw error('必须是Node或Prefab');
}
if (uiPrefab instanceof Prefab) {
this.uiCanvas = instantiate(uiPrefab);
director.getScene().addChild(this.uiCanvas);
} else {
this.uiCanvas = uiPrefab;
}
this.uiCanvas.name = '$UICanvas$';
director.addPersistRootNode(this.uiCanvas);
this.waiting = this.uiCanvas.getChildByName("Waiting");
this.panel = this.uiCanvas.getChildByName("Panel");
this.panelMask = this.panel.getChildByName("mask");
this.toast = this.uiCanvas.getChildByName("Toast");
this.toastBg = this.toast.getChildByName("bg");
this.toastLabel = this.toastBg.getChildByName("label");
this.waiting.active = false;
this.toast.active = false;
}
/********* Scene *********/
// 节省判断
currentScene = {data: undefined};
static async changeScene(cls: typeof Scene, data: any = {}) {
await UIMgr.ins.changeScene(cls, data);
}
async changeScene(cls: typeof Scene, data: any = {}) {
const {skin, group = skin, bundle} = cls;
const loadPs = [];
if (bundle) {
const assetBundle = assetManager.getBundle(bundle);
if (!assetBundle) {
loadPs.push(new Promise<void>((resolve, reject) => {
assetManager.loadBundle(bundle, (err, loadedBundle) => {
if (err) {
reject(err);
} else {
resolve();
}
});
}));
}
} else {
if (Array.isArray(group)) {
group.forEach((item) => {
loadPs.push(RES.loadDir(item));
});
} else {
loadPs.push(RES.loadDir(group));
}
}
this.showWaiting();
await Promise.all(loadPs);
cls.data = data;
director.loadScene(
skin,
() => {
this.hideWaiting();
this.currentScene = cls;
},
() => {
this.currentScene.data = {};
}
);
}
/********* Scene *********/
/********* Panel *********/
panel: Node;
panelMask: Node;
panelStack: any[] = [];
curPanel: {
cls: any,
data: any,
node: Node,
showMask: boolean,
} = null;
async showPanel(cls: typeof Panel, data = {}, showMask = true) {
const {skin, group = skin, bundle} = cls;
const loadPs = [];
loadPs.push(
RES.loadRes<Prefab>(`${skin}/${skin}`, Prefab)
);
if (Array.isArray(group)) {
group.forEach((item) => {
loadPs.push(RES.loadDir(item));
});
} else {
loadPs.push(RES.loadDir(group));
}
this.showWaiting();
const resArr = await Promise.all(loadPs);
this.hideWaiting();
// 当前弹窗处理
if (this.curPanel) {
this.curPanel.node.active = false;
this.panelStack.push(this.curPanel);
}
this.panelMask.active = true;
if (showMask) {
this.panelMask.getComponent(UIOpacity).opacity = 255 * 0.85;
} else {
this.panelMask.getComponent(UIOpacity).opacity = 0;
}
const panel = instantiate(resArr[0]);
let ctrl: Panel = panel.getComponent(skin);
// 2023/12/22 如果没有这个脚本,就直接添加
if (!ctrl) {
ctrl = panel.addComponent(skin);
}
this.panel.active = true;
this.panel.addChild(panel);
panel.layer = this.panel.layer;
ctrl.data = data;
ctrl.onShow();
this.curPanel = {
cls, data, showMask, node: panel
};
return ctrl;
}
hidePanel() {
if (!this.curPanel) return;
const { node: currPanelNode } = this.curPanel;
currPanelNode.destroy();
this.panel.removeChild(currPanelNode);
this.panel.active = false;
this.curPanel = null;
this.curPanel = this.panelStack.pop();
if (!!this.curPanel) {
const { node, showMask } = this.curPanel;
node.active = true;
if (showMask) {
this.panel.active = true;
this.panelMask.getComponent(UIOpacity).opacity = 255 * 0.8;
}
}
}
hideAllPanel() {
console.log("执行了");
for (let i = 0; i < this.panelStack.length; i++) {
this.panelStack[i].node.destroy();
this.panel.removeChild(this.panelStack[i].node);
}
this.panelStack = [];
this.hidePanel();
this.panelMask.active = false;
this.curPanel = null;
}
/********* Panel *********/
/********* Toast *********/
toast: Node;
toastBg: Node;
toastLabel: Node;
static showToast(content: string, mask: boolean = false) {
UIMgr.ins.showToast(content, mask);
}
static hideToast() {
UIMgr.ins.hideToast();
}
showToast(content: string, mask: boolean = false) {
const toastMask = this.toast.getChildByName("mask");
const uiOpacity = this.toast.getComponent(UIOpacity);
this.toastLabel.getComponent(Label).string = content.toString();
this.toast.active = true;
toastMask.active = mask;
tween(uiOpacity).stop()
.to(0.25, {opacity: 255})
.delay(1.7)
.to(0.25, {opacity: 0})
.call(() => this.hideToast())
.start();
}
hideToast() {
this.toast.active = false;
tween(this.toast).stop();
}
/********* Toast *********/
/********* Waiting *********/
waiting: Node;
static showWaiting(mask: boolean = true) {
UIMgr.ins.showWaiting(mask);
}
static hideWaiting() {
UIMgr.ins.hideWaiting();
}
showWaiting(mask: boolean = true) {
const waitingRot = this.waiting.getChildByName("waitingRot");
const waitingMask = this.waiting.getChildByName("mask");
this.waiting.active = true;
waitingMask.active = mask;
tween(waitingRot)
.repeatForever(
tween(waitingRot).by(1, {angle: 360})
)
.start();
}
hideWaiting() {
const waitingRot = this.waiting.getChildByName("waitingRot");
this.waiting.active = false;
tween(waitingRot).stop();
}
/********* Waiting *********/
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "b314fde9-1d5b-4b29-9bdc-e11c9809519a",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a22ef710-dc14-4bc8-a7b6-eeda167fd5db",
"files": [],
"subMetas": {},
"userData": {}
}
import {assetManager, ImageAsset, Sprite, SpriteFrame, Texture2D} from "cc";
import {EDITOR} from "cc/env";
const SpCache: { [key in string]: SpriteFrame } = {}
function loadRemoteSp(url): Promise<SpriteFrame> {
return new Promise((resolve) => {
if (!url) {
resolve(null);
return null;
}
if (SpCache[url]) {
resolve(SpCache[url]);
return;
}
assetManager.loadRemote<Texture2D>(url, (err, imageAsset: ImageAsset) => {
const texture = new Texture2D();
texture.image = imageAsset;
const sp = new SpriteFrame();
sp.texture = texture;
SpCache[url] = sp;
resolve(sp);
});
});
}
Sprite.prototype["_spriteFrameId"] = 0;
Object.defineProperty(Sprite.prototype, "spriteFrame", {
// get(): any {
// return this._spriteFrame;
// },
set(value) {
if (this._spriteFrame === value) {
return;
}
const id = ++this["_spriteFrameId"];
if (typeof value === 'string') {
loadRemoteSp(value).then((sp: SpriteFrame) => {
if (id !== this["_spriteFrameId"]) return;
const lastSprite = this._spriteFrame;
this._spriteFrame = sp;
this.markForUpdateRenderData();
this._applySpriteFrame(lastSprite);
if (EDITOR) {
this.node.emit(Sprite.EventType.SPRITE_FRAME_CHANGED, this);
}
});
// assetManager.loadRemote<Texture2D>(value, (err, imageAsset: ImageAsset) => {
// if (id !== this["_spriteFrameId"]) return;
// const texture = new Texture2D();
// texture.image = imageAsset;
// const sp = new SpriteFrame();
// sp.texture = texture;
//
// const lastSprite = this._spriteFrame;
// this._spriteFrame = sp;
// this.markForUpdateRenderData();
// this._applySpriteFrame(lastSprite);
//
// if (EDITOR) {
// this.node.emit(Sprite.EventType.SPRITE_FRAME_CHANGED, this);
// }
//
// });
} else {
const lastSprite = this._spriteFrame;
this._spriteFrame = value;
this.markForUpdateRenderData();
this._applySpriteFrame(lastSprite);
if (EDITOR) {
this.node.emit(Sprite.EventType.SPRITE_FRAME_CHANGED, this);
}
}
}
});
\ No newline at end of file
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "99940a25-2306-4a08-8306-047659abde9a",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "1b31aa7c-343d-45dd-b7b1-b5046a36f62f",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component, screen, ResolutionPolicy, Size, size, view, UITransform, Sprite, Canvas } from 'cc';
const { ccclass, property } = _decorator;
const CHECK_INTERVAL = 0.1;
@ccclass('FullScreenBgAutoFit')
export class FullScreenBgAutoFit extends Component {
@property(Canvas) canvasUITrans:UITransform;
private _oldSize:Size = size();
private _originalSize:Size;
private _uiTransform:UITransform;
private _sprite:Sprite;
start() {
this._uiTransform = this.getComponent(UITransform);
this._sprite = this.getComponent(Sprite);
if(!this._uiTransform || !this._sprite){
return;
}
this._originalSize = this._sprite.spriteFrame.originalSize;
this._sprite.sizeMode = Sprite.SizeMode.CUSTOM;
if(!this.canvasUITrans){
let parent = this.node.parent;
while(parent){
let canvas = parent.getComponent(Canvas);
if(canvas){
this.canvasUITrans = canvas.getComponent(UITransform);
break;
}
parent = parent.parent;
}
}
this.adjustResolutionPolicy();
}
private lastCheckTime = 0;
update(deltaTime: number) {
this.lastCheckTime+=deltaTime;
if(this.lastCheckTime < CHECK_INTERVAL){
return;
}
this.lastCheckTime = 0;
this.adjustResolutionPolicy();
}
adjustResolutionPolicy(){
let winSize = this.canvasUITrans.contentSize;
if(!this._oldSize.equals(winSize)){
let ratio = winSize.width / winSize.height;
let imgW2H = this._originalSize.width / this._originalSize.height;
if(ratio > imgW2H){
//wider than desgin.
this._uiTransform.width = winSize.width;
this._uiTransform.height = winSize.width / imgW2H;
}
else{
//higher than desgin.
this._uiTransform.width = winSize.height * imgW2H;
this._uiTransform.height = winSize.height;
}
this._oldSize.set(winSize);
}
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "31975f4f-3b2b-4d22-a2fb-8598998ce23c",
"files": [],
"subMetas": {},
"userData": {}
}
import { sendWebNet, sendWebNetWithToken, WebNetName } from "./Utils/WebNet/WebNet";
import { changeScene, hideWaiting, showPanel, showWaiting } from "db://assets/Module/UIFast";
import PrizePanel from "db://assets/Scripts/Panels/PrizePanel";
import NoPrizePanel from "db://assets/Scripts/Panels/NoPrizePanel";
import { HomeScene } from "./Scenes/HomeScene";
import { AESEncrypt } from "./Utils/Crypto";
export default class GameMgr {
private static _ins: GameMgr = null;
public static get ins() {
!GameMgr._ins && (GameMgr._ins = new GameMgr());
return GameMgr._ins;
}
gameInfo: {
startId: number,
isUsedDelay: boolean,
newGuide: boolean,
difficultyLevel: string,
targetNum: number,
rongNum: number,
richManNum: number,
loopType: string,
handType: string,
beautyStartTime: number,
beautyEndTime: number,
delaySecond: number,
delayConsumeNum: number,
isDouble: boolean,
} = {
startId: 0,
isUsedDelay: false,
newGuide: false,
difficultyLevel: "1",
targetNum: 5,
rongNum: 8,
richManNum: 0,
loopType: "1",
handType: "1",
beautyStartTime: 0,
beautyEndTime: 0,
delaySecond: 30,
delayConsumeNum: 10,
isDouble: false,
};
/**
* 开始游戏
*/
async start() {
const gameIndex = await sendWebNet(WebNetName.gameIndex);
if (!gameIndex.success) {
return false;
}
const startRes = await sendWebNetWithToken(WebNetName.start);
if (!startRes.success) {
return false;
}
const isDouble = (gameIndex.timeStamp >= gameIndex.data.hqStartTime)
&& (gameIndex.timeStamp <= gameIndex.data.hqEndTime);
this.gameInfo = {
...startRes.data,
...gameIndex.data,
isDouble,
}
return true;
}
/**
* 提交游戏结果
*/
async submit(score, hitNum) {
showWaiting();
const params = {
startId: this.gameInfo.startId,
score,
hitNum,
}
const decrypt = AESEncrypt(JSON.stringify(params), "3C8C48E792E9241B", "cDOiBC1n2QrkAY2P");
const {success, data} = await sendWebNetWithToken(WebNetName.submit, {
params: decrypt,
startId: this.gameInfo.startId,
score: 0
}, null, false);
hideWaiting();
if (!success) {
changeScene(HomeScene);
return false;
}
const {
ifReachTarget, scoreSum,
prizeName, prizeImg, prizeId,
} = data;
const openBox = () => {
if (prizeId && prizeId != "thanks") {
showPanel(PrizePanel, {
prizeName,
prizeImg,
score
});
} else {
showPanel(NoPrizePanel);
}
}
return success;
}
/**
* 使用道具
*/
async useSp() {
// showWaiting();
const res = await sendWebNetWithToken(WebNetName.consume);
// hideWaiting();
if (!res?.success) return false;
return true;
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "81ea2780-52ff-45dc-8fa1-ed314e321790",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "decb7556-4852-484a-adb8-2d7dc16c62be",
"files": [],
"subMetas": {},
"userData": {}
}
import Panel from "../../Module/Panel";
import {_decorator, Button, Node} from "cc";
import {changeScene} from "db://assets/Module/UIFast";
import {HomeScene} from "db://assets/Scripts/Scenes/HomeScene";
const {ccclass, property} = _decorator;
@ccclass('BackPanel')
export default class BackPanel extends Panel {
static skin = "BackPanel";
static group = "BackPanel";
@property(Node)
cancel: Node = null;
@property(Node)
ok: Node = null;
@property(Node)
close: Node = null;
async start() {
this.ok.on(Button.EventType.CLICK, this.clickOk, this);
this.cancel.on(Button.EventType.CLICK, this.clickCancel, this);
this.close.on(Button.EventType.CLICK, this.onClose, this);
}
clickOk() {
this.hidePanel();
changeScene(HomeScene);
}
clickCancel() {
this.data.cancel();
this.hidePanel();
}
onClose() {
this.data.cancel();
this.hidePanel();
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "ab79b766-839a-49fb-84b7-332a6266b2ee",
"files": [],
"subMetas": {},
"userData": {}
}
import Panel from "../../Module/Panel";
import { _decorator, Button, Label, Node } from "cc";
import { changeScene } from "db://assets/Module/UIFast";
import { HomeScene } from "db://assets/Scripts/Scenes/HomeScene";
const {ccclass, property} = _decorator;
@ccclass('NoPrizePanel')
export default class NoPrizePanel extends Panel {
static bundle: string = "";
static skin = "NoPrizePanel";
static group = "NoPrizePanel";
@property(Node)
close: Node = null!;
@property(Node)
cancel: Node = null!;
async start() {
this.close.on(Button.EventType.CLICK, this.onClose, this);
this.cancel.on(Button.EventType.CLICK, this.onClose, this);
}
/**
* 返回首页
*/
onClose = () => {
changeScene(HomeScene);
this.hidePanel();
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "40e916b7-335e-4d9b-8972-458386770feb",
"files": [],
"subMetas": {},
"userData": {}
}
import Panel from "../../Module/Panel";
import { _decorator, Button, Label, Node, Sprite } from "cc";
import { changeScene } from "db://assets/Module/UIFast";
import { HomeScene } from "db://assets/Scripts/Scenes/HomeScene";
import { SHARE_TYPE } from "../const";
import { strFormat } from "../Utils/Utils";
import { LOG_TYPE, sendLog } from "../Utils/WebNet/WebNet";
const {ccclass, property} = _decorator;
@ccclass('PrizePanel')
export default class PrizePanel extends Panel {
static bundle: string = "";
static skin = "PrizePanel";
static group = "PrizePanel";
@property(Node)
close: Node = null!;
@property(Node)
get: Node = null!;
@property(Node)
share: Node = null!;
@property(Label)
score: Label = null!;
@property(Label)
prizeName: Label = null!;
@property(Sprite)
img: Sprite = null!;
async start() {
sendLog(LOG_TYPE.EXPOSURE,19)
this.close.on(Button.EventType.CLICK, this.onClose, this);
this.get.on(Button.EventType.CLICK, this.onClose, this);
this.share.on(Button.EventType.CLICK, this.onShare, this);
const {prizeName, prizeImg, score} = this.data;
this.score.string = `本次游园币:${score}`;
this.prizeName.string = strFormat(
prizeName,
20
);
this.img.spriteFrame = prizeImg;
}
/**
* 返回首页
*/
onClose = () => {
changeScene(HomeScene);
this.hidePanel();
}
onShare = () => {
// 去炫耀 分享
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "acaccc5b-70bb-44c8-aadd-e478f85b6894",
"files": [],
"subMetas": {},
"userData": {}
}
import Panel from "../../Module/Panel";
import { _decorator, Button, RichText, UITransform } from "cc";
import { sendWebNet, WebNetName } from "../Utils/WebNet/WebNet";
const {ccclass, property} = _decorator;
@ccclass('RulePanel')
export default class RulePanel extends Panel {
static skin = "RulePanel";
static group = "RulePanel";
async start() {
const {data = ""} = await sendWebNet(WebNetName.projectRule);
this.setRuleTxt(data);
this.view["close"].on(Button.EventType.CLICK, () => {
this.hidePanel();
}, this);
}
setRuleTxt(txt) {
const ruleNode = this.view['ScrollView/view/content/ruleTxt'];
const ruleTxt = ruleNode.getComponent(RichText);
const content = this.view['ScrollView/view/content'];
ruleTxt.maxWidth = content.getComponent(UITransform).width;
this.scheduleOnce(() => {
ruleTxt.string = txt
.replace(/<p\b.*?(?:\>|\/>)/gi, "")
.replace(/<\/p\>/gi, "<br/>")
.replace(/<strong>/gi, "<b>")
.replace(/<\/strong>/gi, "</b>");
content.getComponent(UITransform).height = ruleNode.getComponent(UITransform).height;
}, 0.188);
}
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "fbcc1b3c-0879-4ad4-8067-d6948e7588d8",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a822ad24-2bb3-4ab4-967f-5bc029834e85",
"files": [],
"subMetas": {},
"userData": {}
}
This diff is collapsed.
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "b909f943-6b18-4557-a1bb-52f0a64e12cf",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "edf5eada-17b5-4e1f-9381-0c85cf7864a6",
"files": [],
"subMetas": {},
"userData": {}
}
This diff is collapsed.
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "2e4cf7c8-0c0b-4eef-a9bb-f1996e6461dd",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "0f51efdc-0a9e-4d8e-8bba-6e37636f3525",
"files": [],
"subMetas": {},
"userData": {}
}
This diff is collapsed.
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "5f49d944-6159-4bf4-853a-c0b18500f599",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component, Prefab, instantiate } from "cc";
const {ccclass, property} = _decorator;
@ccclass("ScrollListItem")
export class ScrollListItem extends Component {
data: any;
/**滚动列表数据变更*/
onItemRender(data, index) {
this.data = data;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment