定义 ScriptableBakedReflectionSystem 实现所需成员。
您可以使用空实现作为基类,请参见 ScriptableBakedReflectionSystem。
using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; using UnityEditor.Experimental.Rendering;
public interface IBakeJobs { // Add job counts + remove jobs count int count { get; } int toAddCount { get; } int toRemoveCount { get; } }
public interface IBaker<TProbe> { IBakeJobs PrepareBakeJobsFor(SceneStateHash sceneStateHash); void IssueJobs(IBakeJobs jobs); List<TProbe> bakedProbes { get; set; } void StopRunningJobs(); }
abstract class CustomScriptableBakedReflectionSystem : ScriptableBakedReflectionSystem { enum Stage { None, BakeReflectionProbes }
IBaker<ReflectionProbe> m_ReflectionProbeBaker;
public CustomScriptableBakedReflectionSystem( IBaker<ReflectionProbe> reflectionProbeBaker) // Our custom system processes in 1 stage: reflection probes : base(1) { m_ReflectionProbeBaker = reflectionProbeBaker; }
public override void Tick( SceneStateHash sceneStateHash, IScriptableBakedReflectionSystemStageNotifier handle) { // Reflection Probes { // Calculate reflection probes to remove and to bake and add var jobs = m_ReflectionProbeBaker.PrepareBakeJobsFor(sceneStateHash); if (jobs.count > 0) { // Update progression information of current stage // Progress is the progression of to bake and add jobs handle.EnterStage( (int)Stage.BakeReflectionProbes, string.Format("Reflection Probes | {0} jobs", jobs.toAddCount), 1 - (jobs.toAddCount / (float)m_ReflectionProbeBaker.bakedProbes.Count));
// Perform removal of remove jobs // Issue baking of add jobs if they are not in progress m_ReflectionProbeBaker.IssueJobs(jobs);
return; } handle.ExitStage((int)Stage.BakeReflectionProbes); }
// Update the hash of the reflection system stateHashes = CalculateStateHash(); // Baking is complete for this sceneStateHash handle.SetIsDone(true); }
public override void SynchronizeReflectionProbes() { // Synchronize Reflection Probes for (int i = 0, c = m_ReflectionProbeBaker.bakedProbes.Count; i < c; ++i) { var probe = m_ReflectionProbeBaker.bakedProbes[i]; probe.bakedTexture = GetReflectionProbeBakedTexture(probe); } }
public override void Clear() { m_ReflectionProbeBaker.bakedProbes.Clear(); DeleteBakedReflectionProbeTextures(); }
public override void Cancel() { m_ReflectionProbeBaker.StopRunningJobs(); }
Cubemap GetReflectionProbeBakedTexture(ReflectionProbe probe) { throw new System.NotImplementedException(); }
protected abstract void DeleteBakedReflectionProbeTextures(); protected abstract Hash128[] CalculateStateHash(); }
stageCount | 烘焙进程的阶段数。 |
stateHashes | ScriptableBakedReflectionSystem 当前烘焙状态的哈希。 |
BakeAllReflectionProbes | 实现此方法以烘焙所有已加载的反射探针。 |
取消 | 取消正在运行的烘焙作业。 |
Clear | 清除 ScriptableBakedReflectionSystem 的状态。 |
SynchronizeReflectionProbes | 将烘焙数据与实际组件和渲染设置同步。 |
Tick | 此方法在每个编辑器更新时调用,直到 ScriptableBakedReflectionSystem 指示烘焙已完成,handle.SetIsDone(true)。(请参阅 IScriptableBakedReflectionSystemStageNotifier.SetIsDone)。 |