Fix the error that occurs when creating a component. (#38)

This commit is contained in:
qiuguohua
2025-10-29 11:23:10 +08:00
committed by GitHub
parent 6decfca50d
commit 06fd724d3a
4 changed files with 12 additions and 12 deletions
+2 -2
View File
@@ -23,7 +23,7 @@
*/
import { ccclass } from 'cc.decorator';
import { EDITOR } from 'internal:constants';
import { EDITOR, NODEJS } from 'internal:constants';
import { lerp, RealCurve, CCClass, geometry, Enum, approx, EPSILON } from '../../core';
import { PixelFormat, TextureFilter, WrapMode } from '../../asset/assets/asset-enum';
import { Texture2D, ImageAsset } from '../../asset/assets';
@@ -197,7 +197,7 @@ export default class CurveRange {
constructor () {
/* Only create RealCurves in Editor, in order to show the Splines in Editor,
in RunTime the RealCurves will only be created when it is in Curve mode*/
if (EDITOR) {
if (EDITOR || NODEJS) {
this.spline = geometry.constructLegacyCurveAndConvert();
this.splineMin = geometry.constructLegacyCurveAndConvert();
this.splineMax = geometry.constructLegacyCurveAndConvert();
+5 -5
View File
@@ -22,7 +22,7 @@
THE SOFTWARE.
*/
import { EDITOR, SUPPORT_JIT, DEV, TEST } from 'internal:constants';
import { EDITOR, SUPPORT_JIT, DEV, TEST, NODEJS } from 'internal:constants';
import { CCObjectFlags } from '../core/data/object';
import { js } from '../core';
import { tryCatchFunctor_EDITOR } from '../core/utils/misc';
@@ -36,9 +36,9 @@ const IsStartCalled = CCObjectFlags.IsStartCalled;
const IsOnEnableCalled = CCObjectFlags.IsOnEnableCalled;
const IsEditorOnEnableCalled = CCObjectFlags.IsEditorOnEnableCalled;
const callerFunctor: any = EDITOR && tryCatchFunctor_EDITOR;
const callOnEnableInTryCatch: any = EDITOR && callerFunctor('onEnable');
const callOnDisableInTryCatch: any = EDITOR && callerFunctor('onDisable');
const callerFunctor: any = (EDITOR || NODEJS) && tryCatchFunctor_EDITOR;
const callOnEnableInTryCatch: any = (EDITOR || NODEJS) && callerFunctor('onEnable');
const callOnDisableInTryCatch: any = (EDITOR || NODEJS) && callerFunctor('onDisable');
function sortedIndex (array, comp): number {
const order = comp.constructor._executionOrder;
@@ -550,7 +550,7 @@ export class ComponentScheduler {
}
}
if (EDITOR) {
if (EDITOR || NODEJS) {
ComponentScheduler.prototype.enableComp = function (comp, invoker): void {
// NOTE: _executeInEditMode is dynamically injected on Editor environment
if (legacyCC.GAME_VIEW || (comp.constructor as any)._executeInEditMode) {
+3 -3
View File
@@ -22,7 +22,7 @@
THE SOFTWARE.
*/
import { EDITOR, DEV, SUPPORT_JIT, DEBUG } from 'internal:constants';
import { EDITOR, DEV, SUPPORT_JIT, DEBUG, NODEJS } from 'internal:constants';
import { CCObjectFlags, isValid } from '../core/data/object';
import { array, Pool } from '../core/utils/js';
import { tryCatchFunctor_EDITOR } from '../core/utils/misc';
@@ -327,7 +327,7 @@ export default class NodeActivator {
}
}
if (EDITOR) {
if (EDITOR || NODEJS) {
const callPreloadInTryCatch = tryCatchFunctor_EDITOR('__preload');
const callOnLoadInTryCatch = function (c: Component): void {
try {
@@ -344,7 +344,7 @@ if (EDITOR) {
const _onLoadInEditor = (comp: Component): void => {
if (comp.internalOnLoad && !legacyCC.GAME_VIEW) {
const focused = Editor.Selection.getLastSelected('node') === comp.node.uuid;
const focused = !NODEJS && Editor.Selection.getLastSelected('node') === comp.node.uuid;
if (focused) {
if (comp.onFocusInEditor && callOnFocusInTryCatch) {
callOnFocusInTryCatch(comp);
+2 -2
View File
@@ -23,7 +23,7 @@
*/
import { ccclass, displayOrder, executeInEditMode, help, menu, slide, range, requireComponent, tooltip, type, serializable } from 'cc.decorator';
import { EDITOR_NOT_IN_PREVIEW } from 'internal:constants';
import { EDITOR_NOT_IN_PREVIEW, NODEJS } from 'internal:constants';
import { warn } from '../core/platform';
import { Component, EventHandler as ComponentEventHandler } from '../scene-graph';
import { UITransform } from '../2d/framework';
@@ -393,7 +393,7 @@ export class VideoPlayer extends Component {
}
public __preload (): void {
if (EDITOR_NOT_IN_PREVIEW) {
if (EDITOR_NOT_IN_PREVIEW || NODEJS) {
return;
}
this._impl = VideoPlayerImplManager.getImpl(this);