@richlox/core v0.22.1
@richlox/core
Richlox Engine 核心库
安装
npm install @richlox/coreor
yarn add @richlox/core使用说明
- Actor - Component- Actor - 场景内最小单位
- Component - 挂载在 Actor 上的功能组件
 
    import { AActor, CSphere } from '@richlox/core';
    /**
     * 继承 Actor
     */
    export class ACustomActor extends AActor {
        /**
         * 异步初始化方法
         * 创建 Component,初始化 Actor
         * 注册输入事件
         * 开启或关闭 tick (默认开启)
         */
        async initialize(): Promise<void> {
            await super.initialize();
            // 创建球体组件
            this.createComponent(CSphere);
            // 不执行 tick
            this.tickable = false;
            // 为 Actor 注册输入事件,注册后才能接收输入
            this.registerInput();
            // your code here
            // this.position =
            // this.rotation =
            // this.scale =
        }
        /**
         * Actor 添加到场景中以后执行
         */
        async beginPlay(): Promise<void> {
            await super.beginPlay();
            // your code here
        }
        /**
         * 每帧执行
         */
        tick(deltaTime: number): void {
            super.tick(deltaTime);
            // your code here
        }
        /**
         * Actor 销毁后执行
         */
        endPlay(reason: EDisposeReason): void {
            super.endPlay(reason);
        }
        /**
         * 输入事件
         * onMouseClick(event: MouseEvent): void;
         * onMouseDoubleClick(event: MouseEvent): void;
         * onMouseMouseWheel(event: WheelEvent): void;
         * onKeyDown(event: KeyboardEvent): void;
         * onKeyPress(event: KeyboardEvent): void;
         * onKeyUp(event: KeyboardEvent): void;
         */
    }    import { CComponent } from '@richlox/core';
    /**
     * 继承 Component
     **/
    export class CCustomComponent extends CComponent {
        /**
         * 生命周期
         * async beforeInitialize(): Promise<void>;
         * async initialize(): Promise<void>;
         * async afterInitialize(): Promise<void>;
         * async beginPlay(): Promise<void>;
         * tick(deltaTime: number): void;
         * endPlay(reason: EDisposeReason): void;
         **/
        /**
         * 输入事件
         * onMouseClick(event: MouseEvent): void;
         * onMouseDoubleClick(event: MouseEvent): void;
         * onMouseMouseWheel(event: WheelEvent): void;
         * onKeyDown(event: KeyboardEvent): void;
         * onKeyPress(event: KeyboardEvent): void;
         * onKeyUp(event: KeyboardEvent): void;
         */
        async beginPlay(): Promise<void> {
            await super.beginPlay();
            // your code here
        }
    }    import { CComponent, editable, expose } from '@richlox/core';
    /**
     * 创建一个让其所挂载 Actor 不停旋转的 component
     **/
    @expose('Rotation')
    export class CRotationComponent extends CComponent {
        @editable(Number) speed: number = 1;
        tick(deltaSecond: number): void {
            super.tick(deltaSecond);
            this.owner.rotation.x += this.speed * 0.01;
            this.owner.rotation.y += this.speed * 0.01;
            this.owner.rotation.z += this.speed * 0.01;
        }
    }- GWorld - 游戏世界
    /**
     * GWorld 中的接口方法
     **/
    /**
     * 在当前激活场景中生成 Actor
     *
     * @template T Actor 子类类型
     * @param {IInitializer<T>} c Actor 构造器
     * @param {...ConstructorParameters<IInitializer<T>>} constructorArgs 构造参数
     * @returns {Promise<InstanceType<IInitializer<T>>>} Actor
     * @memberof IWorld
     */
    spawnActor<T extends AActor>(
        c: IInitializer<T>,
        ...constructorArgs: ConstructorParameters<IInitializer<T>>
    ): Promise<InstanceType<IInitializer<T>>>;
    /**
     * 查找场景中符合特定类型所有 Actor
     *
     * @template T Actor 子类类型
     * @param {IInitializer<T>} c Actor 子类构造器
     * @param {Array<InstanceType<IInitializer<T>>>} actors 结果
     * @memberof RLScene
     */
    findActorsByClass<T extends AActor>(
        c: IInitializer<T>,
        actors: Array<InstanceType<IInitializer<T>>>
    ): void;
    /**
     * 射线检测,返回第一个结果
     *
     * @param {FVector3} start 起点
     * @param {FVector3} direction 方向
     * @returns {(IHitResult | undefined)} 第一个检测结果
     * @memberof IWorld
     */
    lineTrace(start: FVector3, direction: FVector3): IHitResult | undefined;
    /**
     * 射线检测,返回所有结果
     *
     * @param {FVector3} start 起点
     * @param {FVector3} direction 方向
     * @returns {IHitResult[]} 所有检测结果
     * @memberof IWorld
     */
    multiLineTrace(start: FVector3, direction: FVector3): IHitResult[];
    /**
     * 鼠标位置的射线检测,返回第一个结果
     *
     * @param {Camera} camera 当前摄像机
     * @param {FVector2} mousePosition 鼠标位置
     * @returns {(IHitResult | undefined)} 第一个检测结果
     * @memberof IWorld
     */
    mouseLineTrace(camera: Camera, mousePosition: FVector2): IHitResult | undefined;
    /**
     * 鼠标位置的射线检测,返回所有结果
     *
     * @param {Camera} camera 当前摄像机
     * @param {FVector2} mousePosition 鼠标位置
     * @returns {IHitResult[]} 所有检测结果
     * @memberof IWorld
     */
    multiMouseLineTrace(camera: Camera, mousePosition: FVector2): IHitResult[];
    /**
     * 获取鼠标在当前 canvas 中的位置
     *
     * @param {MouseEvent} event
     * @returns {FVector2}
     * @memberof IWorld
     */
    getMousePosition(event: MouseEvent): FVector2;    import { GWorld } from '@richlox/core';
    /**
     * 动态创建 Actor
     * 在 beginPaly 或 beginPaly 以后可以动态创建新 Actor
     */
    const customActor = await GWorld.spawnActor(ACustomActor);- 路径 - /Game - 项目目录下的 contents 目录
- /Script - 项目目录下的 source 目录
- /###{plugin name} - 插件目录(/###myPlugin,插件myPlugin的所在目录)
- /###{plugin name}/Game - 插件目录下的 contents 目录
- /###{plugin name}/Script - 插件目录下的 source 目录
- 类路径- /Script/actor/custom-actor.ts#?class=ACustomActor
 
 
- 加载资源 
    import { FContext, FLoader } from '@richlox/core';
    /**
     * 加载器
     * RLTexture            贴图
     * RLSpriteMaterial     材质
     * RLStandardMaterial   材质
     * RLGeometry           几何体
     * RLStaticMesh         静态网格
     * RLSkeletonMesh       骨骼网格
     * RLAnimationAsset     动画
     * RLAudio              音频
     * RLClass              类
     */
    const loader = FContext.get(FLoader);
    /**
     * 加载贴图
     * 加载 contents/textures 目录下的 myTexture.rltex
     */
    const texture = await loader.loadObject<RLTexture>('/Game/textures/myTexture.tex.rltex');
    /**
     * 加载材质
     * 加载 contents/materials 目录下的 myMaterial.rlmat
     */
    const material = await loader.loadObject<RLMaterial>('/Game/materials/myMaterial.mat.rlmat');
    /**
     * 加载类
     * 加载 source/actor/custom-actor.ts 里导出的 ACustomActor
     */
    const customActorClass = await loader.loadObject<RLClass<AActor>>('/Script/actor/custom-actor.ts#?class=ACustomActor');
    /**
     * 动态生成 actor
     */
    const customActor = await GWorld.spawnActor(customActorClass.ctor);5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago