同步主题包内容
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.RhythmGame.Beatmap;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.RhythmGame.ThemeBundles.DepartureToMultiverse.Beatmap
|
||||
{
|
||||
[System.Serializable]
|
||||
public class DTMStarrySkybox_BM : EnvironmentObject_BM
|
||||
{
|
||||
// --- Sky ---
|
||||
public float skyColorR = 0.1f, skyColorG = 0.0f, skyColorB = 0.3f, skyColorA = 1f;
|
||||
public float horizonR = 0.2f, horizonG = 0.4f, horizonB = 0.8f, horizonA = 1f;
|
||||
public float horizonStrength = 2f;
|
||||
public float horizonSkyHeight = 0.7f;
|
||||
|
||||
// --- Stars ---
|
||||
public bool useStarMap = true;
|
||||
public float starDensity = 30f;
|
||||
public float starSize = 75f;
|
||||
public float starColorR = 1f, starColorG = 1f, starColorB = 1f, starColorA = 1f;
|
||||
public bool preventStarsInFrontOfSun = true;
|
||||
public string starMapTextureName = "None";
|
||||
|
||||
// --- Sun Mask ---
|
||||
public bool haveSun = false;
|
||||
public string sunMaskTextureName = "None";
|
||||
public float sunMaskSize = 0.02f;
|
||||
public float sunMaskSpherize = 13.2f;
|
||||
public float sunDiscSize = 1f;
|
||||
public float sunColorOneR = 0.4f, sunColorOneG = 0.2f, sunColorOneB = 0.6f, sunColorOneA = 1f;
|
||||
public float sunColorTwoR = 0.1f, sunColorTwoG = 0.2f, sunColorTwoB = 0.4f, sunColorTwoA = 1f;
|
||||
public float sunGradientStrength = 3.7f;
|
||||
public float sunGradientHeight = 1.23f;
|
||||
|
||||
// --- Fog ---
|
||||
public float fogHeight = 1f;
|
||||
public float fogPower = 0.5f;
|
||||
public float fogContrast = 40f;
|
||||
|
||||
public DTMStarrySkybox_BM()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ExecuteBM()
|
||||
{
|
||||
matchedElement = DTMStarrySkybox.GenerateElement(
|
||||
elementName, elementGuid, tags, false,
|
||||
themeBundleName, objectName, GetElement(attachedElementGuid), isStatic,
|
||||
// Sky
|
||||
new Color(skyColorR, skyColorG, skyColorB, skyColorA),
|
||||
new Color(horizonR, horizonG, horizonB, horizonA),
|
||||
horizonStrength, horizonSkyHeight,
|
||||
// Stars
|
||||
useStarMap, starDensity, starSize,
|
||||
new Color(starColorR, starColorG, starColorB, starColorA),
|
||||
preventStarsInFrontOfSun, starMapTextureName,
|
||||
// Sun
|
||||
haveSun, sunMaskTextureName,
|
||||
sunMaskSize, sunMaskSpherize, sunDiscSize,
|
||||
new Color(sunColorOneR, sunColorOneG, sunColorOneB, sunColorOneA),
|
||||
new Color(sunColorTwoR, sunColorTwoG, sunColorTwoB, sunColorTwoA),
|
||||
sunGradientStrength, sunGradientHeight,
|
||||
// Fog
|
||||
fogHeight, fogPower, fogContrast);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8b6a302b0938b24593b2ec43d23d2b0
|
||||
@@ -1,9 +1,191 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.RhythmGame.Beatmap;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.RhythmGame.ThemeBundles.DepartureToMultiverse
|
||||
{
|
||||
public class DTMStarrySkybox : GameElement
|
||||
/// <summary>
|
||||
/// 游星空天空盒环境物体,加载 DTM_Skybox_Starry 材质并将其设置为场景天空盒,
|
||||
/// 同时暴露天空盒 Shader 的全量参数以接受 PropertyAnimation 动态控制。
|
||||
/// </summary>
|
||||
public class DTMStarrySkybox : EnvironmentObject
|
||||
{
|
||||
|
||||
#region [暴露属性字段] Exposed Fields
|
||||
|
||||
// 天空盒材质(运行时实例)
|
||||
[NonSerialized] public Material skyboxMaterial;
|
||||
|
||||
// --- Sky ---
|
||||
public Color skyColor = Color.blue;
|
||||
public Color horizon = Color.cyan;
|
||||
public float horizonStrength = 2f;
|
||||
public float horizonSkyHeight = 0.7f;
|
||||
|
||||
// --- Stars ---
|
||||
public bool useStarMap = true;
|
||||
public float starDensity = 30f;
|
||||
public float starSize = 75f;
|
||||
public Color starColor = Color.white;
|
||||
public bool preventStarsInFrontOfSun = true;
|
||||
// 通过 ThemeBundle 字符串名称查找贴图
|
||||
public string starMapTextureName = "None";
|
||||
|
||||
// --- Sun Mask ---
|
||||
public bool haveSun = false;
|
||||
public string sunMaskTextureName = "None";
|
||||
public float sunMaskSize = 0.02f;
|
||||
public float sunMaskSpherize = 13.2f;
|
||||
public float sunDiscSize = 1f;
|
||||
public Color sunColorOne = Color.white;
|
||||
public Color sunColorTwo = Color.white;
|
||||
public float sunGradientStrength = 3.7f;
|
||||
public float sunGradientHeight = 1.23f;
|
||||
|
||||
// --- Fog ---
|
||||
public float fogHeight = 1f;
|
||||
public float fogPower = 0.5f;
|
||||
public float fogContrast = 40f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region [生命周期与工厂] Lifecycle & Factory
|
||||
|
||||
public static DTMStarrySkybox GenerateElement(string elementName, Guid id, List<string> tags,
|
||||
bool isFirstGenerated, string themeBundleName, string objectName, GameElement parentElement,
|
||||
bool isStatic,
|
||||
// Sky
|
||||
Color skyColor, Color horizon, float horizonStrength, float horizonSkyHeight,
|
||||
// Stars
|
||||
bool useStarMap, float starDensity, float starSize, Color starColor,
|
||||
bool preventStarsInFrontOfSun, string starMapTextureName,
|
||||
// Sun
|
||||
bool haveSun, string sunMaskTextureName,
|
||||
float sunMaskSize, float sunMaskSpherize, float sunDiscSize,
|
||||
Color sunColorOne, Color sunColorTwo, float sunGradientStrength, float sunGradientHeight,
|
||||
// Fog
|
||||
float fogHeight, float fogPower, float fogContrast)
|
||||
{
|
||||
DTMStarrySkybox skybox = EnvironmentObject.GenerateElement(elementName, id, tags,
|
||||
isFirstGenerated, themeBundleName, objectName, parentElement, isStatic)
|
||||
.GetComponent<DTMStarrySkybox>();
|
||||
|
||||
skybox.skyColor = skyColor;
|
||||
skybox.horizon = horizon;
|
||||
skybox.horizonStrength = horizonStrength;
|
||||
skybox.horizonSkyHeight = horizonSkyHeight;
|
||||
|
||||
skybox.useStarMap = useStarMap;
|
||||
skybox.starDensity = starDensity;
|
||||
skybox.starSize = starSize;
|
||||
skybox.starColor = starColor;
|
||||
skybox.preventStarsInFrontOfSun = preventStarsInFrontOfSun;
|
||||
skybox.starMapTextureName = starMapTextureName;
|
||||
|
||||
skybox.haveSun = haveSun;
|
||||
skybox.sunMaskTextureName = sunMaskTextureName;
|
||||
skybox.sunMaskSize = sunMaskSize;
|
||||
skybox.sunMaskSpherize = sunMaskSpherize;
|
||||
skybox.sunDiscSize = sunDiscSize;
|
||||
skybox.sunColorOne = sunColorOne;
|
||||
skybox.sunColorTwo = sunColorTwo;
|
||||
skybox.sunGradientStrength = sunGradientStrength;
|
||||
skybox.sunGradientHeight = sunGradientHeight;
|
||||
|
||||
skybox.fogHeight = fogHeight;
|
||||
skybox.fogPower = fogPower;
|
||||
skybox.fogContrast = fogContrast;
|
||||
|
||||
return skybox;
|
||||
}
|
||||
|
||||
public override void FirstSetUpObject(bool isFirstGenerated)
|
||||
{
|
||||
// 从 ThemeBundle 中加载天空盒材质并实例化,赋给场景天空盒
|
||||
Material sourceMat = ThemeBundleManager.instance.GetObject<Material>(themeBundleName, "DTM_Skybox_Starry");
|
||||
if (sourceMat != null)
|
||||
{
|
||||
skyboxMaterial = new Material(sourceMat); // 实例化,隔离修改
|
||||
RenderSettings.skybox = skyboxMaterial;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"[DTMStarrySkybox] 无法在 ThemeBundle '{themeBundleName}' 中找到 'DTM_Skybox_Starry' 材质!");
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateSkyboxProperties();
|
||||
}
|
||||
|
||||
public override void OnDirtyRefresh(Dictionary<string, bool> flags)
|
||||
{
|
||||
UpdateSkyboxProperties();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region [效果核心逻辑] Core Effect Logic
|
||||
|
||||
/// <summary>
|
||||
/// 将所有本地缓存参数一次性批量写入天空盒材质,并通知 DynamicGI 刷新。
|
||||
/// </summary>
|
||||
public void UpdateSkyboxProperties()
|
||||
{
|
||||
if (skyboxMaterial == null) return;
|
||||
|
||||
// -- Sky --
|
||||
skyboxMaterial.SetColor("_SkyColor", skyColor);
|
||||
skyboxMaterial.SetColor("_Horizon", horizon);
|
||||
skyboxMaterial.SetFloat("_HorizonStrength", horizonStrength);
|
||||
skyboxMaterial.SetFloat("_HorizonSkyHeight", horizonSkyHeight);
|
||||
|
||||
// -- Stars --
|
||||
skyboxMaterial.SetFloat("_UseStarMap", useStarMap ? 1f : 0f);
|
||||
skyboxMaterial.SetFloat("_StarDensity", starDensity);
|
||||
skyboxMaterial.SetFloat("_StarSize", starSize);
|
||||
skyboxMaterial.SetColor("_StarColor", starColor);
|
||||
skyboxMaterial.SetFloat("_PreventStarsInFrontOfSun", preventStarsInFrontOfSun ? 1f : 0f);
|
||||
|
||||
// 星图贴图通过 ThemeBundle 按名称查找
|
||||
if (!string.IsNullOrEmpty(starMapTextureName) && starMapTextureName != "None")
|
||||
{
|
||||
Texture2D starMap = ThemeBundleManager.instance.GetObject<Texture2D>(themeBundleName, starMapTextureName);
|
||||
if (starMap != null) skyboxMaterial.SetTexture("_StarMap", starMap);
|
||||
}
|
||||
|
||||
// -- Sun Mask --
|
||||
skyboxMaterial.SetFloat("_HaveSun", haveSun ? 1f : 0f);
|
||||
|
||||
if (!string.IsNullOrEmpty(sunMaskTextureName) && sunMaskTextureName != "None")
|
||||
{
|
||||
Texture2D sunMask = ThemeBundleManager.instance.GetObject<Texture2D>(themeBundleName, sunMaskTextureName);
|
||||
if (sunMask != null) skyboxMaterial.SetTexture("_SunMask", sunMask);
|
||||
}
|
||||
|
||||
skyboxMaterial.SetFloat("_SunMaskSize", sunMaskSize);
|
||||
skyboxMaterial.SetFloat("_SunMaskSpherize", sunMaskSpherize);
|
||||
skyboxMaterial.SetFloat("_SunDiscSize", sunDiscSize);
|
||||
skyboxMaterial.SetColor("_SunColorOne", sunColorOne);
|
||||
skyboxMaterial.SetColor("_SunColorTwo", sunColorTwo);
|
||||
skyboxMaterial.SetFloat("_SunGradientStrength", sunGradientStrength);
|
||||
skyboxMaterial.SetFloat("_SunGradientHeight", sunGradientHeight);
|
||||
|
||||
// -- Fog --
|
||||
skyboxMaterial.SetFloat("_FogHeight", fogHeight);
|
||||
skyboxMaterial.SetFloat("_FogPower", fogPower);
|
||||
skyboxMaterial.SetFloat("_FogContrast", fogContrast);
|
||||
|
||||
// 通知引擎重烤全局间接光
|
||||
DynamicGI.UpdateEnvironment();
|
||||
}
|
||||
|
||||
public override void OnDelete()
|
||||
{
|
||||
base.OnDelete();
|
||||
// 还原场景天空盒,防止场景切换后残留
|
||||
RenderSettings.skybox = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user