136 lines
6.0 KiB
C#
136 lines
6.0 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
|
||
|
|
{
|
||
|
|
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(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;
|
||
|
|
}
|
||
|
|
|
||
|
|
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 = GameManager.instance.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();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void SaveBM()
|
||
|
|
{
|
||
|
|
matchedBM = new SkyboxSubsetter_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM,
|
||
|
|
skyBoxThemeBundleList, skyboxNameList, blendTimeList, blendSpeedList);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|