Repository navigation
Expand file tree
/
Copy pathAssets.cs
More file actions
85 lines (69 loc) · 2.85 KB
/
Copy pathAssets.cs
File metadata and controls
85 lines (69 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.IO;
using System.Reflection;
using REPOLib;
using REPOLib.Modules;
using UnityEngine;
namespace ExtractionPointConfirmButtonNext;
internal static class Assets
{
private const string ConfirmButtonBundleFileName = "extractionpointconfirmbutton_assets";
private const string ConfirmButtonAssetName = "ConfirmButton";
private static bool _loadAttempted;
public static GameObject? ConfirmButtonPrefab { get; private set; }
public static PrefabRef? ConfirmButtonPrefabRef { get; private set; }
public static bool IsReady => ConfirmButtonPrefab && ConfirmButtonPrefabRef != null;
public static void Initialize()
{
if (_loadAttempted)
{
return;
}
_loadAttempted = true;
string? pluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (string.IsNullOrWhiteSpace(pluginDirectory))
{
ExtractionPointConfirmButtonNext.Logger.LogError("Failed to load confirm button assets. Plugin directory was not found.");
return;
}
string bundlePath = Path.Combine(pluginDirectory, ConfirmButtonBundleFileName);
if (!File.Exists(bundlePath))
{
ExtractionPointConfirmButtonNext.Logger.LogError(
$"Failed to load confirm button assets. Missing \"{ConfirmButtonBundleFileName}\" next to the plugin DLL.");
return;
}
ExtractionPointConfirmButtonNext.Logger.LogInfo($"Loading confirm button assets from \"{bundlePath}\".");
BundleLoader.LoadBundle(bundlePath, (Action<AssetBundle>)OnAssetBundleLoaded, false);
}
private static void OnAssetBundleLoaded(AssetBundle assetBundle)
{
ConfirmButtonPrefab = LoadAsset<GameObject>(ConfirmButtonAssetName, assetBundle);
if (ConfirmButtonPrefab == null)
{
return;
}
ConfirmButtonPrefabRef = NetworkPrefabs.RegisterNetworkPrefab(ConfirmButtonPrefab);
if (ConfirmButtonPrefabRef == null)
{
ExtractionPointConfirmButtonNext.Logger.LogError("Failed to register confirm button network prefab.");
return;
}
ExtractionPointConfirmButtonNext.Logger.LogInfo("Confirm button asset loaded and network prefab registered.");
}
private static T? LoadAsset<T>(string name, AssetBundle assetBundle) where T : UnityEngine.Object
{
if (!assetBundle)
{
ExtractionPointConfirmButtonNext.Logger.LogError($"Failed to load asset \"{name}\". AssetBundle is null.");
return null;
}
T asset = assetBundle.LoadAsset<T>(name);
if (!asset)
{
ExtractionPointConfirmButtonNext.Logger.LogError($"Failed to load asset \"{name}\" from confirm button AssetBundle.");
return null;
}
return asset;
}
}