mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-09 11:15:07 +00:00
Game loading optimization
This commit is contained in:
parent
90f03dc4ff
commit
581435fe5d
15 changed files with 25229 additions and 25059 deletions
8
Assets/Resources/Games.meta
Normal file
8
Assets/Resources/Games.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c04ea7a42d21b13459ecf762850e629f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3500
Assets/Resources/Games/clappyTrio.prefab
Normal file
3500
Assets/Resources/Games/clappyTrio.prefab
Normal file
File diff suppressed because it is too large
Load diff
7
Assets/Resources/Games/clappyTrio.prefab.meta
Normal file
7
Assets/Resources/Games/clappyTrio.prefab.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 173e013ff4d3a9840a07c87396707723
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3132
Assets/Resources/Games/forkLifter.prefab
Normal file
3132
Assets/Resources/Games/forkLifter.prefab
Normal file
File diff suppressed because it is too large
Load diff
7
Assets/Resources/Games/forkLifter.prefab.meta
Normal file
7
Assets/Resources/Games/forkLifter.prefab.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ad00d37ecb55f634fa1c43e1b85dd5bf
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12044
Assets/Resources/Games/karateman.prefab
Normal file
12044
Assets/Resources/Games/karateman.prefab
Normal file
File diff suppressed because it is too large
Load diff
7
Assets/Resources/Games/karateman.prefab.meta
Normal file
7
Assets/Resources/Games/karateman.prefab.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0b1209c434c230e4ea7a17b19b76849c
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
6335
Assets/Resources/Games/spaceball.prefab
Normal file
6335
Assets/Resources/Games/spaceball.prefab
Normal file
File diff suppressed because it is too large
Load diff
7
Assets/Resources/Games/spaceball.prefab.meta
Normal file
7
Assets/Resources/Games/spaceball.prefab.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bf2953f802dad28418241082be985e95
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -73,17 +73,17 @@ AnimationClip:
|
|||
- serializedVersion: 3
|
||||
time: 0.28333333
|
||||
value: {x: 0.69, y: 1.73, z: 0}
|
||||
inSlope: {x: -8.095612, y: 0, z: 0}
|
||||
outSlope: {x: -8.095612, y: 0, z: 0}
|
||||
inSlope: {x: -6.840001, y: 0, z: 0}
|
||||
outSlope: {x: -6.840001, y: 0, z: 0}
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
|
||||
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
|
||||
- serializedVersion: 3
|
||||
time: 0.68333334
|
||||
value: {x: -0.693, y: -0.137, z: 0}
|
||||
inSlope: {x: -2.251914, y: -5.50851, z: 0}
|
||||
outSlope: {x: -2.251914, y: -5.50851, z: 0}
|
||||
value: {x: -0.7602383, y: -0.137, z: 0}
|
||||
inSlope: {x: -1.3614501, y: -5.50851, z: 0}
|
||||
outSlope: {x: -1.3614501, y: -5.50851, z: 0}
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
|
||||
|
@ -91,11 +91,11 @@ AnimationClip:
|
|||
- serializedVersion: 3
|
||||
time: 1.0666667
|
||||
value: {x: -1.134, y: -2.585, z: 0}
|
||||
inSlope: {x: 0, y: -2.739737, z: 0}
|
||||
outSlope: {x: 0, y: -2.739737, z: 0}
|
||||
inSlope: {x: -1.4613318, y: -2.739737, z: 0}
|
||||
outSlope: {x: -1.4613318, y: -2.739737, z: 0}
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: {x: 0.33333334, y: 0.30750114, z: 0.33333334}
|
||||
inWeight: {x: 0.13127278, y: 0.30750114, z: 0.33333334}
|
||||
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
|
@ -537,17 +537,8 @@ AnimationClip:
|
|||
- serializedVersion: 3
|
||||
time: 0.28333333
|
||||
value: 0.69
|
||||
inSlope: -8.095612
|
||||
outSlope: -8.095612
|
||||
tangentMode: 136
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.68333334
|
||||
value: -0.693
|
||||
inSlope: -2.251914
|
||||
outSlope: -2.251914
|
||||
inSlope: -6.840001
|
||||
outSlope: -6.840001
|
||||
tangentMode: 136
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
|
@ -555,11 +546,11 @@ AnimationClip:
|
|||
- serializedVersion: 3
|
||||
time: 1.0666667
|
||||
value: -1.134
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 136
|
||||
inSlope: -1.4613318
|
||||
outSlope: -1.4613318
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
inWeight: 0.13127278
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
|
|
25017
Assets/Scenes/Game.unity
25017
Assets/Scenes/Game.unity
File diff suppressed because it is too large
Load diff
|
@ -74,6 +74,14 @@ namespace RhythmHeavenMania
|
|||
public void Play(float startBeat)
|
||||
{
|
||||
timeKeeper.Play();
|
||||
SetTime(startBeat);
|
||||
}
|
||||
|
||||
public void SetTime(float startBeat)
|
||||
{
|
||||
musicSource.time = GetSongPosFromBeat(startBeat);
|
||||
songPositionInBeats = musicSource.time / secPerBeat;
|
||||
GameManager.instance.SetCurrentEventToClosest(songPositionInBeats);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
|
@ -83,12 +91,9 @@ namespace RhythmHeavenMania
|
|||
//determine how many seconds since the song started
|
||||
// songPosition = (float)(timeKeeper.dspTime - dspSongTime - firstBeatOffset);
|
||||
songPosition = (float)timeKeeper.GetCurrentTimeInSong();
|
||||
print(songPosition);
|
||||
|
||||
//determine how many beats since the song started
|
||||
songPositionInBeats = songPosition / secPerBeat;
|
||||
// print($"{mst_f}(AudioSource.time), {Time.frameCount}(Time.fasrameCount)");
|
||||
// print($"{musicSource.time}(0), {songPosition}");
|
||||
|
||||
|
||||
//calculate the loop position
|
||||
|
@ -105,6 +110,11 @@ namespace RhythmHeavenMania
|
|||
return a;
|
||||
}
|
||||
|
||||
private float GetSongPosFromBeat(float beat)
|
||||
{
|
||||
return secPerBeat * beat;
|
||||
}
|
||||
|
||||
public void SetBpm(float bpm)
|
||||
{
|
||||
this.songBpm = bpm;
|
||||
|
|
|
@ -107,9 +107,18 @@ namespace RhythmHeavenMania
|
|||
})
|
||||
};
|
||||
|
||||
for (int i = 1; i < minigames.Count; i++)
|
||||
List<MiniGame> minigamesInBeatmap = new List<MiniGame>();
|
||||
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
|
||||
{
|
||||
minigames[i].holder = GamesHolder.Find(minigames[i].name).gameObject;
|
||||
if (!minigamesInBeatmap.Contains(minigames.Find(c => c.name == GameManager.instance.Beatmap.entities[i].datamodel.Split('/')[0])) && GameManager.instance.Beatmap.entities[i].datamodel.Split('/')[0] != "gameManager")
|
||||
{
|
||||
minigamesInBeatmap.Add(minigames.Find(c => c.name == GameManager.instance.Beatmap.entities[i].datamodel.Split('/')[0]));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < minigamesInBeatmap.Count; i++)
|
||||
{
|
||||
minigames[minigames.FindIndex(c => c.name == minigamesInBeatmap[i].name)].holder = Resources.Load<GameObject>($"Games/{minigamesInBeatmap[i].name}");
|
||||
}
|
||||
|
||||
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
|
||||
|
@ -124,6 +133,7 @@ namespace RhythmHeavenMania
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Debug.LogWarning(GameManager.instance.Beatmap.entities[i].datamodel);
|
||||
Debug.LogWarning(ex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,10 @@ namespace RhythmHeavenMania
|
|||
|
||||
public float startBeat;
|
||||
|
||||
private GameObject currentGameO;
|
||||
|
||||
private List<GameObject> preloadedGames = new List<GameObject>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
|
@ -68,7 +72,7 @@ namespace RhythmHeavenMania
|
|||
private IEnumerator Begin()
|
||||
{
|
||||
yield return new WaitForSeconds(startOffset);
|
||||
Conductor.instance.Play(0);
|
||||
Conductor.instance.Play(startBeat);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
@ -80,14 +84,14 @@ namespace RhythmHeavenMania
|
|||
|
||||
if (Input.GetKeyDown(KeyCode.A))
|
||||
{
|
||||
Conductor.instance.musicSource.time += 3;
|
||||
SetCurrentEventToClosest();
|
||||
Conductor.instance.SetTime(Conductor.instance.songPositionInBeats + 3);
|
||||
|
||||
GetGame(currentGame).holder.GetComponent<Minigame>().OnTimeChange();
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.S))
|
||||
{
|
||||
Conductor.instance.musicSource.time -= 3;
|
||||
SetCurrentEventToClosest();
|
||||
Conductor.instance.SetTime(Conductor.instance.songPositionInBeats - 3);
|
||||
|
||||
GetGame(currentGame).holder.GetComponent<Minigame>().OnTimeChange();
|
||||
}
|
||||
|
||||
|
@ -98,17 +102,26 @@ namespace RhythmHeavenMania
|
|||
if (Conductor.instance.songPositionInBeats >= entities[currentEvent])
|
||||
{
|
||||
// allows for multiple events on the same beat to be executed on the same frame, so no more 1-frame delay
|
||||
List<Beatmap.Entity> entitesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat);
|
||||
var entitesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && c.datamodel.Split('/')[0] != "gameManager");
|
||||
var gameManagerEntities = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && c.datamodel.Split('/')[0] == "gameManager");
|
||||
|
||||
// GameManager entities should ALWAYS execute before gameplay entities
|
||||
for (int i = 0; i < gameManagerEntities.Count; i++)
|
||||
{
|
||||
eventCaller.CallEvent(gameManagerEntities[i].datamodel);
|
||||
}
|
||||
|
||||
for (int i = 0; i < entitesAtSameBeat.Count; i++)
|
||||
{
|
||||
// if game isn't loaded, preload game so whatever event that would be called will still run outside if needed
|
||||
if (entitesAtSameBeat[i].datamodel.Split('/')[0] != currentGame && !preloadedGames.Contains(preloadedGames.Find(c => c.name == entitesAtSameBeat[i].datamodel.Split('/')[0])))
|
||||
{
|
||||
PreloadGame(entitesAtSameBeat[i].datamodel.Split('/')[0]);
|
||||
}
|
||||
eventCaller.CallEvent(entitesAtSameBeat[i].datamodel);
|
||||
currentEvent++;
|
||||
}
|
||||
|
||||
// eventCaller.CallEvent(Beatmap.entities[currentEvent].datamodel);
|
||||
|
||||
// currentEvent++;
|
||||
currentEvent += entitesAtSameBeat.Count + gameManagerEntities.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,14 +131,22 @@ namespace RhythmHeavenMania
|
|||
Beatmap.entities.Sort((x, y) => x.beat.CompareTo(y.beat));
|
||||
}
|
||||
|
||||
public void SetCurrentEventToClosest()
|
||||
public void SetCurrentEventToClosest(float beat)
|
||||
{
|
||||
if (Beatmap.entities.Count > 0)
|
||||
{
|
||||
List<float> entities = Beatmap.entities.Select(c => c.beat).ToList();
|
||||
List<float> entities_p = playerEntities.Select(c => c.beat).ToList();
|
||||
currentEvent = entities.IndexOf(Mathp.GetClosestInList(entities, Conductor.instance.songPositionInBeats));
|
||||
currentPlayerEvent = entities_p.IndexOf(Mathp.GetClosestInList(entities_p, Conductor.instance.songPositionInBeats));
|
||||
currentEvent = entities.IndexOf(Mathp.GetClosestInList(entities, beat));
|
||||
currentPlayerEvent = entities_p.IndexOf(Mathp.GetClosestInList(entities_p, beat));
|
||||
|
||||
print(currentEvent);
|
||||
|
||||
string newGame = Beatmap.entities[currentEvent].datamodel.Split('/')[0];
|
||||
if (newGame != currentGame)
|
||||
{
|
||||
SwitchGame(newGame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,14 +169,30 @@ namespace RhythmHeavenMania
|
|||
|
||||
private void SetGame(string game, bool onGameSwitch = true)
|
||||
{
|
||||
if (onGameSwitch)
|
||||
Destroy(currentGameO);
|
||||
|
||||
var instantiate = true;
|
||||
|
||||
if (preloadedGames.Count > 0)
|
||||
{
|
||||
if (GetGame(currentGame).holder.GetComponent<Minigame>() != null)
|
||||
GetGame(currentGame).holder.GetComponent<Minigame>().OnGameSwitch();
|
||||
for (int i = 0; i < preloadedGames.Count; i++)
|
||||
{
|
||||
if (preloadedGames[i].gameObject.name == game)
|
||||
{
|
||||
preloadedGames[i].SetActive(true);
|
||||
currentGameO = preloadedGames[i];
|
||||
preloadedGames.Remove(preloadedGames[i]);
|
||||
instantiate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GetGame(currentGame).holder.SetActive(false);
|
||||
GetGame(game).holder.SetActive(true);
|
||||
if (instantiate)
|
||||
{
|
||||
currentGameO = Instantiate(GetGame(game).holder);
|
||||
currentGameO.transform.parent = eventCaller.GamesHolder.transform;
|
||||
currentGameO.name = game;
|
||||
}
|
||||
|
||||
GameCamera.orthographic = true;
|
||||
|
||||
|
@ -168,6 +205,18 @@ namespace RhythmHeavenMania
|
|||
SetCurrentGame(game);
|
||||
}
|
||||
|
||||
private void PreloadGame(string game)
|
||||
{
|
||||
if (preloadedGames.Contains(preloadedGames.Find(c => c.name == game)))
|
||||
return;
|
||||
|
||||
var g = Instantiate(GetGame(game).holder);
|
||||
g.transform.parent = eventCaller.GamesHolder.transform;
|
||||
g.SetActive(false);
|
||||
g.name = game;
|
||||
preloadedGames.Add(g);
|
||||
}
|
||||
|
||||
public EventCaller.MiniGame GetGame(string name)
|
||||
{
|
||||
return eventCaller.minigames.Find(c => c.name == name);
|
||||
|
|
|
@ -165,7 +165,7 @@
|
|||
"datamodel":"spaceball/shoot"
|
||||
},
|
||||
{
|
||||
"beat": 65,
|
||||
"beat": 64.75,
|
||||
"datamodel":"gameManager/switchGame/clappyTrio"
|
||||
},
|
||||
{
|
||||
|
@ -228,7 +228,7 @@
|
|||
},
|
||||
{
|
||||
"beat": 85,
|
||||
"datamodel": "karateman/pot"
|
||||
"datamodel": "karateman/bulb"
|
||||
},
|
||||
{
|
||||
"beat": 86,
|
||||
|
@ -242,5 +242,73 @@
|
|||
"beat": 87.5,
|
||||
"datamodel": "karateman/rock"
|
||||
},
|
||||
{
|
||||
"beat": 89,
|
||||
"datamodel":"gameManager/switchGame/spaceball"
|
||||
},
|
||||
{
|
||||
"beat": 90,
|
||||
"datamodel": "spaceball/shootHigh"
|
||||
},
|
||||
{
|
||||
"beat": 92,
|
||||
"datamodel": "spaceball/shoot"
|
||||
},
|
||||
{
|
||||
"beat": 93,
|
||||
"datamodel": "spaceball/shoot"
|
||||
},
|
||||
{
|
||||
"beat": 93.5,
|
||||
"datamodel": "spaceball/shoot"
|
||||
},
|
||||
{
|
||||
"beat": 97,
|
||||
"datamodel":"gameManager/switchGame/karateman"
|
||||
},
|
||||
{
|
||||
"beat": 97,
|
||||
"datamodel": "karateman/bgfxOn"
|
||||
},
|
||||
{
|
||||
"beat": 97,
|
||||
"datamodel": "karateman/bop"
|
||||
},
|
||||
{
|
||||
"beat": 98,
|
||||
"datamodel": "karateman/bop"
|
||||
},
|
||||
{
|
||||
"beat": 99,
|
||||
"datamodel": "karateman/bop"
|
||||
},
|
||||
{
|
||||
"beat": 99,
|
||||
"datamodel": "karateman/pot"
|
||||
},
|
||||
{
|
||||
"beat": 100,
|
||||
"datamodel": "karateman/bop"
|
||||
},
|
||||
{
|
||||
"beat": 101,
|
||||
"datamodel": "karateman/bop"
|
||||
},
|
||||
{
|
||||
"beat": 101,
|
||||
"datamodel": "karateman/pot"
|
||||
},
|
||||
{
|
||||
"beat": 102.5,
|
||||
"datamodel": "karateman/pot"
|
||||
},
|
||||
{
|
||||
"beat": 103,
|
||||
"datamodel": "karateman/pot"
|
||||
},
|
||||
{
|
||||
"beat": 103.5,
|
||||
"datamodel": "karateman/rock"
|
||||
},
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue