0.33.0 • Published 4 years ago

@richlox/core v0.33.0

Weekly downloads
3
License
Apache License 2....
Repository
-
Last release
4 years ago

@richlox/core

Richlox Engine 核心库

安装

npm install @richlox/core

or

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);
0.33.0

4 years ago

0.32.3

4 years ago

0.32.2

4 years ago

0.32.1

4 years ago

0.32.0

4 years ago

0.31.0

4 years ago

0.30.5

4 years ago

0.30.2

4 years ago

0.30.1

4 years ago

0.30.0

4 years ago

0.28.0

4 years ago

0.27.0

4 years ago

0.26.0

4 years ago

0.25.0

4 years ago

0.24.0

4 years ago

0.23.2

4 years ago

0.23.0

4 years ago

0.22.6

4 years ago

0.22.5

4 years ago

0.22.4

4 years ago

0.22.3

4 years ago

0.22.2

4 years ago

0.22.1

4 years ago

0.22.0

4 years ago

0.21.10

4 years ago

0.21.9

4 years ago

0.21.8

4 years ago

0.21.6

4 years ago

0.21.5

4 years ago

0.20.59

4 years ago

0.20.57

4 years ago

0.20.58

4 years ago

0.20.56

4 years ago

0.20.55

4 years ago

0.20.54

4 years ago

0.20.53

4 years ago

0.20.52

4 years ago

0.20.51

4 years ago

0.20.50

4 years ago

0.20.33

4 years ago

0.20.32

4 years ago

0.20.31

4 years ago

0.20.30

4 years ago

0.20.29

4 years ago

0.20.27

4 years ago

0.20.26

4 years ago

0.20.25

4 years ago

0.20.24

4 years ago

0.20.23

4 years ago

0.20.22

4 years ago

0.20.20

4 years ago

0.20.21

4 years ago

0.20.19

4 years ago

0.20.17

4 years ago

0.20.18

4 years ago

0.20.16

4 years ago

0.20.15

4 years ago

0.20.14

4 years ago

0.20.13

4 years ago

0.20.12

4 years ago

0.20.11

4 years ago

0.20.10

4 years ago

0.20.9

4 years ago

0.20.8

4 years ago

0.20.7

4 years ago

0.20.5

4 years ago

0.20.3

4 years ago

0.20.1

4 years ago

0.20.0

4 years ago

0.15.5

4 years ago

0.15.4

4 years ago

0.15.3

4 years ago

0.15.2

4 years ago

0.15.1

4 years ago

0.15.0

4 years ago

0.3.20

4 years ago

0.3.24

4 years ago

0.3.23

4 years ago

0.3.21

4 years ago

0.3.19

4 years ago

0.3.17

4 years ago

0.3.18

4 years ago

0.3.16

4 years ago

0.3.15

4 years ago

0.3.14

4 years ago

0.3.13

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago