Laya3D基础和物体移动到某一点

一:Laya运用:

1:普通加载资源:

let resource = [
            "文件地址1",
            "文件地址2"
        ];
Laya.loader.create(resource, Laya.Handler.create(this, this.onPreLoadFinish));
onPreLoadFinish(){
。。。=Laya.loader.getRes("文件地址1");
。。。=Laya.loader.getRes("文件地址2");
}

然后场景添加在舞台上,3D物体添加在场景上;

2:动画的播放:

在unity中添加好所有的动画状态;
unity中添加动画状态
在Laya中重复添加动画状态会报错;
加载对应的资源之后:

。。。 = this.物体.getComponent(Laya.Animator);
。。。.play("idle");

就能实现播放动画。

3:实现unity中的moveto方法的效果:

export default class Sprite3DMoveContorller {
    static frompostion: Laya.Vector3;
    static topostion: Laya.Vector3;
    static moveDistance: Laya.Vector3;
    static moveObjcet: Laya.Sprite3D;
    static moveTime: number = 0;
    static moveValue: number = 0.01;
    static callback: Function;
    static obj: any;

    /**
     * Sprite3D移动方法
     * @param gameObject 需要移动的3D对象
     * @param toPos 移动目标点
     * @param playTime 移动总耗时
     * @param easeFun 缓动函数 (Laya.Ease) 默认为线性移动
     * @param obj 回调域
     * @param callback 回调函数 
     */
    public static onPositionMoveTo(gameObject: Laya.Sprite3D, toPos: Laya.Vector3, playValue: number, easeFun: Function, obj: any = null, callback: Function = null) {
        this.moveDistance = new Laya.Vector3(toPos.x - gameObject.transform.position.x, toPos.y - gameObject.transform.position.y, toPos.z - gameObject.transform.position.z);
        this.frompostion = gameObject.transform.position;
        this.topostion = toPos;
        this.moveObjcet = gameObject;
        this.moveValue = playValue;
        this.callback = callback;
        this.obj = obj;
        this.startMove();
    }

    private static startMove() {
        Laya.timer.frameLoop(1, this, this.moveUpdate);
    }

    private static endMove(handler: Laya.Handler) {
        Laya.timer.clear(this, this.moveUpdate);
        //this.moveObjcet.transform.position = this.topostion;
        console.log(handler);
        if (handler != null) {
            handler.run();
        }
    }

    private static moveUpdate() {
        let a = Laya.Vector3.distance(this.moveObjcet.transform.position, this.topostion);
        if (a < 0.1) {
            this.endMove(Laya.Handler.create(this.obj, this.callback));
        } else {
            this.moveObjcet.transform.position = new Laya.Vector3(
                this.frompostion.x + (this.moveDistance.x * this.moveValue),
                this.frompostion.y + (this.moveDistance.y * this.moveValue),
                this.frompostion.z + (this.moveDistance.z * this.moveValue)
            );
        }
    }
}

实际就是改变物体的坐标;

总结

加油!努力!

就回来吧~~~回来吧~~~~有人~在等你啊!!!!
有人~在~等你~说完~那句~说一半的话~~~~
就别走了~~~留下吧~~~~外面~它太复杂~~~~
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值