fix asset unloading jank with karate man

This commit is contained in:
minenice55 2024-01-20 23:59:26 -05:00
parent 81e546e3fe
commit dbf28debe0
4 changed files with 106 additions and 77 deletions

View file

@ -59,7 +59,8 @@ namespace HeavenStudio.Games.Loaders
e.CreateProperty("ease", fade ? (int)Util.EasingFunction.Ease.Linear : (int)Util.EasingFunction.Ease.Instant); e.CreateProperty("ease", fade ? (int)Util.EasingFunction.Ease.Linear : (int)Util.EasingFunction.Ease.Instant);
e.CreateProperty("fxType", !fade ? (int)e["type3"] : 3); e.CreateProperty("fxType", !fade ? (int)e["type3"] : 3);
foreach (var remove in toRemove) { foreach (var remove in toRemove)
{
e.dynamicData.Remove(remove); e.dynamicData.Remove(remove);
} }
@ -402,9 +403,9 @@ namespace HeavenStudio.Games.Loaders
}, },
}, },
}, },
new List<string>() {"agb", "ntr", "rvl", "ctr", "pco", "normal"}, new List<string>() { "agb", "ntr", "rvl", "ctr", "pco", "normal" },
"karate", "en", "karate", "en",
new List<string>() {"en"} new List<string>() { "en" }
); );
} }
} }
@ -595,7 +596,7 @@ namespace HeavenStudio.Games
//public static Queue<Beatmap.Entity> ItemQueue = new Queue<Beatmap.Entity>(); //public static Queue<Beatmap.Entity> ItemQueue = new Queue<Beatmap.Entity>();
public static bool WantBop = true; public static bool WantBop = true;
public static bool WantNori = true; public static bool WantNori = true;
public static int WantNoriType = (int) NoriMode.None; public static int WantNoriType = (int)NoriMode.None;
public static double WantBgChangeStart = double.MinValue; public static double WantBgChangeStart = double.MinValue;
public static float WantBgChangeLength = 0f; public static float WantBgChangeLength = 0f;
@ -709,8 +710,6 @@ namespace HeavenStudio.Games
TintColor(BackgroundColors[0]), TintColor(BackgroundColors[0]),
new Color(), new Color(),
}; };
Update();
} }
private void Start() private void Start()
@ -721,14 +720,17 @@ namespace HeavenStudio.Games
public override void OnGameSwitch(double beat) public override void OnGameSwitch(double beat)
{ {
// queued objects // queued objects
if (queuedCues.Count > 0) { if (queuedCues.Count > 0)
foreach (var e in queuedCues) { {
switch (e.datamodel) { foreach (var e in queuedCues)
case "karateman/hit" : CreateItem(e.beat, e["type"], e["type2"]); break; {
case "karateman/bulb" : CreateBulbSpecial(e.beat, e["type"], e["colorA"], e["type2"], e["sfx"], e["hitSfx"]); break; switch (e.datamodel)
case "karateman/kick" : Kick(e.beat, e["toggle"], e["shouldGlow"], e["type"], e["pitchVoice"], e["forcePitch"], e["cutOut"], e["disableVoice"], e["woodColor"], e["hoopColor"]); break; {
case "karateman/hit": CreateItem(e.beat, e["type"], e["type2"]); break;
case "karateman/bulb": CreateBulbSpecial(e.beat, e["type"], e["colorA"], e["type2"], e["sfx"], e["hitSfx"]); break;
case "karateman/kick": Kick(e.beat, e["toggle"], e["shouldGlow"], e["type"], e["pitchVoice"], e["forcePitch"], e["cutOut"], e["disableVoice"], e["woodColor"], e["hoopColor"]); break;
case "karateman/combo": Combo(e.beat, e["type"], e["pitchVoice"], e["forcePitch"], e["cutOut"], e["disableVoice"]); break; case "karateman/combo": Combo(e.beat, e["type"], e["pitchVoice"], e["forcePitch"], e["cutOut"], e["disableVoice"]); break;
default : Debug.LogError($"Karate Man has failed to cue an object with datamodel {e.datamodel} at beat {e.beat}"); break; default: Debug.LogError($"Karate Man has failed to cue an object with datamodel {e.datamodel} at beat {e.beat}"); break;
} }
} }
queuedCues.Clear(); queuedCues.Clear();
@ -747,7 +749,8 @@ namespace HeavenStudio.Games
List<RiqEntity> prevEntities = GameManager.instance.Beatmap.Entities.FindAll(c => c.datamodel.Split(0) == "karateman"); List<RiqEntity> prevEntities = GameManager.instance.Beatmap.Entities.FindAll(c => c.datamodel.Split(0) == "karateman");
RiqEntity voice = prevEntities.FindLast(c => c.beat < beat && c.datamodel == "karateman/warnings"); RiqEntity voice = prevEntities.FindLast(c => c.beat < beat && c.datamodel == "karateman/warnings");
if (wordClearTime > beat && wordStartTime < beat && voice != null) { if (wordClearTime > beat && wordStartTime < beat && voice != null)
{
DoWord(voice.beat, voice.length, voice["whichWarning"], false, 1, voice["customLength"], false); DoWord(voice.beat, voice.length, voice["whichWarning"], false, 1, voice["customLength"], false);
} }
@ -755,21 +758,27 @@ namespace HeavenStudio.Games
RiqEntity bg = prevEntities.FindLast(c => c.beat <= beat && c.datamodel == "karateman/background appearance"); RiqEntity bg = prevEntities.FindLast(c => c.beat <= beat && c.datamodel == "karateman/background appearance");
RiqEntity obj = prevEntities.FindLast(c => c.beat <= beat && c.datamodel == "karateman/set object colors"); RiqEntity obj = prevEntities.FindLast(c => c.beat <= beat && c.datamodel == "karateman/set object colors");
if (bg != null) { if (bg != null)
{
BackgroundColor( BackgroundColor(
bg.beat, bg.length, bg["fxType"], bg.beat, bg.length, bg["fxType"],
bg["presetBg"], bg["startColor"], bg["endColor"], bg["ease"], bg["presetBg"], bg["startColor"], bg["endColor"], bg["ease"],
bg["shadowType"], bg["shadowStart"], bg["shadowEnd"], bg["shadowType"], bg["shadowStart"], bg["shadowEnd"],
bg["textureType"], bg["autoColor"], bg["startTexture"], bg["endTexture"] bg["textureType"], bg["autoColor"], bg["startTexture"], bg["endTexture"]
); );
} else { }
else
{
var c = new Color(); var c = new Color();
BackgroundColor(0, 0, 0, 0, c, c, (int)Util.EasingFunction.Ease.Instant, 0, c, c, 0, true, c, c); BackgroundColor(0, 0, 0, 0, c, c, (int)Util.EasingFunction.Ease.Instant, 0, c, c, 0, true, c, c);
} }
if (obj != null) { if (obj != null)
{
UpdateMaterialColour(obj["colorA"], obj["colorB"], obj["colorC"], obj["colorD"], obj["star"]); UpdateMaterialColour(obj["colorA"], obj["colorB"], obj["colorC"], obj["colorD"], obj["star"]);
} else { }
else
{
UpdateMaterialColour(Color.white, new Color(0.81f, 0.81f, 0.81f), Color.white, Color.white, (int)StarColorOption.ItemColor); UpdateMaterialColour(Color.white, new Color(0.81f, 0.81f, 0.81f), Color.white, Color.white, (int)StarColorOption.ItemColor);
} }
@ -779,7 +788,8 @@ namespace HeavenStudio.Games
ToggleBop(0, 0, false, bop?["toggle"] ?? true); ToggleBop(0, 0, false, bop?["toggle"] ?? true);
if (flow != null) { if (flow != null)
{
int fxType = bg == null || flow.beat > bg.beat ? flow["fxType"] : bg["fxType"]; int fxType = bg == null || flow.beat > bg.beat ? flow["fxType"] : bg["fxType"];
SetGameplayMods(beat, fxType, flow["type"], flow["toggle"]); SetGameplayMods(beat, fxType, flow["type"], flow["toggle"]);
} }
@ -792,19 +802,19 @@ namespace HeavenStudio.Games
private void Update() private void Update()
{ {
var cond = Conductor.instance; var songPos = conductor.songPositionInBeatsAsDouble;
var songPos = cond.songPositionInBeatsAsDouble;
if (!cond.isPlaying) { if (conductor != null && !conductor.isPlaying)
{
EntityPreCheck(songPos); EntityPreCheck(songPos);
} }
switch (currentBgEffect) switch (currentBgEffect)
{ {
case (int) BackgroundFXType.Sunburst: case (int)BackgroundFXType.Sunburst:
bgEffectAnimator.DoNormalizedAnimation("Sunburst", (float)(songPos * 0.5) % 1f); bgEffectAnimator.DoNormalizedAnimation("Sunburst", (float)(songPos * 0.5) % 1f);
break; break;
case (int) BackgroundFXType.Rings: case (int)BackgroundFXType.Rings:
bgEffectAnimator.DoNormalizedAnimation("Rings", (float)(songPos * 0.5) % 1f); bgEffectAnimator.DoNormalizedAnimation("Rings", (float)(songPos * 0.5) % 1f);
break; break;
default: default:
@ -812,7 +822,8 @@ namespace HeavenStudio.Games
break; break;
} }
if (songPos >= wordClearTime || songPos < wordStartTime) { if (songPos >= wordClearTime || songPos < wordStartTime)
{
Word.Play("NoPose"); Word.Play("NoPose");
} }
@ -823,7 +834,7 @@ namespace HeavenStudio.Games
float camZ = 0f; float camZ = 0f;
if (songPos <= startCamSpecial + cameraReturnLength) if (songPos <= startCamSpecial + cameraReturnLength)
{ {
float prog = cond.GetPositionFromBeat(startCamSpecial, cameraReturnLength); float prog = conductor.GetPositionFromBeat(startCamSpecial, cameraReturnLength);
camX = Util.EasingFunction.EaseOutCubic(CameraPosition[0].position.x, CameraPosition[1].position.x, prog); camX = Util.EasingFunction.EaseOutCubic(CameraPosition[0].position.x, CameraPosition[1].position.x, prog);
camY = Util.EasingFunction.EaseOutCubic(CameraPosition[0].position.y, CameraPosition[1].position.y, prog); camY = Util.EasingFunction.EaseOutCubic(CameraPosition[0].position.y, CameraPosition[1].position.y, prog);
camZ = Util.EasingFunction.EaseOutCubic(CameraPosition[0].position.z, CameraPosition[1].position.z, prog); camZ = Util.EasingFunction.EaseOutCubic(CameraPosition[0].position.z, CameraPosition[1].position.z, prog);
@ -831,7 +842,7 @@ namespace HeavenStudio.Games
} }
else if (songPos >= wantsReturn - cameraReturnLength) else if (songPos >= wantsReturn - cameraReturnLength)
{ {
float prog = cond.GetPositionFromBeat(wantsReturn - cameraReturnLength, cameraReturnLength); float prog = conductor.GetPositionFromBeat(wantsReturn - cameraReturnLength, cameraReturnLength);
camX = Util.EasingFunction.EaseOutQuad(CameraPosition[1].position.x, CameraPosition[0].position.x, prog); camX = Util.EasingFunction.EaseOutQuad(CameraPosition[1].position.x, CameraPosition[0].position.x, prog);
camY = Util.EasingFunction.EaseOutQuad(CameraPosition[1].position.y, CameraPosition[0].position.y, prog); camY = Util.EasingFunction.EaseOutQuad(CameraPosition[1].position.y, CameraPosition[0].position.y, prog);
camZ = Util.EasingFunction.EaseOutQuad(CameraPosition[1].position.z, CameraPosition[0].position.z, prog); camZ = Util.EasingFunction.EaseOutQuad(CameraPosition[1].position.z, CameraPosition[0].position.z, prog);
@ -856,10 +867,12 @@ namespace HeavenStudio.Games
private void OnDestroy() private void OnDestroy()
{ {
foreach (var evt in scheduledInputs) { foreach (var evt in scheduledInputs)
{
evt.Disable(); evt.Disable();
} }
if (!Conductor.instance.NotStopped()) { if (!Conductor.instance.NotStopped())
{
if (queuedCues.Count > 0) queuedCues.Clear(); if (queuedCues.Count > 0) queuedCues.Clear();
startCamSpecial = double.MinValue; startCamSpecial = double.MinValue;
wantsReturn = double.MinValue; wantsReturn = double.MinValue;
@ -888,7 +901,8 @@ namespace HeavenStudio.Games
public static string DoWordSound(double beat, double length, int type, bool bpmPitch = false, float forcePitch = 1, bool customLength = false, bool doSound = true) public static string DoWordSound(double beat, double length, int type, bool bpmPitch = false, float forcePitch = 1, bool customLength = false, bool doSound = true)
{ {
double clear = type switch { double clear = type switch
{
<= (int)HitThree.HitFour => beat + 4f, <= (int)HitThree.HitFour => beat + 4f,
<= (int)HitThree.Warning => beat + 1f, <= (int)HitThree.Warning => beat + 1f,
_ => beat + 3f, _ => beat + 3f,
@ -907,7 +921,8 @@ namespace HeavenStudio.Games
} }
var songPos = Conductor.instance.songPositionInBeatsAsDouble; var songPos = Conductor.instance.songPositionInBeatsAsDouble;
if (songPos <= clear && songPos >= beat) { if (songPos <= clear && songPos >= beat)
{
wordClearTime = customLength ? (beat + length) : clear; wordClearTime = customLength ? (beat + length) : clear;
wordStartTime = beat; wordStartTime = beat;
} }
@ -926,13 +941,15 @@ namespace HeavenStudio.Games
public static void CreateBulbSFX(double beat, int type, int sfx, string throwSfx) public static void CreateBulbSFX(double beat, int type, int sfx, string throwSfx)
{ {
string obj = sfx switch { string obj = sfx switch
{
(int)LightBulbSfx.Automatic => type == (int)LightBulbType.Yellow ? "LightbulbNtr" : "Lightbulb", (int)LightBulbSfx.Automatic => type == (int)LightBulbType.Yellow ? "LightbulbNtr" : "Lightbulb",
(int)LightBulbSfx.DS => "LightbulbNtr", (int)LightBulbSfx.DS => "LightbulbNtr",
(int)LightBulbSfx.Custom => throwSfx, (int)LightBulbSfx.Custom => throwSfx,
_ => "Lightbulb", _ => "Lightbulb",
}; };
if (sfx != (int)LightBulbSfx.Custom) { if (sfx != (int)LightBulbSfx.Custom)
{
obj = (beat % 1.0 == 0.5) ? $"offbeat{obj}Out" : obj.ToLower() + "Out"; obj = (beat % 1.0 == 0.5) ? $"offbeat{obj}Out" : obj.ToLower() + "Out";
} }
SoundByte.PlayOneShotGame($"karateman/{obj}", forcePlay: true); SoundByte.PlayOneShotGame($"karateman/{obj}", forcePlay: true);
@ -942,29 +959,29 @@ namespace HeavenStudio.Games
{ {
switch (type) switch (type)
{ {
case (int) HitType.Pot: case (int)HitType.Pot:
CreateItemInstance(beat, "Item00", expression); CreateItemInstance(beat, "Item00", expression);
break; break;
case (int) HitType.Lightbulb: case (int)HitType.Lightbulb:
var mobj = CreateItemInstance(beat, "Item01", expression, KarateManPot.ItemType.Bulb); var mobj = CreateItemInstance(beat, "Item01", expression, KarateManPot.ItemType.Bulb);
mobj.SetBulbColor(LightBulbColors[0]); mobj.SetBulbColor(LightBulbColors[0]);
break; break;
case (int) HitType.Rock: case (int)HitType.Rock:
CreateItemInstance(beat, "Item02", expression, KarateManPot.ItemType.Rock); CreateItemInstance(beat, "Item02", expression, KarateManPot.ItemType.Rock);
break; break;
case (int) HitType.Ball: case (int)HitType.Ball:
CreateItemInstance(beat, "Item03", expression, KarateManPot.ItemType.Ball); CreateItemInstance(beat, "Item03", expression, KarateManPot.ItemType.Ball);
break; break;
case (int) HitType.CookingPot: case (int)HitType.CookingPot:
CreateItemInstance(beat, "Item06", expression, KarateManPot.ItemType.Cooking); CreateItemInstance(beat, "Item06", expression, KarateManPot.ItemType.Cooking);
break; break;
case (int) HitType.Alien: case (int)HitType.Alien:
CreateItemInstance(beat, "Item07", expression, KarateManPot.ItemType.Alien); CreateItemInstance(beat, "Item07", expression, KarateManPot.ItemType.Alien);
break; break;
case (int) HitType.Bomb: case (int)HitType.Bomb:
CreateItemInstance(beat, "Item04", expression, KarateManPot.ItemType.Bomb); CreateItemInstance(beat, "Item04", expression, KarateManPot.ItemType.Bomb);
break; break;
case (int) HitType.TacoBell: case (int)HitType.TacoBell:
CreateItemInstance(beat, "Item99", expression, KarateManPot.ItemType.TacoBell); CreateItemInstance(beat, "Item99", expression, KarateManPot.ItemType.TacoBell);
break; break;
default: default:
@ -975,7 +992,8 @@ namespace HeavenStudio.Games
public void CreateBulbSpecial(double beat, int type, Color color, int expression, int sfx, string hitSfx = "") public void CreateBulbSpecial(double beat, int type, Color color, int expression, int sfx, string hitSfx = "")
{ {
string obj = sfx switch { string obj = sfx switch
{
(int)LightBulbSfx.Automatic => type == (int)LightBulbType.Yellow ? "LightbulbNtr" : "Lightbulb", (int)LightBulbSfx.Automatic => type == (int)LightBulbType.Yellow ? "LightbulbNtr" : "Lightbulb",
(int)LightBulbSfx.DS => "LightbulbNtr", (int)LightBulbSfx.DS => "LightbulbNtr",
(int)LightBulbSfx.Custom => hitSfx, (int)LightBulbSfx.Custom => hitSfx,
@ -1088,7 +1106,8 @@ namespace HeavenStudio.Games
{ {
currentBgEffect = fxType; currentBgEffect = fxType;
for (int i = 0; i < colorStarts.Length; i++) { for (int i = 0; i < colorStarts.Length; i++)
{
colorStartBeats[i] = beat; colorStartBeats[i] = beat;
colorLengths[i] = length; colorLengths[i] = length;
colorEases[i] = (Util.EasingFunction.Ease)colorEaseSet; colorEases[i] = (Util.EasingFunction.Ease)colorEaseSet;
@ -1111,7 +1130,8 @@ namespace HeavenStudio.Games
autoColor ? TintColor(bgColorEnd) : filterEnd, autoColor ? TintColor(bgColorEnd) : filterEnd,
}; };
for (int i = 0; i < BGTextures.Length; i++) { for (int i = 0; i < BGTextures.Length; i++)
{
BGTextures[i].gameObject.SetActive(textureType == (i + 1)); BGTextures[i].gameObject.SetActive(textureType == (i + 1));
} }
@ -1137,7 +1157,8 @@ namespace HeavenStudio.Games
func(colorStarts[i].b, colorEnds[i].b, normalizedBeat), func(colorStarts[i].b, colorEnds[i].b, normalizedBeat),
}; };
foreach (var renderer in spriteRenderers[i]) { foreach (var renderer in spriteRenderers[i])
{
renderer.color = new Color(color[0], color[1], color[2]); renderer.color = new Color(color[0], color[1], color[2]);
} }
} }
@ -1169,7 +1190,8 @@ namespace HeavenStudio.Games
public void SetParticleEffect(double beat, int type, bool instant, float windStrength, float particleStrength) public void SetParticleEffect(double beat, int type, bool instant, float windStrength, float particleStrength)
{ {
if (type == (int) ParticleType.None) { if (type == (int)ParticleType.None)
{
foreach (var eff in Effects) eff.Stop(); foreach (var eff in Effects) eff.Stop();
return; return;
} }

View file

@ -382,6 +382,8 @@ namespace HeavenStudio.Games.Scripts_KarateMan
public void UpdateJoeColour() public void UpdateJoeColour()
{ {
Material mappingMat = KarateMan.instance.MappingMaterial;
if (mappingMat == null) return;
Color mainCol = KarateMan.instance.BodyColor; Color mainCol = KarateMan.instance.BodyColor;
Color highlightCol = KarateMan.instance.HighlightColor; Color highlightCol = KarateMan.instance.HighlightColor;
@ -391,9 +393,9 @@ namespace HeavenStudio.Games.Scripts_KarateMan
mainCol = Color.LerpUnclamped(mainCol, BombGlowTint, bombGlowIntensity * bombGlowRatio); mainCol = Color.LerpUnclamped(mainCol, BombGlowTint, bombGlowIntensity * bombGlowRatio);
} }
KarateMan.instance.MappingMaterial.SetColor("_ColorAlpha", mainCol); mappingMat.SetColor("_ColorAlpha", mainCol);
KarateMan.instance.MappingMaterial.SetColor("_ColorBravo", new Color(1, 0, 0, 1)); mappingMat.SetColor("_ColorBravo", new Color(1, 0, 0, 1));
KarateMan.instance.MappingMaterial.SetColor("_ColorDelta", highlightCol); mappingMat.SetColor("_ColorDelta", highlightCol);
} }
public void Prepare(double beat, float length) public void Prepare(double beat, float length)

View file

@ -52,6 +52,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
public void SetNoriMode(double fromBeat, int mode, int startingNori = 0) public void SetNoriMode(double fromBeat, int mode, int startingNori = 0)
{ {
if (GameManager.instance == null) return;
float scaleFactor = 0f; float scaleFactor = 0f;
//clear all children of the holder //clear all children of the holder
if (NoriHolder != null) { if (NoriHolder != null) {
@ -288,6 +289,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
void Update() void Update()
{ {
if (Conductor.instance == null) return;
Transform target = GameCamera.instance.transform; Transform target = GameCamera.instance.transform;
Vector3 displacement = target.forward * CameraOffset; Vector3 displacement = target.forward * CameraOffset;

View file

@ -32,5 +32,8 @@ MonoBehaviour:
- Assets/Scripts/JudgementManager.cs - Assets/Scripts/JudgementManager.cs
- Assets/Scripts/LevelEditor/RemixPropertiesDialog/PropertyPrefabs/RatingScreenPropertyDialog.cs - Assets/Scripts/LevelEditor/RemixPropertiesDialog/PropertyPrefabs/RatingScreenPropertyDialog.cs
- Assets/Scripts/GlobalGameManager.cs - Assets/Scripts/GlobalGameManager.cs
- Assets/Scripts/Games/KarateMan/KarateMan.cs
- Assets/Scripts/Games/KarateMan/KarateManJoe.cs
- Assets/Scripts/Games/KarateMan/KarateManNoriController.cs
PathsToSkipImportEvent: [] PathsToSkipImportEvent: []
PathsToIgnoreOverwriteSettingOnAttribute: [] PathsToIgnoreOverwriteSettingOnAttribute: []