更新
This commit is contained in:
63
Assets/Scripts/Game/Components/DirtyMarkSubmodule.cs
Normal file
63
Assets/Scripts/Game/Components/DirtyMarkSubmodule.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ichni.RhythmGame
|
||||
{
|
||||
public class DirtyMarkSubmodule : SubmoduleBase
|
||||
{
|
||||
public bool isAnyDirty { get; private set; }
|
||||
public Dictionary<string, bool> dirtyFlags;
|
||||
|
||||
public DirtyMarkSubmodule(GameElement attachedGameElement) : base(attachedGameElement)
|
||||
{
|
||||
isAnyDirty = false;
|
||||
dirtyFlags = new Dictionary<string, bool>();
|
||||
|
||||
if (!HaveSameSubmodule && attachedGameElement is IHaveDirtyMarkSubmodule host)
|
||||
{
|
||||
host.dirtyMarkSubmodule = this;
|
||||
}
|
||||
}
|
||||
|
||||
public void MarkDirty(string flagKey = "All")
|
||||
{
|
||||
isAnyDirty = true;
|
||||
if (!string.IsNullOrEmpty(flagKey))
|
||||
{
|
||||
dirtyFlags[flagKey] = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void ExecuteDeferredRefresh()
|
||||
{
|
||||
if (isAnyDirty && attachedGameElement is IHaveDirtyMarkSubmodule host)
|
||||
{
|
||||
host.OnDirtyRefresh(dirtyFlags);
|
||||
ClearDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearDirty()
|
||||
{
|
||||
isAnyDirty = false;
|
||||
dirtyFlags.Clear();
|
||||
}
|
||||
|
||||
public override void Refresh()
|
||||
{
|
||||
MarkDirty("All");
|
||||
}
|
||||
|
||||
public override void CheckAndRemoveObservers() { }
|
||||
}
|
||||
|
||||
public interface IHaveDirtyMarkSubmodule
|
||||
{
|
||||
DirtyMarkSubmodule dirtyMarkSubmodule { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当有一帧收到来自于动画或者其它管理器的脏标记篡改时,在此方法中处理推送至具体表现层的工作。
|
||||
/// </summary>
|
||||
void OnDirtyRefresh(Dictionary<string, bool> flags);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user