split skin assets into seperate async bundle

This commit is contained in:
_nebula 2023-10-29 23:55:44 +00:00
parent 4ab010637f
commit 64d83fcf15
4 changed files with 56 additions and 17 deletions

Binary file not shown.

BIN
QSB/AssetBundles/qsb_skins Normal file

Binary file not shown.

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using OWML.Common;
using QSB.Utility;
using UnityEngine;
@ -14,8 +15,19 @@ public class BodyCustomizer : MonoBehaviour, IAddComponentOnStart
private void Start()
{
Instance = this;
QSBCore.OnSkinsBundleLoaded += LoadAssets;
}
skinMap.Add("Default", (QSBCore.BigBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Traveller_HEA_Player_Skin_d.png"), QSBCore.BigBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Traveller_HEA_Player_Skin_n.png")));
private void OnDestroy()
{
QSBCore.OnSkinsBundleLoaded -= LoadAssets;
}
private void LoadAssets()
{
DebugLog.DebugWrite($"Loading skin assets...", MessageType.Info);
skinMap.Add("Default", (QSBCore.SkinsBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Traveller_HEA_Player_Skin_d.png"), QSBCore.SkinsBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Traveller_HEA_Player_Skin_n.png")));
skinMap.Add("Type 1", LoadSkin("Type 1"));
skinMap.Add("Type 2", LoadSkin("Type 2"));
skinMap.Add("Type 3", LoadSkin("Type 3"));
@ -34,7 +46,7 @@ public class BodyCustomizer : MonoBehaviour, IAddComponentOnStart
skinMap.Add("Type 16", LoadSkin("Type 16"));
skinMap.Add("Type 17", LoadSkin("Type 17"));
jetpackMap.Add("Orange", QSBCore.BigBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Props_HEA_Jetpack_d.png"));
jetpackMap.Add("Orange", QSBCore.SkinsBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Props_HEA_Jetpack_d.png"));
jetpackMap.Add("Yellow", LoadJetpack("yellow"));
jetpackMap.Add("Red", LoadJetpack("red"));
jetpackMap.Add("Pink", LoadJetpack("pink"));
@ -48,12 +60,12 @@ public class BodyCustomizer : MonoBehaviour, IAddComponentOnStart
private (Texture2D d, Texture2D n) LoadSkin(string skinName)
{
var number = skinName.Replace($"Type ", "");
return (QSBCore.BigBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Skin Variations/{number}d.png"), QSBCore.BigBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Skin Variations/{number}n.png"));
return (QSBCore.SkinsBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Skin Variations/{number}d.png"), QSBCore.SkinsBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Skin Variations/{number}n.png"));
}
private Texture2D LoadJetpack(string jetpackName)
{
return QSBCore.BigBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Jetpack Variations/{jetpackName}.png");
return QSBCore.SkinsBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Jetpack Variations/{jetpackName}.png");
}
public void CustomizeRemoteBody(GameObject REMOTE_Traveller_HEA_Player_v2, string skinType, string jetpackType)

View File

@ -14,6 +14,7 @@ using QSB.WorldSync;
using Steamworks;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
@ -54,7 +55,7 @@ public class QSBCore : ModBehaviour
public static AssetBundle ConversationAssetBundle { get; private set; }
public static AssetBundle DebugAssetBundle { get; private set; }
public static AssetBundle HUDAssetBundle { get; private set; }
public static AssetBundle BigBundle { get; private set; }
public static AssetBundle SkinsBundle { get; private set; }
public static bool IsHost => NetworkServer.active;
public static bool IsInMultiplayer;
public static string QSBVersion => Helper.Manifest.Version;
@ -78,8 +79,6 @@ public class QSBCore : ModBehaviour
public static IMenuAPI MenuApi { get; private set; }
public static DebugSettings DebugSettings { get; private set; } = new();
public const string NEW_HORIZONS = "xen.NewHorizons";
public const string NEW_HORIZONS_COMPAT = "xen.NHQSBCompat";
public static readonly string[] IncompatibleMods =
{
@ -92,6 +91,8 @@ public class QSBCore : ModBehaviour
"PacificEngine.OW_Randomizer",
};
public static event Action OnSkinsBundleLoaded;
public override object GetApi() => new QSBAPI();
private static void DetermineGameVendor()
@ -258,18 +259,19 @@ public class QSBCore : ModBehaviour
MenuApi = ModHelper.Interaction.TryGetModApi<IMenuAPI>(ModHelper.Manifest.Dependencies[0]);
DebugLog.DebugWrite("loading qsb_network_big bundle", MessageType.Info);
var path = Path.Combine(ModHelper.Manifest.ModFolderPath, "AssetBundles/qsb_network_big");
var request = AssetBundle.LoadFromFileAsync(path);
request.completed += _ => DebugLog.DebugWrite("qsb_network_big bundle loaded", MessageType.Success);
BigBundle = request.assetBundle;
LoadBundleAsync("qsb_network_big");
LoadBundleAsync("qsb_skins", request =>
{
SkinsBundle = request.assetBundle;
OnSkinsBundleLoaded?.SafeInvoke();
});
NetworkAssetBundle = Helper.Assets.LoadBundle("AssetBundles/qsb_network");
ConversationAssetBundle = Helper.Assets.LoadBundle("AssetBundles/qsb_conversation");
DebugAssetBundle = Helper.Assets.LoadBundle("AssetBundles/qsb_debug");
HUDAssetBundle = Helper.Assets.LoadBundle("AssetBundles/qsb_hud");
NetworkAssetBundle = LoadBundle("qsb_network");
ConversationAssetBundle = LoadBundle("qsb_conversation");
DebugAssetBundle = LoadBundle("qsb_debug");
HUDAssetBundle = LoadBundle("qsb_hud");
if (NetworkAssetBundle == null || ConversationAssetBundle == null || DebugAssetBundle == null)
if (NetworkAssetBundle == null || ConversationAssetBundle == null || DebugAssetBundle == null || HUDAssetBundle == null)
{
DebugLog.ToConsole($"FATAL - An assetbundle is missing! Re-install mod or contact devs.", MessageType.Fatal);
return;
@ -287,6 +289,31 @@ public class QSBCore : ModBehaviour
QSBPatchManager.OnUnpatchType += OnUnpatchType;
}
private AssetBundle LoadBundle(string name)
{
var timer = new Stopwatch();
timer.Start();
var ret = Helper.Assets.LoadBundle($"AssetBundles/{name}");
timer.Stop();
DebugLog.ToConsole($"Bundle {name} loaded in {timer.ElapsedMilliseconds} ms!", MessageType.Success);
return ret;
}
private void LoadBundleAsync(string bundleName, Action<AssetBundleCreateRequest> runOnLoaded = null)
{
DebugLog.DebugWrite($"Loading {bundleName}...", MessageType.Info);
var timer = new Stopwatch();
timer.Start();
var path = Path.Combine(ModHelper.Manifest.ModFolderPath, $"AssetBundles/{bundleName}");
var request = AssetBundle.LoadFromFileAsync(path);
request.completed += _ =>
{
timer.Stop();
DebugLog.ToConsole($"Bundle {bundleName} loaded in {timer.ElapsedMilliseconds} ms!", MessageType.Success);
runOnLoaded?.Invoke(request);
};
}
private static void OnPatchType(QSBPatchTypes type)
{
if (type == QSBPatchTypes.OnClientConnect)