当前位置:网站首页>关于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;
}
}
边栏推荐
- ArcEngine (5) use the ICommand interface to achieve zoom in and zoom out
- AI mid-stage sequence labeling task: three data set construction process records
- Evaluate: A detailed introduction to the introduction of huggingface evaluation indicator module
- sqlserver2019安装失败
- pyspark @udf loop using variable problem
- Poke the myth of Web3?Poke the iron plate.
- 《剑指Offer》刷题之打印从1到最大的n位数
- 分析型数据库性能测试总结
- PowerShell:执行 Install-Module 时,不能从 URI 下载
- 如何在安装GBase 8c数据库的时候,报错显示“Host ips belong to different cluster?
猜你喜欢
随机推荐
sqlite date field plus one day
requests库
word之个人设置
ArcEngine (3) zoom in and zoom out through the MapControl control to achieve full-image roaming
MySQL数据库————数据库与vs的连接
redis键值出现 xacxedx00x05tx00&的解决方法
Taro框架-微信小程序-内嵌h5页面
并发之ReentrantLock
基于SSM开发的的小区物业管理系统小程序源码
【TPC-DS】25张表的详细介绍,SQL的查询特征
AI mid-stage sequence labeling task: three data set construction process records
FusionAccess软件架构、FusionAccess必须配置的四个组件、桌面发放流程、虚拟机组类型、桌面组类型
解决移动端有纵向滚动条但是不能滚动的问题
ArcEngine(五)用ICommand接口实现放大缩小
mysql5.7服务器The innodb_system data file 'ibdata1' must be writable导致无法启动服务器
PowerShell:执行 Install-Module 时,不能从 URI 下载
审批流设计
netstat 及 ifconfig 是如何工作的。
“唯一索引允许为空“ 的说法是不严谨的
ArcEngine (4) Use of MapControl_OnMouseDown








