Files
ichni_Official/Assets/Scripts/Game/GameElements/Environment/SkyboxSubsetter.cs
SoulliesOfficial 7580c4d87c 大更
2026-03-14 03:13:10 -04:00

110 lines
4.8 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
namespace Ichni.RhythmGame
{
public partial class SkyboxSubsetter : GameElement
{
#region [] Core Components & Skybox Lists
public SkyboxBlender skyboxBlender;
public List<string> skyBoxThemeBundleList;
public List<string> skyboxNameList;
public List<Material> skyboxMaterialList;
public List<float> blendSpeedList;
public List<float> blendTimeList;
public int currentSkyboxIndex = 0;
#endregion
#region [UI支持] Editor Selection Tools
public List<string> themeBundleListForSelection;
public List<string> skyboxNameListForSelection;
public string selectedThemeBundle;
public string selectedSkybox;
#endregion
#region [] Lifecycle & Factory
public static SkyboxSubsetter GenerateElement(string elementName, Guid id, List<string> tags,
bool isFirstGenerated, GameElement parentElement, List<string> themeBundleList,List<string> skyboxList,
List<float> blendTimeList, List<float> blendSpeedList)
{
SkyboxSubsetter skyboxSubsetter = Instantiate(GameManager.Instance.basePrefabs.emptyObject)
.AddComponent<SkyboxSubsetter>();
GameManager.Instance.backgroundSetter.skyboxSubsetter = skyboxSubsetter;
skyboxSubsetter.Initialize(elementName, id, tags, isFirstGenerated, parentElement);
skyboxSubsetter.skyBoxThemeBundleList = themeBundleList;
skyboxSubsetter.skyboxNameList = skyboxList;
skyboxSubsetter.skyboxMaterialList = new List<Material>();
skyboxSubsetter.blendTimeList = blendTimeList;
skyboxSubsetter.blendSpeedList = blendSpeedList;
skyboxSubsetter.SetUpBlender();
skyboxSubsetter.themeBundleListForSelection = ThemeBundleManager.instance.loadedThemeBundleList.ConvertAll(x => x.themeBundleName);
skyboxSubsetter.skyboxNameListForSelection = new List<string>();
skyboxSubsetter.selectedThemeBundle = String.Empty;
skyboxSubsetter.selectedSkybox = String.Empty;
return skyboxSubsetter;
}
#endregion
#region [] Internal Configs & Utils
private void SetUpBlender()
{
skyboxBlender = gameObject.AddComponent<SkyboxBlender>();
skyboxBlender.loop = false;
skyboxBlender.timeToWait = 0f;
skyboxBlender.updateLighting = false;
skyboxBlender.updateReflections = false;
skyboxBlender.skyboxMaterials = new List<Material>();
for (int i = 0; i < skyBoxThemeBundleList.Count; i++)
{
Material skybox = ThemeBundleManager.instance.GetObject<Material>(skyBoxThemeBundleList[i], skyboxNameList[i]);
skyboxMaterialList.Add(skybox);
skyboxBlender.skyboxMaterials.Add(skybox);
}
skyboxBlender.makeFirstMaterialSkybox = true;
skyboxBlender.InspectorAndAwakeChanges();
}
private void AddSkybox(string skyboxThemeBundleName, string skyboxObjectName)
{
Material skybox = ThemeBundleManager.instance.GetObject<Material>(skyboxThemeBundleName, skyboxObjectName);
if (skybox != null)
{
skyBoxThemeBundleList.Add(skyboxThemeBundleName);
skyboxNameList.Add(skyboxObjectName);
skyboxMaterialList.Add(skybox);
skyboxBlender.skyboxMaterials.Add(skybox);
}
}
#endregion
#region [] Main Update
private void Update()
{
if (skyBoxThemeBundleList.Count > 1)
{
float songTime = CoreServices.TimeProvider.SongTime;
float delay = GameManager.Instance.songInformation.delay;
float finalTime = 32767; // 曲目长度
for (var index = 0; index < blendTimeList.Count + 1; index++)
{
float startTime = index == 0 ? -delay : blendTimeList[index - 1];
float endTime = index >= blendTimeList.Count ? finalTime : blendTimeList[index];
if(songTime >= startTime && songTime < endTime && currentSkyboxIndex != index)
{
currentSkyboxIndex = index;
if(currentSkyboxIndex != 0) skyboxBlender.blendSpeed = blendSpeedList[currentSkyboxIndex - 1];
skyboxBlender.Blend(currentSkyboxIndex, false);
DynamicGI.UpdateEnvironment();
}
}
}
}
#endregion
}
}