切换天空盒
第一步先把SKY 天空球资源导入到工程里,
第二步:天空球文件下的SKY预制件拖入到场景里
第三步 选着SKY材质球,拖入自己的全景图片(图片分辨率不能超过5000*5000,否则手机无法显示)
如果并没有效果,看看图片的设置
还没有效果的话,重新烘焙场景,这样就能正常显示了
const { regClass, property } = Laya;
import MeshRenderer = Laya.MeshRenderer;
import Material = Laya.Material;
@regClass()
export class Script extends Laya.Script {//declare owner : Laya.Sprite3D;//declare owner : Laya.Sprite;public scene3D: Laya.Scene3D;@property({ type: Laya.Button })public button: Laya.Button;switch: boolean = false;sky: MeshRenderer;public onStart() {console.log("Script Start");this.scene3D = Laya.stage.getChildAt(0) as Laya.Scene3Dlet sky = this.scene3D.getChildByName("SKY");if (sky) {this.sky = sky.getChildAt(0).getComponent(MeshRenderer)}else {console.log("没有找到SKY");}this.button.on(Laya.Event.CLICK, this, () => {this.switch = !this.switch;this.SwitchSkyBoxMaterial(this.switch ? "resources/1.lmat" : "resources/2.lmat", () => { });});}public SwitchSkyBoxMaterial(skyBoxPath: string, action: () => void) {//程序化天空盒Laya.loader.load(skyBoxPath).then((mat: Material) => {this.sky.material = mat;action?.();});}
}