├── .gitignore ├── README.md ├── assets ├── libs.meta ├── libs │ ├── framework.d.ts │ ├── framework.d.ts.meta │ ├── framework.min.js │ └── framework.min.js.meta ├── resources.meta ├── resources │ ├── effects.meta │ ├── effects │ │ ├── Basic.effect │ │ ├── Basic.effect.meta │ │ ├── Bevels.effect │ │ ├── Bevels.effect.meta │ │ ├── BloomCombine.effect │ │ ├── BloomCombine.effect.meta │ │ ├── DeferredSprite.effect │ │ ├── DeferredSprite.effect.meta │ │ ├── Dissolve.effect │ │ └── Dissolve.effect.meta │ ├── materials.meta │ ├── materials │ │ ├── Basic.mtl │ │ ├── Basic.mtl.meta │ │ ├── Bevels.mtl │ │ ├── Bevels.mtl.meta │ │ ├── BloomCombine.mtl │ │ ├── BloomCombine.mtl.meta │ │ ├── DeferredSprite.mtl │ │ ├── DeferredSprite.mtl.meta │ │ ├── Dissolve.mtl │ │ └── Dissolve.mtl.meta │ ├── prefabs.meta │ ├── prefabs │ │ ├── Button.prefab │ │ ├── Button.prefab.meta │ │ ├── moon.prefab │ │ ├── moon.prefab.meta │ │ ├── moon_polygon.prefab │ │ └── moon_polygon.prefab.meta │ ├── shared.meta │ └── shared │ │ ├── moon.png │ │ └── moon.png.meta ├── scene.scene ├── scene.scene.meta ├── scripts.meta └── scripts │ ├── Input.meta │ ├── Input │ ├── Input.ts │ ├── Input.ts.meta │ ├── KeyboardUtils.ts │ ├── KeyboardUtils.ts.meta │ ├── Keys.ts │ ├── Keys.ts.meta │ ├── MouseState.ts │ ├── MouseState.ts.meta │ ├── VirtualAxis.ts │ ├── VirtualAxis.ts.meta │ ├── VirtualInput.ts │ ├── VirtualInput.ts.meta │ ├── VirtualIntegerAxis.ts │ └── VirtualIntegerAxis.ts.meta │ ├── Main.ts │ ├── Main.ts.meta │ ├── Scene_Game.ts.meta │ ├── components.meta │ ├── components │ ├── IRenderable.ts.meta │ ├── Mesh.ts │ ├── Mesh.ts.meta │ ├── PolygonMesh.ts │ ├── PolygonMesh.ts.meta │ ├── PolygonSprite.ts │ ├── PolygonSprite.ts.meta │ ├── SpriteRenderer.ts │ ├── SpriteRenderer.ts.meta │ ├── component_camera.ts │ └── component_camera.ts.meta │ ├── graphics.meta │ ├── graphics │ ├── Batcher.ts │ └── Batcher.ts.meta │ ├── scenes.meta │ └── scenes │ ├── BasicScene.ts │ ├── BasicScene.ts.meta │ ├── RenderScene.ts │ ├── RenderScene.ts.meta │ ├── collider.meta │ ├── collider │ ├── ColliderScene.ts │ ├── ColliderScene.ts.meta │ ├── ColliderTrigger.ts │ └── ColliderTrigger.ts.meta │ ├── lineCasting.meta │ ├── lineCasting │ ├── LineCaster.ts │ ├── LineCaster.ts.meta │ ├── LineCastingScene.ts │ └── LineCastingScene.ts.meta │ ├── rigidBodies.meta │ ├── rigidBodies │ ├── RigidBodyScene.ts │ └── RigidBodyScene.ts.meta │ ├── verletPhysics.meta │ └── verletPhysics │ ├── VerletPhysicsScene.ts │ ├── VerletPhysicsScene.ts.meta │ ├── VerletSystem.ts │ └── VerletSystem.ts.meta ├── images ├── screenshot.png ├── screenshot1.png └── screenshot2.png ├── package.json ├── settings └── v2 │ └── packages │ ├── builder.json │ ├── cocos-service.json │ ├── device.json │ ├── engine.json │ ├── program.json │ └── project.json └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #/////////////////////////// 3 | # Cocos Creator 3D Project 4 | #/////////////////////////// 5 | library/ 6 | temp/ 7 | local/ 8 | build/ 9 | profiles/ 10 | native 11 | #////////////////////////// 12 | # NPM 13 | #////////////////////////// 14 | node_modules/ 15 | 16 | #////////////////////////// 17 | # VSCode 18 | #////////////////////////// 19 | .vscode/ 20 | 21 | #////////////////////////// 22 | # WebStorm 23 | #////////////////////////// 24 | .idea/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cocos-framework 2 | 该项目旨在将ecs框架与cocos3.0+渲染部分进行结合,并新增一套适用于cocos的游戏帮助类。 3 | 4 | ## 渲染框架介绍 5 | 关于渲染,框架有几个子系统(例如渲染器)。这些保证了每个对象可以在基础上进行配置。 6 | 7 | 框架渲染设置的设计非常易于启动和运行,但同时又非常灵活,以便高级用户可以开箱即用地进行所需的任何操作,渲染系统主要围绕`Renderer`类。你可以将一个或多个渲染你其添加到场景中(`addRenderer`和`removeRenderer`方法)。当所有实体、组件都调用了他们的`update`方法后就会开始执行渲染器。框架提供了默认的渲染器。 8 | 9 | - DefaultRenderer:渲染场景中每个`component_render`都会被进行渲染 10 | 11 | 你可以随意继承`Renderer`并以所需的任何方式渲染。场景中包含一个`renderableComponents`字段,该字段包含所有的`component_render`以便于访问和过滤。 12 | 13 | ## 渲染截图 14 | ![avatar1](/images/screenshot.png) 15 | ![avatar2](/images/screenshot1.png) 16 | ![avatar3](/images/screenshot2.png) 17 | -------------------------------------------------------------------------------- /assets/libs.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "2f831e44-6d01-40c7-8d1e-c8a13a742145", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/libs/framework.d.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "79595f0c-d680-408f-b396-4e2a6b3faed8", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/libs/framework.min.js.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "javascript", 4 | "imported": true, 5 | "uuid": "583135d6-c8b5-460f-9628-f7573d94037c", 6 | "files": [ 7 | ".js" 8 | ], 9 | "subMetas": {}, 10 | "userData": { 11 | "dependencies": [], 12 | "isPlugin": true, 13 | "loadPluginInWeb": true, 14 | "loadPluginInNative": true, 15 | "loadPluginInEditor": true, 16 | "importAsPlugin": true 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /assets/resources.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "441ad107-9a9b-4df3-8f41-8037eeb33dcc", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {}, 11 | "isBundle": true, 12 | "bundleName": "resources", 13 | "priority": 8 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /assets/resources/effects.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "90fb3412-d9b5-45c5-8384-89c27fd9b7db", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/resources/effects/Basic.effect: -------------------------------------------------------------------------------- 1 | // Effect Syntax Guide: https://github.com/cocos-creator/docs-3d/blob/master/zh/material-system/effect-syntax.md 2 | 3 | CCEffect %{ 4 | techniques: 5 | - name: opaque 6 | passes: 7 | - vert: basic-vs:vert # builtin header 8 | frag: basic-fs:frag 9 | depthStencilState: 10 | depthTest: false 11 | depthWrite: false 12 | blendState: 13 | targets: 14 | - blend: true 15 | blendSrc: src_alpha 16 | blendDst: one_minus_src_alpha 17 | blendDstAlpha: one_minus_src_alpha 18 | rasterizerState: 19 | cullMode: none 20 | properties: 21 | color: { value: [1, 1, 1, 1], editor: { type: color } } 22 | }% 23 | 24 | CCProgram basic-vs %{ 25 | precision highp float; 26 | #include 27 | in vec3 a_position; 28 | in vec2 a_texCoord; 29 | 30 | vec4 vert () { 31 | vec4 pos = vec4(a_position, 1); 32 | 33 | return pos; 34 | } 35 | }% 36 | 37 | CCProgram basic-fs %{ 38 | precision highp float; 39 | 40 | uniform Constant { 41 | vec4 color; 42 | }; 43 | 44 | vec4 frag () { 45 | vec4 o = vec4(1, 1, 1, 1); 46 | 47 | #if USE_VERTEX_COLOR 48 | o *= color; 49 | #endif 50 | return o; 51 | } 52 | }% 53 | -------------------------------------------------------------------------------- /assets/resources/effects/Basic.effect.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.4.6", 3 | "importer": "effect", 4 | "imported": true, 5 | "uuid": "6d972495-322b-4cd6-aee0-d1fbb6445792", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/effects/Bevels.effect: -------------------------------------------------------------------------------- 1 | // Effect Syntax Guide: https://github.com/cocos-creator/docs-3d/blob/master/zh/material-system/effect-syntax.md 2 | 3 | CCEffect %{ 4 | techniques: 5 | - name: opaque 6 | passes: 7 | - vert: general-vs:vert # builtin header 8 | frag: unlit-fs:frag 9 | properties: &props 10 | s0: { value: white } 11 | - name: transparent 12 | passes: 13 | - vert: general-vs:vert # builtin header 14 | frag: unlit-fs:frag 15 | blendState: 16 | targets: 17 | - blend: true 18 | blendSrc: src_alpha 19 | blendDst: one_minus_src_alpha 20 | blendSrcAlpha: src_alpha 21 | blendDstAlpha: one_minus_src_alpha 22 | properties: *props 23 | }% 24 | 25 | CCProgram unlit-fs %{ 26 | precision mediump float; 27 | 28 | in vec2 v_uv; 29 | uniform sampler2D s0; 30 | 31 | vec4 frag () { 32 | vec4 color = texture(s0, v_uv); 33 | color -= texture(s0, v_uv - 0.002) * 2.5; 34 | color += texture(s0, v_uv + 0.002) * 2.5; 35 | 36 | return color; 37 | } 38 | }% 39 | -------------------------------------------------------------------------------- /assets/resources/effects/Bevels.effect.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.4.6", 3 | "importer": "effect", 4 | "imported": true, 5 | "uuid": "793ec069-fc94-492e-a275-30c0e45cb9bc", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/effects/BloomCombine.effect: -------------------------------------------------------------------------------- 1 | // Effect Syntax Guide: https://github.com/cocos-creator/docs-3d/blob/master/zh/material-system/effect-syntax.md 2 | 3 | CCEffect %{ 4 | techniques: 5 | - name: opaque 6 | passes: 7 | - vert: general-vs:vert # builtin header 8 | frag: unlit-fs:frag 9 | properties: &props 10 | mainTexture: { value: white } 11 | _baseMap: {value: white} 12 | mainColor: { value: [1, 1, 1, 1], editor: { type: color } } 13 | _bloomIntensity: {value: 1} 14 | _baseIntensity: {value: 1} 15 | _bloomSaturation: {value: 1} 16 | _baseSaturation: {value: 1} 17 | - name: transparent 18 | passes: 19 | - vert: general-vs:vert # builtin header 20 | frag: unlit-fs:frag 21 | blendState: 22 | targets: 23 | - blend: true 24 | blendSrc: src_alpha 25 | blendDst: one_minus_src_alpha 26 | blendSrcAlpha: src_alpha 27 | blendDstAlpha: one_minus_src_alpha 28 | properties: *props 29 | }% 30 | 31 | CCProgram unlit-fs %{ 32 | precision highp float; 33 | #include 34 | 35 | in vec2 v_uv; 36 | uniform sampler2D mainTexture; 37 | uniform sampler2D _baseMap; 38 | in float factor_fog; 39 | 40 | uniform Constant { 41 | vec4 mainColor; 42 | float _bloomIntensity; 43 | float _baseIntensity; 44 | float _bloomSaturation; 45 | float _baseSaturation; 46 | }; 47 | 48 | vec4 lerp(float from, vec4 to, float t) { 49 | return from + (to - from) * t; 50 | } 51 | 52 | float saturate(vec4 i) { 53 | return clamp(i.x, 0.0, 1.0); 54 | } 55 | 56 | vec4 adjustSaturation(vec4 color, float saturation) { 57 | float grey = dot(color.xyz, vec3(0.3, 0.59, 0.11)); 58 | return lerp(grey, color, saturation); 59 | } 60 | 61 | vec4 frag () { 62 | vec4 bloom = texture(mainTexture, v_uv); 63 | vec4 base = texture(_baseMap, v_uv); 64 | 65 | bloom = adjustSaturation(bloom, _bloomSaturation) * _bloomIntensity; 66 | base = adjustSaturation(base, _baseSaturation) * _baseIntensity; 67 | 68 | base *= (1.0 - saturate(bloom)); 69 | 70 | return base + bloom; 71 | } 72 | }% 73 | -------------------------------------------------------------------------------- /assets/resources/effects/BloomCombine.effect.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.4.6", 3 | "importer": "effect", 4 | "imported": true, 5 | "uuid": "e7843767-a781-4ee5-9367-0af688b9a9ad", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/effects/DeferredSprite.effect: -------------------------------------------------------------------------------- 1 | // Effect Syntax Guide: https://github.com/cocos-creator/docs-3d/blob/master/zh/material-system/effect-syntax.md 2 | 3 | CCEffect %{ 4 | techniques: 5 | - name: opaque 6 | passes: 7 | - vert: general-vs:vert # builtin header 8 | frag: unlit-fs:frag 9 | properties: &props 10 | s0: { value: white } 11 | color: { value: [1, 1, 1, 1], editor: { type: color } } 12 | _alphaCutoff: {value: 0.0} 13 | - name: transparent 14 | passes: 15 | - vert: general-vs:vert # builtin header 16 | frag: unlit-fs:frag 17 | blendState: 18 | targets: 19 | - blend: true 20 | blendSrc: src_alpha 21 | blendDst: one_minus_src_alpha 22 | blendSrcAlpha: src_alpha 23 | blendDstAlpha: one_minus_src_alpha 24 | properties: *props 25 | }% 26 | 27 | CCProgram unlit-fs %{ 28 | precision mediump float; 29 | 30 | in vec2 v_uv; 31 | uniform sampler2D s0; 32 | 33 | uniform Constant { 34 | vec4 color; 35 | float _alphaCutoff; 36 | }; 37 | 38 | vec4 frag () { 39 | vec4 col = color * texture(s0, v_uv); 40 | 41 | // 如果aplha测试不通过就返回 42 | if (color.w < _alphaCutoff) discard; 43 | 44 | return col; 45 | } 46 | }% 47 | -------------------------------------------------------------------------------- /assets/resources/effects/DeferredSprite.effect.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.4.6", 3 | "importer": "effect", 4 | "imported": true, 5 | "uuid": "1875aea2-fd05-4cf7-b75a-8cb0b4bc1786", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/effects/Dissolve.effect: -------------------------------------------------------------------------------- 1 | // Effect Syntax Guide: https://github.com/cocos-creator/docs-3d/blob/master/zh/material-system/effect-syntax.md 2 | 3 | CCEffect %{ 4 | techniques: 5 | - name: opaque 6 | passes: 7 | - vert: general-vs:vert # builtin header 8 | frag: unlit-fs:frag 9 | properties: &props 10 | _dissolveTexSampler: { value: white } 11 | mainColor: { value: [1, 1, 1, 1], editor: { type: color } } 12 | _progress: { value: 0.0 } 13 | _dissolveThreshold: {value: 0.0} 14 | _dissolveThresholdColor: {value: [1, 0, 0, 1], editor: {type: color}} 15 | - name: transparent 16 | passes: 17 | - vert: general-vs:vert # builtin header 18 | frag: unlit-fs:frag 19 | blendState: 20 | targets: 21 | - blend: true 22 | blendSrc: src_alpha 23 | blendDst: one_minus_src_alpha 24 | blendSrcAlpha: src_alpha 25 | blendDstAlpha: one_minus_src_alpha 26 | properties: *props 27 | }% 28 | 29 | CCProgram unlit-fs %{ 30 | precision highp float; 31 | 32 | in vec2 v_uv; 33 | uniform sampler2D _dissolveTexSampler; 34 | 35 | uniform Constant { 36 | vec4 mainColor; 37 | vec4 _dissolveThresholdColor; 38 | float _progress; 39 | float _dissolveThreshold; 40 | }; 41 | 42 | float saturate(float i) { 43 | return clamp(i, 0.0, 1.0); 44 | } 45 | 46 | vec4 lerp(vec4 from, vec4 to, float t) { 47 | return from + (to - from) * t; 48 | } 49 | 50 | float lerp1(float from, float to, float t) { 51 | return from + (to - from) * t; 52 | } 53 | 54 | vec4 frag () { 55 | float progress = _progress + _dissolveThreshold; 56 | vec4 color = texture(_dissolveTexSampler, v_uv); 57 | 58 | float dissolveAmount = 1.0 - texture( _dissolveTexSampler, v_uv ).r; 59 | if( dissolveAmount < progress - _dissolveThreshold ) 60 | discard; 61 | 62 | bool b = dissolveAmount < progress; 63 | float colorAmount = lerp1( 1.0, 0.0, 1.0 - saturate( abs( progress - _dissolveThreshold - dissolveAmount ) / _dissolveThreshold ) ); 64 | vec4 thresholdColor = lerp( vec4(0, 0, 0, 1), _dissolveThresholdColor, colorAmount); 65 | return lerp(color, color * thresholdColor, b ? 1.0 : 0.0); 66 | } 67 | }% 68 | -------------------------------------------------------------------------------- /assets/resources/effects/Dissolve.effect.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.4.6", 3 | "importer": "effect", 4 | "imported": true, 5 | "uuid": "53c02bae-80df-45c0-a971-9a73393764fd", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/materials.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "ea646a42-0236-45df-92f3-be45d096e4a5", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/resources/materials/Basic.mtl: -------------------------------------------------------------------------------- 1 | { 2 | "__type__": "cc.Material", 3 | "_name": "", 4 | "_objFlags": 0, 5 | "_native": "", 6 | "_effectAsset": { 7 | "__uuid__": "6d972495-322b-4cd6-aee0-d1fbb6445792", 8 | "__expectedType__": "cc.EffectAsset" 9 | }, 10 | "_techIdx": 0, 11 | "_defines": [ 12 | { 13 | "USE_VERTEX_COLOR": true 14 | } 15 | ], 16 | "_states": [ 17 | { 18 | "rasterizerState": {}, 19 | "depthStencilState": {}, 20 | "blendState": { 21 | "targets": [ 22 | {} 23 | ] 24 | } 25 | } 26 | ], 27 | "_props": [ 28 | { 29 | "color": { 30 | "__type__": "cc.Color", 31 | "r": 133, 32 | "g": 65, 33 | "b": 65, 34 | "a": 255 35 | } 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /assets/resources/materials/Basic.mtl.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.9", 3 | "importer": "material", 4 | "imported": true, 5 | "uuid": "cd775137-dd78-4360-b065-9373dd9d4783", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/materials/Bevels.mtl: -------------------------------------------------------------------------------- 1 | { 2 | "__type__": "cc.Material", 3 | "_name": "", 4 | "_objFlags": 0, 5 | "_native": "", 6 | "_effectAsset": { 7 | "__uuid__": "793ec069-fc94-492e-a275-30c0e45cb9bc" 8 | }, 9 | "_techIdx": 0, 10 | "_defines": [ 11 | {} 12 | ], 13 | "_states": [ 14 | { 15 | "rasterizerState": {}, 16 | "depthStencilState": {}, 17 | "blendState": { 18 | "targets": [ 19 | {} 20 | ] 21 | } 22 | } 23 | ], 24 | "_props": [ 25 | { 26 | "s0": { 27 | "__uuid__": "57520716-48c8-4a19-8acf-41c9f8777fb0@6c48a" 28 | } 29 | } 30 | ] 31 | } -------------------------------------------------------------------------------- /assets/resources/materials/Bevels.mtl.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.9", 3 | "importer": "material", 4 | "imported": true, 5 | "uuid": "9a1ac363-05e1-48b4-9738-cca3d9d606d4", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/materials/BloomCombine.mtl: -------------------------------------------------------------------------------- 1 | { 2 | "__type__": "cc.Material", 3 | "_name": "", 4 | "_objFlags": 0, 5 | "_native": "", 6 | "_effectAsset": { 7 | "__uuid__": "e7843767-a781-4ee5-9367-0af688b9a9ad" 8 | }, 9 | "_techIdx": 0, 10 | "_defines": [ 11 | {} 12 | ], 13 | "_states": [ 14 | { 15 | "rasterizerState": {}, 16 | "depthStencilState": {}, 17 | "blendState": { 18 | "targets": [ 19 | {} 20 | ] 21 | } 22 | } 23 | ], 24 | "_props": [ 25 | { 26 | "mainTexture": { 27 | "__uuid__": "57520716-48c8-4a19-8acf-41c9f8777fb0@6c48a" 28 | }, 29 | "_baseMap": { 30 | "__uuid__": "57520716-48c8-4a19-8acf-41c9f8777fb0@6c48a" 31 | }, 32 | "_bloomIntensity": 0.5, 33 | "_baseIntensity": 0.5, 34 | "_bloomSaturation": 0.5, 35 | "_baseSaturation": 0.5 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /assets/resources/materials/BloomCombine.mtl.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.9", 3 | "importer": "material", 4 | "imported": true, 5 | "uuid": "5fead98b-a57a-4a5a-8ea2-120ac9c58975", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/materials/DeferredSprite.mtl: -------------------------------------------------------------------------------- 1 | { 2 | "__type__": "cc.Material", 3 | "_name": "", 4 | "_objFlags": 0, 5 | "_native": "", 6 | "_effectAsset": { 7 | "__uuid__": "1875aea2-fd05-4cf7-b75a-8cb0b4bc1786" 8 | }, 9 | "_techIdx": 0, 10 | "_defines": [ 11 | {} 12 | ], 13 | "_states": [ 14 | { 15 | "rasterizerState": {}, 16 | "depthStencilState": {}, 17 | "blendState": { 18 | "targets": [ 19 | {} 20 | ] 21 | } 22 | } 23 | ], 24 | "_props": [ 25 | { 26 | "s0": { 27 | "__uuid__": "57520716-48c8-4a19-8acf-41c9f8777fb0@6c48a" 28 | }, 29 | "_alphaCutoff": 0 30 | } 31 | ] 32 | } -------------------------------------------------------------------------------- /assets/resources/materials/DeferredSprite.mtl.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.9", 3 | "importer": "material", 4 | "imported": true, 5 | "uuid": "30661d39-98b9-4c86-8259-e8c8d4c36030", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/materials/Dissolve.mtl: -------------------------------------------------------------------------------- 1 | { 2 | "__type__": "cc.Material", 3 | "_name": "", 4 | "_objFlags": 0, 5 | "_native": "", 6 | "_effectAsset": { 7 | "__uuid__": "53c02bae-80df-45c0-a971-9a73393764fd" 8 | }, 9 | "_techIdx": 0, 10 | "_defines": [ 11 | {} 12 | ], 13 | "_states": [ 14 | { 15 | "rasterizerState": {}, 16 | "depthStencilState": {}, 17 | "blendState": { 18 | "targets": [ 19 | {} 20 | ] 21 | } 22 | } 23 | ], 24 | "_props": [ 25 | { 26 | "_dissolveTexSampler": { 27 | "__uuid__": "57520716-48c8-4a19-8acf-41c9f8777fb0@6c48a" 28 | }, 29 | "_progress": 0.5, 30 | "_dissolveThreshold": 0.5 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /assets/resources/materials/Dissolve.mtl.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.9", 3 | "importer": "material", 4 | "imported": true, 5 | "uuid": "3ac978ca-7844-46d6-a716-ae0874c1e0bd", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/resources/prefabs.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "508e8bbd-e1cf-45ce-99d2-9a0b9ac4f100", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/resources/prefabs/Button.prefab: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "__type__": "cc.Prefab", 4 | "_name": "", 5 | "_objFlags": 0, 6 | "_native": "", 7 | "data": { 8 | "__id__": 1 9 | }, 10 | "optimizationPolicy": 0, 11 | "asyncLoadAssets": false 12 | }, 13 | { 14 | "__type__": "cc.Node", 15 | "_name": "Button", 16 | "_objFlags": 0, 17 | "_parent": null, 18 | "_children": [ 19 | { 20 | "__id__": 2 21 | } 22 | ], 23 | "_active": true, 24 | "_components": [ 25 | { 26 | "__id__": 8 27 | }, 28 | { 29 | "__id__": 10 30 | }, 31 | { 32 | "__id__": 12 33 | } 34 | ], 35 | "_prefab": { 36 | "__id__": 14 37 | }, 38 | "_lpos": { 39 | "__type__": "cc.Vec3", 40 | "x": -425, 41 | "y": 201.60000000000002, 42 | "z": 0 43 | }, 44 | "_lrot": { 45 | "__type__": "cc.Quat", 46 | "x": 0, 47 | "y": 0, 48 | "z": 0, 49 | "w": 1 50 | }, 51 | "_lscale": { 52 | "__type__": "cc.Vec3", 53 | "x": 1, 54 | "y": 1, 55 | "z": 1 56 | }, 57 | "_layer": 33554432, 58 | "_euler": { 59 | "__type__": "cc.Vec3", 60 | "x": 0, 61 | "y": 0, 62 | "z": 0 63 | }, 64 | "_id": "" 65 | }, 66 | { 67 | "__type__": "cc.Node", 68 | "_name": "Label", 69 | "_objFlags": 0, 70 | "_parent": { 71 | "__id__": 1 72 | }, 73 | "_children": [], 74 | "_active": true, 75 | "_components": [ 76 | { 77 | "__id__": 3 78 | }, 79 | { 80 | "__id__": 5 81 | } 82 | ], 83 | "_prefab": { 84 | "__id__": 7 85 | }, 86 | "_lpos": { 87 | "__type__": "cc.Vec3", 88 | "x": 0, 89 | "y": 0, 90 | "z": 0 91 | }, 92 | "_lrot": { 93 | "__type__": "cc.Quat", 94 | "x": 0, 95 | "y": 0, 96 | "z": 0, 97 | "w": 1 98 | }, 99 | "_lscale": { 100 | "__type__": "cc.Vec3", 101 | "x": 1, 102 | "y": 1, 103 | "z": 1 104 | }, 105 | "_layer": 33554432, 106 | "_euler": { 107 | "__type__": "cc.Vec3", 108 | "x": 0, 109 | "y": 0, 110 | "z": 0 111 | }, 112 | "_id": "" 113 | }, 114 | { 115 | "__type__": "cc.UITransform", 116 | "_name": "", 117 | "_objFlags": 0, 118 | "node": { 119 | "__id__": 2 120 | }, 121 | "_enabled": true, 122 | "__prefab": { 123 | "__id__": 4 124 | }, 125 | "_priority": 0, 126 | "_contentSize": { 127 | "__type__": "cc.Size", 128 | "width": 100, 129 | "height": 40 130 | }, 131 | "_anchorPoint": { 132 | "__type__": "cc.Vec2", 133 | "x": 0.5, 134 | "y": 0.5 135 | }, 136 | "_id": "" 137 | }, 138 | { 139 | "__type__": "cc.CompPrefabInfo", 140 | "fileId": "07QMd0h1dLcYd/vjigaip6" 141 | }, 142 | { 143 | "__type__": "cc.Label", 144 | "_name": "", 145 | "_objFlags": 0, 146 | "node": { 147 | "__id__": 2 148 | }, 149 | "_enabled": true, 150 | "__prefab": { 151 | "__id__": 6 152 | }, 153 | "_visFlags": 0, 154 | "_customMaterial": null, 155 | "_srcBlendFactor": 2, 156 | "_dstBlendFactor": 4, 157 | "_color": { 158 | "__type__": "cc.Color", 159 | "r": 0, 160 | "g": 0, 161 | "b": 0, 162 | "a": 255 163 | }, 164 | "_string": "button", 165 | "_horizontalAlign": 1, 166 | "_verticalAlign": 1, 167 | "_actualFontSize": 20, 168 | "_fontSize": 20, 169 | "_fontFamily": "Arial", 170 | "_lineHeight": 40, 171 | "_overflow": 1, 172 | "_enableWrapText": false, 173 | "_font": null, 174 | "_isSystemFontUsed": true, 175 | "_isItalic": false, 176 | "_isBold": false, 177 | "_isUnderline": false, 178 | "_underlineHeight": 2, 179 | "_cacheMode": 0, 180 | "_id": "" 181 | }, 182 | { 183 | "__type__": "cc.CompPrefabInfo", 184 | "fileId": "ee3IZdy2dLIaAWpjI7P0FL" 185 | }, 186 | { 187 | "__type__": "cc.PrefabInfo", 188 | "root": { 189 | "__id__": 1 190 | }, 191 | "asset": { 192 | "__id__": 0 193 | }, 194 | "fileId": "e6xdKjT5xBA5zuZAYaxfAA" 195 | }, 196 | { 197 | "__type__": "cc.UITransform", 198 | "_name": "", 199 | "_objFlags": 0, 200 | "node": { 201 | "__id__": 1 202 | }, 203 | "_enabled": true, 204 | "__prefab": { 205 | "__id__": 9 206 | }, 207 | "_priority": 0, 208 | "_contentSize": { 209 | "__type__": "cc.Size", 210 | "width": 100, 211 | "height": 40 212 | }, 213 | "_anchorPoint": { 214 | "__type__": "cc.Vec2", 215 | "x": 0.5, 216 | "y": 0.5 217 | }, 218 | "_id": "" 219 | }, 220 | { 221 | "__type__": "cc.CompPrefabInfo", 222 | "fileId": "98TYGMtwRBTYZZn4EZmhzJ" 223 | }, 224 | { 225 | "__type__": "cc.Sprite", 226 | "_name": "", 227 | "_objFlags": 0, 228 | "node": { 229 | "__id__": 1 230 | }, 231 | "_enabled": true, 232 | "__prefab": { 233 | "__id__": 11 234 | }, 235 | "_visFlags": 0, 236 | "_customMaterial": null, 237 | "_srcBlendFactor": 2, 238 | "_dstBlendFactor": 4, 239 | "_color": { 240 | "__type__": "cc.Color", 241 | "r": 255, 242 | "g": 255, 243 | "b": 255, 244 | "a": 255 245 | }, 246 | "_spriteFrame": { 247 | "__uuid__": "20835ba4-6145-4fbc-a58a-051ce700aa3e@f9941" 248 | }, 249 | "_type": 1, 250 | "_fillType": 0, 251 | "_sizeMode": 0, 252 | "_fillCenter": { 253 | "__type__": "cc.Vec2", 254 | "x": 0, 255 | "y": 0 256 | }, 257 | "_fillStart": 0, 258 | "_fillRange": 0, 259 | "_isTrimmedMode": true, 260 | "_useGrayscale": false, 261 | "_atlas": null, 262 | "_id": "" 263 | }, 264 | { 265 | "__type__": "cc.CompPrefabInfo", 266 | "fileId": "77BcV1zfNHo4LI4KRqZupe" 267 | }, 268 | { 269 | "__type__": "cc.Button", 270 | "_name": "", 271 | "_objFlags": 0, 272 | "node": { 273 | "__id__": 1 274 | }, 275 | "_enabled": true, 276 | "__prefab": { 277 | "__id__": 13 278 | }, 279 | "clickEvents": [], 280 | "_interactable": true, 281 | "_transition": 2, 282 | "_normalColor": { 283 | "__type__": "cc.Color", 284 | "r": 214, 285 | "g": 214, 286 | "b": 214, 287 | "a": 255 288 | }, 289 | "_hoverColor": { 290 | "__type__": "cc.Color", 291 | "r": 211, 292 | "g": 211, 293 | "b": 211, 294 | "a": 255 295 | }, 296 | "_pressedColor": { 297 | "__type__": "cc.Color", 298 | "r": 255, 299 | "g": 255, 300 | "b": 255, 301 | "a": 255 302 | }, 303 | "_disabledColor": { 304 | "__type__": "cc.Color", 305 | "r": 124, 306 | "g": 124, 307 | "b": 124, 308 | "a": 255 309 | }, 310 | "_normalSprite": { 311 | "__uuid__": "20835ba4-6145-4fbc-a58a-051ce700aa3e@f9941" 312 | }, 313 | "_hoverSprite": { 314 | "__uuid__": "20835ba4-6145-4fbc-a58a-051ce700aa3e@f9941" 315 | }, 316 | "_pressedSprite": { 317 | "__uuid__": "544e49d6-3f05-4fa8-9a9e-091f98fc2ce8@f9941" 318 | }, 319 | "_disabledSprite": { 320 | "__uuid__": "951249e0-9f16-456d-8b85-a6ca954da16b@f9941" 321 | }, 322 | "_duration": 0.1, 323 | "_zoomScale": 1.2, 324 | "_target": { 325 | "__id__": 1 326 | }, 327 | "_id": "" 328 | }, 329 | { 330 | "__type__": "cc.CompPrefabInfo", 331 | "fileId": "2fOwBXUwBNvaJ4NyyrOq4C" 332 | }, 333 | { 334 | "__type__": "cc.PrefabInfo", 335 | "root": { 336 | "__id__": 1 337 | }, 338 | "asset": { 339 | "__id__": 0 340 | }, 341 | "fileId": "69B7xJuIJHJ6rwt9pxJZpN" 342 | } 343 | ] -------------------------------------------------------------------------------- /assets/resources/prefabs/Button.prefab.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.27", 3 | "importer": "prefab", 4 | "imported": true, 5 | "uuid": "acc9e07b-5d05-46e6-be64-7a97c0e9150f", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": { 11 | "syncNodeName": "Button" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /assets/resources/prefabs/moon.prefab: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "__type__": "cc.Prefab", 4 | "_name": "", 5 | "_objFlags": 0, 6 | "_native": "", 7 | "data": { 8 | "__id__": 1 9 | }, 10 | "optimizationPolicy": 0, 11 | "asyncLoadAssets": false 12 | }, 13 | { 14 | "__type__": "cc.Node", 15 | "_name": "moon", 16 | "_objFlags": 0, 17 | "_parent": null, 18 | "_children": [], 19 | "_active": true, 20 | "_components": [ 21 | { 22 | "__id__": 2 23 | }, 24 | { 25 | "__id__": 4 26 | } 27 | ], 28 | "_prefab": { 29 | "__id__": 6 30 | }, 31 | "_lpos": { 32 | "__type__": "cc.Vec3", 33 | "x": 0, 34 | "y": 0, 35 | "z": 0 36 | }, 37 | "_lrot": { 38 | "__type__": "cc.Quat", 39 | "x": 0, 40 | "y": 0, 41 | "z": 0, 42 | "w": 1 43 | }, 44 | "_lscale": { 45 | "__type__": "cc.Vec3", 46 | "x": 1, 47 | "y": 1, 48 | "z": 1 49 | }, 50 | "_layer": 1073741824, 51 | "_euler": { 52 | "__type__": "cc.Vec3", 53 | "x": 0, 54 | "y": 0, 55 | "z": 0 56 | }, 57 | "_id": "" 58 | }, 59 | { 60 | "__type__": "cc.UITransform", 61 | "_name": "", 62 | "_objFlags": 0, 63 | "node": { 64 | "__id__": 1 65 | }, 66 | "_enabled": true, 67 | "__prefab": { 68 | "__id__": 3 69 | }, 70 | "_contentSize": { 71 | "__type__": "cc.Size", 72 | "width": 128, 73 | "height": 128 74 | }, 75 | "_anchorPoint": { 76 | "__type__": "cc.Vec2", 77 | "x": 0.5, 78 | "y": 0.5 79 | }, 80 | "_id": "" 81 | }, 82 | { 83 | "__type__": "cc.CompPrefabInfo", 84 | "fileId": "bbfQaFtxdKvIAuLmPDNqjv" 85 | }, 86 | { 87 | "__type__": "cc.Sprite", 88 | "_name": "", 89 | "_objFlags": 0, 90 | "node": { 91 | "__id__": 1 92 | }, 93 | "_enabled": true, 94 | "__prefab": { 95 | "__id__": 5 96 | }, 97 | "_visFlags": 0, 98 | "_customMaterial": null, 99 | "_srcBlendFactor": 2, 100 | "_dstBlendFactor": 4, 101 | "_color": { 102 | "__type__": "cc.Color", 103 | "r": 255, 104 | "g": 255, 105 | "b": 255, 106 | "a": 255 107 | }, 108 | "_spriteFrame": { 109 | "__uuid__": "f03eaeb0-0254-47d1-87c5-546745cb6cbd@f9941", 110 | "__expectedType__": "cc.SpriteFrame" 111 | }, 112 | "_type": 0, 113 | "_fillType": 0, 114 | "_sizeMode": 1, 115 | "_fillCenter": { 116 | "__type__": "cc.Vec2", 117 | "x": 0, 118 | "y": 0 119 | }, 120 | "_fillStart": 0, 121 | "_fillRange": 0, 122 | "_isTrimmedMode": true, 123 | "_useGrayscale": false, 124 | "_atlas": null, 125 | "_id": "" 126 | }, 127 | { 128 | "__type__": "cc.CompPrefabInfo", 129 | "fileId": "c9HUxtYGBDMpv/RHAHFcE3" 130 | }, 131 | { 132 | "__type__": "cc.PrefabInfo", 133 | "root": { 134 | "__id__": 1 135 | }, 136 | "asset": { 137 | "__id__": 0 138 | }, 139 | "fileId": "e6dtP49PJC0KFaeG+jO8YY" 140 | } 141 | ] -------------------------------------------------------------------------------- /assets/resources/prefabs/moon.prefab.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.27", 3 | "importer": "prefab", 4 | "imported": true, 5 | "uuid": "841ae291-dce6-4daa-a0fd-1f8d21a3c1e5", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": { 11 | "syncNodeName": "moon" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /assets/resources/prefabs/moon_polygon.prefab: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "__type__": "cc.Prefab", 4 | "_name": "", 5 | "_objFlags": 0, 6 | "_native": "", 7 | "data": { 8 | "__id__": 1 9 | }, 10 | "optimizationPolicy": 0, 11 | "asyncLoadAssets": false 12 | }, 13 | { 14 | "__type__": "cc.Node", 15 | "_name": "moon_polygon", 16 | "_objFlags": 0, 17 | "_parent": null, 18 | "_children": [], 19 | "_active": true, 20 | "_components": [ 21 | { 22 | "__id__": 2 23 | }, 24 | { 25 | "__id__": 4 26 | } 27 | ], 28 | "_prefab": { 29 | "__id__": 6 30 | }, 31 | "_lpos": { 32 | "__type__": "cc.Vec3", 33 | "x": 0, 34 | "y": 0, 35 | "z": 0 36 | }, 37 | "_lrot": { 38 | "__type__": "cc.Quat", 39 | "x": 0, 40 | "y": 0, 41 | "z": 0, 42 | "w": 1 43 | }, 44 | "_lscale": { 45 | "__type__": "cc.Vec3", 46 | "x": 1, 47 | "y": 1, 48 | "z": 1 49 | }, 50 | "_layer": 1073741824, 51 | "_euler": { 52 | "__type__": "cc.Vec3", 53 | "x": 0, 54 | "y": 0, 55 | "z": 0 56 | }, 57 | "_id": "" 58 | }, 59 | { 60 | "__type__": "cc.UITransform", 61 | "_name": "", 62 | "_objFlags": 0, 63 | "node": { 64 | "__id__": 1 65 | }, 66 | "_enabled": true, 67 | "__prefab": { 68 | "__id__": 3 69 | }, 70 | "_contentSize": { 71 | "__type__": "cc.Size", 72 | "width": 128, 73 | "height": 128 74 | }, 75 | "_anchorPoint": { 76 | "__type__": "cc.Vec2", 77 | "x": 0.5, 78 | "y": 0.5 79 | }, 80 | "_id": "" 81 | }, 82 | { 83 | "__type__": "cc.CompPrefabInfo", 84 | "fileId": "bbfQaFtxdKvIAuLmPDNqjv" 85 | }, 86 | { 87 | "__type__": "2e4f6mWLJ5O/oK8xHFNYnf8", 88 | "_name": "", 89 | "_objFlags": 0, 90 | "node": { 91 | "__id__": 1 92 | }, 93 | "_enabled": true, 94 | "__prefab": { 95 | "__id__": 5 96 | }, 97 | "_visFlags": 0, 98 | "_customMaterial": null, 99 | "_srcBlendFactor": 2, 100 | "_dstBlendFactor": 4, 101 | "_color": { 102 | "__type__": "cc.Color", 103 | "r": 255, 104 | "g": 255, 105 | "b": 255, 106 | "a": 255 107 | }, 108 | "_spriteFrame": { 109 | "__uuid__": "f03eaeb0-0254-47d1-87c5-546745cb6cbd@f9941", 110 | "__expectedType__": "cc.SpriteFrame" 111 | }, 112 | "_type": 0, 113 | "_fillType": 0, 114 | "_sizeMode": 1, 115 | "_fillCenter": { 116 | "__type__": "cc.Vec2", 117 | "x": 0, 118 | "y": 0 119 | }, 120 | "_fillStart": 0, 121 | "_fillRange": 0, 122 | "_isTrimmedMode": true, 123 | "_useGrayscale": false, 124 | "_atlas": null, 125 | "_id": "" 126 | }, 127 | { 128 | "__type__": "cc.CompPrefabInfo", 129 | "fileId": "69s9/s/ChGlqbIb8aghSBn" 130 | }, 131 | { 132 | "__type__": "cc.PrefabInfo", 133 | "root": { 134 | "__id__": 1 135 | }, 136 | "asset": { 137 | "__id__": 0 138 | }, 139 | "fileId": "e6dtP49PJC0KFaeG+jO8YY" 140 | } 141 | ] -------------------------------------------------------------------------------- /assets/resources/prefabs/moon_polygon.prefab.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.27", 3 | "importer": "prefab", 4 | "imported": true, 5 | "uuid": "c4c7d901-f3fa-42aa-a535-efc0cf951dfe", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": { 11 | "syncNodeName": "moon_polygon" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /assets/resources/shared.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "f8fdf627-48a2-4da4-80ba-edb7c2965ede", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/resources/shared/moon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esengine/cocos-framework/f789e39c23c5ff802c02223c8dc2d3542e4459e0/assets/resources/shared/moon.png -------------------------------------------------------------------------------- /assets/resources/shared/moon.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.21", 3 | "importer": "image", 4 | "imported": true, 5 | "uuid": "f03eaeb0-0254-47d1-87c5-546745cb6cbd", 6 | "files": [ 7 | ".png", 8 | ".json" 9 | ], 10 | "subMetas": { 11 | "6c48a": { 12 | "importer": "texture", 13 | "uuid": "f03eaeb0-0254-47d1-87c5-546745cb6cbd@6c48a", 14 | "displayName": "moon", 15 | "id": "6c48a", 16 | "name": "texture", 17 | "userData": { 18 | "wrapModeS": "repeat", 19 | "wrapModeT": "repeat", 20 | "minfilter": "linear", 21 | "magfilter": "linear", 22 | "mipfilter": "none", 23 | "anisotropy": 1, 24 | "isUuid": true, 25 | "imageUuidOrDatabaseUri": "f03eaeb0-0254-47d1-87c5-546745cb6cbd" 26 | }, 27 | "ver": "1.0.21", 28 | "imported": true, 29 | "files": [ 30 | ".json" 31 | ], 32 | "subMetas": {} 33 | }, 34 | "f9941": { 35 | "importer": "sprite-frame", 36 | "uuid": "f03eaeb0-0254-47d1-87c5-546745cb6cbd@f9941", 37 | "displayName": "moon", 38 | "id": "f9941", 39 | "name": "spriteFrame", 40 | "userData": { 41 | "trimType": "auto", 42 | "trimThreshold": 1, 43 | "rotated": false, 44 | "offsetX": 0, 45 | "offsetY": 0, 46 | "trimX": 0, 47 | "trimY": 0, 48 | "width": 128, 49 | "height": 128, 50 | "rawWidth": 128, 51 | "rawHeight": 128, 52 | "borderTop": 0, 53 | "borderBottom": 0, 54 | "borderLeft": 0, 55 | "borderRight": 0, 56 | "packable": true, 57 | "isUuid": true, 58 | "imageUuidOrDatabaseUri": "f03eaeb0-0254-47d1-87c5-546745cb6cbd@6c48a", 59 | "atlasUuid": "" 60 | }, 61 | "ver": "1.0.9", 62 | "imported": true, 63 | "files": [ 64 | ".json" 65 | ], 66 | "subMetas": {} 67 | } 68 | }, 69 | "userData": { 70 | "hasAlpha": true, 71 | "type": "sprite-frame", 72 | "redirect": "f03eaeb0-0254-47d1-87c5-546745cb6cbd@f9941" 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /assets/scene.scene: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "__type__": "cc.SceneAsset", 4 | "_name": "", 5 | "_objFlags": 0, 6 | "_native": "", 7 | "scene": { 8 | "__id__": 1 9 | } 10 | }, 11 | { 12 | "__type__": "cc.Scene", 13 | "_name": "scene", 14 | "_objFlags": 0, 15 | "_parent": null, 16 | "_children": [ 17 | { 18 | "__id__": 2 19 | }, 20 | { 21 | "__id__": 17 22 | } 23 | ], 24 | "_active": true, 25 | "_components": [], 26 | "_prefab": null, 27 | "autoReleaseAssets": false, 28 | "_globals": { 29 | "__id__": 54 30 | }, 31 | "_id": "03ea5323-ad72-42ad-834b-e77db667e973" 32 | }, 33 | { 34 | "__type__": "cc.Node", 35 | "_name": "Canvas", 36 | "_objFlags": 0, 37 | "_parent": { 38 | "__id__": 1 39 | }, 40 | "_children": [ 41 | { 42 | "__id__": 3 43 | }, 44 | { 45 | "__id__": 5 46 | } 47 | ], 48 | "_active": true, 49 | "_components": [ 50 | { 51 | "__id__": 10 52 | }, 53 | { 54 | "__id__": 12 55 | }, 56 | { 57 | "__id__": 14 58 | }, 59 | { 60 | "__id__": 16 61 | } 62 | ], 63 | "_prefab": null, 64 | "_lpos": { 65 | "__type__": "cc.Vec3", 66 | "x": 480, 67 | "y": 320, 68 | "z": 0 69 | }, 70 | "_lrot": { 71 | "__type__": "cc.Quat", 72 | "x": 0, 73 | "y": 0, 74 | "z": 0, 75 | "w": 1 76 | }, 77 | "_lscale": { 78 | "__type__": "cc.Vec3", 79 | "x": 1, 80 | "y": 1, 81 | "z": 1 82 | }, 83 | "_layer": 33554432, 84 | "_euler": { 85 | "__type__": "cc.Vec3", 86 | "x": 0, 87 | "y": 0, 88 | "z": 0 89 | }, 90 | "_id": "2cn+xmDrxIaoqNj+JzaXmb" 91 | }, 92 | { 93 | "__type__": "cc.Node", 94 | "_name": "Camera", 95 | "_objFlags": 0, 96 | "_parent": { 97 | "__id__": 2 98 | }, 99 | "_children": [], 100 | "_active": true, 101 | "_components": [ 102 | { 103 | "__id__": 4 104 | } 105 | ], 106 | "_prefab": null, 107 | "_lpos": { 108 | "__type__": "cc.Vec3", 109 | "x": 0, 110 | "y": 0, 111 | "z": 1000 112 | }, 113 | "_lrot": { 114 | "__type__": "cc.Quat", 115 | "x": 0, 116 | "y": 0, 117 | "z": 0, 118 | "w": 1 119 | }, 120 | "_lscale": { 121 | "__type__": "cc.Vec3", 122 | "x": 1, 123 | "y": 1, 124 | "z": 1 125 | }, 126 | "_layer": 1073741824, 127 | "_euler": { 128 | "__type__": "cc.Vec3", 129 | "x": 0, 130 | "y": 0, 131 | "z": 0 132 | }, 133 | "_id": "edLAMj6axG4J3bHZPqvT2K" 134 | }, 135 | { 136 | "__type__": "cc.Camera", 137 | "_name": "", 138 | "_objFlags": 0, 139 | "node": { 140 | "__id__": 3 141 | }, 142 | "_enabled": true, 143 | "__prefab": null, 144 | "_projection": 0, 145 | "_priority": 0, 146 | "_fov": 45, 147 | "_fovAxis": 0, 148 | "_orthoHeight": 338.9217391304348, 149 | "_near": 1, 150 | "_far": 2000, 151 | "_color": { 152 | "__type__": "cc.Color", 153 | "r": 0, 154 | "g": 0, 155 | "b": 0, 156 | "a": 255 157 | }, 158 | "_depth": 1, 159 | "_stencil": 0, 160 | "_clearFlags": 6, 161 | "_rect": { 162 | "__type__": "cc.Rect", 163 | "x": 0, 164 | "y": 0, 165 | "width": 1, 166 | "height": 1 167 | }, 168 | "_aperture": 19, 169 | "_shutter": 7, 170 | "_iso": 0, 171 | "_screenScale": 1, 172 | "_visibility": 1082130432, 173 | "_targetTexture": null, 174 | "_id": "27YdHqxvZAtI0gzOdpdbXW" 175 | }, 176 | { 177 | "__type__": "cc.Node", 178 | "_name": "Graphics", 179 | "_objFlags": 0, 180 | "_parent": { 181 | "__id__": 2 182 | }, 183 | "_children": [], 184 | "_active": true, 185 | "_components": [ 186 | { 187 | "__id__": 6 188 | }, 189 | { 190 | "__id__": 8 191 | } 192 | ], 193 | "_prefab": null, 194 | "_lpos": { 195 | "__type__": "cc.Vec3", 196 | "x": 0, 197 | "y": 0, 198 | "z": 0 199 | }, 200 | "_lrot": { 201 | "__type__": "cc.Quat", 202 | "x": 0, 203 | "y": 0, 204 | "z": 0, 205 | "w": 1 206 | }, 207 | "_lscale": { 208 | "__type__": "cc.Vec3", 209 | "x": 1, 210 | "y": 1, 211 | "z": 1 212 | }, 213 | "_layer": 1073741824, 214 | "_euler": { 215 | "__type__": "cc.Vec3", 216 | "x": 0, 217 | "y": 0, 218 | "z": 0 219 | }, 220 | "_id": "c4BpNjUp9CXpP5YzkIyG3h" 221 | }, 222 | { 223 | "__type__": "cc.UITransform", 224 | "_name": "", 225 | "_objFlags": 0, 226 | "node": { 227 | "__id__": 5 228 | }, 229 | "_enabled": true, 230 | "__prefab": { 231 | "__id__": 7 232 | }, 233 | "_contentSize": { 234 | "__type__": "cc.Size", 235 | "width": 100, 236 | "height": 100 237 | }, 238 | "_anchorPoint": { 239 | "__type__": "cc.Vec2", 240 | "x": 0.5, 241 | "y": 0.5 242 | }, 243 | "_id": "60RIlcTnlA1IoMo7gCoqIT" 244 | }, 245 | { 246 | "__type__": "cc.CompPrefabInfo", 247 | "fileId": "c3dMMH5KBHA7aaNq/gxfrr" 248 | }, 249 | { 250 | "__type__": "cc.Graphics", 251 | "_name": "", 252 | "_objFlags": 0, 253 | "node": { 254 | "__id__": 5 255 | }, 256 | "_enabled": true, 257 | "__prefab": { 258 | "__id__": 9 259 | }, 260 | "_visFlags": 0, 261 | "_customMaterial": null, 262 | "_srcBlendFactor": 2, 263 | "_dstBlendFactor": 4, 264 | "_color": { 265 | "__type__": "cc.Color", 266 | "r": 255, 267 | "g": 255, 268 | "b": 255, 269 | "a": 255 270 | }, 271 | "_lineWidth": 1, 272 | "_strokeColor": { 273 | "__type__": "cc.Color", 274 | "r": 0, 275 | "g": 0, 276 | "b": 0, 277 | "a": 255 278 | }, 279 | "_lineJoin": 2, 280 | "_lineCap": 0, 281 | "_fillColor": { 282 | "__type__": "cc.Color", 283 | "r": 255, 284 | "g": 255, 285 | "b": 255, 286 | "a": 255 287 | }, 288 | "_miterLimit": 10, 289 | "_id": "52y7D51yxHPY/TsCXc9Gf1" 290 | }, 291 | { 292 | "__type__": "cc.CompPrefabInfo", 293 | "fileId": "b72j61fNtG9IH3vOo7HXe7" 294 | }, 295 | { 296 | "__type__": "cc.UITransform", 297 | "_name": "", 298 | "_objFlags": 0, 299 | "node": { 300 | "__id__": 2 301 | }, 302 | "_enabled": true, 303 | "__prefab": { 304 | "__id__": 11 305 | }, 306 | "_contentSize": { 307 | "__type__": "cc.Size", 308 | "width": 960, 309 | "height": 640 310 | }, 311 | "_anchorPoint": { 312 | "__type__": "cc.Vec2", 313 | "x": 0.5, 314 | "y": 0.5 315 | }, 316 | "_id": "82qllbRelP3pWPu1uw3dKW" 317 | }, 318 | { 319 | "__type__": "cc.CompPrefabInfo", 320 | "fileId": "0dngp/9gNO34wUQjZfN/CX" 321 | }, 322 | { 323 | "__type__": "cc.Canvas", 324 | "_name": "", 325 | "_objFlags": 0, 326 | "node": { 327 | "__id__": 2 328 | }, 329 | "_enabled": true, 330 | "__prefab": { 331 | "__id__": 13 332 | }, 333 | "_cameraComponent": { 334 | "__id__": 4 335 | }, 336 | "_alignCanvasWithScreen": true, 337 | "_id": "c5kCn0i0hGnJ2bMvZ0Pi8p" 338 | }, 339 | { 340 | "__type__": "cc.CompPrefabInfo", 341 | "fileId": "3f2oTdCepERZdpmIfLsrhd" 342 | }, 343 | { 344 | "__type__": "cc.Widget", 345 | "_name": "", 346 | "_objFlags": 0, 347 | "node": { 348 | "__id__": 2 349 | }, 350 | "_enabled": true, 351 | "__prefab": { 352 | "__id__": 15 353 | }, 354 | "_alignFlags": 45, 355 | "_target": null, 356 | "_left": 0, 357 | "_right": 0, 358 | "_top": 0, 359 | "_bottom": 0, 360 | "_horizontalCenter": 0, 361 | "_verticalCenter": 0, 362 | "_isAbsLeft": true, 363 | "_isAbsRight": true, 364 | "_isAbsTop": true, 365 | "_isAbsBottom": true, 366 | "_isAbsHorizontalCenter": true, 367 | "_isAbsVerticalCenter": true, 368 | "_originalWidth": 0, 369 | "_originalHeight": 0, 370 | "_alignMode": 2, 371 | "_lockFlags": 0, 372 | "_id": "75zJ6+h+NBVov2vMudoAML" 373 | }, 374 | { 375 | "__type__": "cc.CompPrefabInfo", 376 | "fileId": "e8a+bU/8dPDbbJguUzLdoF" 377 | }, 378 | { 379 | "__type__": "44fe3nKgN5Du7XCIUMP+uQB", 380 | "_name": "", 381 | "_objFlags": 0, 382 | "node": { 383 | "__id__": 2 384 | }, 385 | "_enabled": true, 386 | "__prefab": null, 387 | "_id": "87/OYX8elKdYZ7mC6s4yCG" 388 | }, 389 | { 390 | "__type__": "cc.Node", 391 | "_name": "Canvas_UI", 392 | "_objFlags": 0, 393 | "_parent": { 394 | "__id__": 1 395 | }, 396 | "_children": [ 397 | { 398 | "__id__": 18 399 | }, 400 | { 401 | "__id__": 21 402 | } 403 | ], 404 | "_active": true, 405 | "_components": [ 406 | { 407 | "__id__": 48 408 | }, 409 | { 410 | "__id__": 50 411 | }, 412 | { 413 | "__id__": 52 414 | } 415 | ], 416 | "_prefab": null, 417 | "_lpos": { 418 | "__type__": "cc.Vec3", 419 | "x": 480, 420 | "y": 320, 421 | "z": 0 422 | }, 423 | "_lrot": { 424 | "__type__": "cc.Quat", 425 | "x": 0, 426 | "y": 0, 427 | "z": 0, 428 | "w": 1 429 | }, 430 | "_lscale": { 431 | "__type__": "cc.Vec3", 432 | "x": 1, 433 | "y": 1, 434 | "z": 1 435 | }, 436 | "_layer": 33554432, 437 | "_euler": { 438 | "__type__": "cc.Vec3", 439 | "x": 0, 440 | "y": 0, 441 | "z": 0 442 | }, 443 | "_id": "feoLzQKjxMpK4KGQVVILHH" 444 | }, 445 | { 446 | "__type__": "cc.Node", 447 | "_name": "Camera-001", 448 | "_objFlags": 0, 449 | "_parent": { 450 | "__id__": 17 451 | }, 452 | "_children": [], 453 | "_active": true, 454 | "_components": [ 455 | { 456 | "__id__": 19 457 | } 458 | ], 459 | "_prefab": null, 460 | "_lpos": { 461 | "__type__": "cc.Vec3", 462 | "x": 0, 463 | "y": 0, 464 | "z": 1000 465 | }, 466 | "_lrot": { 467 | "__type__": "cc.Quat", 468 | "x": 0, 469 | "y": 0, 470 | "z": 0, 471 | "w": 1 472 | }, 473 | "_lscale": { 474 | "__type__": "cc.Vec3", 475 | "x": 1, 476 | "y": 1, 477 | "z": 1 478 | }, 479 | "_layer": 1073741824, 480 | "_euler": { 481 | "__type__": "cc.Vec3", 482 | "x": 0, 483 | "y": 0, 484 | "z": 0 485 | }, 486 | "_id": "90O0YJ/jpDn66/1aP6ZZwn" 487 | }, 488 | { 489 | "__type__": "cc.Camera", 490 | "_name": "Camera", 491 | "_objFlags": 0, 492 | "node": { 493 | "__id__": 18 494 | }, 495 | "_enabled": true, 496 | "__prefab": { 497 | "__id__": 20 498 | }, 499 | "_projection": 0, 500 | "_priority": 1, 501 | "_fov": 45, 502 | "_fovAxis": 0, 503 | "_orthoHeight": 338.9217391304348, 504 | "_near": 1, 505 | "_far": 1000, 506 | "_color": { 507 | "__type__": "cc.Color", 508 | "r": 51, 509 | "g": 76, 510 | "b": 120, 511 | "a": 255 512 | }, 513 | "_depth": 1, 514 | "_stencil": 0, 515 | "_clearFlags": 6, 516 | "_rect": { 517 | "__type__": "cc.Rect", 518 | "x": 0, 519 | "y": 0, 520 | "width": 1, 521 | "height": 1 522 | }, 523 | "_aperture": 19, 524 | "_shutter": 7, 525 | "_iso": 0, 526 | "_screenScale": 1, 527 | "_visibility": 33554432, 528 | "_targetTexture": null, 529 | "_id": "23YAy/DnZB3rSyi1rxg1+a" 530 | }, 531 | { 532 | "__type__": "cc.CompPrefabInfo", 533 | "fileId": "dbCiGR9T1E0oZwxclTRFEj" 534 | }, 535 | { 536 | "__type__": "cc.Node", 537 | "_name": "Layout", 538 | "_objFlags": 0, 539 | "_parent": { 540 | "__id__": 17 541 | }, 542 | "_children": [ 543 | { 544 | "__id__": 22 545 | }, 546 | { 547 | "__id__": 27 548 | } 549 | ], 550 | "_active": true, 551 | "_components": [ 552 | { 553 | "__id__": 44 554 | }, 555 | { 556 | "__id__": 46 557 | } 558 | ], 559 | "_prefab": null, 560 | "_lpos": { 561 | "__type__": "cc.Vec3", 562 | "x": 0, 563 | "y": 0, 564 | "z": 0 565 | }, 566 | "_lrot": { 567 | "__type__": "cc.Quat", 568 | "x": 0, 569 | "y": 0, 570 | "z": 0, 571 | "w": 1 572 | }, 573 | "_lscale": { 574 | "__type__": "cc.Vec3", 575 | "x": 1, 576 | "y": 1, 577 | "z": 1 578 | }, 579 | "_layer": 33554432, 580 | "_euler": { 581 | "__type__": "cc.Vec3", 582 | "x": 0, 583 | "y": 0, 584 | "z": 0 585 | }, 586 | "_id": "55YPMV2vlMr6JM7myGdjjg" 587 | }, 588 | { 589 | "__type__": "cc.Node", 590 | "_name": "Label", 591 | "_objFlags": 0, 592 | "_parent": { 593 | "__id__": 21 594 | }, 595 | "_children": [], 596 | "_active": true, 597 | "_components": [ 598 | { 599 | "__id__": 23 600 | }, 601 | { 602 | "__id__": 25 603 | } 604 | ], 605 | "_prefab": null, 606 | "_lpos": { 607 | "__type__": "cc.Vec3", 608 | "x": -415, 609 | "y": 294.8, 610 | "z": 0 611 | }, 612 | "_lrot": { 613 | "__type__": "cc.Quat", 614 | "x": 0, 615 | "y": 0, 616 | "z": 0, 617 | "w": 1 618 | }, 619 | "_lscale": { 620 | "__type__": "cc.Vec3", 621 | "x": 1, 622 | "y": 1, 623 | "z": 1 624 | }, 625 | "_layer": 33554432, 626 | "_euler": { 627 | "__type__": "cc.Vec3", 628 | "x": 0, 629 | "y": 0, 630 | "z": 0 631 | }, 632 | "_id": "245KhtOFRCLYHQ2Qpf4QYJ" 633 | }, 634 | { 635 | "__type__": "cc.UITransform", 636 | "_name": "", 637 | "_objFlags": 0, 638 | "node": { 639 | "__id__": 22 640 | }, 641 | "_enabled": true, 642 | "__prefab": { 643 | "__id__": 24 644 | }, 645 | "_contentSize": { 646 | "__type__": "cc.Size", 647 | "width": 120, 648 | "height": 50.4 649 | }, 650 | "_anchorPoint": { 651 | "__type__": "cc.Vec2", 652 | "x": 0.5, 653 | "y": 0.5 654 | }, 655 | "_id": "43Q2MIU5dHWa3zSWY1kppU" 656 | }, 657 | { 658 | "__type__": "cc.CompPrefabInfo", 659 | "fileId": "c68UOAlNhN171Umca6yVvF" 660 | }, 661 | { 662 | "__type__": "cc.Label", 663 | "_name": "", 664 | "_objFlags": 0, 665 | "node": { 666 | "__id__": 22 667 | }, 668 | "_enabled": true, 669 | "__prefab": { 670 | "__id__": 26 671 | }, 672 | "_visFlags": 0, 673 | "_customMaterial": null, 674 | "_srcBlendFactor": 2, 675 | "_dstBlendFactor": 4, 676 | "_color": { 677 | "__type__": "cc.Color", 678 | "r": 255, 679 | "g": 255, 680 | "b": 255, 681 | "a": 255 682 | }, 683 | "_string": "切换场景列表", 684 | "_horizontalAlign": 1, 685 | "_verticalAlign": 1, 686 | "_actualFontSize": 20, 687 | "_fontSize": 20, 688 | "_fontFamily": "Arial", 689 | "_lineHeight": 40, 690 | "_overflow": 0, 691 | "_enableWrapText": true, 692 | "_font": null, 693 | "_isSystemFontUsed": true, 694 | "_isItalic": false, 695 | "_isBold": false, 696 | "_isUnderline": false, 697 | "_underlineHeight": 2, 698 | "_cacheMode": 0, 699 | "_id": "98CreIwbNCGIBN8kLVwTgj" 700 | }, 701 | { 702 | "__type__": "cc.CompPrefabInfo", 703 | "fileId": "2frm37uaJHQr0AEEaYyM82" 704 | }, 705 | { 706 | "__type__": "cc.Node", 707 | "_name": "DebugRender", 708 | "_objFlags": 0, 709 | "_parent": { 710 | "__id__": 21 711 | }, 712 | "_children": [ 713 | { 714 | "__id__": 28 715 | }, 716 | { 717 | "__id__": 33 718 | } 719 | ], 720 | "_active": true, 721 | "_components": [ 722 | { 723 | "__id__": 38 724 | }, 725 | { 726 | "__id__": 40 727 | }, 728 | { 729 | "__id__": 42 730 | } 731 | ], 732 | "_prefab": null, 733 | "_lpos": { 734 | "__type__": "cc.Vec3", 735 | "x": -461, 736 | "y": 245.60000000000002, 737 | "z": 0 738 | }, 739 | "_lrot": { 740 | "__type__": "cc.Quat", 741 | "x": 0, 742 | "y": 0, 743 | "z": 0, 744 | "w": 1 745 | }, 746 | "_lscale": { 747 | "__type__": "cc.Vec3", 748 | "x": 1, 749 | "y": 1, 750 | "z": 1 751 | }, 752 | "_layer": 33554432, 753 | "_euler": { 754 | "__type__": "cc.Vec3", 755 | "x": 0, 756 | "y": 0, 757 | "z": 0 758 | }, 759 | "_id": "6bFklTd4dNzbcQBVD+qDmu" 760 | }, 761 | { 762 | "__type__": "cc.Node", 763 | "_name": "Checkmark", 764 | "_objFlags": 0, 765 | "_parent": { 766 | "__id__": 27 767 | }, 768 | "_children": [], 769 | "_active": true, 770 | "_components": [ 771 | { 772 | "__id__": 29 773 | }, 774 | { 775 | "__id__": 31 776 | } 777 | ], 778 | "_prefab": null, 779 | "_lpos": { 780 | "__type__": "cc.Vec3", 781 | "x": 0, 782 | "y": 0, 783 | "z": 0 784 | }, 785 | "_lrot": { 786 | "__type__": "cc.Quat", 787 | "x": 0, 788 | "y": 0, 789 | "z": 0, 790 | "w": 1 791 | }, 792 | "_lscale": { 793 | "__type__": "cc.Vec3", 794 | "x": 1, 795 | "y": 1, 796 | "z": 1 797 | }, 798 | "_layer": 33554432, 799 | "_euler": { 800 | "__type__": "cc.Vec3", 801 | "x": 0, 802 | "y": 0, 803 | "z": 0 804 | }, 805 | "_id": "8eY+/rzNRDDpvu1LrDKHv/" 806 | }, 807 | { 808 | "__type__": "cc.UITransform", 809 | "_name": "", 810 | "_objFlags": 0, 811 | "node": { 812 | "__id__": 28 813 | }, 814 | "_enabled": true, 815 | "__prefab": { 816 | "__id__": 30 817 | }, 818 | "_contentSize": { 819 | "__type__": "cc.Size", 820 | "width": 26, 821 | "height": 26 822 | }, 823 | "_anchorPoint": { 824 | "__type__": "cc.Vec2", 825 | "x": 0.5, 826 | "y": 0.5 827 | }, 828 | "_id": "28UzTK891NZpb6ZvX5qkLT" 829 | }, 830 | { 831 | "__type__": "cc.CompPrefabInfo", 832 | "fileId": "e4k6OSwohL75lyfsntvPC5" 833 | }, 834 | { 835 | "__type__": "cc.Sprite", 836 | "_name": "", 837 | "_objFlags": 0, 838 | "node": { 839 | "__id__": 28 840 | }, 841 | "_enabled": true, 842 | "__prefab": { 843 | "__id__": 32 844 | }, 845 | "_visFlags": 0, 846 | "_customMaterial": null, 847 | "_srcBlendFactor": 2, 848 | "_dstBlendFactor": 4, 849 | "_color": { 850 | "__type__": "cc.Color", 851 | "r": 255, 852 | "g": 255, 853 | "b": 255, 854 | "a": 255 855 | }, 856 | "_spriteFrame": { 857 | "__uuid__": "158e7e52-3220-4cd7-9694-713e0e6e8278@f9941", 858 | "__expectedType__": "cc.SpriteFrame" 859 | }, 860 | "_type": 0, 861 | "_fillType": 0, 862 | "_sizeMode": 0, 863 | "_fillCenter": { 864 | "__type__": "cc.Vec2", 865 | "x": 0, 866 | "y": 0 867 | }, 868 | "_fillStart": 0, 869 | "_fillRange": 0, 870 | "_isTrimmedMode": true, 871 | "_useGrayscale": false, 872 | "_atlas": null, 873 | "_id": "89q242Mv5NgbKFHomVsJs6" 874 | }, 875 | { 876 | "__type__": "cc.CompPrefabInfo", 877 | "fileId": "25nHiyhlVLhbUiFI4JJ9Sn" 878 | }, 879 | { 880 | "__type__": "cc.Node", 881 | "_name": "Label", 882 | "_objFlags": 0, 883 | "_parent": { 884 | "__id__": 27 885 | }, 886 | "_children": [], 887 | "_active": true, 888 | "_components": [ 889 | { 890 | "__id__": 34 891 | }, 892 | { 893 | "__id__": 36 894 | } 895 | ], 896 | "_prefab": null, 897 | "_lpos": { 898 | "__type__": "cc.Vec3", 899 | "x": 60, 900 | "y": 0, 901 | "z": 0 902 | }, 903 | "_lrot": { 904 | "__type__": "cc.Quat", 905 | "x": 0, 906 | "y": 0, 907 | "z": 0, 908 | "w": 1 909 | }, 910 | "_lscale": { 911 | "__type__": "cc.Vec3", 912 | "x": 1, 913 | "y": 1, 914 | "z": 1 915 | }, 916 | "_layer": 33554432, 917 | "_euler": { 918 | "__type__": "cc.Vec3", 919 | "x": 0, 920 | "y": 0, 921 | "z": 0 922 | }, 923 | "_id": "d2VgS/QttBaZ/+Is1mwxw+" 924 | }, 925 | { 926 | "__type__": "cc.UITransform", 927 | "_name": "", 928 | "_objFlags": 0, 929 | "node": { 930 | "__id__": 33 931 | }, 932 | "_enabled": true, 933 | "__prefab": { 934 | "__id__": 35 935 | }, 936 | "_contentSize": { 937 | "__type__": "cc.Size", 938 | "width": 80, 939 | "height": 50.4 940 | }, 941 | "_anchorPoint": { 942 | "__type__": "cc.Vec2", 943 | "x": 0.5, 944 | "y": 0.5 945 | }, 946 | "_id": "7bdcTWN1pFxbY6TdDxuK3a" 947 | }, 948 | { 949 | "__type__": "cc.CompPrefabInfo", 950 | "fileId": "c68UOAlNhN171Umca6yVvF" 951 | }, 952 | { 953 | "__type__": "cc.Label", 954 | "_name": "", 955 | "_objFlags": 0, 956 | "node": { 957 | "__id__": 33 958 | }, 959 | "_enabled": true, 960 | "__prefab": { 961 | "__id__": 37 962 | }, 963 | "_visFlags": 0, 964 | "_customMaterial": null, 965 | "_srcBlendFactor": 2, 966 | "_dstBlendFactor": 4, 967 | "_color": { 968 | "__type__": "cc.Color", 969 | "r": 255, 970 | "g": 255, 971 | "b": 255, 972 | "a": 255 973 | }, 974 | "_string": "调试渲染", 975 | "_horizontalAlign": 1, 976 | "_verticalAlign": 1, 977 | "_actualFontSize": 20, 978 | "_fontSize": 20, 979 | "_fontFamily": "Arial", 980 | "_lineHeight": 40, 981 | "_overflow": 0, 982 | "_enableWrapText": true, 983 | "_font": null, 984 | "_isSystemFontUsed": true, 985 | "_isItalic": false, 986 | "_isBold": false, 987 | "_isUnderline": false, 988 | "_underlineHeight": 2, 989 | "_cacheMode": 0, 990 | "_id": "a5uYOQ1ahHPLMMV2Tt/7ZX" 991 | }, 992 | { 993 | "__type__": "cc.CompPrefabInfo", 994 | "fileId": "2frm37uaJHQr0AEEaYyM82" 995 | }, 996 | { 997 | "__type__": "cc.UITransform", 998 | "_name": "", 999 | "_objFlags": 0, 1000 | "node": { 1001 | "__id__": 27 1002 | }, 1003 | "_enabled": true, 1004 | "__prefab": { 1005 | "__id__": 39 1006 | }, 1007 | "_contentSize": { 1008 | "__type__": "cc.Size", 1009 | "width": 28, 1010 | "height": 28 1011 | }, 1012 | "_anchorPoint": { 1013 | "__type__": "cc.Vec2", 1014 | "x": 0.5, 1015 | "y": 0.5 1016 | }, 1017 | "_id": "9ePJ3acmlLkqav5I+YGkIe" 1018 | }, 1019 | { 1020 | "__type__": "cc.CompPrefabInfo", 1021 | "fileId": "a7yxb8GDhNnIT24rnD3lO4" 1022 | }, 1023 | { 1024 | "__type__": "cc.Sprite", 1025 | "_name": "", 1026 | "_objFlags": 0, 1027 | "node": { 1028 | "__id__": 27 1029 | }, 1030 | "_enabled": true, 1031 | "__prefab": { 1032 | "__id__": 41 1033 | }, 1034 | "_visFlags": 0, 1035 | "_customMaterial": null, 1036 | "_srcBlendFactor": 2, 1037 | "_dstBlendFactor": 4, 1038 | "_color": { 1039 | "__type__": "cc.Color", 1040 | "r": 255, 1041 | "g": 255, 1042 | "b": 255, 1043 | "a": 255 1044 | }, 1045 | "_spriteFrame": { 1046 | "__uuid__": "11bdc4b0-64a8-4eb7-a2a7-9fb9e233e977@f9941", 1047 | "__expectedType__": "cc.SpriteFrame" 1048 | }, 1049 | "_type": 0, 1050 | "_fillType": 0, 1051 | "_sizeMode": 1, 1052 | "_fillCenter": { 1053 | "__type__": "cc.Vec2", 1054 | "x": 0, 1055 | "y": 0 1056 | }, 1057 | "_fillStart": 0, 1058 | "_fillRange": 0, 1059 | "_isTrimmedMode": true, 1060 | "_useGrayscale": false, 1061 | "_atlas": null, 1062 | "_id": "02PsUbWkBM5qb9y6VXKrtu" 1063 | }, 1064 | { 1065 | "__type__": "cc.CompPrefabInfo", 1066 | "fileId": "3a4GKzsKZCNLuWHErVRJ1B" 1067 | }, 1068 | { 1069 | "__type__": "cc.Toggle", 1070 | "_name": "", 1071 | "_objFlags": 0, 1072 | "node": { 1073 | "__id__": 27 1074 | }, 1075 | "_enabled": true, 1076 | "__prefab": { 1077 | "__id__": 43 1078 | }, 1079 | "clickEvents": [], 1080 | "_interactable": true, 1081 | "_transition": 0, 1082 | "_normalColor": { 1083 | "__type__": "cc.Color", 1084 | "r": 214, 1085 | "g": 214, 1086 | "b": 214, 1087 | "a": 255 1088 | }, 1089 | "_hoverColor": { 1090 | "__type__": "cc.Color", 1091 | "r": 211, 1092 | "g": 211, 1093 | "b": 211, 1094 | "a": 255 1095 | }, 1096 | "_pressedColor": { 1097 | "__type__": "cc.Color", 1098 | "r": 255, 1099 | "g": 255, 1100 | "b": 255, 1101 | "a": 255 1102 | }, 1103 | "_disabledColor": { 1104 | "__type__": "cc.Color", 1105 | "r": 124, 1106 | "g": 124, 1107 | "b": 124, 1108 | "a": 255 1109 | }, 1110 | "_normalSprite": { 1111 | "__uuid__": "11bdc4b0-64a8-4eb7-a2a7-9fb9e233e977@f9941", 1112 | "__expectedType__": "cc.SpriteFrame" 1113 | }, 1114 | "_hoverSprite": null, 1115 | "_pressedSprite": null, 1116 | "_disabledSprite": null, 1117 | "_duration": 0.1, 1118 | "_zoomScale": 1.2, 1119 | "_target": { 1120 | "__id__": 27 1121 | }, 1122 | "checkEvents": [], 1123 | "_isChecked": true, 1124 | "_checkMark": { 1125 | "__id__": 31 1126 | }, 1127 | "_id": "d1bK6mkOZIjJLTIpDlQX3w" 1128 | }, 1129 | { 1130 | "__type__": "cc.CompPrefabInfo", 1131 | "fileId": "58GFHdMmJFBa4quSrrbzsk" 1132 | }, 1133 | { 1134 | "__type__": "cc.UITransform", 1135 | "_name": "", 1136 | "_objFlags": 0, 1137 | "node": { 1138 | "__id__": 21 1139 | }, 1140 | "_enabled": true, 1141 | "__prefab": { 1142 | "__id__": 45 1143 | }, 1144 | "_contentSize": { 1145 | "__type__": "cc.Size", 1146 | "width": 960, 1147 | "height": 640 1148 | }, 1149 | "_anchorPoint": { 1150 | "__type__": "cc.Vec2", 1151 | "x": 0.5, 1152 | "y": 0.5 1153 | }, 1154 | "_id": "20ZJbkXmlBS7Yg0l8UMIgZ" 1155 | }, 1156 | { 1157 | "__type__": "cc.CompPrefabInfo", 1158 | "fileId": "71F9vsVsZH7ZFd+PpN0azA" 1159 | }, 1160 | { 1161 | "__type__": "cc.Layout", 1162 | "_name": "", 1163 | "_objFlags": 0, 1164 | "node": { 1165 | "__id__": 21 1166 | }, 1167 | "_enabled": true, 1168 | "__prefab": { 1169 | "__id__": 47 1170 | }, 1171 | "_resizeMode": 0, 1172 | "_layoutType": 3, 1173 | "_cellSize": { 1174 | "__type__": "cc.Size", 1175 | "width": 40, 1176 | "height": 40 1177 | }, 1178 | "_startAxis": 1, 1179 | "_paddingLeft": 5, 1180 | "_paddingRight": 5, 1181 | "_paddingTop": 0, 1182 | "_paddingBottom": 0, 1183 | "_spacingX": 0, 1184 | "_spacingY": 10, 1185 | "_verticalDirection": 1, 1186 | "_horizontalDirection": 0, 1187 | "_constraint": 0, 1188 | "_constraintNum": 2, 1189 | "_affectedByScale": false, 1190 | "_isAlign": false, 1191 | "_id": "ecEp6Z6ilPl5kBewvCbeXS" 1192 | }, 1193 | { 1194 | "__type__": "cc.CompPrefabInfo", 1195 | "fileId": "eaGEkmlCpANK+GS6CImtZa" 1196 | }, 1197 | { 1198 | "__type__": "cc.UITransform", 1199 | "_name": "", 1200 | "_objFlags": 0, 1201 | "node": { 1202 | "__id__": 17 1203 | }, 1204 | "_enabled": true, 1205 | "__prefab": { 1206 | "__id__": 49 1207 | }, 1208 | "_contentSize": { 1209 | "__type__": "cc.Size", 1210 | "width": 960, 1211 | "height": 640 1212 | }, 1213 | "_anchorPoint": { 1214 | "__type__": "cc.Vec2", 1215 | "x": 0.5, 1216 | "y": 0.5 1217 | }, 1218 | "_id": "e5hDiGytdIw4ZMoh0Nj4PZ" 1219 | }, 1220 | { 1221 | "__type__": "cc.CompPrefabInfo", 1222 | "fileId": "0dngp/9gNO34wUQjZfN/CX" 1223 | }, 1224 | { 1225 | "__type__": "cc.Canvas", 1226 | "_name": "", 1227 | "_objFlags": 0, 1228 | "node": { 1229 | "__id__": 17 1230 | }, 1231 | "_enabled": true, 1232 | "__prefab": { 1233 | "__id__": 51 1234 | }, 1235 | "_cameraComponent": { 1236 | "__id__": 19 1237 | }, 1238 | "_alignCanvasWithScreen": true, 1239 | "_id": "52XMdJ56BP9IhxgNhHaxwP" 1240 | }, 1241 | { 1242 | "__type__": "cc.CompPrefabInfo", 1243 | "fileId": "3f2oTdCepERZdpmIfLsrhd" 1244 | }, 1245 | { 1246 | "__type__": "cc.Widget", 1247 | "_name": "", 1248 | "_objFlags": 0, 1249 | "node": { 1250 | "__id__": 17 1251 | }, 1252 | "_enabled": true, 1253 | "__prefab": { 1254 | "__id__": 53 1255 | }, 1256 | "_alignFlags": 45, 1257 | "_target": null, 1258 | "_left": 0, 1259 | "_right": 0, 1260 | "_top": 0, 1261 | "_bottom": 0, 1262 | "_horizontalCenter": 0, 1263 | "_verticalCenter": 0, 1264 | "_isAbsLeft": true, 1265 | "_isAbsRight": true, 1266 | "_isAbsTop": true, 1267 | "_isAbsBottom": true, 1268 | "_isAbsHorizontalCenter": true, 1269 | "_isAbsVerticalCenter": true, 1270 | "_originalWidth": 0, 1271 | "_originalHeight": 0, 1272 | "_alignMode": 2, 1273 | "_lockFlags": 0, 1274 | "_id": "baPwotUmZGN7ojey9YHL3D" 1275 | }, 1276 | { 1277 | "__type__": "cc.CompPrefabInfo", 1278 | "fileId": "e8a+bU/8dPDbbJguUzLdoF" 1279 | }, 1280 | { 1281 | "__type__": "cc.SceneGlobals", 1282 | "ambient": { 1283 | "__id__": 55 1284 | }, 1285 | "shadows": { 1286 | "__id__": 56 1287 | }, 1288 | "_skybox": { 1289 | "__id__": 57 1290 | }, 1291 | "fog": { 1292 | "__id__": 58 1293 | } 1294 | }, 1295 | { 1296 | "__type__": "cc.AmbientInfo", 1297 | "_skyColor": { 1298 | "__type__": "cc.Color", 1299 | "r": 51, 1300 | "g": 128, 1301 | "b": 204, 1302 | "a": 1 1303 | }, 1304 | "_skyIllum": 20000, 1305 | "_groundAlbedo": { 1306 | "__type__": "cc.Color", 1307 | "r": 51, 1308 | "g": 51, 1309 | "b": 51, 1310 | "a": 255 1311 | } 1312 | }, 1313 | { 1314 | "__type__": "cc.ShadowsInfo", 1315 | "_type": 0, 1316 | "_enabled": false, 1317 | "_normal": { 1318 | "__type__": "cc.Vec3", 1319 | "x": 0, 1320 | "y": 1, 1321 | "z": 0 1322 | }, 1323 | "_distance": 0, 1324 | "_shadowColor": { 1325 | "__type__": "cc.Color", 1326 | "r": 76, 1327 | "g": 76, 1328 | "b": 76, 1329 | "a": 255 1330 | }, 1331 | "_autoAdapt": true, 1332 | "_pcf": 0, 1333 | "_bias": 0.00001, 1334 | "_packing": false, 1335 | "_linear": true, 1336 | "_selfShadow": false, 1337 | "_normalBias": 0, 1338 | "_near": 1, 1339 | "_far": 30, 1340 | "_aspect": 1, 1341 | "_orthoSize": 5, 1342 | "_maxReceived": 4, 1343 | "_size": { 1344 | "__type__": "cc.Vec2", 1345 | "x": 512, 1346 | "y": 512 1347 | } 1348 | }, 1349 | { 1350 | "__type__": "cc.SkyboxInfo", 1351 | "_envmap": null, 1352 | "_isRGBE": false, 1353 | "_enabled": false, 1354 | "_useIBL": false 1355 | }, 1356 | { 1357 | "__type__": "cc.FogInfo", 1358 | "_type": 0, 1359 | "_fogColor": { 1360 | "__type__": "cc.Color", 1361 | "r": 200, 1362 | "g": 200, 1363 | "b": 200, 1364 | "a": 255 1365 | }, 1366 | "_enabled": false, 1367 | "_fogDensity": 0.3, 1368 | "_fogStart": 0.5, 1369 | "_fogEnd": 300, 1370 | "_fogAtten": 5, 1371 | "_fogTop": 1.5, 1372 | "_fogRange": 1.2 1373 | } 1374 | ] -------------------------------------------------------------------------------- /assets/scene.scene.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.27", 3 | "importer": "scene", 4 | "imported": true, 5 | "uuid": "03ea5323-ad72-42ad-834b-e77db667e973", 6 | "files": [ 7 | ".json" 8 | ], 9 | "subMetas": {}, 10 | "userData": {} 11 | } 12 | -------------------------------------------------------------------------------- /assets/scripts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "c6095ba6-51a3-4a12-8f0f-ae68bde894c8", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/scripts/Input.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "42d267ba-e2bd-4933-98de-7c87208ac029", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/scripts/Input/Input.ts: -------------------------------------------------------------------------------- 1 | import { EventMouse, EventTouch, macro, SystemEvent, systemEvent, Touch } from "cc"; 2 | import { KeyboardUtils } from "./KeyboardUtils"; 3 | import { Keys } from "./Keys"; 4 | import { ButtonState, MouseState } from "./MouseState"; 5 | import { VirtualInput } from "./VirtualInput"; 6 | 7 | export class TouchState { 8 | public x = 0; 9 | public y = 0; 10 | public touchPoint: number = -1; 11 | public touchDown: boolean = false; 12 | 13 | public get position() { 14 | return new es.Vector2(this.x, this.y); 15 | } 16 | 17 | public reset() { 18 | this.x = 0; 19 | this.y = 0; 20 | this.touchDown = false; 21 | this.touchPoint = -1; 22 | } 23 | } 24 | 25 | export class Input { 26 | private static _init: boolean = false; 27 | private static _previousTouchState: TouchState = new TouchState(); 28 | private static _resolutionOffset: es.Vector2 = es.Vector2.zero; 29 | private static _touchIndex: number = 0; 30 | 31 | private static _gameTouchs: TouchState[] = []; 32 | private static _mousePosition: es.Vector2 = new es.Vector2(-1, -1); 33 | 34 | /** 35 | * 触摸列表 存放最大个数量触摸点信息 36 | * 可通过判断touchPoint是否为-1 来确定是否为有触摸 37 | * 通过判断touchDown 判断触摸点是否有按下 38 | */ 39 | public static get gameTouchs() { 40 | return this._gameTouchs; 41 | } 42 | 43 | private static _resolutionScale: es.Vector2 = es.Vector2.one; 44 | 45 | /** 获取缩放值 默认为1 */ 46 | public static get resolutionScale() { 47 | return this._resolutionScale; 48 | } 49 | 50 | private static _totalTouchCount: number = 0; 51 | 52 | /** 当前触摸点数量 */ 53 | public static get totalTouchCount() { 54 | return this._totalTouchCount; 55 | } 56 | 57 | /** 返回第一个触摸点的坐标 */ 58 | public static get touchPosition() { 59 | if (!this._gameTouchs[0]) 60 | return es.Vector2.zero; 61 | return this._gameTouchs[0].position; 62 | } 63 | 64 | public static get mousePosition() { 65 | return this._mousePosition; 66 | } 67 | 68 | public static _virtualInputs: VirtualInput[] = []; 69 | 70 | /** 获取最大触摸数 */ 71 | public static get maxSupportedTouch(): number { 72 | return EventTouch.MAX_TOUCHES; 73 | } 74 | 75 | /** 获取第一个触摸点距离上次距离的增量 */ 76 | public static get touchPositionDelta() { 77 | let delta = this.touchPosition.sub(this._previousTouchState.position); 78 | if (delta.magnitude() > 0) { 79 | this.setpreviousTouchState(this._gameTouchs[0]); 80 | } 81 | return delta; 82 | } 83 | 84 | public static initialize() { 85 | if (this._init) 86 | return; 87 | 88 | this._init = true; 89 | systemEvent.on(SystemEvent.EventType.TOUCH_START, this.touchBegin, this); 90 | systemEvent.on(SystemEvent.EventType.TOUCH_MOVE, this.touchMove, this); 91 | systemEvent.on(SystemEvent.EventType.TOUCH_END, this.touchEnd, this); 92 | systemEvent.on(SystemEvent.EventType.TOUCH_CANCEL, this.touchEnd, this); 93 | 94 | systemEvent.on(SystemEvent.EventType.MOUSE_DOWN, this.mouseDown, this); 95 | systemEvent.on(SystemEvent.EventType.MOUSE_UP, this.mouseUp, this); 96 | systemEvent.on(SystemEvent.EventType.MOUSE_MOVE, this.mouseMove, this); 97 | systemEvent.on(SystemEvent.EventType.MOUSE_LEAVE, this.mouseLeave, this); 98 | 99 | this.initTouchCache(); 100 | } 101 | 102 | public static update(){ 103 | KeyboardUtils.update(); 104 | for (let i = 0; i < this._virtualInputs.length; i ++) 105 | this._virtualInputs[i].update(); 106 | 107 | this._previousMouseState = this._currentMouseState.clone(); 108 | } 109 | 110 | public static scaledPosition(position: es.Vector2) { 111 | let scaledPos = new es.Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y); 112 | return scaledPos.multiply(this.resolutionScale); 113 | } 114 | 115 | /** 116 | * 只有在当前帧按下并且在上一帧没有按下时才算press 117 | * @param key 118 | */ 119 | public static isKeyPressed(key: Keys): boolean{ 120 | return new es.List(KeyboardUtils.currentKeys).contains(key) && !new es.List(KeyboardUtils.previousKeys).contains(key); 121 | } 122 | 123 | public static isKeyPressedBoth(keyA: Keys, keyB: Keys){ 124 | return this.isKeyPressed(keyA) || this.isKeyPressed(keyB); 125 | } 126 | 127 | public static isKeyDown(key: Keys): boolean { 128 | return new es.List(KeyboardUtils.currentKeys).contains(key); 129 | } 130 | 131 | public static isKeyDownBoth(keyA: Keys, keyB: Keys){ 132 | return this.isKeyDown(keyA) || this.isKeyDown(keyB); 133 | } 134 | 135 | public static isKeyReleased(key: Keys){ 136 | return !new es.List(KeyboardUtils.currentKeys).contains(key) && new es.List(KeyboardUtils.previousKeys).contains(key); 137 | } 138 | 139 | public static isKeyReleasedBoth(keyA: Keys, keyB: Keys){ 140 | return this.isKeyReleased(keyA) || this.isKeyReleased(keyB); 141 | } 142 | 143 | public static get leftMouseButtonPressed() { 144 | return this._currentMouseState.leftButton == ButtonState.pressed && 145 | this._previousMouseState.leftButton == ButtonState.released; 146 | } 147 | 148 | public static get rightMouseButtonPressed() { 149 | return this._currentMouseState.rightButton == ButtonState.pressed && 150 | this._previousMouseState.rightButton == ButtonState.released; 151 | } 152 | 153 | public static get leftMouseButtonDown() { 154 | return this._currentMouseState.leftButton == ButtonState.pressed; 155 | } 156 | 157 | public static get leftMouseButtonRelease() { 158 | return this._currentMouseState.leftButton == ButtonState.released; 159 | } 160 | 161 | public static get rightMouseButtonDown() { 162 | return this._currentMouseState.rightButton == ButtonState.pressed; 163 | } 164 | 165 | public static get rightMouseButtonRelease() { 166 | return this._currentMouseState.rightButton == ButtonState.released; 167 | } 168 | 169 | private static _previousMouseState: MouseState = new MouseState(); 170 | private static _currentMouseState: MouseState = new MouseState(); 171 | 172 | private static initTouchCache() { 173 | this._totalTouchCount = 0; 174 | this._touchIndex = 0; 175 | this._gameTouchs.length = 0; 176 | for (let i = 0; i < this.maxSupportedTouch; i++) { 177 | this._gameTouchs.push(new TouchState()); 178 | } 179 | } 180 | 181 | private static touchBegin(touch: Touch, event: EventTouch) { 182 | if (this._touchIndex < this.maxSupportedTouch) { 183 | this._gameTouchs[this._touchIndex].touchPoint = touch.getID(); 184 | this._gameTouchs[this._touchIndex].touchDown = true; 185 | this._gameTouchs[this._touchIndex].x = touch.getLocationX(); 186 | this._gameTouchs[this._touchIndex].y = touch.getLocationY(); 187 | if (this._touchIndex == 0) { 188 | this.setpreviousTouchState(this._gameTouchs[0]); 189 | } 190 | this._touchIndex++; 191 | this._totalTouchCount++; 192 | } 193 | } 194 | 195 | private static touchMove(touch: Touch, event: EventTouch) { 196 | if (touch.getID() == this._gameTouchs[0].touchPoint) { 197 | this.setpreviousTouchState(this._gameTouchs[0]); 198 | } 199 | 200 | let touchIndex = this._gameTouchs.findIndex(t => t.touchPoint == touch.getID()); 201 | if (touchIndex != -1) { 202 | let touchData = this._gameTouchs[touchIndex]; 203 | touchData.x = touch.getLocationX(); 204 | touchData.y = touch.getLocationY(); 205 | } 206 | } 207 | 208 | 209 | private static touchEnd(touch: Touch, event: EventTouch) { 210 | let touchIndex = this._gameTouchs.findIndex(t => t.touchPoint == touch.getID()); 211 | if (touchIndex != -1) { 212 | let touchData = this._gameTouchs[touchIndex]; 213 | touchData.reset(); 214 | if (touchIndex == 0) 215 | this._previousTouchState.reset(); 216 | this._totalTouchCount--; 217 | if (this.totalTouchCount == 0) { 218 | this._touchIndex = 0; 219 | } 220 | } 221 | } 222 | 223 | private static mouseDown(event: EventMouse) { 224 | if (event.getButton() == EventMouse.BUTTON_LEFT) { 225 | this._currentMouseState.leftButton = ButtonState.pressed; 226 | } 227 | 228 | if (event.getButton() == EventMouse.BUTTON_RIGHT) { 229 | this._currentMouseState.rightButton = ButtonState.pressed; 230 | } 231 | } 232 | 233 | private static mouseUp(event: EventMouse) { 234 | if (event.getButton() == EventMouse.BUTTON_LEFT) { 235 | this._currentMouseState.leftButton = ButtonState.released; 236 | } 237 | 238 | if (event.getButton() == EventMouse.BUTTON_RIGHT) { 239 | this._currentMouseState.rightButton = ButtonState.released; 240 | } 241 | } 242 | 243 | private static mouseMove(event: EventMouse) { 244 | this._mousePosition = new es.Vector2(event.getLocationX(), event.getLocationY()); 245 | } 246 | 247 | private static mouseLeave(event: EventMouse) { 248 | this._mousePosition = new es.Vector2(-1, -1); 249 | this._currentMouseState = new MouseState(); 250 | } 251 | 252 | private static setpreviousTouchState(touchState: TouchState) { 253 | this._previousTouchState = new TouchState(); 254 | this._previousTouchState.x = touchState.position.x; 255 | this._previousTouchState.y = touchState.position.y; 256 | this._previousTouchState.touchPoint = touchState.touchPoint; 257 | this._previousTouchState.touchDown = touchState.touchDown; 258 | } 259 | } -------------------------------------------------------------------------------- /assets/scripts/Input/Input.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "2434d6d4-eaf1-4734-a964-72726e0bb4ae", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/Input/KeyboardUtils.ts: -------------------------------------------------------------------------------- 1 | import { EventKeyboard, SystemEvent, systemEvent } from "cc"; 2 | import { Keys } from "./Keys"; 3 | 4 | export class KeyboardUtils { 5 | /** 6 | * 当前帧按键状态 7 | */ 8 | public static currentKeys: Keys[] = []; 9 | /** 10 | * 上一帧按键状态 11 | */ 12 | public static previousKeys: Keys[] = []; 13 | private static keyStatusKeys: Keys[] = []; 14 | 15 | public static init(): void { 16 | systemEvent.on(SystemEvent.EventType.KEY_UP, KeyboardUtils.onKeyUpHandler, this); 17 | systemEvent.on(SystemEvent.EventType.KEY_DOWN, KeyboardUtils.onKeyDownHandler, this); 18 | } 19 | 20 | public static update(){ 21 | KeyboardUtils.previousKeys.length = 0; 22 | for (let key of KeyboardUtils.currentKeys){ 23 | KeyboardUtils.previousKeys.push(key); 24 | new es.List(KeyboardUtils.currentKeys).remove(key); 25 | } 26 | KeyboardUtils.currentKeys.length = 0; 27 | for (let key of KeyboardUtils.keyStatusKeys){ 28 | KeyboardUtils.currentKeys.push(key); 29 | } 30 | } 31 | 32 | public static destroy(): void { 33 | KeyboardUtils.currentKeys.length = 0; 34 | 35 | systemEvent.off(SystemEvent.EventType.KEY_UP, KeyboardUtils.onKeyUpHandler, this); 36 | systemEvent.off(SystemEvent.EventType.KEY_DOWN, KeyboardUtils.onKeyDownHandler, this); 37 | } 38 | 39 | private static onKeyDownHandler(event: EventKeyboard): void { 40 | if (!new es.List(KeyboardUtils.keyStatusKeys).contains(event.keyCode)) 41 | KeyboardUtils.keyStatusKeys.push(event.keyCode); 42 | } 43 | 44 | private static onKeyUpHandler(event: EventKeyboard): void { 45 | let linqList = new es.List(KeyboardUtils.keyStatusKeys); 46 | if (linqList.contains(event.keyCode)) 47 | linqList.remove(event.keyCode); 48 | } 49 | } -------------------------------------------------------------------------------- /assets/scripts/Input/KeyboardUtils.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "6590a5c7-8a5d-4360-8f73-b652ff7f977f", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/Input/Keys.ts: -------------------------------------------------------------------------------- 1 | export enum Keys { 2 | none, 3 | back = 8, 4 | tab = 9, 5 | enter = 13, 6 | capsLock = 20, 7 | escape = 27, 8 | space = 32, 9 | pageUp = 33, 10 | pageDown = 34, 11 | end = 35, 12 | home = 36, 13 | left = 37, 14 | up = 38, 15 | right = 39, 16 | down = 40, 17 | select = 41, 18 | print = 42, 19 | execute = 43, 20 | printScreen = 44, 21 | insert = 45, 22 | delete = 46, 23 | help = 47, 24 | d0 = 48, 25 | d1 = 49, 26 | d2 = 50, 27 | d3 = 51, 28 | d4 = 52, 29 | d5 = 53, 30 | d6 = 54, 31 | d7 = 55, 32 | d8 = 56, 33 | d9 = 57, 34 | a = 65, 35 | b = 66, 36 | c = 67, 37 | d = 68, 38 | e = 69, 39 | f = 70, 40 | g = 71, 41 | h = 72, 42 | i = 73, 43 | j = 74, 44 | k = 75, 45 | l = 76, 46 | m = 77, 47 | n = 78, 48 | o = 79, 49 | p = 80, 50 | q = 81, 51 | r = 82, 52 | s = 83, 53 | t = 84, 54 | u = 85, 55 | v = 86, 56 | w = 87, 57 | x = 88, 58 | y = 89, 59 | z = 90, 60 | leftWindows = 91, 61 | rightWindows = 92, 62 | apps = 93, 63 | sleep = 95, 64 | numPad0 = 96, 65 | numPad1 = 97, 66 | numPad2 = 98, 67 | numPad3 = 99, 68 | numPad4 = 100, 69 | numPad5 = 101, 70 | numPad6 = 102, 71 | numPad7 = 103, 72 | numPad8 = 104, 73 | numPad9 = 105, 74 | multiply = 106, 75 | add = 107, 76 | seperator = 108, 77 | subtract = 109, 78 | decimal = 110, 79 | divide = 111, 80 | f1 = 112, 81 | f2 = 113, 82 | f3 = 114, 83 | f4 = 115, 84 | f5 = 116, 85 | f6 = 117, 86 | f7 = 118, 87 | f8 = 119, 88 | f9 = 120, 89 | f10 = 121, 90 | f11 = 122, 91 | f12 = 123, 92 | f13 = 124, 93 | f14 = 125, 94 | f15 = 126, 95 | f16 = 127, 96 | f17 = 128, 97 | f18 = 129, 98 | f19 = 130, 99 | f20 = 131, 100 | f21 = 132, 101 | f22 = 133, 102 | f23 = 134, 103 | f24 = 135, 104 | numLock = 144, 105 | scroll = 145, 106 | leftShift = 160, 107 | rightShift = 161, 108 | leftControl = 162, 109 | rightControl = 163, 110 | leftAlt = 164, 111 | rightAlt = 165, 112 | browserBack = 166, 113 | browserForward = 167 114 | } -------------------------------------------------------------------------------- /assets/scripts/Input/Keys.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "71b1fc88-4e85-44c2-8134-1f64e312589e", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/Input/MouseState.ts: -------------------------------------------------------------------------------- 1 | export enum ButtonState { 2 | pressed, 3 | released, 4 | } 5 | 6 | export class MouseState { 7 | public leftButton: ButtonState = ButtonState.released; 8 | public rightButton: ButtonState = ButtonState.released; 9 | 10 | public clone() { 11 | let mouseState = new MouseState(); 12 | mouseState.leftButton = this.leftButton; 13 | mouseState.rightButton = this.rightButton; 14 | return mouseState; 15 | } 16 | } -------------------------------------------------------------------------------- /assets/scripts/Input/MouseState.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "5e0e5932-5247-4401-8ab2-a8e7408b5c22", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/Input/VirtualAxis.ts: -------------------------------------------------------------------------------- 1 | import { Input } from "./Input"; 2 | import { Keys } from "./Keys"; 3 | import { OverlapBehavior, VirtualInput } from "./VirtualInput"; 4 | import { VirtualAxisNode } from "./VirtualIntegerAxis"; 5 | 6 | export class VirtualAxis extends VirtualInput { 7 | public nodes: VirtualAxisNode[] = []; 8 | 9 | public get value() { 10 | for (let i = 0; i < this.nodes.length; i++) { 11 | let val = this.nodes[i].value; 12 | if (val != 0) 13 | return val; 14 | } 15 | 16 | return 0; 17 | } 18 | 19 | constructor(...nodes: VirtualAxisNode[]) { 20 | super(); 21 | this.nodes.concat(nodes); 22 | } 23 | 24 | public update() { 25 | for (let i = 0; i < this.nodes.length; i++) 26 | this.nodes[i].update(); 27 | } 28 | } 29 | 30 | export class KeyboardKeys extends VirtualAxisNode { 31 | public overlapBehavior: OverlapBehavior; 32 | public positive: Keys; 33 | public negative: Keys; 34 | public _value: number = 0; 35 | public _turned: boolean = false; 36 | 37 | constructor(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys) { 38 | super(); 39 | this.overlapBehavior = overlapBehavior; 40 | this.negative = negative; 41 | this.positive = positive; 42 | } 43 | 44 | public update() { 45 | if (Input.isKeyDown(this.positive)) { 46 | if (Input.isKeyDown(this.negative)) { 47 | switch (this.overlapBehavior) { 48 | default: 49 | case OverlapBehavior.cancelOut: 50 | this._value = 0; 51 | break; 52 | case OverlapBehavior.takeNewer: 53 | if (!this._turned) { 54 | this._value *= -1; 55 | this._turned = true; 56 | } 57 | break; 58 | case OverlapBehavior.takeOlder: 59 | break; 60 | } 61 | } else { 62 | this._turned = false; 63 | this._value = 1; 64 | } 65 | } else if (Input.isKeyDown(this.negative)) { 66 | this._turned = false; 67 | this._value = -1; 68 | } else { 69 | this._turned = false; 70 | this._value = 0; 71 | } 72 | } 73 | 74 | public get value(){ 75 | return this._value; 76 | } 77 | } -------------------------------------------------------------------------------- /assets/scripts/Input/VirtualAxis.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "76eb1d5e-6796-4864-bce6-3e4b60c8e260", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/Input/VirtualInput.ts: -------------------------------------------------------------------------------- 1 | import { Input } from "./Input"; 2 | 3 | export enum OverlapBehavior { 4 | /** 5 | * 重复的输入将导致相互抵消,并且不会记录任何输入。 6 | * 例如:按左箭头键,按住时按右箭头键。这将导致相互抵消。 7 | */ 8 | cancelOut, 9 | /** 10 | * 将使用找到的第一个输入 11 | */ 12 | takeOlder, 13 | /** 14 | * 将使用找到的最后一个输入 15 | */ 16 | takeNewer, 17 | } 18 | 19 | /** 20 | * 虚拟按钮,其状态由其VirtualInputNodes的状态决定 21 | */ 22 | export abstract class VirtualInput { 23 | protected constructor() { 24 | Input._virtualInputs.push(this); 25 | } 26 | 27 | /** 28 | * 从输入系统取消虚拟输入的注册。在轮询VirtualInput之后调用这个函数 29 | */ 30 | public deregister(){ 31 | new es.List(Input._virtualInputs).remove(this); 32 | } 33 | 34 | public abstract update(): void; 35 | } 36 | 37 | /** 38 | * 将它们添加到您的VirtualInput中,以定义它如何确定当前输入状态。 39 | * 例如,如果你想检查一个键盘键是否被按下,创建一个VirtualButton并添加一个VirtualButton.keyboardkey 40 | */ 41 | export abstract class VirtualInputNode { 42 | public update() {} 43 | } -------------------------------------------------------------------------------- /assets/scripts/Input/VirtualInput.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "693baa37-45a2-4395-b745-5eb5bf9390f8", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/Input/VirtualIntegerAxis.ts: -------------------------------------------------------------------------------- 1 | import { Keys } from "./Keys"; 2 | import { KeyboardKeys } from "./VirtualAxis"; 3 | import { OverlapBehavior, VirtualInput, VirtualInputNode } from "./VirtualInput"; 4 | 5 | export class VirtualIntegerAxis extends VirtualInput { 6 | public nodes: VirtualAxisNode[] = []; 7 | 8 | public get value(){ 9 | for (let i = 0; i < this.nodes.length; i ++){ 10 | let val = this.nodes[i].value; 11 | if (val != 0) 12 | return Math.sign(val); 13 | } 14 | 15 | return 0; 16 | } 17 | 18 | constructor(...nodes: VirtualAxisNode[]){ 19 | super(); 20 | this.nodes.concat(nodes); 21 | } 22 | 23 | public update() { 24 | for (let i = 0; i < this.nodes.length; i ++) 25 | this.nodes[i].update(); 26 | } 27 | 28 | /** 29 | * 添加键盘键来模拟这个虚拟输入的左/右或上/下 30 | * @param overlapBehavior 31 | * @param negative 32 | * @param positive 33 | */ 34 | public addKeyboardKeys(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys){ 35 | this.nodes.push(new KeyboardKeys(overlapBehavior, negative, positive)); 36 | return this; 37 | } 38 | } 39 | 40 | export abstract class VirtualAxisNode extends VirtualInputNode { 41 | public abstract value: number; 42 | } -------------------------------------------------------------------------------- /assets/scripts/Input/VirtualIntegerAxis.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "a6159918-34b3-46b4-9f1c-fc48bb8e3d59", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/Main.ts: -------------------------------------------------------------------------------- 1 | 2 | import { _decorator, Component, Node, Button, find, instantiate, Label, Prefab, resources, Toggle, ToggleComponent } from 'cc'; 3 | import { PolygonSprite } from './components/PolygonSprite'; 4 | import { Batcher } from './graphics/Batcher'; 5 | import { Input } from './Input/Input'; 6 | import { KeyboardUtils } from './Input/KeyboardUtils'; 7 | import { BasicScene } from './scenes/BasicScene'; 8 | import { RenderScene, sampleList, SceneEmitType } from './scenes/RenderScene'; 9 | const { ccclass, property } = _decorator; 10 | 11 | @ccclass('Main') 12 | export class Main extends Component { 13 | start () { 14 | es.Core.debugRenderEndabled = true; 15 | es.Core.create(true); 16 | 17 | es.Graphics.instance = new es.Graphics(new Batcher()); 18 | KeyboardUtils.init(); 19 | Input.initialize(); 20 | 21 | es.Core.scene = new BasicScene(); 22 | 23 | this.setupSceneSelector(); 24 | } 25 | 26 | setupSceneSelector() { 27 | const checkBox = find("Canvas_UI/Layout/DebugRender")?.getComponent(Toggle); 28 | if (checkBox) { 29 | checkBox.isChecked = es.Core.debugRenderEndabled; 30 | checkBox.node.on('toggle', (toggle: ToggleComponent) => { 31 | es.Core.debugRenderEndabled = toggle.isChecked; 32 | }, this); 33 | } 34 | 35 | const layout = find("Canvas_UI/Layout"); 36 | sampleList.forEach((value, key)=>{ 37 | resources.load('prefabs/Button', Prefab, (err, data)=>{ 38 | const buttonNode = instantiate(data); 39 | layout?.addChild(buttonNode); 40 | 41 | const label = buttonNode.getChildByName("Label")?.getComponent(Label); 42 | if (label) label.string = key; 43 | buttonNode.on(Button.EventType.CLICK, ()=>{ 44 | es.Core.scene = new value(); 45 | }, this); 46 | }); 47 | }); 48 | 49 | } 50 | 51 | update (deltaTime: number) { 52 | es.Core.emitter.emit(es.CoreEvents.frameUpdated, deltaTime); 53 | 54 | Input.update(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /assets/scripts/Main.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "44fe39ca-80de-43bb-b5c2-21430ffae401", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "simulateGlobals": [] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /assets/scripts/Scene_Game.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "5dcc586b-18de-48ab-953b-a746fb0fbbf0", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/components.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "c5d1c2e0-d9eb-45ae-a1c6-6fe41df6e216", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/scripts/components/IRenderable.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "082372a4-3c58-4ec5-b18a-e9095ea73b94", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "simulateGlobals": [] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /assets/scripts/components/Mesh.ts: -------------------------------------------------------------------------------- 1 | import { find, gfx, instantiate, Material, MeshRenderer, PrimitiveType, resources, SpriteFrame, UITransform } from "cc"; 2 | import { PolygonSprite } from "./PolygonSprite"; 3 | 4 | export class Mesh extends es.RenderableComponent { 5 | public getbounds() { 6 | if (this._areBoundsDirty) { 7 | this._bounds.calculateBounds(this.entity.transform.position, es.Vector2.zero, 8 | es.Vector2.zero, this.entity.transform.scale, this.entity.transform.rotation, this._width, this._height); 9 | this._areBoundsDirty = false; 10 | } 11 | 12 | return this._bounds; 13 | } 14 | 15 | _vertexColorEnabled: boolean = true; 16 | _texture: PolygonSprite | null = null; 17 | 18 | _primitiveCount: number = 0; 19 | _width: number = 0; 20 | _height: number = 0; 21 | _triangles: number[] = []; 22 | _verts: { position: es.Vector2, color: es.Color }[] = []; 23 | _nu: number[] = []; 24 | _nv: number[] = []; 25 | _x: number[] = []; 26 | _y: number[] = []; 27 | _material: Material | null = null; 28 | 29 | public recalculateBounds(recalculateUVs: boolean): Mesh { 30 | const max = new es.Vector2(Number.MIN_VALUE, Number.MIN_VALUE); 31 | 32 | for (let i = 0; i < this._verts.length; i++) { 33 | max.x = Math.max(max.x, this._verts[i].position.x); 34 | max.y = Math.max(max.y, this._verts[i].position.y); 35 | } 36 | 37 | this._width = max.x; 38 | this._height = max.y; 39 | this._areBoundsDirty = true; 40 | 41 | if (recalculateUVs) { 42 | const uiTransform = this._texture?.getComponent(UITransform); 43 | if (uiTransform) 44 | for (let i = 0; i < this._verts.length; i++) { 45 | this._x[i] = this._verts[i].position.x; 46 | this._y[i] = this._verts[i].position.y; 47 | this._nu[i] = this._verts[i].position.x / uiTransform.width; 48 | this._nv[i] = this._verts[i].position.y / uiTransform.height; 49 | } 50 | } 51 | 52 | return this; 53 | } 54 | 55 | public setTexture(texture: PolygonSprite) { 56 | this._texture = texture; 57 | this.recalculateBounds(true); 58 | return this; 59 | } 60 | 61 | public setVertexColorEnabled(shouldEnableVertexColors: boolean) { 62 | if (this._material != null) { 63 | this._material.recompileShaders({ "USE_VERTEX_COLOR": this._vertexColorEnabled }); 64 | } else { 65 | this._vertexColorEnabled = shouldEnableVertexColors; 66 | } 67 | } 68 | 69 | public setVertPositions(positions: es.Vector2[]) { 70 | const createVerts = this._verts == null || this._verts.length != positions.length; 71 | if (createVerts) { 72 | for (let i = 0; i < positions.length; i++) { 73 | this._verts[i] = { 74 | position: positions[i], 75 | color: this.color 76 | }; 77 | } 78 | } 79 | 80 | this.recalculateBounds(true); 81 | return this; 82 | } 83 | 84 | public setTriangles(triangles: number[]) { 85 | es.Insist.isTrue(triangles.length % 3 == 0, "triangles must be a multiple of 3"); 86 | this._primitiveCount = triangles.length / 3; 87 | this._triangles = triangles; 88 | return this; 89 | } 90 | 91 | public setColor(color: es.Color) { 92 | this.color = color; 93 | this.setColorForAllVerts(color); 94 | return this; 95 | } 96 | 97 | public setColorForAllVerts(color: es.Color) { 98 | for (let i = 0; i < this._verts.length; i++) 99 | this._verts[i].color = color; 100 | return this; 101 | } 102 | 103 | onAddedToEntity() { 104 | resources.load("materials/Basic", Material, (err, data) => { 105 | if (this._texture != null) { 106 | // this._texture.material = data; 107 | // this._material = this._texture?.node.getComponent(MeshRenderer)?.getMaterialInstance(0)!; 108 | find('Canvas')?.addChild(this._texture.node); 109 | 110 | // this._material?.recompileShaders({ "USE_VERTEX_COLOR": this._vertexColorEnabled }); 111 | } 112 | }); 113 | } 114 | 115 | onRemovedFromEntity() { 116 | this._texture?.node.removeFromParent(); 117 | this._texture = null; 118 | } 119 | 120 | render(batcher: es.IBatcher, camera: es.ICamera): void { 121 | if (this._texture && this._texture.node.parent) { 122 | this._texture.vertices = { 123 | x: this._x, 124 | y: this._y, 125 | triangles: this._triangles, 126 | nu: this._nu, 127 | nv: this._nv, 128 | u: [], 129 | v: [] 130 | } 131 | } 132 | } 133 | } -------------------------------------------------------------------------------- /assets/scripts/components/Mesh.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "eb8e7996-d927-480b-97df-9dafe9e346d2", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/components/PolygonMesh.ts: -------------------------------------------------------------------------------- 1 | import { Mesh } from "./Mesh"; 2 | 3 | export class PolygonMesh extends Mesh { 4 | constructor(points: es.Vector2[], arePointsCCW: boolean = true) { 5 | super(); 6 | 7 | const triangulator = new es.Triangulator(); 8 | triangulator.triangulate(points, arePointsCCW); 9 | 10 | this.setVertPositions(points); 11 | this.setTriangles(triangulator.triangleIndices); 12 | } 13 | } -------------------------------------------------------------------------------- /assets/scripts/components/PolygonMesh.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "d33e0aa0-91e2-4075-95fd-e9d1e2b92017", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/components/PolygonSprite.ts: -------------------------------------------------------------------------------- 1 | import { Color, dynamicAtlasManager, IAssembler, IVertices, Mat4, Node, PolygonCollider2D, renderer, Sprite, UI, UITransform, Vec2, Vec3, _decorator } from "cc"; 2 | const { ccclass, property } = _decorator; 3 | 4 | const vec3_temp = new Vec3(); 5 | 6 | const polygonAssembler: IAssembler = { 7 | 8 | createData(sprite: Sprite) { 9 | const renderData = sprite.requestRenderData(); 10 | return renderData; 11 | }, 12 | 13 | updateRenderData(sprite: PolygonSprite) { 14 | const renderData = sprite.renderData; 15 | if (renderData) { 16 | const vertices = sprite.vertices; 17 | if (vertices) { 18 | if (renderData.vertexCount !== vertices.x.length) { 19 | renderData.vertexCount = vertices.x.length; 20 | 21 | // 1 for world vertices, 2 for local vertices 22 | renderData.dataLength = renderData.vertexCount * 2; 23 | 24 | renderData.uvDirty = renderData.vertDirty = true; 25 | } 26 | renderData.indicesCount = vertices.triangles.length; 27 | 28 | if (renderData.uvDirty) { 29 | this.updateUvs(sprite); 30 | } 31 | 32 | if (renderData.vertDirty) { 33 | this.updateVertices(sprite); 34 | this.updateWorldVertices(sprite); 35 | } 36 | } 37 | } 38 | }, 39 | 40 | fillBuffers(sprite: PolygonSprite, renderer: any) { 41 | if (sprite === null) { 42 | return; 43 | } 44 | 45 | const vertices = sprite!.vertices; 46 | if (!vertices) { 47 | return; 48 | } 49 | 50 | // update world vertices 51 | this.updateWorldVertices(sprite); 52 | 53 | // buffer 54 | const buffer = renderer.acquireBufferBatch()!; 55 | let indicesOffset = buffer.indicesOffset; 56 | const vertexId: number = buffer.vertexOffset; 57 | 58 | const node = sprite.node; 59 | this.fillVerticesWithoutCalc3D(node, renderer, sprite.renderData!, sprite.color); 60 | 61 | // buffer data may be realloc, need get reference after request. 62 | const iBuf = buffer.iData!; 63 | const triangles = vertices.triangles; 64 | for (let i = 0, l = triangles.length; i < l; i++) { 65 | iBuf[indicesOffset++] = vertexId + (triangles[i] as number); 66 | } 67 | }, 68 | 69 | fillVerticesWithoutCalc3D(node: Node, renderer: any, renderData: any, color: Color) { 70 | const dataList = renderData.data; 71 | let buffer = renderer.acquireBufferBatch()!; 72 | let vertexOffset = buffer.byteOffset >> 2; 73 | 74 | // buffer 75 | let vertexCount = renderData.vertexCount; 76 | let indicesOffset: number = buffer.indicesOffset; 77 | let vertexId: number = buffer.vertexOffset; 78 | const isRecreate = buffer.request(vertexCount, renderData.indicesCount); 79 | if (!isRecreate) { 80 | buffer = renderer.currBufferBatch!; 81 | vertexCount = 0; 82 | indicesOffset = 0; 83 | vertexId = 0; 84 | } 85 | 86 | // buffer data may be realloc, need get reference after request. 87 | const vBuf = buffer.vData!; 88 | 89 | for (let i = 0; i < vertexCount; i++) { 90 | const vert = dataList[i]; 91 | vBuf[vertexOffset++] = vert.x; 92 | vBuf[vertexOffset++] = vert.y; 93 | vBuf[vertexOffset++] = vert.z; 94 | vBuf[vertexOffset++] = vert.u; 95 | vBuf[vertexOffset++] = vert.v; 96 | Color.toArray(vBuf, color, vertexOffset); 97 | vertexOffset += 4; 98 | } 99 | 100 | // buffer data may be realloc, need get reference after request. 101 | const iBuf = buffer.iData; 102 | iBuf![indicesOffset++] = vertexId; 103 | iBuf![indicesOffset++] = vertexId + 1; 104 | iBuf![indicesOffset++] = vertexId + 2; 105 | iBuf![indicesOffset++] = vertexId + 1; 106 | iBuf![indicesOffset++] = vertexId + 3; 107 | iBuf![indicesOffset++] = vertexId + 2; 108 | }, 109 | 110 | updateVertices(sprite: PolygonSprite) { 111 | const node = sprite.node!; 112 | const uiTransform = node.getComponent(UITransform)!; 113 | const contentWidth = Math.abs(uiTransform.width); 114 | const contentHeight = Math.abs(uiTransform.height); 115 | const appX = uiTransform.anchorX * contentWidth; 116 | const appY = uiTransform.anchorY * contentHeight; 117 | 118 | const frame = sprite.spriteFrame!; 119 | const vertices = sprite!.vertices!; 120 | const x = vertices.x; 121 | const y = vertices.y; 122 | const originalWidth = frame.originalSize.width; 123 | const originalHeight = frame.originalSize.height; 124 | const rectWidth = frame.rect.width; 125 | const rectHeight = frame.rect.height; 126 | const offsetX: number = frame.offset.x; 127 | const offsetY: number = frame.offset.y; 128 | const trimX = offsetX + (originalWidth - rectWidth) / 2; 129 | const trimY = offsetY + (originalHeight - rectHeight) / 2; 130 | 131 | const scaleX = contentWidth / (sprite.trim ? rectWidth : originalWidth); 132 | const scaleY = contentHeight / (sprite.trim ? rectHeight : originalHeight); 133 | 134 | const renderData = sprite.renderData!; 135 | const data = renderData.data; 136 | 137 | if (!sprite.trim) { 138 | for (let i = 0, l: number = x.length; i < l; i++) { 139 | const vertex = data[i + l]; 140 | vertex.x = (x[i]) * scaleX - appX; 141 | vertex.y = (originalHeight - y[i]) * scaleY - appY; 142 | } 143 | } else { 144 | for (let i = 0, l: number = x.length; i < l; i++) { 145 | const vertex = data[i + l]; 146 | vertex.x = (x[i] - trimX) * scaleX - appX; 147 | vertex.y = (originalHeight - y[i] - trimY) * scaleY - appY; 148 | } 149 | } 150 | 151 | renderData.vertDirty = false; 152 | }, 153 | 154 | updateWorldVertices(sprite: PolygonSprite) { 155 | const node = sprite.node; 156 | const renderData = sprite.renderData!; 157 | const data = renderData.data; 158 | 159 | node.updateWorldTransform(); 160 | const matrix = node.worldMatrix; 161 | for (let i = 0, l: number = renderData.vertexCount; i < l; i++) { 162 | const local = data[i + l]; 163 | const world = data[i]; 164 | Vec3.set(vec3_temp, local.x, local.y, 0); 165 | Vec3.transformMat4(world, vec3_temp, matrix); 166 | } 167 | }, 168 | 169 | updateUvs(sprite: PolygonSprite) { 170 | const vertices = sprite.vertices!; 171 | const u = vertices.nu; 172 | const v = vertices.nv; 173 | 174 | const renderData = sprite.renderData!; 175 | const data = renderData.data; 176 | for (let i = 0, l = u.length; i < l; i++) { 177 | const vertex = data[i]; 178 | vertex.u = u[i]; 179 | vertex.v = v[i]; 180 | } 181 | 182 | renderData.uvDirty = false; 183 | }, 184 | 185 | }; 186 | 187 | @ccclass('PolygonSprite') 188 | export class PolygonSprite extends Sprite { 189 | protected _vertices: IVertices | null = null; 190 | get vertices() { 191 | return this._vertices; 192 | } 193 | set vertices(value) { 194 | this._vertices = value; 195 | this.markForUpdateRenderData(); 196 | } 197 | 198 | protected _flushAssembler() { 199 | let assembler = polygonAssembler; 200 | if (this._assembler !== assembler) { 201 | this.destroyRenderData(); 202 | this._assembler = assembler; 203 | } 204 | 205 | if (!this._renderData) { 206 | if (this._assembler && this._assembler.createData) { 207 | this._renderData = this._assembler.createData(this); 208 | this._renderData!.material = this.getRenderMaterial(0); 209 | this.markForUpdateRenderData(); 210 | this._updateColor(); 211 | } 212 | } 213 | } 214 | } -------------------------------------------------------------------------------- /assets/scripts/components/PolygonSprite.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "2e4f6996-2c9e-4efe-82bc-c4714d6277fc", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/components/SpriteRenderer.ts: -------------------------------------------------------------------------------- 1 | import { find, Graphics, Size, Sprite, UITransform, utils, Vec2, Vec3 } from "cc"; 2 | import { Batcher } from "../graphics/Batcher"; 3 | import { SceneEmitType, RenderScene } from "../scenes/RenderScene"; 4 | import { component_camera } from "./component_camera"; 5 | 6 | export class SpriteRenderer extends es.RenderableComponent { 7 | public getbounds() { 8 | if (this._areBoundsDirty) { 9 | if (this._sprite.spriteFrame != null) { 10 | this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, 11 | this.entity.transform.scale, this.entity.transform.rotation, 12 | this.getwidth(), this.getheight()); 13 | } 14 | this._areBoundsDirty = false; 15 | } 16 | 17 | return this._bounds; 18 | } 19 | 20 | public getwidth() { 21 | const ui_transform = this._sprite.getComponent(UITransform); 22 | if (!ui_transform) 23 | return 0; 24 | 25 | return ui_transform.width; 26 | } 27 | 28 | public getheight() { 29 | const ui_transform = this._sprite.getComponent(UITransform); 30 | if (!ui_transform) 31 | return 0; 32 | 33 | return ui_transform.height; 34 | } 35 | 36 | public get origin() { 37 | return this._origin; 38 | } 39 | public set origin(value: es.Vector2) { 40 | this.setOrigin(value); 41 | } 42 | public setOrigin(origin: es.Vector2) { 43 | if (!this._origin.equals(origin)) { 44 | this._origin = origin; 45 | this._areBoundsDirty = true; 46 | } 47 | 48 | return this; 49 | } 50 | 51 | public get sprite() { 52 | return this._sprite; 53 | } 54 | public set sprite(value: Sprite) { 55 | this.setSprite(value); 56 | } 57 | 58 | public get originNormalized() { 59 | return new es.Vector2(this._origin.x / this.getwidth() * this.entity.transform.scale.x, 60 | this._origin.y / this.getheight() * this.entity.transform.scale.y); 61 | } 62 | public set originNormalized(value: es.Vector2) { 63 | this.setOrigin(new es.Vector2(value.x * this.getwidth() / this.entity.transform.scale.x, 64 | value.y * this.getheight() / this.entity.transform.scale.y)); 65 | 66 | const ui_transform = this._sprite.getComponent(UITransform); 67 | if (ui_transform) { 68 | const originNormalized = new Vec2(value.x, value.y) 69 | ui_transform.anchorPoint = originNormalized; 70 | } 71 | } 72 | 73 | protected _origin: es.Vector2 = new es.Vector2(); 74 | protected _sprite!: Sprite; 75 | 76 | constructor(sprite: Sprite) { 77 | super(); 78 | this.setSprite(sprite); 79 | } 80 | 81 | onAddedToEntity() { 82 | super.onAddedToEntity(); 83 | if (!this._sprite.node.parent) { 84 | find('Canvas')?.addChild(this._sprite.node); 85 | } 86 | } 87 | 88 | onRemovedFromEntity() { 89 | super.onRemovedFromEntity(); 90 | this._sprite.node.removeFromParent(); 91 | this._sprite.node.destroy(); 92 | } 93 | 94 | public setSprite(sprite: Sprite) { 95 | this._sprite = sprite; 96 | if (this._sprite != null) { 97 | const uiTransform = this._sprite.getComponent(UITransform); 98 | if (uiTransform) { 99 | const originPoint = uiTransform.anchorPoint; 100 | if (originPoint) { 101 | const scale = this.entity ? this.entity.transform.scale : this._sprite.node.scale; 102 | const newOrigin = new es.Vector2(originPoint.x * this.getwidth() / scale.x, 103 | originPoint.y * this.getheight() / scale.y); 104 | this._origin = newOrigin; 105 | } 106 | } 107 | } 108 | return this; 109 | } 110 | 111 | onEntityTransformChanged(comp: es.ComponentTransform) { 112 | if (!this._sprite) 113 | return; 114 | 115 | switch (comp) { 116 | case es.ComponentTransform.position: 117 | this._sprite.node.setPosition(this.entity.position.x, this.entity.position.y, 0); 118 | break; 119 | case es.ComponentTransform.rotation: 120 | this._sprite.node.setRotationFromEuler(0, 0, this.entity.rotationDegrees); 121 | break; 122 | case es.ComponentTransform.scale: 123 | this._sprite.node.setScale(new Vec3(this.entity.scale.x, this.entity.scale.y, 1)); 124 | break; 125 | } 126 | } 127 | 128 | public render(batcher: Batcher, camera: component_camera): void { 129 | 130 | } 131 | } -------------------------------------------------------------------------------- /assets/scripts/components/SpriteRenderer.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "c0fa9249-030f-4f09-a54c-54746ce98f9d", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/components/component_camera.ts: -------------------------------------------------------------------------------- 1 | import { Camera, clamp, find, Label, Node, Vec3, view } from "cc"; 2 | import { Input } from "../Input/Input"; 3 | 4 | class CameraInset { 5 | left: number = 0; 6 | right: number = 0; 7 | top: number = 0; 8 | bottom: number = 0; 9 | } 10 | 11 | export class component_camera extends es.Component implements es.IUpdatable, es.ICamera { 12 | public get position() { 13 | return this.entity.transform.position; 14 | } 15 | 16 | public get rotation() { 17 | return this.entity.transform.rotation; 18 | } 19 | 20 | public get bounds() { 21 | if (this._areMatrixesDirty) 22 | this.updateMatrixes(); 23 | 24 | if (this._areBoundsDirty) { 25 | let viewport = view.getViewportRect(); 26 | let topLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, this._inset.top)); 27 | let bottomRight = this.screenToWorldPoint(new es.Vector2(viewport.width - this._inset.right, 28 | viewport.height - this._inset.bottom)); 29 | 30 | if (this.entity.transform.rotation != 0) { 31 | let topRight = this.screenToWorldPoint(new es.Vector2(viewport.width - this._inset.right, 32 | this._inset.top)); 33 | let bottomLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, 34 | viewport.height - this._inset.bottom)); 35 | 36 | let minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); 37 | let maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); 38 | let minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); 39 | let maxY = Math.max(topLeft.x, bottomRight.y, topRight.y, bottomLeft.y); 40 | 41 | this._bounds.location = new es.Vector2(minX, minY); 42 | this._bounds.width = maxX - minX; 43 | this._bounds.height = maxY - minY; 44 | } else { 45 | this._bounds.location = topLeft; 46 | this._bounds.width = bottomRight.x - topLeft.x; 47 | this._bounds.height = bottomRight.y - topLeft.y; 48 | } 49 | 50 | this._areBoundsDirty = false; 51 | } 52 | 53 | return this._bounds; 54 | } 55 | 56 | public get transformMatrix() { 57 | if (this._areBoundsDirty) 58 | this.updateMatrixes(); 59 | 60 | return this._transformMatrix; 61 | } 62 | 63 | public get inverseTransformMatrix() { 64 | if (this._areBoundsDirty) 65 | this.updateMatrixes(); 66 | 67 | return this._inverseTransformMatrix; 68 | } 69 | 70 | public get origin() { 71 | return this._origin; 72 | } 73 | 74 | public set origin(value: es.Vector2) { 75 | if (!this._origin.equals(value)) { 76 | this._origin = value; 77 | this._areMatrixesDirty = true; 78 | } 79 | } 80 | 81 | public get zoom() { 82 | if (this._zoom == 0) 83 | return 1; 84 | 85 | if (this._zoom < 1) 86 | return es.MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); 87 | 88 | return es.MathHelper.map(this._zoom, 1, this._maxmumZoom, 0, 1); 89 | } 90 | 91 | public set zoom(value: number) { 92 | this.setZoom(value); 93 | } 94 | 95 | public get rawZoom() { 96 | return this._zoom; 97 | } 98 | 99 | public set rawZoom(value: number) { 100 | if (value != this._zoom) { 101 | this._zoom = value; 102 | this._areMatrixesDirty = true; 103 | } 104 | } 105 | 106 | public get minimumZoom() { 107 | return this._minimumZoom; 108 | } 109 | 110 | public set minimumZoom(value: number) { 111 | this.setMinimumZoom(value); 112 | } 113 | 114 | public get maximumZoom() { 115 | return this._maxmumZoom; 116 | } 117 | 118 | public set maximumZoom(value: number) { 119 | this.setMaximumZoom(value); 120 | } 121 | 122 | public get ratio() { 123 | return this._ratio; 124 | } 125 | 126 | public set ratio(value: es.Vector2) { 127 | this.setRatio(value); 128 | } 129 | 130 | private _transformMatrix: es.Matrix2D = es.Matrix2D.identity; 131 | private _inverseTransformMatrix = es.Matrix2D.identity; 132 | 133 | private _bounds: es.Rectangle = new es.Rectangle(); 134 | private _inset: CameraInset = new CameraInset(); 135 | private _zoom: number = 0; 136 | private _minimumZoom = 0.3; 137 | private _maxmumZoom = 3; 138 | private _origin: es.Vector2 = es.Vector2.zero; 139 | private _ratio: es.Vector2 = es.Vector2.one; 140 | 141 | private _areMatrixesDirty: boolean = true; 142 | private _areBoundsDirty: boolean = true; 143 | 144 | private camera: Camera; 145 | 146 | constructor() { 147 | super(); 148 | this.setZoom(0); 149 | let camera = find('Canvas/Camera')?.getComponent(Camera); 150 | if (camera) { 151 | this.camera = camera; 152 | } else { 153 | let cameraNode = new Node('Camera'); 154 | this.camera = cameraNode.addComponent(Camera); 155 | find('Canvas')?.addChild(cameraNode); 156 | } 157 | 158 | const visibleSize = view.getVisibleSize(); 159 | this.origin = new es.Vector2(visibleSize.width / 2, visibleSize.height / 2); 160 | 161 | const canvasSize = view.getCanvasSize(); 162 | this.ratio = new es.Vector2(visibleSize.width / canvasSize.width, visibleSize.height / canvasSize.height); 163 | } 164 | 165 | protected updateMatrixes() { 166 | if (!this._areBoundsDirty) 167 | return; 168 | 169 | let tempMat: es.Matrix2D = new es.Matrix2D(); 170 | es.Matrix2D.createTranslation(-this.entity.transform.position.x, -this.entity.transform.position.y, this._transformMatrix); 171 | 172 | if (this._zoom != 1) { 173 | es.Matrix2D.createScale(this._zoom, this._zoom, tempMat); 174 | this._transformMatrix = this._transformMatrix.multiply(tempMat); 175 | } 176 | 177 | if (this.entity.transform.rotation != 0) { 178 | es.Matrix2D.createRotation(this.entity.transform.rotation, tempMat); 179 | this._transformMatrix = this._transformMatrix.multiply(tempMat); 180 | } 181 | 182 | es.Matrix2D.createTranslation(Math.trunc(this._origin.x), Math.trunc(this._origin.y), tempMat); 183 | this._transformMatrix = this._transformMatrix.multiply(tempMat); 184 | 185 | this._inverseTransformMatrix = es.Matrix2D.invert(this._transformMatrix); 186 | 187 | this._areBoundsDirty = true; 188 | this._areMatrixesDirty = false; 189 | } 190 | 191 | public setZoom(zoom: number) { 192 | let newZoom = clamp(zoom, -1, 1); 193 | if (newZoom == 0) 194 | this._zoom = 1; 195 | else if(newZoom < 0) 196 | this._zoom = es.MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); 197 | else 198 | this._zoom = es.MathHelper.map(newZoom, 0, 1, 1, this._maxmumZoom); 199 | 200 | this._areMatrixesDirty = true; 201 | 202 | return this; 203 | } 204 | 205 | public setMinimumZoom(minZoom: number) { 206 | es.Insist.isTrue(minZoom > 0, "minimumZoom必须大于零"); 207 | 208 | if (this._zoom < minZoom) 209 | this._zoom = this.minimumZoom; 210 | 211 | this._minimumZoom = minZoom; 212 | return this; 213 | } 214 | 215 | public setMaximumZoom(maxZoom: number) { 216 | es.Insist.isTrue(maxZoom > 0, "MaximumZoom必须大于零"); 217 | 218 | if (this._zoom > maxZoom) 219 | this._zoom = maxZoom; 220 | 221 | this._maxmumZoom = maxZoom; 222 | return this; 223 | } 224 | 225 | public setRatio(value: es.Vector2) { 226 | if (!this._ratio.equals(value)) { 227 | this._ratio = value; 228 | this._areBoundsDirty = true; 229 | } 230 | 231 | return this; 232 | } 233 | 234 | public setInset(left: number, right: number, top: number, bottom: number) { 235 | this._inset = new CameraInset(); 236 | this._inset.left = left; 237 | this._inset.right = right; 238 | this._inset.top = top; 239 | this._inset.bottom = bottom; 240 | this._areBoundsDirty = true; 241 | return this; 242 | } 243 | 244 | public zoomIn(deltaZoom: number) { 245 | this.zoom += deltaZoom; 246 | } 247 | 248 | public zoomOut(deltaZoom: number) { 249 | this.zoom -= deltaZoom; 250 | } 251 | 252 | public screenToWorldPoint(screenPosition: es.Vector2): es.Vector2 { 253 | this.updateMatrixes(); 254 | es.Vector2Ext.transformR(screenPosition.multiply(this.ratio), this._inverseTransformMatrix, screenPosition); 255 | return screenPosition; 256 | } 257 | 258 | public worldToScreenPoint(worldPosition: es.Vector2): es.Vector2 { 259 | this.updateMatrixes(); 260 | es.Vector2Ext.transformR(worldPosition.multiply(this.ratio), this._transformMatrix, worldPosition); 261 | return worldPosition; 262 | } 263 | 264 | public forceMatrixUpdate() { 265 | this._areMatrixesDirty = true; 266 | } 267 | 268 | public onEntityTransformChanged(comp: transform.Component) { 269 | this._areMatrixesDirty = true; 270 | } 271 | 272 | public touchToWorldPoint() { 273 | return this.screenToWorldPoint(Input.scaledPosition(Input.touchPosition)); 274 | } 275 | 276 | public mouseToWorldPoint() { 277 | return this.screenToWorldPoint(Input.scaledPosition(Input.mousePosition)); 278 | } 279 | 280 | public update() { 281 | this.camera.node.setPosition(new Vec3(this.position.x, this.position.y, 1000)); 282 | // let camera = this.camera.getComponent(Camera); 283 | // if (camera) camera.orthoHeight = 320 + 320 * this.zoom; 284 | } 285 | } -------------------------------------------------------------------------------- /assets/scripts/components/component_camera.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "dae371aa-4ce5-4354-bddc-77bcdf9bcc45", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/graphics.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "61024a54-9de6-4c26-bbaa-2e56e2bb1938", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/scripts/graphics/Batcher.ts: -------------------------------------------------------------------------------- 1 | import { Camera, Color, find, Graphics, Node } from "cc"; 2 | import { component_camera } from "../components/component_camera"; 3 | 4 | export class Batcher implements es.IBatcher { 5 | public graphics: Graphics; 6 | public camera: component_camera | null = null; 7 | public strokeNum: number = 0; 8 | 9 | public readonly MAX_STROKE = 4096; 10 | 11 | constructor() { 12 | let graphics = find('Canvas/Graphics')?.getComponent(Graphics); 13 | if (graphics) { 14 | this.graphics = graphics; 15 | } else { 16 | let graphics = new Node('Graphics'); 17 | this.graphics = graphics.addComponent(Graphics); 18 | find('Canvas')?.addChild(graphics); 19 | } 20 | } 21 | 22 | public begin(cam: component_camera) { 23 | this.graphics.clear(); 24 | this.camera = cam; 25 | this.strokeNum = 0; 26 | } 27 | 28 | public end() { 29 | if (this.strokeNum > 0) { 30 | this.strokeNum = 0; 31 | this.graphics.stroke(); 32 | } 33 | } 34 | 35 | public drawPoints(points: es.Vector2[], color: es.Color, thickness: number = 2) { 36 | if (points.length < 2) 37 | return; 38 | 39 | for (let i = 1; i < points.length; i++) 40 | this.drawLine(points[i - 1], points[i], color, thickness); 41 | } 42 | 43 | public drawPolygon(position: es.Vector2, points: es.Vector2[], color: es.Color, 44 | closePoly: boolean = true, thickness: number = 1) { 45 | if (points.length < 2) 46 | return; 47 | 48 | for (let i = 1; i < points.length; i ++) 49 | this.drawLine(es.Vector2.add(position, points[i - 1]), es.Vector2.add(position, points[i]), color, thickness); 50 | 51 | if (closePoly) 52 | this.drawLine(es.Vector2.add(position, points[points.length - 1]), es.Vector2.add(position, points[0]), color, thickness); 53 | } 54 | 55 | public drawHollowRect(x: number, y: number, width: number, height: number, color: es.Color, thickness: number = 2) { 56 | this.graphics.strokeColor = new Color(color.r, color.g, color.b); 57 | this.graphics.lineWidth = thickness; 58 | 59 | const tl = es.Vector2Ext.round(new es.Vector2(x, y)); 60 | const tr = es.Vector2Ext.round(new es.Vector2(x + width, y)); 61 | const br = es.Vector2Ext.round(new es.Vector2(x + width, y + height)); 62 | const bl = es.Vector2Ext.round(new es.Vector2(x, y + height)); 63 | 64 | this.drawLine(tl, tr, color, thickness); 65 | this.drawLine(tr, br, color, thickness); 66 | this.drawLine(br, bl, color, thickness); 67 | this.drawLine(bl, tl, color, thickness); 68 | } 69 | 70 | public drawCircle(position: es.Vector2, radius: number, color: es.Color, thickness: number = 2) { 71 | const bounds = new es.Rectangle(position.x - radius, position.y - radius, radius * 2, radius * 2); 72 | if (this.camera && !this.camera.bounds.intersects(bounds)) 73 | return; 74 | 75 | this.graphics.strokeColor = new Color(color.r, color.g, color.b); 76 | this.graphics.lineWidth = thickness; 77 | this.graphics.circle(position.x, position.y, radius); 78 | this.strokeNum ++; 79 | this.flushBatch(); 80 | } 81 | 82 | public drawCircleLow(position: es.Vector2, radius: number, color: es.Color, thickness: number = 2, resolution: number = 12) { 83 | let last = es.Vector2.unitX.multiplyScaler(radius); 84 | let lastP = es.Vector2Ext.perpendicularFlip(last); 85 | 86 | for (let i = 1; i <= resolution; i ++) { 87 | const at = es.MathHelper.angleToVector(i * es.MathHelper.PiOver2 / resolution, radius); 88 | const atP = es.Vector2Ext.perpendicularFlip(at); 89 | 90 | this.drawLine(es.Vector2.add(position, last), es.Vector2.add(position, at), color, thickness); 91 | this.drawLine(position.sub(last), position.sub(at), color, thickness); 92 | this.drawLine(es.Vector2.add(position, lastP), es.Vector2.add(position, atP), color, thickness); 93 | this.drawLine(position.sub(lastP), position.sub(atP), color, thickness); 94 | 95 | last = at; 96 | lastP = atP; 97 | } 98 | } 99 | 100 | public drawRect(x: number, y: number, width: number, height: number, color: es.Color) { 101 | const rect = new es.Rectangle(x, y, width, height); 102 | if (this.camera && !this.camera.bounds.intersects(rect)) 103 | return; 104 | 105 | this.graphics.strokeColor = new Color(color.r, color.g, color.b); 106 | this.graphics.lineWidth = 1; 107 | this.graphics.rect(Math.trunc(x), Math.trunc(y), Math.trunc(width), Math.trunc(height)); 108 | this.strokeNum ++; 109 | this.flushBatch(); 110 | } 111 | 112 | public drawLine(start: es.Vector2, end: es.Vector2, color: es.Color, thickness: number = 2) { 113 | const bounds = es.RectangleExt.boundsFromPolygonVector([start, end]); 114 | if (this.camera && !this.camera.bounds.intersects(bounds)) 115 | return; 116 | 117 | this.graphics.lineWidth = thickness; 118 | this.graphics.strokeColor = new Color(color.r, color.g, color.b); 119 | this.graphics.moveTo(start.x, start.y); 120 | this.graphics.lineTo(end.x, end.y); 121 | this.strokeNum ++; 122 | this.flushBatch(); 123 | } 124 | 125 | public drawPixel(position: es.Vector2, color: es.Color, size: number = 1) { 126 | const destRect = new es.Rectangle(Math.trunc(position.x), Math.trunc(position.y), size, size); 127 | if (size != 1) { 128 | destRect.x -= Math.trunc(size * 0.5); 129 | destRect.y -= Math.trunc(size * 0.5); 130 | } 131 | 132 | if (this.camera && !this.camera.bounds.intersects(destRect)) 133 | return; 134 | 135 | this.graphics.strokeColor = new Color(color.r, color.g, color.b); 136 | this.graphics.lineWidth = size; 137 | this.graphics.rect(destRect.x, destRect.y, destRect.width, destRect.height); 138 | this.strokeNum ++; 139 | this.flushBatch(); 140 | } 141 | 142 | public flushBatch() { 143 | if (this.strokeNum >= this.MAX_STROKE) { 144 | this.strokeNum = 0; 145 | this.graphics.stroke(); 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /assets/scripts/graphics/Batcher.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "57068a3f-3b33-47dc-9d4f-c09249a18368", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "simulateGlobals": [] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /assets/scripts/scenes.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "f80a010f-9b9d-48dc-be6f-001389379de8", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/scripts/scenes/BasicScene.ts: -------------------------------------------------------------------------------- 1 | import { instantiate, Prefab, resources, Sprite } from "cc"; 2 | import { SpriteRenderer } from "../components/SpriteRenderer"; 3 | import { RenderScene, sampleScene } from "./RenderScene"; 4 | 5 | @sampleScene("基础场景") 6 | export class BasicScene extends RenderScene { 7 | public initialize() { 8 | resources.load('prefabs/moon', Prefab, (err, data)=>{ 9 | let moonTex = instantiate(data).getComponent(Sprite); 10 | let playerEntity = this.createEntity("player"); 11 | if (moonTex) playerEntity.addComponent(new SpriteRenderer(moonTex)) 12 | }); 13 | } 14 | } -------------------------------------------------------------------------------- /assets/scripts/scenes/BasicScene.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "802e6015-eaa0-4781-8531-72be2705fdcf", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/scenes/RenderScene.ts: -------------------------------------------------------------------------------- 1 | import { Button, EventHandler, find, instantiate, Label, Prefab, resources, Sprite, Toggle, ToggleComponent } from "cc"; 2 | import { component_camera as component_camera } from "../components/component_camera"; 3 | import { SpriteRenderer } from "../components/SpriteRenderer"; 4 | 5 | export enum SceneEmitType { 6 | graphics_dirty 7 | } 8 | 9 | export var sampleList: Map RenderScene> = new Map(); 10 | 11 | export function sampleScene(buttonName: string) { 12 | return function(target: any) { 13 | sampleList.set(buttonName, target); 14 | } 15 | } 16 | 17 | export abstract class RenderScene extends es.Scene { 18 | constructor() { 19 | super(); 20 | 21 | let cameraEntity = this.createEntity("camera"); 22 | this.camera = cameraEntity.addComponent(new component_camera()); 23 | } 24 | } -------------------------------------------------------------------------------- /assets/scripts/scenes/RenderScene.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "06f92185-dceb-49a6-83d9-43861ce9dc4a", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/scenes/collider.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "ff9837ac-3a96-4dfd-9f4a-6f0ae253ee88", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/scripts/scenes/collider/ColliderScene.ts: -------------------------------------------------------------------------------- 1 | import { instantiate, Prefab, resources, Sprite } from "cc"; 2 | import { SpriteRenderer } from "../../components/SpriteRenderer"; 3 | import { RenderScene, sampleScene } from "../RenderScene"; 4 | import { ColliderTrigger } from "./ColliderTrigger"; 5 | 6 | @sampleScene("collider") 7 | export class ColliderScene extends RenderScene { 8 | public initialize() { 9 | let box1 = this.createEntity("box1"); 10 | resources.load('prefabs/moon', Prefab, (err, data)=>{ 11 | let moonTex = instantiate(data).getComponent(Sprite); 12 | if (moonTex) { 13 | box1.addComponent(new ColliderTrigger()); 14 | box1.addComponent(new es.Mover()); 15 | box1.addComponent(new SpriteRenderer(moonTex)) 16 | if (moonTex.spriteFrame) 17 | box1.addComponent(new es.BoxCollider()).isTrigger = true; 18 | } 19 | box1.setPosition(200, 100); 20 | }); 21 | 22 | let box2 = this.createEntity("box2"); 23 | resources.load('prefabs/moon', Prefab, (err, data)=>{ 24 | let moonTex = instantiate(data).getComponent(Sprite); 25 | if (moonTex) { 26 | box2.addComponent(new ColliderTrigger()); 27 | box2.addComponent(new SpriteRenderer(moonTex)) 28 | if (moonTex.spriteFrame) 29 | box2.addComponent(new es.BoxCollider()); 30 | } 31 | box2.setPosition(100, 200); 32 | }); 33 | 34 | es.Core.schedule(0, true, this, ()=> { 35 | const collisionResult = new es.CollisionResult(); 36 | box1.getComponent(es.Mover)?.move(es.Vector2.up, collisionResult); 37 | }); 38 | } 39 | } -------------------------------------------------------------------------------- /assets/scripts/scenes/collider/ColliderScene.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "61919a78-2967-4b75-87b5-80289862b40b", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/scenes/collider/ColliderTrigger.ts: -------------------------------------------------------------------------------- 1 | export class ColliderTrigger extends es.Component implements es.ITriggerListener { 2 | onTriggerEnter(other: es.Collider, local: es.Collider) { 3 | console.log("onTriggerEnter", other, local); 4 | } 5 | 6 | onTriggerExit(other: es.Collider, local: es.Collider) { 7 | console.log("onTriggerExit", other, local); 8 | } 9 | } -------------------------------------------------------------------------------- /assets/scripts/scenes/collider/ColliderTrigger.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "e23539e9-d13b-4f12-b720-90c38166ab4b", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/scenes/lineCasting.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "5e04a2b8-98f9-4d3b-b921-3a8a03987f10", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/scripts/scenes/lineCasting/LineCaster.ts: -------------------------------------------------------------------------------- 1 | import { Color } from "cc"; 2 | import { component_camera } from "../../components/component_camera"; 3 | import { Batcher } from "../../graphics/Batcher"; 4 | import { Input } from "../../Input/Input"; 5 | import { Keys } from "../../Input/Keys"; 6 | export class LineCaster extends es.RenderableComponent implements es.IUpdatable { 7 | private _lastPosition: es.Vector2 = new es.Vector2(101, 101); 8 | private _collisionPosition: es.Vector2 = new es.Vector2(-1, -1); 9 | 10 | public getwidth() { 11 | return 1000; 12 | } 13 | 14 | public getheight() { 15 | return 1000; 16 | } 17 | 18 | public render(batcher: Batcher, camera: component_camera): void { 19 | batcher.drawPixel(this._lastPosition, new es.Color(255, 255, 0), 4); 20 | batcher.end(); 21 | 22 | batcher.drawPixel(this.transform.position, new es.Color(255, 255, 255), 4); 23 | batcher.end(); 24 | 25 | batcher.drawLine(this._lastPosition, this.transform.position, new es.Color(255, 255, 255), 2); 26 | batcher.end(); 27 | 28 | if (this._collisionPosition.x > 0 && this._collisionPosition.y > 0) { 29 | batcher.drawPixel(this._collisionPosition, new es.Color(255, 0, 0), 10); 30 | batcher.end(); 31 | } 32 | } 33 | 34 | update() { 35 | if (Input.leftMouseButtonPressed) { 36 | this._lastPosition = this.transform.position.clone(); 37 | let pos = this.entity.scene.findEntity('camera').getComponent(component_camera).mouseToWorldPoint(); 38 | this.transform.position = pos.clone(); 39 | this._collisionPosition = new es.Vector2(-1, -1); 40 | } 41 | 42 | if (Input.rightMouseButtonPressed || Input.isKeyPressed(Keys.space)) { 43 | let hit = es.Physics.linecast(this._lastPosition, this.transform.position); 44 | if (hit.collider != null) { 45 | this._collisionPosition = hit.point; 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /assets/scripts/scenes/lineCasting/LineCaster.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "a22e2223-f155-4d03-8640-431af9a982f4", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/scenes/lineCasting/LineCastingScene.ts: -------------------------------------------------------------------------------- 1 | import { resources, Prefab, instantiate, Sprite, BoxCollider } from "cc"; 2 | import { SpriteRenderer } from "../../components/SpriteRenderer"; 3 | import { RenderScene, sampleScene } from "../RenderScene"; 4 | import { LineCaster } from "./LineCaster"; 5 | 6 | @sampleScene("lineCasting") 7 | export class LineCastingScene extends RenderScene { 8 | public initialize() { 9 | let playerEntity = this.createEntity("player"); 10 | resources.load('prefabs/moon', Prefab, (err, data)=>{ 11 | let moonTex = instantiate(data).getComponent(Sprite); 12 | if (moonTex) { 13 | playerEntity.addComponent(new SpriteRenderer(moonTex)) 14 | if (moonTex.spriteFrame) 15 | playerEntity.addComponent(new es.BoxCollider()); 16 | } 17 | playerEntity.setPosition(200, 100); 18 | }); 19 | 20 | 21 | let lineCaster = this.createEntity("linecaster") 22 | .addComponent(new LineCaster()); 23 | lineCaster.transform.position = new es.Vector2(300, 100); 24 | } 25 | } -------------------------------------------------------------------------------- /assets/scripts/scenes/lineCasting/LineCastingScene.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "68b57bbf-6f33-468b-9140-fa3655e33b04", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/scenes/rigidBodies.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "39a96a4e-3b1e-48c6-af9a-1fc9352c28da", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/scripts/scenes/rigidBodies/RigidBodyScene.ts: -------------------------------------------------------------------------------- 1 | import { find, instantiate, Prefab, resources, Sprite, view } from "cc"; 2 | import { component_camera } from "../../components/component_camera"; 3 | import { SpriteRenderer } from "../../components/SpriteRenderer"; 4 | import { RenderScene, sampleScene } from "../RenderScene"; 5 | 6 | @sampleScene("RigidBody") 7 | export class RigidBodyScene extends RenderScene { 8 | public onStart() { 9 | // let camera = this.findEntity('camera')?.getComponent(component_camera); 10 | // if (camera) { 11 | // camera.zoom = 2; 12 | // } 13 | (this.camera as component_camera).position.add(new es.Vector2(200, 0)) 14 | 15 | resources.load('prefabs/moon', Prefab, (err, data)=>{ 16 | this.initAfter(data); 17 | }); 18 | } 19 | 20 | private initAfter(moonTex: Prefab) { 21 | let friction = 0.3; 22 | let elasticity = 0.4; 23 | this.createBody(new es.Vector2(50, 200), 50, friction, elasticity, new es.Vector2(150, 0), moonTex) 24 | .addImpulse(new es.Vector2(10, 0)); 25 | this.createBody(new es.Vector2(800, 260), 5, friction, elasticity, new es.Vector2(-180, 0), moonTex); 26 | 27 | this.createBody(new es.Vector2(50, 400), 50, friction, elasticity, new es.Vector2(150, -40), moonTex); 28 | this.createBody(new es.Vector2(800, 460), 5, friction, elasticity, new es.Vector2(-180, -40), moonTex); 29 | 30 | this.createBody(new es.Vector2(400, 0), 60, friction, elasticity, new es.Vector2(10, 90), moonTex); 31 | this.createBody(new es.Vector2(500, 400), 4, friction, elasticity, new es.Vector2(0, -270), moonTex); 32 | 33 | this.createBody(new es.Vector2(-200, 250), 0, friction, elasticity, new es.Vector2(0, -270), moonTex); 34 | 35 | this.createBody(new es.Vector2(200, 700), 15, friction, elasticity, new es.Vector2(150, -150), moonTex); 36 | this.createBody(new es.Vector2(800, 760), 15, friction, elasticity, new es.Vector2(-180, -150), moonTex); 37 | this.createBody(new es.Vector2(1200, 700), 1, friction, elasticity, new es.Vector2(0, 0), moonTex) 38 | .addImpulse(new es.Vector2(-5, -20)); 39 | 40 | this.createBody(new es.Vector2(100, 100), 1, friction, elasticity, new es.Vector2(100, 90), moonTex) 41 | .addImpulse(new es.Vector2(40, -10)); 42 | this.createBody(new es.Vector2(100, 700), 100, friction, elasticity, new es.Vector2(200, -270), moonTex); 43 | } 44 | 45 | private createBody(position: es.Vector2, mass: number, friction: number, elasticity: number, velocity: es.Vector2, texture: Prefab) { 46 | let rigidBody = new es.ArcadeRigidbody() 47 | .setMass(mass) 48 | .setFriction(friction) 49 | .setElasticity(elasticity) 50 | .setVelocity(velocity); 51 | 52 | let entity = this.createEntity(es.UUID.randomUUID()); 53 | let sprite = instantiate(texture).getComponent(Sprite) 54 | if (sprite) entity.addComponent(new SpriteRenderer(sprite)); 55 | entity.setPosition(position.x, position.y); 56 | entity.addComponent(rigidBody); 57 | entity.addComponent(new es.CircleCollider()); 58 | 59 | return rigidBody; 60 | } 61 | 62 | update() { 63 | super.update(); 64 | 65 | es.Core.emitter.emit(es.CoreEvents.renderChanged, es.Time.deltaTime); 66 | } 67 | } -------------------------------------------------------------------------------- /assets/scripts/scenes/rigidBodies/RigidBodyScene.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "15663d4c-0622-4555-a8d0-48807d11b2f1", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/scenes/verletPhysics.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "importer": "directory", 4 | "imported": true, 5 | "uuid": "48679130-c836-44df-82cc-1a270a4c9ee2", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": { 9 | "compressionType": {}, 10 | "isRemoteBundle": {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /assets/scripts/scenes/verletPhysics/VerletPhysicsScene.ts: -------------------------------------------------------------------------------- 1 | import { instantiate, Prefab, resources, Sprite } from "cc"; 2 | import { PolygonMesh } from "../../components/PolygonMesh"; 3 | import { PolygonSprite } from "../../components/PolygonSprite"; 4 | import { SpriteRenderer } from "../../components/SpriteRenderer"; 5 | import { RenderScene, sampleScene } from "../RenderScene"; 6 | import { VerletSystem } from "./VerletSystem"; 7 | 8 | @sampleScene("Verlet Physics") 9 | export class VerletPhysicsScene extends RenderScene { 10 | initialize() { 11 | const verletSystem = this.createEntity("verlet-system") 12 | .addComponent(new VerletSystem()); 13 | 14 | this.createPolygons(); 15 | 16 | this.createRope(verletSystem.world); 17 | 18 | verletSystem.world.addComposite(new es.Tire(new es.Vector2(175, 32), 64, 32, 0.3, 0.5)); 19 | verletSystem.world.addComposite(new es.Tire(new es.Vector2(300, 16), 50, 4, 0.2, 0.7)); 20 | verletSystem.world.addComposite(new es.Tire(new es.Vector2(450, 64), 64, 7, 0.1, 0.3)); 21 | 22 | verletSystem.world.addComposite(new es.Cloth(new es.Vector2(200, 200), 200, 200, 20, 0.25, 50)); 23 | 24 | verletSystem.world.addComposite(new es.Ragdoll(200, 20, es.RandomUtils.randint(140, 240))); 25 | verletSystem.world.addComposite(new es.Ragdoll(250, 20, es.RandomUtils.randint(140, 240))); 26 | verletSystem.world.addComposite(new es.Ragdoll(300, 20, es.RandomUtils.randint(140, 240))); 27 | 28 | verletSystem.world.addComposite(new es.Ball(new es.Vector2(100, 60), es.RandomUtils.randint(10, 50))); 29 | verletSystem.world.addComposite(new es.Ball(new es.Vector2(150, 60), es.RandomUtils.randint(10, 50))); 30 | verletSystem.world.addComposite(new es.Ball(new es.Vector2(200, 60), es.RandomUtils.randint(10, 50))); 31 | } 32 | 33 | createPolygons() { 34 | // const trianglePoints: es.Vector2[] = [new es.Vector2(0, 0), new es.Vector2(128, 0), new es.Vector2(128, 128)]; 35 | // const triangleEntity = this.createEntity("triangle"); 36 | 37 | // resources.load('prefabs/moon_polygon', Prefab, (err, data) => { 38 | // let moonTex = instantiate(data).getComponent(PolygonSprite)!; 39 | // triangleEntity.setPosition(50, 150); 40 | // triangleEntity.addComponent(new PolygonMesh(trianglePoints, false)).setColor(es.Color.Green).setTexture(moonTex); 41 | // triangleEntity.addComponent(new es.PolygonCollider(trianglePoints)); 42 | // }); 43 | 44 | const circleEntity = this.createEntity("circle"); 45 | resources.load('prefabs/moon', Prefab, (err, data) => { 46 | let moonTex = instantiate(data).getComponent(Sprite); 47 | if (moonTex) circleEntity.addComponent(new SpriteRenderer(moonTex)); 48 | circleEntity.setPosition(250, 60); 49 | circleEntity.addComponent(new es.CircleCollider(64)); 50 | }); 51 | 52 | 53 | // const polyPoints = es.Polygon.buildSymmetricalPolygon(5, 140); 54 | // const polygonEntity = this.createEntity("boxCollider"); 55 | // resources.load('prefabs/moon_polygon', Prefab, (err, data) => { 56 | // let moonTex = instantiate(data).getComponent(PolygonSprite)!; 57 | // polygonEntity.setPosition(230, 225); 58 | // polygonEntity.addComponent(new PolygonMesh(polyPoints)).setColor(es.Color.Green).setTexture(moonTex); 59 | // polygonEntity.addComponent(new es.PolygonCollider(polyPoints)); 60 | // }); 61 | 62 | // polygonEntity.tweenRotationDegreesTo(180, 3) 63 | // .setLoops(es.LoopType.pingpong, 50) 64 | // .setEaseType(es.EaseType.linear) 65 | // .start(); 66 | } 67 | 68 | createRope(world: es.VerletWorld) { 69 | const linePoints = []; 70 | for (var i = 0; i < 10; i++) 71 | linePoints[i] = new es.Vector2(30 * i + 50, 10); 72 | 73 | const line = new es.LineSegments(linePoints, 0.3) 74 | .pinParticleAtIndex(0); 75 | world.addComposite(line); 76 | } 77 | 78 | update() { 79 | super.update(); 80 | 81 | es.Core.emitter.emit(es.CoreEvents.renderChanged, es.Time.deltaTime); 82 | } 83 | } -------------------------------------------------------------------------------- /assets/scripts/scenes/verletPhysics/VerletPhysicsScene.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "bcb9ffa5-137b-4e5b-82ee-207a87f1409e", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /assets/scripts/scenes/verletPhysics/VerletSystem.ts: -------------------------------------------------------------------------------- 1 | import { component_camera } from "../../components/component_camera"; 2 | import { Input } from "../../Input/Input"; 3 | import { Keys } from "../../Input/Keys"; 4 | 5 | export class VerletSystem extends es.RenderableComponent implements es.IUpdatable { 6 | public getwidth() { 7 | return 960; 8 | } 9 | 10 | public getheight() { 11 | return 640; 12 | } 13 | 14 | public world: es.VerletWorld; 15 | 16 | constructor() { 17 | super(); 18 | 19 | this.world = new es.VerletWorld(new es.Rectangle(-this.getwidth() / 2, -this.getheight() / 2, this.getwidth() / 2, this.getheight() / 2)); 20 | this.world.onHandleDrag = this.handleDragging.bind(this); 21 | } 22 | 23 | handleDragging() { 24 | let pos = this.entity.scene.findEntity('camera').getComponent(component_camera).mouseToWorldPoint(); 25 | if (Input.leftMouseButtonPressed) { 26 | this.world._draggedParticle = this.world.getNearestParticle(pos); 27 | } else if(Input.leftMouseButtonDown) { 28 | if (this.world._draggedParticle != null) { 29 | this.world._draggedParticle.position = pos; 30 | } 31 | } else if(Input.leftMouseButtonRelease) { 32 | if (this.world._draggedParticle != null) 33 | this.world._draggedParticle.position = pos; 34 | (this.world._draggedParticle as any) = null; 35 | } 36 | } 37 | 38 | toggleZeroGravity() { 39 | if (this.world.gravity.y == 0) { 40 | this.world.gravity.y = -980; 41 | } else { 42 | this.world.gravity.y = 0; 43 | } 44 | } 45 | 46 | update() { 47 | if (Input.isKeyPressed(Keys.z)) 48 | this.toggleZeroGravity(); 49 | 50 | this.world.update(); 51 | } 52 | 53 | render(batcher: es.IBatcher, camera: es.ICamera): void { 54 | this.world.debugRender(batcher); 55 | } 56 | } -------------------------------------------------------------------------------- /assets/scripts/scenes/verletPhysics/VerletSystem.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "4.0.22", 3 | "importer": "typescript", 4 | "imported": true, 5 | "uuid": "48ad382b-01e4-4822-941c-6cafd0559690", 6 | "files": [], 7 | "subMetas": {}, 8 | "userData": {} 9 | } 10 | -------------------------------------------------------------------------------- /images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esengine/cocos-framework/f789e39c23c5ff802c02223c8dc2d3542e4459e0/images/screenshot.png -------------------------------------------------------------------------------- /images/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esengine/cocos-framework/f789e39c23c5ff802c02223c8dc2d3542e4459e0/images/screenshot1.png -------------------------------------------------------------------------------- /images/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esengine/cocos-framework/f789e39c23c5ff802c02223c8dc2d3542e4459e0/images/screenshot2.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "creator": { 3 | "version": "3.1.1" 4 | }, 5 | "name": "imagine-game-editor", 6 | "type": "3d", 7 | "uuid": "d25ac024-2210-4466-a566-caebac66622a", 8 | "version": "3.1.1" 9 | } 10 | -------------------------------------------------------------------------------- /settings/v2/packages/builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "__version__": "1.2.8" 3 | } 4 | -------------------------------------------------------------------------------- /settings/v2/packages/cocos-service.json: -------------------------------------------------------------------------------- 1 | { 2 | "__version__": "3.0.0", 3 | "game": { 4 | "name": "UNKNOW GAME", 5 | "app_id": "UNKNOW", 6 | "c_id": "0" 7 | }, 8 | "appConfigMaps": [ 9 | { 10 | "app_id": "UNKNOW", 11 | "config_id": "8f35fe" 12 | } 13 | ], 14 | "configs": [ 15 | { 16 | "app_id": "UNKNOW", 17 | "config_id": "8f35fe", 18 | "config_name": "Default", 19 | "config_remarks": "", 20 | "services": [] 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /settings/v2/packages/device.json: -------------------------------------------------------------------------------- 1 | { 2 | "__version__": "1.0.1" 3 | } 4 | -------------------------------------------------------------------------------- /settings/v2/packages/engine.json: -------------------------------------------------------------------------------- 1 | { 2 | "__version__": "1.0.5" 3 | } 4 | -------------------------------------------------------------------------------- /settings/v2/packages/program.json: -------------------------------------------------------------------------------- 1 | { 2 | "__version__": "1.0.0" 3 | } 4 | -------------------------------------------------------------------------------- /settings/v2/packages/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "__version__": "1.0.1" 3 | } 4 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | /* Base configuration. Do not edit this field. */ 3 | "extends": "./temp/tsconfig.cocos.json" 4 | 5 | /* Add your custom configuration here. */ 6 | } 7 | --------------------------------------------------------------------------------