Files
ichni_Official/Assets/Scripts/Game/GameElements/Environment/SkyboxSubsetter.cs
SoulliesOfficial 7c60c40d6b 同步
2026-06-05 04:45:57 -04:00

125 lines
5.3 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, IScheduledElement
{
#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;
}
public override void AfterInitialize()
{
base.AfterInitialize();
CoreServices.UpdateScheduler.Register(UpdatePhase.Misc, this);
}
public override void OnDelete()
{
base.OnDelete();
CoreServices.UpdateScheduler.Unregister(UpdatePhase.Misc, this);
}
#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
#region [IScheduledElement] Scheduler Interface
public void ScheduledUpdate(UpdatePhase phase, float songTime)
{
if (skyBoxThemeBundleList.Count > 1)
{
float delay = GameManager.Instance.songInformation.delay;
const float finalTime = 32767f; // 曲目长度上限
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();
}
}
}
}
public bool IsScheduledActive => isActiveAndEnabled;
#endregion
#endregion
}
}