skybox subsetter

This commit is contained in:
SoulliesOfficial
2025-07-09 01:01:06 -04:00
parent 6533997d59
commit 537caabfa9
128 changed files with 13280 additions and 2268 deletions

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using Ichni.Editor;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
using UnityEngine.Serialization;
namespace Ichni.RhythmGame
{
@@ -15,6 +16,8 @@ namespace Ichni.RhythmGame
public Material skyboxMaterial;
public string backgroundSpriteName;
public Sprite backgroundSprite;
[FormerlySerializedAs("skyboxController")] public SkyboxSubsetter skyboxSubsetter;
public static BackgroundSetter GenerateElement(string elementName, Guid id, List<string> tags,
bool isFirstGenerated, GameElement parentElement, bool useSkybox, string skyboxThemeBundleName,
@@ -36,10 +39,11 @@ namespace Ichni.RhythmGame
backgroundSetter.backgroundSpriteName = backgroundSpriteName;
return backgroundSetter;
}
public override void Refresh()
{
EditorManager.instance.backgroundController.EnableBackground(!useSkybox);
if (useSkybox)
if (useSkybox && skyboxSubsetter == null)
{
SetSkybox(skyboxThemeBundleName, skyboxMaterialName);
}
@@ -80,6 +84,21 @@ namespace Ichni.RhythmGame
useSkyboxToggle.AddListenerFunction(() => EditorManager.instance.backgroundController.EnableBackground(!useSkybox));
useSkyboxToggle.AddListenerFunction(() => SetInputFields(useSkybox));
var generateContainer = inspector.GenerateContainer("Generate");
var generateSubContainer = generateContainer.GenerateSubcontainer(3);
var generateSkyboxControllerButton = inspector.GenerateButton(this, generateSubContainer, "Skybox Controller", () =>
{
if (skyboxSubsetter == null)
{
SkyboxSubsetter.GenerateElement("New Skybox Subsetter", Guid.NewGuid(), new List<string>(), true, this,
new List<string>(), new List<string>(), new List<float>(), new List<float>());
}
else
{
LogWindow.Log("There is already a Skybox Subsetter in the scene.", Color.yellow);
}
});
}
}

View File

@@ -0,0 +1,200 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.Editor;
using Ichni.RhythmGame;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
using UnityEngine.Serialization;
using Object = UnityEngine.Object;
namespace Ichni.RhythmGame
{
public partial class SkyboxSubsetter : GameElement
{
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;
public List<string> themeBundleListForSelection;
public List<string> skyboxNameListForSelection;
public string selectedThemeBundle;
public string selectedSkybox;
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(EditorManager.instance.basePrefabs.emptyObject)
.AddComponent<SkyboxSubsetter>();
EditorManager.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;
}
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);
}
}
private void Update()
{
if (skyBoxThemeBundleList.Count > 1)
{
float songTime = EditorManager.instance.songInformation.songTime;
float delay = EditorManager.instance.songInformation.delay;
float finalTime = EditorManager.instance.songInformation.songLength;
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 override void SaveBM()
{
matchedBM = new SkyboxSubsetter_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM,
skyBoxThemeBundleList, skyboxNameList, blendTimeList, blendSpeedList);
}
}
public partial class SkyboxSubsetter
{
public override void SetUpInspector()
{
IHaveInspection inspector = EditorManager.instance.uiManager.inspector;
Inspector inspectorMain = EditorManager.instance.uiManager.inspector;
var container = inspector.GenerateContainer("Skybox Subsetter");
DynamicUISubcontainer mainSettings = container.GenerateSubcontainer(3);
var blendSpeedListButton = inspector.GenerateButton(this, mainSettings, "Blend Speed List", () =>
{
inspector.GenerateCompositeParameterWindow(this, "Blend Speed List", nameof(blendSpeedList))
.SetAsFloatList();
});
var blendTimeListButton = inspector.GenerateButton(this, mainSettings, "Blend Time List", () =>
{
inspector.GenerateCompositeParameterWindow(this, "Blend Time List", nameof(blendTimeList))
.SetAsFloatList();
});
DynamicUISubcontainer materialSettings = container.GenerateSubcontainer(3);
Debug.Log((mainSettings == null) + " " + (themeBundleListForSelection == null) + " " + (selectedThemeBundle == null));
var themeBundleDropdown =
inspector.GenerateDropdown(this, materialSettings, "Theme Bundle", themeBundleListForSelection, nameof(selectedThemeBundle))
.AddListenerFunction(() => inspectorMain.SetInspector(this));
if (selectedThemeBundle != String.Empty && ThemeBundleManager.instance.TryGetThemeBundle(selectedThemeBundle, out ThemeBundle themeBundle))
{
skyboxNameListForSelection = themeBundle.assetList_Material.ConvertAll(x => x.name);
var objectNameDropdown =
inspector.GenerateDropdown(this, materialSettings, "Material Name", skyboxNameListForSelection, nameof(selectedSkybox))
.AddListenerFunction(() => inspectorMain.SetInspector(this));
}
else
{
var objectNameDropdown =
inspector.GenerateDropdown(this, materialSettings, "Material Name", new List<string>(), nameof(selectedSkybox));
objectNameDropdown.dropdown.interactable = false;
} // 如果没有选择主题包,则材质名称下拉框不可用
var setMaterialButton = inspector.GenerateButton(this, materialSettings, "Add Skybox", () =>
{
AddSkybox(selectedThemeBundle, selectedSkybox);
});
if (selectedThemeBundle == String.Empty || selectedSkybox == String.Empty)
{
setMaterialButton.button.interactable = false;
}
}
}
namespace Beatmap
{
public class SkyboxSubsetter_BM : GameElement_BM
{
public List<string> skyBoxThemeBundleList;
public List<string> skyboxNameList;
public List<float> blendTimeList;
public List<float> blendSpeedList;
public SkyboxSubsetter_BM()
{
}
public SkyboxSubsetter_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement,
List<string> skyBoxThemeBundleList, List<string> skyboxNameList, List<float> blendTimeList, List<float> blendSpeedList)
: base(elementName, elementGuid, tags, attachedElement)
{
this.skyBoxThemeBundleList = skyBoxThemeBundleList;
this.skyboxNameList = skyboxNameList;
this.blendTimeList = blendTimeList;
this.blendSpeedList = blendSpeedList;
}
public override void ExecuteBM()
{
matchedElement = SkyboxSubsetter.GenerateElement(elementName, elementGuid, tags, false,
GetElement(attachedElementGuid), skyBoxThemeBundleList, skyboxNameList, blendTimeList, blendSpeedList);
}
public override GameElement DuplicateBM(GameElement attached)
{
return SkyboxSubsetter.GenerateElement(elementName, Guid.NewGuid(), tags, false,
attached, skyBoxThemeBundleList, skyboxNameList, blendTimeList, blendSpeedList);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2312c9a28a322f445b6a61d3c72a9d26
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: