177 lines
5.7 KiB
C#
177 lines
5.7 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using Ichni.RhythmGame.Beatmap;
|
||
|
|
using UniRx;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.Events;
|
||
|
|
|
||
|
|
namespace Ichni.RhythmGame
|
||
|
|
{
|
||
|
|
public class BeatmapContainer : IBaseElement
|
||
|
|
{
|
||
|
|
public List<GameElement> gameElementList;
|
||
|
|
|
||
|
|
[NonSerialized]
|
||
|
|
public List<UnityAction> lowPriorityActions;
|
||
|
|
|
||
|
|
public BaseElement_BM matchedBM { get; set; }
|
||
|
|
|
||
|
|
public BeatmapContainer()
|
||
|
|
{
|
||
|
|
gameElementList = new List<GameElement>();
|
||
|
|
lowPriorityActions = new List<UnityAction>();
|
||
|
|
Observable.EveryUpdate().Subscribe(_ => ExecuteLowPriorityActions());
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ExecuteLowPriorityActions()
|
||
|
|
{
|
||
|
|
if (lowPriorityActions.Count > 0)
|
||
|
|
{
|
||
|
|
lowPriorityActions.ForEach(low => low.Invoke());
|
||
|
|
lowPriorityActions.Clear();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void SaveBM()
|
||
|
|
{
|
||
|
|
matchedBM = new BeatmapContainer_BM(gameElementList);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void SetUpInspector()
|
||
|
|
{
|
||
|
|
throw new System.NotImplementedException();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Refresh()
|
||
|
|
{
|
||
|
|
throw new System.NotImplementedException();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
namespace Beatmap
|
||
|
|
{
|
||
|
|
public partial class BeatmapContainer_BM : BaseElement_BM
|
||
|
|
{
|
||
|
|
public List<BaseElement_BM> elementList;
|
||
|
|
public IntReactiveProperty remainingElementAmount;
|
||
|
|
|
||
|
|
public int loadAmount = 0;
|
||
|
|
public int loadMaximumAmountPerFrame = 300;
|
||
|
|
|
||
|
|
public BeatmapContainer_BM()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public BeatmapContainer_BM(List<GameElement> gameElementList)
|
||
|
|
{
|
||
|
|
elementList = new List<BaseElement_BM>();
|
||
|
|
|
||
|
|
gameElementList.ForEach(e =>
|
||
|
|
{
|
||
|
|
e.SaveBM();
|
||
|
|
e.submoduleList.RemoveAll(s => s == null);
|
||
|
|
e.submoduleList.ForEach(s => s.SaveBM());
|
||
|
|
});
|
||
|
|
|
||
|
|
foreach (var gameElement in gameElementList)
|
||
|
|
{
|
||
|
|
if (gameElement.matchedBM != null)
|
||
|
|
{
|
||
|
|
elementList.Add(gameElement.matchedBM);
|
||
|
|
}
|
||
|
|
|
||
|
|
List<BaseElement_BM> submodules = gameElement.submoduleList.ConvertAll(s => s.matchedBM);
|
||
|
|
submodules.RemoveAll(s => s == null);
|
||
|
|
elementList.AddRange(submodules);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void ExecuteBM()
|
||
|
|
{
|
||
|
|
GameManager.instance.beatmapContainer = new BeatmapContainer();
|
||
|
|
GameManager.instance.beatmapContainer.matchedBM = this;
|
||
|
|
|
||
|
|
remainingElementAmount = new IntReactiveProperty(elementList.Count);
|
||
|
|
|
||
|
|
GameManager.instance.StartCoroutine(ExecuteLoadElements());
|
||
|
|
}
|
||
|
|
|
||
|
|
private IEnumerator ExecuteLoadElements()
|
||
|
|
{
|
||
|
|
List<BaseElement_BM> lowPriorityElements = new List<BaseElement_BM>();
|
||
|
|
|
||
|
|
for (int index = 0; index < elementList.Count; index++)
|
||
|
|
{
|
||
|
|
BaseElement_BM element = elementList[index];
|
||
|
|
|
||
|
|
if (LowPriorityGameElementTypes.Contains(element.GetType()))
|
||
|
|
{
|
||
|
|
lowPriorityElements.Add(element);
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (element is GameElement_BM gameElement)
|
||
|
|
{
|
||
|
|
GameElement_BM.identifier.Add(gameElement.elementGuid, gameElement);
|
||
|
|
}
|
||
|
|
|
||
|
|
element.ExecuteBM();
|
||
|
|
remainingElementAmount.Value--;
|
||
|
|
|
||
|
|
loadAmount++;
|
||
|
|
Debug.Log(loadAmount + " " + Time.time);
|
||
|
|
if (loadAmount >= loadMaximumAmountPerFrame)
|
||
|
|
{
|
||
|
|
loadAmount = 0;
|
||
|
|
yield return new WaitForEndOfFrame();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach (var element in lowPriorityElements)
|
||
|
|
{
|
||
|
|
if (element == null)
|
||
|
|
{
|
||
|
|
Debug.LogError("Null element detected in low-priority elements. Skipping execution.");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
element.ExecuteBM();
|
||
|
|
remainingElementAmount.Value--;
|
||
|
|
|
||
|
|
loadAmount++;
|
||
|
|
if (loadAmount >= loadMaximumAmountPerFrame)
|
||
|
|
{
|
||
|
|
loadAmount = 0;
|
||
|
|
yield return new WaitForEndOfFrame();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
GameManager.instance.beatmapContainer.ExecuteLowPriorityActions();
|
||
|
|
|
||
|
|
GameManager.instance.beatmapContainer.gameElementList.ForEach(gameElement =>
|
||
|
|
{
|
||
|
|
gameElement.AfterInitialize();
|
||
|
|
gameElement.Refresh();
|
||
|
|
});
|
||
|
|
|
||
|
|
Debug.Log("All elements loaded.");
|
||
|
|
yield return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public partial class BeatmapContainer_BM : BaseElement_BM
|
||
|
|
{
|
||
|
|
public static readonly List<Type> LowPriorityGameElementTypes = new()
|
||
|
|
{
|
||
|
|
typeof(NoteJudgeSubmodule_BM),
|
||
|
|
};
|
||
|
|
|
||
|
|
public static readonly List<Type> LowPriorityDataTypes = new()
|
||
|
|
{
|
||
|
|
typeof(EnableControlEffect_BM),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|