Laya中天空盒的操作

Laya版本:2.7.1
Unity版本:2018.4.4f1

1.普通的材质球天空

普通的材质球天空在Unity窗口设置的Rendering设置中,调整Linghting Settings中Scene下的Skybox Material的材质球,并用LayaAir3D导出场景即可自动使用。
在这里插入图片描述
对应材质球的属性:
在这里插入图片描述

2. 六面天空盒的加载

1. 直接在代码中创建

为了方便小游戏的打包,Skybox的资源我放在res下面新建skyBox的文件夹中。同时用Visual Studio Code创建lmat文件和ltc文件。

在这里插入图片描述
lmat文件代码如下:

{
    
    
	"version":"LAYAMATERIAL:02",
	"props":{
    
    
        "type":"Laya.SkyBoxMaterial",
        "exposure":1,
        "rotation":0,
        "vectors":[
            {
    
    
                "name":"tintColor",
                "value":[
                    0.5,
                    0.5,
                    0.5,
                    0.5
                ]
            }
        ],
        "textures":[
            {
    
    
                "name":"textureCube",
                "path":"Skybox.ltc"
            }
        ]
 
    }
}

textures下的path是ltc文件的路径
ltc文件为天空盒6个面对应的图片地址:

{
    
    
    "front": "skyBox/skybox_front.jpg",
    "back": "skyBox/skybox_back.jpg",
    "left": "skyBox/skybox_left.jpg",
    "right": "skyBox/skybox_right.jpg",
    "up": "skyBox/sskybox_up.jpg",
    "down": "skyBox/skybox_down.jpg",
    "size":1024
}

6面天空盒的加载:

    loadSkyBox(){
    
    
        Laya.Material.load("res/skyBox.lmat", Laya.Handler.create(this, this.onLoadedSky));
    }

    private exposureNumber = 0;
    onLoadedSky(mat : Laya.SkyBoxMaterial){
    
    
        // console.log("onLoadedSky:", mat);
        // Laya.timer.frameLoop(1, this, ()=>{
    
    
        //     // 调节曝光度,黑->白循环
        //     mat.exposure = Math.sin(this.exposureNumber += 0.01) + 1;
        //     // 旋转天空盒的材质
        //     mat.rotation += 0.1;
        // })
        var skyRenderer : Laya.SkyRenderer = this.mianScene.skyRenderer;
        // 创建SkyBox
        skyRenderer.mesh     = Laya.SkyBox.instance;
        skyRenderer.material = mat;        
    }

2. 在Unity中创建

1. 导入LayaAir3D后。在Unity资源文件夹新建存放SkyBox的文件夹。右键文件夹:Create->Legacy->CubeMap,创建一个新的CubeMap。
2. 点击新创建的CubeMap,在Inspector中添加6面的贴图。

请添加图片描述

Face size用于调整球体面数。面数越多越清晰。
注意 Readable必须勾选,否则无法导出。
3. 右键天空盒文件夹,Create->Material新建一个材质球,打开Inspector,现将Shader切换为LayaAir3D/Sky/CubeMap。再将新建好的CubeMap拖到材质球的Cubemap(HDR)中。
4. 在这里插入图片描述
5. 打开Unity的Window->Rendering->Lighting settings,将做好的天空盒材质球拖到Skybox Material中。Source修改为Skybox。然后直接导出场景即可。 在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/the_vnas/article/details/118226230