一: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中添加好所有的动画状态;
在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)
);
}
}
}
实际就是改变物体的坐标;
总结
加油!努力!
就回来吧~~~回来吧~~~~有人~在等你啊!!!!
有人~在~等你~说完~那句~说一半的话~~~~
就别走了~~~留下吧~~~~外面~它太复杂~~~~