void UpdateAnimations() { if (cont.LoadState == Controller.State.Finished) { /*if(MapLoader.Loader.visualMaterials != null) { * for (int i = 0; i < MapLoader.Loader.visualMaterials.Count; i++) { * VisualMaterial vm = MapLoader.Loader.visualMaterials[i]; * if (vm.animTextures.Count > 0 && !vm.IsLockedAnimatedTexture) { * vm.currentAnimTexture %= vm.animTextures.Count; * vm.animTextures[vm.currentAnimTexture].currentTime += updateCounter * modifier; * while (vm.animTextures[vm.currentAnimTexture].currentTime > vm.animTextures[vm.currentAnimTexture].time) { * float rest = vm.animTextures[vm.currentAnimTexture].currentTime - vm.animTextures[vm.currentAnimTexture].time; * vm.animTextures[vm.currentAnimTexture].currentTime = 0; * if (vm.animTextures[vm.currentAnimTexture].time <= 0) break; * vm.currentAnimTexture = (vm.currentAnimTexture + 1) % vm.animTextures.Count; * vm.animTextures[vm.currentAnimTexture].currentTime = rest; * } * } * } * }*/ for (int i = 0; i < materials.Count; i++) { MultiTextureMaterial mtm = materials[i]; if (mtm != null) { if (mtm.visMat != null) { VisualMaterial vm = mtm.visMat; if (vm.animTextures.Count > 0 && !vm.IsLockedAnimatedTexture) { vm.currentAnimTexture %= vm.animTextures.Count; vm.animTextures[vm.currentAnimTexture].currentTime += updateCounter * modifier; float time = vm.animTextures[vm.currentAnimTexture].time; if (!UnitySettings.IsRaymapGame && time <= 0) { time = defaultTime; } while (vm.animTextures[vm.currentAnimTexture].currentTime > time) { time = vm.animTextures[vm.currentAnimTexture].time; if (!UnitySettings.IsRaymapGame && time <= 0) { time = defaultTime; } float rest = vm.animTextures[vm.currentAnimTexture].currentTime - time; vm.animTextures[vm.currentAnimTexture].currentTime = 0; if (time <= 0) { break; } vm.currentAnimTexture = (vm.currentAnimTexture + 1) % vm.animTextures.Count; vm.animTextures[vm.currentAnimTexture].currentTime = rest; } } } else if (mtm.visMatROM != null) { OpenSpace.ROM.VisualMaterial vm = mtm.visMatROM; if (vm.num_textures > 0) // && !vm.IsLockedAnimatedTexture) { { mtm.CurrentTextureROM %= vm.num_textures; mtm.CurrentTextureROMTime += updateCounter * modifier; float animTime = vm.textures.Value.vmTex[mtm.CurrentTextureROM].time / 30f; while (mtm.CurrentTextureROMTime > animTime) { float rest = mtm.CurrentTextureROMTime - animTime; //mtm.CurrentTextureROMTime = 0; if (animTime <= 0) { break; } mtm.CurrentTextureROM = (mtm.CurrentTextureROM + 1) % vm.num_textures; mtm.CurrentTextureROMTime = rest; animTime = vm.textures.Value.vmTex[mtm.CurrentTextureROM].time / 30f; } } } } } materials.RemoveAll(m => m == null || m.gameObject == null); } }
private void UpdateBackgroundROM() { // Update background color or material Color?backgroundColor = null; OpenSpace.ROM.VisualMaterial skyMaterial = null; OpenSpace.ROM.VisualMaterial[] skyMaterialsDD = null; SectorComponent activeBackgroundSector = null; OpenSpace.Loader.R2ROMLoader l = MapLoader.Loader as OpenSpace.Loader.R2ROMLoader; OpenSpace.ROM.LevelHeader lh = l.level; if (lh != null && lh.backgroundUpLeft != null && lh.backgroundUpLeft.Value != null && lh.backgroundUpRight != null && lh.backgroundUpRight.Value != null && lh.backgroundDownLeft != null && lh.backgroundDownLeft.Value != null && lh.backgroundDownRight != null && lh.backgroundDownRight.Value != null) { skyMaterial = null; skyMaterialsDD = new OpenSpace.ROM.VisualMaterial[4]; skyMaterialsDD[0] = lh.backgroundUpLeft.Value; skyMaterialsDD[1] = lh.backgroundUpRight.Value; skyMaterialsDD[2] = lh.backgroundDownLeft.Value; skyMaterialsDD[3] = lh.backgroundDownRight.Value; } else { if (sectorManager != null && sectorManager.sectors != null && sectorManager.sectors.Count > 0) { foreach (SectorComponent s in sectorManager.sectors) { if (!s.Loaded) { continue; } if (s.sectorROM == null) { continue; } if (s.sectorROM.background != null && s.sectorROM.background.Value != null && s.sectorROM.background.Value.num_textures > 0 && s.sectorROM.background.Value.textures.Value != null && s.sectorROM.background.Value.textures.Value.vmTex[0].texRef.Value != null && s.sectorROM.background.Value.textures.Value.vmTex[0].texRef.Value.texInfo.Value != null) { skyMaterial = s.sectorROM.background; //print(skyMaterial.Offset); activeBackgroundSector = s; break; } else { /*foreach (LightInfo li in s.sector.staticLights) { * if (li.type == 6) { * backgroundColor = li.background_color; * break; * } * }*/ } } } } if (!controller.viewCollision) { if (skyMaterial != null) { backgroundPanel.gameObject.SetActive(true); if (backgroundMaterialROM != skyMaterial) { backgroundMaterialROM = skyMaterial; Material skyboxMat = skyMaterial.GetMaterial(OpenSpace.ROM.VisualMaterial.Hint.None); /*Texture tex = skyboxMat.GetTexture("_Tex0"); * tex.filterMode = FilterMode.Point; * tex.wrapMode = TextureWrapMode.Clamp; * skyboxMat.SetTexture("_Tex0", tex);*/ backgroundPanel.sharedMaterial = skyboxMat; } //skyboxMat.SetFloat("_DisableLighting", 1f); backgroundPanel.sharedMaterial.SetFloat("_DisableLightingLocal", 1f); if (activeBackgroundSector != null) { if (activeBackgroundSector != previousActiveBackgroundSector) { //backgroundPanel.material.SetFloat("_DisableLightingLocal", 0f); sectorManager.ApplySectorLighting(activeBackgroundSector, backgroundPanel.gameObject, LightInfo.ObjectLightedFlag.Environment); previousActiveBackgroundSector = activeBackgroundSector; } } else { //backgroundPanel.material.SetFloat("_DisableLighting", 1f); } //RenderSettings.skybox = skyboxMat; //Camera.main.clearFlags = CameraClearFlags.Skybox; } else { backgroundPanel.gameObject.SetActive(false); } if (skyMaterialsDD != null) { for (int i = 0; i < 4; i++) { backgroundPanelsROM[i].gameObject.SetActive(true); } if (backgroundMaterialsDDROM == null) { backgroundMaterialsDDROM = skyMaterialsDD; for (int i = 0; i < 4; i++) { Material skyboxMat = skyMaterialsDD[i].GetMaterial(OpenSpace.ROM.VisualMaterial.Hint.None); backgroundPanelsROM[i].sharedMaterial = skyboxMat; backgroundPanelsROM[i].sharedMaterial.SetFloat("_DisableLightingLocal", 1f); } } if (activeBackgroundSector != null) { if (activeBackgroundSector != previousActiveBackgroundSector) { //backgroundPanel.material.SetFloat("_DisableLightingLocal", 0f); //sectorManager.ApplySectorLighting(activeBackgroundSector, backgroundPanel.gameObject, LightInfo.ObjectLightedFlag.Environment); previousActiveBackgroundSector = activeBackgroundSector; } } else { //backgroundPanel.material.SetFloat("_DisableLighting", 1f); } //RenderSettings.skybox = skyboxMat; //Camera.main.clearFlags = CameraClearFlags.Skybox; } else { for (int i = 0; i < 4; i++) { backgroundPanelsROM[i].gameObject.SetActive(false); } } } else { backgroundPanel.gameObject.SetActive(false); for (int i = 0; i < 4; i++) { backgroundPanelsROM[i].gameObject.SetActive(false); } //RenderSettings.skybox = null; //Camera.main.clearFlags = CameraClearFlags.SolidColor; } if (backgroundColor.HasValue && !controller.viewCollision) { Camera.main.backgroundColor = backgroundColor.Value; //Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, backgroundColor.Value, 0.5f * Time.deltaTime); } else { Camera.main.backgroundColor = Color.black; //Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, Color.black, 0.5f * Time.deltaTime); } }