当前位置:网站首页>关于Unity,Laya学习,第一步加载Unity加载场景
关于Unity,Laya学习,第一步加载Unity加载场景
2022-08-03 08:08:00 【charlsdm】
大家都知道Unity和Laya结合在一起可以做网页甚至可以做H5端的游戏,下边附上Laya加载Unity场景的代码
import CameraFollow from "./CameraFollow";
export default class GameLoad extends Laya.Script {
// 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
constructor() {
super();
Laya.init(1920,1080,Laya.WebGL);
}
public CameraObj:Laya.MeshSprite3D;
public characterObj:Laya.MeshSprite3D;
onAwake():void
{
this.LoadU3DScene();
}
private LoadU3DScene():void
{
let MainString:string="D:/Users/Administrator/Documents/CCT/bin/res/Scene/LayaScene_Lobby/Conventional/Lobby.ls";
let SubString:string="res";
let Scenepath:string=MainString.substring(this.Index(MainString,SubString)-1);
Laya.Scene3D.load(Scenepath,Laya.Handler.create(this,this.OnComplete));
}
private OnComplete(scene:Laya.Scene3D):void
{
Laya.stage.addChild(scene);
this.InitMySceneAllThing(scene);
}
private InitMySceneAllThing(scene:Laya.Scene3D):void
{
this.CameraObj=scene.getChildAt(0) as Laya.MeshSprite3D;
console.log("CameraObjName:"+this.CameraObj.name);
this.characterObj=scene.getChildAt(3) as Laya.MeshSprite3D;
console.log("CharacterObjName:"+this.characterObj.name);
var mainCam=scene.getChildByName("Main Camera") as Laya.Camera;
let CameraFollowScript:CameraFollow=this.CameraObj.addComponent(CameraFollow) as CameraFollow;
CameraFollowScript.InitMySelfGameObj(scene,mainCam);
}
private Index(MainString:string,SubString:string):number
{
if(MainString==null||SubString==null)
{
return -1;
}
let MainStringLength:number=MainString.length;
let SubStringLength:number=SubString.length;
console.log("MainStringLength:"+MainStringLength);
console.log("SubStringLength:"+SubStringLength);
let pos=-1;
let prepos=pos;
let i=0;
let j=0;
while(i<MainStringLength&&j<SubStringLength)
{
if(MainString[i]==SubString[j])
{
++i;
++j;
}
else
{
i=i-j+1;
j=0;
}
}
if(j==SubStringLength)
{
prepos=pos;
pos=i-j;
}
return pos+1;
}
}
边栏推荐
猜你喜欢
Logic Pro X自带音色库列表
学习笔记:机器学习之逻辑回归
使用pipreqs导出项目所需的requirements.txt(而非整个环境)
Using pipreqs export requirements needed for the project. TXT (rather than the whole environment)
Charles packet capture tool learning record
mysql备份时的快照原理
mysql服务器上的mysql这个实例中表的介绍
AI mid-stage sequence labeling task: three data set construction process records
redis AOF持久化个人理解
Evaluate: A detailed introduction to the introduction of huggingface evaluation indicator module
随机推荐
审批流设计
pyspark @udf loop using variable problem
行业洞察 | 如何更好的实现与虚拟人的互动体验?
Mysql如何对两张表的相同字段,同时查询两张数据表
wordpress: 裁剪您的图片时发生错误
工控机防勒索病毒浅析
进程信息
Eject stubborn hard drives with diskpart's offline command
Guava的Service
mysql系统变量与状态变量
RViz报错: Error subscribing: Unable to load plugin for transport ‘compressed‘解决方法
001-进程与线程
vim 折叠函数
品牌方发行NFT时,应如何考量实用性?
LeetCode 每日一题——622. 设计循环队列
差分(前缀和的逆运算)
PowerShell:执行 Install-Module 时,不能从 URI 下载
Using pipreqs export requirements needed for the project. TXT (rather than the whole environment)
WPS EXCEL 筛选指定长度的文本 内容 字符串
pyspark df secondary sorting