@eva/plugin-renderer-render 2.0.1-beta.9 → 2.0.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.plugin.renderer.render.js +28 -3
- package/dist/EVA.plugin.renderer.render.min.js +1 -1
- package/dist/plugin-renderer-render.cjs.js +127 -16
- package/dist/plugin-renderer-render.cjs.prod.js +1 -16
- package/dist/plugin-renderer-render.d.ts +76 -0
- package/dist/plugin-renderer-render.esm.js +127 -16
- package/package.json +5 -5
|
@@ -42,6 +42,7 @@ var _EVA_IIFE_render = function (exports, eva_js, pluginRenderer) {
|
|
|
42
42
|
this.alpha = 1;
|
|
43
43
|
this.zIndex = 0;
|
|
44
44
|
this.sortableChildren = false;
|
|
45
|
+
this.resolution = 1;
|
|
45
46
|
}
|
|
46
47
|
init(obj) {
|
|
47
48
|
obj && _extends(this, obj);
|
|
@@ -52,6 +53,7 @@ var _EVA_IIFE_render = function (exports, eva_js, pluginRenderer) {
|
|
|
52
53
|
__decorate([type('number'), step(0.1)], Render$2.prototype, "alpha", void 0);
|
|
53
54
|
__decorate([type('number'), step(1)], Render$2.prototype, "zIndex", void 0);
|
|
54
55
|
__decorate([type('boolean')], Render$2.prototype, "sortableChildren", void 0);
|
|
56
|
+
__decorate([type('number'), step(0.1)], Render$2.prototype, "resolution", void 0);
|
|
55
57
|
let Render = class Render extends pluginRenderer.Renderer {
|
|
56
58
|
constructor() {
|
|
57
59
|
super(...arguments);
|
|
@@ -82,11 +84,24 @@ var _EVA_IIFE_render = function (exports, eva_js, pluginRenderer) {
|
|
|
82
84
|
add(changed) {
|
|
83
85
|
if (changed.component.name === 'Render') {
|
|
84
86
|
this.setDirty(changed);
|
|
87
|
+
const component = changed.component;
|
|
88
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
89
|
+
if (component.resolution !== undefined && component.resolution > 0) {
|
|
90
|
+
this.applyResolution(container, component.resolution);
|
|
91
|
+
}
|
|
85
92
|
}
|
|
86
93
|
}
|
|
87
94
|
change(changed) {
|
|
88
|
-
if (changed.component.name === 'Render'
|
|
89
|
-
|
|
95
|
+
if (changed.component.name === 'Render') {
|
|
96
|
+
if (changed.prop.prop[0] === 'zIndex') {
|
|
97
|
+
this.setDirty(changed);
|
|
98
|
+
} else if (changed.prop.prop[0] === 'resolution') {
|
|
99
|
+
const component = changed.component;
|
|
100
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
101
|
+
if (component.resolution !== undefined && component.resolution > 0) {
|
|
102
|
+
this.applyResolution(container, component.resolution);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
90
105
|
}
|
|
91
106
|
}
|
|
92
107
|
remove(changed) {
|
|
@@ -101,10 +116,20 @@ var _EVA_IIFE_render = function (exports, eva_js, pluginRenderer) {
|
|
|
101
116
|
parentRender.sortDirty = true;
|
|
102
117
|
}
|
|
103
118
|
}
|
|
119
|
+
applyResolution(container, resolution) {
|
|
120
|
+
if (!container) return;
|
|
121
|
+
window.requestAnimationFrame(() => {
|
|
122
|
+
if (container.children && Array.isArray(container.children)) {
|
|
123
|
+
for (const child of container.children) {
|
|
124
|
+
child.resolution = resolution;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
104
129
|
};
|
|
105
130
|
Render.systemName = 'Render';
|
|
106
131
|
Render = __decorate([eva_js.decorators.componentObserver({
|
|
107
|
-
Render: ['zIndex']
|
|
132
|
+
Render: ['zIndex', 'resolution']
|
|
108
133
|
})], Render);
|
|
109
134
|
var Render$1 = Render;
|
|
110
135
|
exports.Render = Render$2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_render=function(e,n,t){"use strict";function r(e,n,t,r){var o,i=arguments.length,s=i<3?n:null===r?r=Object.getOwnPropertyDescriptor(n,t):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,n,t,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(n,t,s):o(n,t))||s);return i>3&&s&&Object.defineProperty(n,t,s),s}function o(e,n){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[n]||(e.constructor.IDEProps[n]={}),e.constructor.IDEProps[n]}function i(e){return function(n,t){var r=o(n,t);r.key=t,r.type=e}}function s(e){return function(n,t){o(n,t).step=e}}class a extends n.Component{constructor(){super(...arguments),this.sortDirty=!1,this.visible=!0,this.alpha=1,this.zIndex=0,this.sortableChildren=!1,this.resolution=1}init(e){e&&_extends(this,e)}}a.componentName="Render",r([i("boolean")],a.prototype,"visible",void 0),r([i("number"),s(.1)],a.prototype,"alpha",void 0),r([i("number"),s(1)],a.prototype,"zIndex",void 0),r([i("boolean")],a.prototype,"sortableChildren",void 0),r([i("number"),s(.1)],a.prototype,"resolution",void 0);let l=class extends t.Renderer{constructor(){super(...arguments),this.name="Render"}init(){this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const n=e.getComponent("Render"),t=this.containerManager.getContainer(e.id);t.alpha=n.alpha,t.visible=n.visible,t.zIndex=n.zIndex}componentChanged(e){e.type!==n.OBSERVER_TYPE.ADD&&e.type!==n.OBSERVER_TYPE.REMOVE||this.add(e),e.type===n.OBSERVER_TYPE.CHANGE&&this.change(e),e.type===n.OBSERVER_TYPE.REMOVE&&this.remove(e)}add(e){if("Render"===e.component.name){this.setDirty(e);const n=e.component,t=this.containerManager.getContainer(e.gameObject.id);void 0!==n.resolution&&n.resolution>0&&this.applyResolution(t,n.resolution)}}change(e){if("Render"===e.component.name)if("zIndex"===e.prop.prop[0])this.setDirty(e);else if("resolution"===e.prop.prop[0]){const n=e.component,t=this.containerManager.getContainer(e.gameObject.id);void 0!==n.resolution&&n.resolution>0&&this.applyResolution(t,n.resolution)}}remove(e){if("Render"===e.component.name){this.containerManager.getContainer(e.gameObject.id).alpha=1}}setDirty(e){const n=e.gameObject.parent&&e.gameObject.parent.getComponent("Render");n&&(n.sortDirty=!0)}applyResolution(e,n){e&&window.requestAnimationFrame(()=>{if(e.children&&Array.isArray(e.children))for(const t of e.children)t.resolution=n})}};l.systemName="Render",l=r([n.decorators.componentObserver({Render:["zIndex","resolution"]})],l);var p=l;return e.Render=a,e.RenderSystem=p,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer);globalThis.EVA.plugin.renderer.render=globalThis.EVA.plugin.renderer.render||_EVA_IIFE_render;
|
|
@@ -6,19 +6,19 @@ var eva_js = require('@eva/eva.js');
|
|
|
6
6
|
var inspectorDecorator = require('@eva/inspector-decorator');
|
|
7
7
|
var pluginRenderer = require('@eva/plugin-renderer');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
Copyright (c) Microsoft Corporation.
|
|
11
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
12
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
13
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
/******************************************************************************
|
|
10
|
+
Copyright (c) Microsoft Corporation.
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
18
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
13
|
+
purpose with or without fee is hereby granted.
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
16
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
17
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
18
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
19
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
20
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
21
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
22
22
|
***************************************************************************** */
|
|
23
23
|
|
|
24
24
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -26,21 +26,97 @@ function __decorate(decorators, target, key, desc) {
|
|
|
26
26
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
27
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
28
28
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
-
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32
|
+
var e = new Error(message);
|
|
33
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
|
+
};
|
|
30
35
|
|
|
36
|
+
/**
|
|
37
|
+
* 渲染属性组件
|
|
38
|
+
*
|
|
39
|
+
* Render 组件控制游戏对象的渲染相关属性,如可见性、透明度、层级等。
|
|
40
|
+
* 这些属性影响对象的显示效果和渲染顺序,
|
|
41
|
+
* 适用于需要控制显示状态、淡入淡出、层级排序等场景。
|
|
42
|
+
*
|
|
43
|
+
* 主要属性:
|
|
44
|
+
* - visible - 控制对象是否可见
|
|
45
|
+
* - alpha - 控制对象透明度(0-1)
|
|
46
|
+
* - zIndex - 控制对象渲染层级
|
|
47
|
+
* - sortableChildren - 是否对子对象按 zIndex 排序
|
|
48
|
+
* - resolution - 渲染分辨率,值越大越清晰但性能消耗越大
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // 创建带渲染属性的对象
|
|
53
|
+
* const sprite = new GameObject('sprite');
|
|
54
|
+
* sprite.addComponent(new Img({ resource: 'player' }));
|
|
55
|
+
* sprite.addComponent(new Render({
|
|
56
|
+
* visible: true,
|
|
57
|
+
* alpha: 1,
|
|
58
|
+
* zIndex: 10
|
|
59
|
+
* }));
|
|
60
|
+
*
|
|
61
|
+
* // 控制可见性
|
|
62
|
+
* const render = sprite.getComponent('Render');
|
|
63
|
+
* render.visible = false; // 隐藏对象
|
|
64
|
+
*
|
|
65
|
+
* // 淡入淡出效果
|
|
66
|
+
* let alpha = 1;
|
|
67
|
+
* setInterval(() => {
|
|
68
|
+
* alpha -= 0.01;
|
|
69
|
+
* if (alpha <= 0) alpha = 1;
|
|
70
|
+
* render.alpha = alpha;
|
|
71
|
+
* }, 16);
|
|
72
|
+
*
|
|
73
|
+
* // 设置渲染层级
|
|
74
|
+
* render.zIndex = 100; // 越大越靠前
|
|
75
|
+
*
|
|
76
|
+
* // 启用子对象排序
|
|
77
|
+
* const container = new GameObject('container');
|
|
78
|
+
* container.addComponent(new Render({
|
|
79
|
+
* sortableChildren: true // 子对象将按 zIndex 排序
|
|
80
|
+
* }));
|
|
81
|
+
*
|
|
82
|
+
* // 设置渲染分辨率
|
|
83
|
+
* const text = new GameObject('text');
|
|
84
|
+
* text.addComponent(new Text({ text: 'High Resolution' }));
|
|
85
|
+
* text.addComponent(new Render({
|
|
86
|
+
* resolution: 2 // 2倍分辨率,使渲染更清晰
|
|
87
|
+
* }));
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
31
90
|
class Render$2 extends eva_js.Component {
|
|
32
91
|
constructor() {
|
|
33
92
|
super(...arguments);
|
|
93
|
+
/** 排序脏标记 */
|
|
34
94
|
this.sortDirty = false;
|
|
95
|
+
/** 是否可见 */
|
|
35
96
|
this.visible = true;
|
|
97
|
+
/** 透明度(0-1,0 为完全透明,1 为完全不透明) */
|
|
36
98
|
this.alpha = 1;
|
|
99
|
+
/** 渲染层级(数值越大越靠前) */
|
|
37
100
|
this.zIndex = 0;
|
|
101
|
+
/** 是否对子对象按 zIndex 排序 */
|
|
38
102
|
this.sortableChildren = false;
|
|
103
|
+
/** 渲染分辨率(值越大越清晰但性能消耗越大,默认为 1) */
|
|
104
|
+
this.resolution = 1;
|
|
39
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* 初始化组件
|
|
108
|
+
* @param obj - 初始化参数
|
|
109
|
+
* @param obj.visible - 是否可见
|
|
110
|
+
* @param obj.alpha - 透明度
|
|
111
|
+
* @param obj.zIndex - 渲染层级
|
|
112
|
+
* @param obj.sortableChildren - 是否对子对象排序
|
|
113
|
+
* @param obj.resolution - 渲染分辨率
|
|
114
|
+
*/
|
|
40
115
|
init(obj) {
|
|
41
116
|
obj && Object.assign(this, obj);
|
|
42
117
|
}
|
|
43
118
|
}
|
|
119
|
+
/** 组件名称 */
|
|
44
120
|
Render$2.componentName = 'Render';
|
|
45
121
|
__decorate([
|
|
46
122
|
inspectorDecorator.type('boolean')
|
|
@@ -55,7 +131,11 @@ __decorate([
|
|
|
55
131
|
], Render$2.prototype, "zIndex", void 0);
|
|
56
132
|
__decorate([
|
|
57
133
|
inspectorDecorator.type('boolean')
|
|
58
|
-
], Render$2.prototype, "sortableChildren", void 0);
|
|
134
|
+
], Render$2.prototype, "sortableChildren", void 0);
|
|
135
|
+
__decorate([
|
|
136
|
+
inspectorDecorator.type('number'),
|
|
137
|
+
inspectorDecorator.step(0.1)
|
|
138
|
+
], Render$2.prototype, "resolution", void 0);
|
|
59
139
|
|
|
60
140
|
let Render = class Render extends pluginRenderer.Renderer {
|
|
61
141
|
constructor() {
|
|
@@ -87,11 +167,27 @@ let Render = class Render extends pluginRenderer.Renderer {
|
|
|
87
167
|
add(changed) {
|
|
88
168
|
if (changed.component.name === 'Render') {
|
|
89
169
|
this.setDirty(changed);
|
|
170
|
+
// 初始化时应用 resolution
|
|
171
|
+
const component = changed.component;
|
|
172
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
173
|
+
if (component.resolution !== undefined && component.resolution > 0) {
|
|
174
|
+
this.applyResolution(container, component.resolution);
|
|
175
|
+
}
|
|
90
176
|
}
|
|
91
177
|
}
|
|
92
178
|
change(changed) {
|
|
93
|
-
if (changed.component.name === 'Render'
|
|
94
|
-
|
|
179
|
+
if (changed.component.name === 'Render') {
|
|
180
|
+
if (changed.prop.prop[0] === 'zIndex') {
|
|
181
|
+
this.setDirty(changed);
|
|
182
|
+
}
|
|
183
|
+
else if (changed.prop.prop[0] === 'resolution') {
|
|
184
|
+
// 当 resolution 改变时,重新应用到子对象
|
|
185
|
+
const component = changed.component;
|
|
186
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
187
|
+
if (component.resolution !== undefined && component.resolution > 0) {
|
|
188
|
+
this.applyResolution(container, component.resolution);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
95
191
|
}
|
|
96
192
|
}
|
|
97
193
|
remove(changed) {
|
|
@@ -106,11 +202,26 @@ let Render = class Render extends pluginRenderer.Renderer {
|
|
|
106
202
|
parentRender.sortDirty = true;
|
|
107
203
|
}
|
|
108
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* 递归应用 resolution 到容器中所有支持该属性的子对象
|
|
207
|
+
*/
|
|
208
|
+
applyResolution(container, resolution) {
|
|
209
|
+
if (!container)
|
|
210
|
+
return;
|
|
211
|
+
window.requestAnimationFrame(() => {
|
|
212
|
+
// 遍历容器的所有子对象
|
|
213
|
+
if (container.children && Array.isArray(container.children)) {
|
|
214
|
+
for (const child of container.children) {
|
|
215
|
+
child.resolution = resolution;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
109
220
|
};
|
|
110
221
|
Render.systemName = 'Render';
|
|
111
222
|
Render = __decorate([
|
|
112
223
|
eva_js.decorators.componentObserver({
|
|
113
|
-
Render: ['zIndex'],
|
|
224
|
+
Render: ['zIndex', 'resolution'],
|
|
114
225
|
})
|
|
115
226
|
], Render);
|
|
116
227
|
var Render$1 = Render;
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer");
|
|
2
|
-
/*! *****************************************************************************
|
|
3
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
6
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
|
|
8
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
9
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
10
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
11
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
-
|
|
13
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
|
-
and limitations under the License.
|
|
15
|
-
***************************************************************************** */
|
|
16
|
-
function n(e,t,r,n){var o,s=arguments.length,i=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(i=(s<3?o(i):s>3?o(t,r,i):o(t,r))||i);return s>3&&i&&Object.defineProperty(t,r,i),i}class o extends e.Component{constructor(){super(...arguments),this.sortDirty=!1,this.visible=!0,this.alpha=1,this.zIndex=0,this.sortableChildren=!1}init(e){e&&Object.assign(this,e)}}o.componentName="Render",n([t.type("boolean")],o.prototype,"visible",void 0),n([t.type("number"),t.step(.1)],o.prototype,"alpha",void 0),n([t.type("number"),t.step(1)],o.prototype,"zIndex",void 0),n([t.type("boolean")],o.prototype,"sortableChildren",void 0);let s=class extends r.Renderer{constructor(){super(...arguments),this.name="Render"}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const t=e.getComponent("Render"),r=this.containerManager.getContainer(e.id);r.alpha=t.alpha,r.visible=t.visible,r.zIndex=t.zIndex}componentChanged(t){t.type!==e.OBSERVER_TYPE.ADD&&t.type!==e.OBSERVER_TYPE.REMOVE||this.add(t),t.type===e.OBSERVER_TYPE.CHANGE&&this.change(t),t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t)}add(e){"Render"===e.component.name&&this.setDirty(e)}change(e){"Render"===e.component.name&&"zIndex"===e.prop.prop[0]&&this.setDirty(e)}remove(e){if("Render"===e.component.name){this.containerManager.getContainer(e.gameObject.id).alpha=1}}setDirty(e){const t=e.gameObject.parent&&e.gameObject.parent.getComponent("Render");t&&(t.sortDirty=!0)}};s.systemName="Render",s=n([e.decorators.componentObserver({Render:["zIndex"]})],s);var i=s;exports.Render=o,exports.RenderSystem=i;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer");function n(e,t,r,n){var o,i=arguments.length,s=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,r,s):o(t,r))||s);return i>3&&s&&Object.defineProperty(t,r,s),s}"function"==typeof SuppressedError&&SuppressedError;class o extends e.Component{constructor(){super(...arguments),this.sortDirty=!1,this.visible=!0,this.alpha=1,this.zIndex=0,this.sortableChildren=!1,this.resolution=1}init(e){e&&Object.assign(this,e)}}o.componentName="Render",n([t.type("boolean")],o.prototype,"visible",void 0),n([t.type("number"),t.step(.1)],o.prototype,"alpha",void 0),n([t.type("number"),t.step(1)],o.prototype,"zIndex",void 0),n([t.type("boolean")],o.prototype,"sortableChildren",void 0),n([t.type("number"),t.step(.1)],o.prototype,"resolution",void 0);let i=class extends r.Renderer{constructor(){super(...arguments),this.name="Render"}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const t=e.getComponent("Render"),r=this.containerManager.getContainer(e.id);r.alpha=t.alpha,r.visible=t.visible,r.zIndex=t.zIndex}componentChanged(t){t.type!==e.OBSERVER_TYPE.ADD&&t.type!==e.OBSERVER_TYPE.REMOVE||this.add(t),t.type===e.OBSERVER_TYPE.CHANGE&&this.change(t),t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t)}add(e){if("Render"===e.component.name){this.setDirty(e);const t=e.component,r=this.containerManager.getContainer(e.gameObject.id);void 0!==t.resolution&&t.resolution>0&&this.applyResolution(r,t.resolution)}}change(e){if("Render"===e.component.name)if("zIndex"===e.prop.prop[0])this.setDirty(e);else if("resolution"===e.prop.prop[0]){const t=e.component,r=this.containerManager.getContainer(e.gameObject.id);void 0!==t.resolution&&t.resolution>0&&this.applyResolution(r,t.resolution)}}remove(e){if("Render"===e.component.name){this.containerManager.getContainer(e.gameObject.id).alpha=1}}setDirty(e){const t=e.gameObject.parent&&e.gameObject.parent.getComponent("Render");t&&(t.sortDirty=!0)}applyResolution(e,t){e&&window.requestAnimationFrame(()=>{if(e.children&&Array.isArray(e.children))for(const r of e.children)r.resolution=t})}};i.systemName="Render",i=n([e.decorators.componentObserver({Render:["zIndex","resolution"]})],i);var s=i;exports.Render=o,exports.RenderSystem=s;
|
|
@@ -6,13 +6,84 @@ import { Renderer } from '@eva/plugin-renderer';
|
|
|
6
6
|
import { RendererManager } from '@eva/plugin-renderer';
|
|
7
7
|
import { RendererSystem } from '@eva/plugin-renderer';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* 渲染属性组件
|
|
11
|
+
*
|
|
12
|
+
* Render 组件控制游戏对象的渲染相关属性,如可见性、透明度、层级等。
|
|
13
|
+
* 这些属性影响对象的显示效果和渲染顺序,
|
|
14
|
+
* 适用于需要控制显示状态、淡入淡出、层级排序等场景。
|
|
15
|
+
*
|
|
16
|
+
* 主要属性:
|
|
17
|
+
* - visible - 控制对象是否可见
|
|
18
|
+
* - alpha - 控制对象透明度(0-1)
|
|
19
|
+
* - zIndex - 控制对象渲染层级
|
|
20
|
+
* - sortableChildren - 是否对子对象按 zIndex 排序
|
|
21
|
+
* - resolution - 渲染分辨率,值越大越清晰但性能消耗越大
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // 创建带渲染属性的对象
|
|
26
|
+
* const sprite = new GameObject('sprite');
|
|
27
|
+
* sprite.addComponent(new Img({ resource: 'player' }));
|
|
28
|
+
* sprite.addComponent(new Render({
|
|
29
|
+
* visible: true,
|
|
30
|
+
* alpha: 1,
|
|
31
|
+
* zIndex: 10
|
|
32
|
+
* }));
|
|
33
|
+
*
|
|
34
|
+
* // 控制可见性
|
|
35
|
+
* const render = sprite.getComponent('Render');
|
|
36
|
+
* render.visible = false; // 隐藏对象
|
|
37
|
+
*
|
|
38
|
+
* // 淡入淡出效果
|
|
39
|
+
* let alpha = 1;
|
|
40
|
+
* setInterval(() => {
|
|
41
|
+
* alpha -= 0.01;
|
|
42
|
+
* if (alpha <= 0) alpha = 1;
|
|
43
|
+
* render.alpha = alpha;
|
|
44
|
+
* }, 16);
|
|
45
|
+
*
|
|
46
|
+
* // 设置渲染层级
|
|
47
|
+
* render.zIndex = 100; // 越大越靠前
|
|
48
|
+
*
|
|
49
|
+
* // 启用子对象排序
|
|
50
|
+
* const container = new GameObject('container');
|
|
51
|
+
* container.addComponent(new Render({
|
|
52
|
+
* sortableChildren: true // 子对象将按 zIndex 排序
|
|
53
|
+
* }));
|
|
54
|
+
*
|
|
55
|
+
* // 设置渲染分辨率
|
|
56
|
+
* const text = new GameObject('text');
|
|
57
|
+
* text.addComponent(new Text({ text: 'High Resolution' }));
|
|
58
|
+
* text.addComponent(new Render({
|
|
59
|
+
* resolution: 2 // 2倍分辨率,使渲染更清晰
|
|
60
|
+
* }));
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
9
63
|
export declare class Render extends Component<RenderParams> {
|
|
64
|
+
/** 组件名称 */
|
|
10
65
|
static componentName: string;
|
|
66
|
+
/** 排序脏标记 */
|
|
11
67
|
sortDirty: boolean;
|
|
68
|
+
/** 是否可见 */
|
|
12
69
|
visible: boolean;
|
|
70
|
+
/** 透明度(0-1,0 为完全透明,1 为完全不透明) */
|
|
13
71
|
alpha: number;
|
|
72
|
+
/** 渲染层级(数值越大越靠前) */
|
|
14
73
|
zIndex: number;
|
|
74
|
+
/** 是否对子对象按 zIndex 排序 */
|
|
15
75
|
sortableChildren: boolean;
|
|
76
|
+
/** 渲染分辨率(值越大越清晰但性能消耗越大,默认为 1) */
|
|
77
|
+
resolution: number;
|
|
78
|
+
/**
|
|
79
|
+
* 初始化组件
|
|
80
|
+
* @param obj - 初始化参数
|
|
81
|
+
* @param obj.visible - 是否可见
|
|
82
|
+
* @param obj.alpha - 透明度
|
|
83
|
+
* @param obj.zIndex - 渲染层级
|
|
84
|
+
* @param obj.sortableChildren - 是否对子对象排序
|
|
85
|
+
* @param obj.resolution - 渲染分辨率
|
|
86
|
+
*/
|
|
16
87
|
init(obj?: RenderParams): void;
|
|
17
88
|
}
|
|
18
89
|
|
|
@@ -21,6 +92,7 @@ export declare interface RenderParams {
|
|
|
21
92
|
zIndex?: number;
|
|
22
93
|
visible?: boolean;
|
|
23
94
|
sortableChildren?: boolean;
|
|
95
|
+
resolution?: number;
|
|
24
96
|
}
|
|
25
97
|
|
|
26
98
|
export declare class RenderSystem extends Renderer {
|
|
@@ -36,6 +108,10 @@ export declare class RenderSystem extends Renderer {
|
|
|
36
108
|
change(changed: ComponentChanged): void;
|
|
37
109
|
remove(changed: ComponentChanged): void;
|
|
38
110
|
setDirty(changed: ComponentChanged): void;
|
|
111
|
+
/**
|
|
112
|
+
* 递归应用 resolution 到容器中所有支持该属性的子对象
|
|
113
|
+
*/
|
|
114
|
+
private applyResolution;
|
|
39
115
|
}
|
|
40
116
|
|
|
41
117
|
export { }
|
|
@@ -2,19 +2,19 @@ import { Component, OBSERVER_TYPE, decorators } from '@eva/eva.js';
|
|
|
2
2
|
import { type, step } from '@eva/inspector-decorator';
|
|
3
3
|
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
Copyright (c) Microsoft Corporation.
|
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
8
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
9
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
14
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
18
|
***************************************************************************** */
|
|
19
19
|
|
|
20
20
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -22,21 +22,97 @@ function __decorate(decorators, target, key, desc) {
|
|
|
22
22
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
23
23
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
24
24
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
+
var e = new Error(message);
|
|
29
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
+
};
|
|
26
31
|
|
|
32
|
+
/**
|
|
33
|
+
* 渲染属性组件
|
|
34
|
+
*
|
|
35
|
+
* Render 组件控制游戏对象的渲染相关属性,如可见性、透明度、层级等。
|
|
36
|
+
* 这些属性影响对象的显示效果和渲染顺序,
|
|
37
|
+
* 适用于需要控制显示状态、淡入淡出、层级排序等场景。
|
|
38
|
+
*
|
|
39
|
+
* 主要属性:
|
|
40
|
+
* - visible - 控制对象是否可见
|
|
41
|
+
* - alpha - 控制对象透明度(0-1)
|
|
42
|
+
* - zIndex - 控制对象渲染层级
|
|
43
|
+
* - sortableChildren - 是否对子对象按 zIndex 排序
|
|
44
|
+
* - resolution - 渲染分辨率,值越大越清晰但性能消耗越大
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // 创建带渲染属性的对象
|
|
49
|
+
* const sprite = new GameObject('sprite');
|
|
50
|
+
* sprite.addComponent(new Img({ resource: 'player' }));
|
|
51
|
+
* sprite.addComponent(new Render({
|
|
52
|
+
* visible: true,
|
|
53
|
+
* alpha: 1,
|
|
54
|
+
* zIndex: 10
|
|
55
|
+
* }));
|
|
56
|
+
*
|
|
57
|
+
* // 控制可见性
|
|
58
|
+
* const render = sprite.getComponent('Render');
|
|
59
|
+
* render.visible = false; // 隐藏对象
|
|
60
|
+
*
|
|
61
|
+
* // 淡入淡出效果
|
|
62
|
+
* let alpha = 1;
|
|
63
|
+
* setInterval(() => {
|
|
64
|
+
* alpha -= 0.01;
|
|
65
|
+
* if (alpha <= 0) alpha = 1;
|
|
66
|
+
* render.alpha = alpha;
|
|
67
|
+
* }, 16);
|
|
68
|
+
*
|
|
69
|
+
* // 设置渲染层级
|
|
70
|
+
* render.zIndex = 100; // 越大越靠前
|
|
71
|
+
*
|
|
72
|
+
* // 启用子对象排序
|
|
73
|
+
* const container = new GameObject('container');
|
|
74
|
+
* container.addComponent(new Render({
|
|
75
|
+
* sortableChildren: true // 子对象将按 zIndex 排序
|
|
76
|
+
* }));
|
|
77
|
+
*
|
|
78
|
+
* // 设置渲染分辨率
|
|
79
|
+
* const text = new GameObject('text');
|
|
80
|
+
* text.addComponent(new Text({ text: 'High Resolution' }));
|
|
81
|
+
* text.addComponent(new Render({
|
|
82
|
+
* resolution: 2 // 2倍分辨率,使渲染更清晰
|
|
83
|
+
* }));
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
27
86
|
class Render$2 extends Component {
|
|
28
87
|
constructor() {
|
|
29
88
|
super(...arguments);
|
|
89
|
+
/** 排序脏标记 */
|
|
30
90
|
this.sortDirty = false;
|
|
91
|
+
/** 是否可见 */
|
|
31
92
|
this.visible = true;
|
|
93
|
+
/** 透明度(0-1,0 为完全透明,1 为完全不透明) */
|
|
32
94
|
this.alpha = 1;
|
|
95
|
+
/** 渲染层级(数值越大越靠前) */
|
|
33
96
|
this.zIndex = 0;
|
|
97
|
+
/** 是否对子对象按 zIndex 排序 */
|
|
34
98
|
this.sortableChildren = false;
|
|
99
|
+
/** 渲染分辨率(值越大越清晰但性能消耗越大,默认为 1) */
|
|
100
|
+
this.resolution = 1;
|
|
35
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* 初始化组件
|
|
104
|
+
* @param obj - 初始化参数
|
|
105
|
+
* @param obj.visible - 是否可见
|
|
106
|
+
* @param obj.alpha - 透明度
|
|
107
|
+
* @param obj.zIndex - 渲染层级
|
|
108
|
+
* @param obj.sortableChildren - 是否对子对象排序
|
|
109
|
+
* @param obj.resolution - 渲染分辨率
|
|
110
|
+
*/
|
|
36
111
|
init(obj) {
|
|
37
112
|
obj && Object.assign(this, obj);
|
|
38
113
|
}
|
|
39
114
|
}
|
|
115
|
+
/** 组件名称 */
|
|
40
116
|
Render$2.componentName = 'Render';
|
|
41
117
|
__decorate([
|
|
42
118
|
type('boolean')
|
|
@@ -51,7 +127,11 @@ __decorate([
|
|
|
51
127
|
], Render$2.prototype, "zIndex", void 0);
|
|
52
128
|
__decorate([
|
|
53
129
|
type('boolean')
|
|
54
|
-
], Render$2.prototype, "sortableChildren", void 0);
|
|
130
|
+
], Render$2.prototype, "sortableChildren", void 0);
|
|
131
|
+
__decorate([
|
|
132
|
+
type('number'),
|
|
133
|
+
step(0.1)
|
|
134
|
+
], Render$2.prototype, "resolution", void 0);
|
|
55
135
|
|
|
56
136
|
let Render = class Render extends Renderer {
|
|
57
137
|
constructor() {
|
|
@@ -83,11 +163,27 @@ let Render = class Render extends Renderer {
|
|
|
83
163
|
add(changed) {
|
|
84
164
|
if (changed.component.name === 'Render') {
|
|
85
165
|
this.setDirty(changed);
|
|
166
|
+
// 初始化时应用 resolution
|
|
167
|
+
const component = changed.component;
|
|
168
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
169
|
+
if (component.resolution !== undefined && component.resolution > 0) {
|
|
170
|
+
this.applyResolution(container, component.resolution);
|
|
171
|
+
}
|
|
86
172
|
}
|
|
87
173
|
}
|
|
88
174
|
change(changed) {
|
|
89
|
-
if (changed.component.name === 'Render'
|
|
90
|
-
|
|
175
|
+
if (changed.component.name === 'Render') {
|
|
176
|
+
if (changed.prop.prop[0] === 'zIndex') {
|
|
177
|
+
this.setDirty(changed);
|
|
178
|
+
}
|
|
179
|
+
else if (changed.prop.prop[0] === 'resolution') {
|
|
180
|
+
// 当 resolution 改变时,重新应用到子对象
|
|
181
|
+
const component = changed.component;
|
|
182
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
183
|
+
if (component.resolution !== undefined && component.resolution > 0) {
|
|
184
|
+
this.applyResolution(container, component.resolution);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
91
187
|
}
|
|
92
188
|
}
|
|
93
189
|
remove(changed) {
|
|
@@ -102,11 +198,26 @@ let Render = class Render extends Renderer {
|
|
|
102
198
|
parentRender.sortDirty = true;
|
|
103
199
|
}
|
|
104
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* 递归应用 resolution 到容器中所有支持该属性的子对象
|
|
203
|
+
*/
|
|
204
|
+
applyResolution(container, resolution) {
|
|
205
|
+
if (!container)
|
|
206
|
+
return;
|
|
207
|
+
window.requestAnimationFrame(() => {
|
|
208
|
+
// 遍历容器的所有子对象
|
|
209
|
+
if (container.children && Array.isArray(container.children)) {
|
|
210
|
+
for (const child of container.children) {
|
|
211
|
+
child.resolution = resolution;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
105
216
|
};
|
|
106
217
|
Render.systemName = 'Render';
|
|
107
218
|
Render = __decorate([
|
|
108
219
|
decorators.componentObserver({
|
|
109
|
-
Render: ['zIndex'],
|
|
220
|
+
Render: ['zIndex', 'resolution'],
|
|
110
221
|
})
|
|
111
222
|
], Render);
|
|
112
223
|
var Render$1 = Render;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-render",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-beta.0",
|
|
4
4
|
"description": "@eva/plugin-renderer-render",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-render.esm.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@eva/inspector-decorator": "^0.0.5",
|
|
22
|
-
"@eva/plugin-renderer": "2.0.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.
|
|
24
|
-
"@eva/eva.js": "2.0.
|
|
25
|
-
"pixi.js": "^8.
|
|
22
|
+
"@eva/plugin-renderer": "2.0.2-beta.0",
|
|
23
|
+
"@eva/renderer-adapter": "2.0.2-beta.0",
|
|
24
|
+
"@eva/eva.js": "2.0.2-beta.0",
|
|
25
|
+
"pixi.js": "^8.17.0"
|
|
26
26
|
}
|
|
27
27
|
}
|