mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
cache camera priority in event listener (#8216)
* Revert "cache first render camera (#8215)"
This reverts commit 4cdb7043c9.
* cut down touch move callback
* cache camera priority in event listener
* Revert "cut down touch move callback"
This reverts commit 19da61e3f16c3d1c14c1e8111b0da98b4997dea4.
* fix esLint
This commit is contained in:
@@ -30,7 +30,6 @@
|
||||
|
||||
import { ccclass, help, executeInEditMode, executionOrder, menu, tooltip, displayOrder, serializable, disallowMultiple } from 'cc.decorator';
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { Camera } from 'cocos/core/renderer/scene';
|
||||
import { Component } from '../../core/components';
|
||||
import { SystemEventType } from '../../core/platform/event-manager/event-enum';
|
||||
import { EventListener } from '../../core/platform/event-manager/event-listener';
|
||||
@@ -62,7 +61,6 @@ const _rect = new Rect();
|
||||
@disallowMultiple
|
||||
@executeInEditMode
|
||||
export class UITransform extends Component {
|
||||
private _camera: Camera|null = null;
|
||||
/**
|
||||
* @en
|
||||
* Size of the UI node.
|
||||
@@ -222,24 +220,14 @@ export class UITransform extends Component {
|
||||
@serializable
|
||||
protected _priority = 0;
|
||||
|
||||
private _updateCamera (force = false) {
|
||||
if (!this._camera || force) {
|
||||
this._camera = director.root!.batcher2D.getFirstRenderCamera(this.node);
|
||||
}
|
||||
}
|
||||
|
||||
private _removeCamera () {
|
||||
this._camera = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get the visibility bit-mask of the rendering camera
|
||||
* @zh 查找被渲染相机的可见性掩码。
|
||||
* @deprecated since v3.0
|
||||
*/
|
||||
get visibility () {
|
||||
this._updateCamera();
|
||||
return this._camera ? this._camera.visibility : 0;
|
||||
const camera = director.root!.batcher2D.getFirstRenderCamera(this.node);
|
||||
return camera ? camera.visibility : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,8 +235,8 @@ export class UITransform extends Component {
|
||||
* @zh 查找被渲染相机的渲染优先级。
|
||||
*/
|
||||
get cameraPriority () {
|
||||
this._updateCamera();
|
||||
return this._camera ? this._camera.priority : 0;
|
||||
const camera = director.root!.batcher2D.getFirstRenderCamera(this.node);
|
||||
return camera ? camera.priority : 0;
|
||||
}
|
||||
|
||||
public static EventType = SystemEventType;
|
||||
@@ -269,13 +257,10 @@ export class UITransform extends Component {
|
||||
if (changed) {
|
||||
this.node.parent!._updateSiblingIndex();
|
||||
}
|
||||
|
||||
this._updateCamera();
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
this.node.off(SystemEventType.PARENT_CHANGED, this._parentChanged, this);
|
||||
this._removeCamera();
|
||||
}
|
||||
|
||||
public onDestroy () {
|
||||
|
||||
@@ -55,6 +55,11 @@ export interface IListenerMask {
|
||||
* 注意:这是一个抽象类,开发者不应该直接实例化这个类,请参考 [[create]] 。
|
||||
*/
|
||||
export class EventListener {
|
||||
/**
|
||||
* to cache camera priority
|
||||
* @internal
|
||||
*/
|
||||
public _cameraPriority = 0;
|
||||
/**
|
||||
* @en The type code of unknown event listener.<br/>
|
||||
* @zh 未知的事件监听器类型
|
||||
|
||||
@@ -759,7 +759,13 @@ class EventManager {
|
||||
}
|
||||
|
||||
// After sort: priority < 0, > 0
|
||||
listeners.getSceneGraphPriorityListeners().sort(this._sortEventListenersOfSceneGraphPriorityDes);
|
||||
const eventListeners = listeners.getSceneGraphPriorityListeners();
|
||||
eventListeners.forEach((listener) => {
|
||||
const node: any = listener._getSceneGraphPriority();
|
||||
const trans = node._uiProps.uiTransformComp;
|
||||
listener._cameraPriority = trans.cameraPriority;
|
||||
});
|
||||
eventListeners.sort(this._sortEventListenersOfSceneGraphPriorityDes);
|
||||
}
|
||||
|
||||
private _sortEventListenersOfSceneGraphPriorityDes (l1: EventListener, l2: EventListener) {
|
||||
@@ -773,10 +779,8 @@ class EventManager {
|
||||
}
|
||||
|
||||
let p1 = node1; let p2 = node2; let ex = false;
|
||||
const trans1 = node1._uiProps.uiTransformComp;
|
||||
const trans2 = node2._uiProps.uiTransformComp;
|
||||
if (trans1.cameraPriority !== trans2.cameraPriority) {
|
||||
return trans2.cameraPriority - trans1.cameraPriority;
|
||||
if (l1._cameraPriority !== l2._cameraPriority) {
|
||||
return l2._cameraPriority - l1._cameraPriority;
|
||||
}
|
||||
while (p1.parent._id !== p2.parent._id) {
|
||||
p1 = p1.parent.parent === null ? (ex = true) && node2 : p1.parent;
|
||||
|
||||
Reference in New Issue
Block a user