Last active
December 10, 2016 08:54
-
-
Save tsubaki/43e02c621cd933a4e2087327cdbb6660 to your computer and use it in GitHub Desktop.
Skyboxの更新
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
public class UpdateSkybox : MonoBehaviour { | |
[SerializeField] Cubemap[] cubemaps; // 複数のIBL画像 | |
IEnumerator Start () | |
{ | |
int skyboxID = Shader.PropertyToID("_Tex"); | |
// cubemapを作成しSkyboxに登録し、 | |
// 反射モードをcustomに入り替え | |
var cubemapMaterial = new Material(Shader.Find("Skybox/Cubemap")); | |
RenderSettings.skybox = cubemapMaterial; | |
RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom; | |
// 2秒ごとにSkyboxを更新 | |
for(int i=0; ; i++) | |
{ | |
if (i >= cubemaps.Length) { i = 0; } | |
// テクスチャとCubemapを更新 | |
cubemapMaterial.SetTexture(skyboxID, cubemaps[i]); | |
RenderSettings.customReflection = cubemaps[i]; | |
yield return new WaitForSeconds(2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment