Skip to content

Commit 0e5dd7f

Browse files
author
Gregory Brutsche
committed
Cleaned up & fixed texture loading, as well as working on first load. No more messy behavior injection.
1 parent b734ac6 commit 0e5dd7f

2 files changed

Lines changed: 28 additions & 43 deletions

File tree

Decal-Loader.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
55
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
66
<Platforms>x64</Platforms>
7-
<Version>1.0.0.0</Version>
7+
<Version>1.1.0.0</Version>
88
<Copyright>Copyright © 2020</Copyright>
99
<Authors>Gregory</Authors>
1010
<Company>None</Company>
@@ -51,6 +51,10 @@
5151
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Volcanoids\Volcanoids_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
5252
<Private>false</Private>
5353
</Reference>
54+
<Reference Include="UnityEngine.ImageConversionModule">
55+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Volcanoids\Volcanoids_Data\Managed\UnityEngine.ImageConversionModule.dll</HintPath>
56+
<Private>false</Private>
57+
</Reference>
5458
<Reference Include="UnityEngine.InputLegacyModule">
5559
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Volcanoids\Volcanoids_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
5660
<Private>false</Private>

Plugin.cs

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,27 @@
1-
using System;
2-
using System.Collections;
3-
using System.IO;
1+
using System.IO;
42
using System.Linq;
53
using Base_Mod;
64
using JetBrains.Annotations;
75
using UnityEngine;
8-
using UnityEngine.SceneManagement;
96

107
namespace Decal_Loader {
118
[UsedImplicitly]
129
public class Plugin : BaseGameMod {
13-
protected override string ModName => "Decal-Loader";
10+
protected override string ModName => "Decal-Loader";
11+
private bool done;
12+
private DecalCategory category;
1413

1514
protected override void Init() {
1615
Database.Init(GetConfigPath(), GetConfigFile());
1716

1817
base.Init();
1918
}
2019

21-
protected override void OnIslandSceneLoaded(Scene scene, LoadSceneMode loadSceneMode) {
22-
base.OnIslandSceneLoaded(scene, loadSceneMode);
20+
protected override void OnDataSetup() {
21+
base.OnDataSetup();
2322

24-
var rootGameObject = scene.GetRootGameObjects()[0];
25-
if (!rootGameObject.HasComponent<LocalDecalLoader>()) {
26-
var localDecalLoader = rootGameObject.AddComponent<LocalDecalLoader>();
27-
localDecalLoader.loadImagePath = GetConfigPath();
28-
}
29-
}
30-
}
31-
32-
[UsedImplicitly]
33-
public class LocalDecalLoader : MonoBehaviour {
34-
public string loadImagePath;
35-
private bool done;
36-
private DecalCategory category;
37-
38-
[UsedImplicitly]
39-
public void Start() {
40-
if (done || !Directory.Exists(loadImagePath)) return;
23+
var loadImagePath = GetConfigPath();
24+
if (!Directory.Exists(loadImagePath)) return;
4125

4226
category = CreateDecalCategory();
4327

@@ -48,17 +32,15 @@ public void Start() {
4832
|| file.EndsWith(".bmp"));
4933

5034
foreach (var file in files) {
51-
var absoluteUri = new Uri(file).AbsoluteUri;
52-
var request = new WWW(absoluteUri);
53-
StartCoroutine(WaitForRequest(request));
35+
CreateDecal(file);
5436
}
5537

5638
done = true;
5739
}
5840

5941
private static DecalCategory CreateDecalCategory() {
6042
const string name = "Modded";
61-
var localizedString = new LocalizedString(".", name, name, name);
43+
var localizedString = new LocalizedString("decals.category.modded", name, ".");
6244
var category = ScriptableObject.CreateInstance<DecalCategory>();
6345
category.name = localizedString;
6446
category.NameLocalization = localizedString;
@@ -74,23 +56,15 @@ private static DecalCategory CreateDecalCategory() {
7456
return category;
7557
}
7658

77-
private IEnumerator WaitForRequest(WWW request) {
78-
yield return request;
79-
80-
if (request.error != null) {
81-
Debug.Log("Error: Request error.");
82-
yield break;
83-
}
84-
85-
var uri = request.url;
86-
var guid = Database.instance.GetGuidForUri(uri);
59+
private void CreateDecal(string file) {
60+
var guid = Database.instance.GetGuidForUri(file);
8761
if (guid == null) {
8862
guid = GUID.Create();
89-
Database.instance.Add(uri, (GUID) guid);
63+
Database.instance.Add(file, (GUID) guid);
9064
}
9165

92-
var decalResource = (DecalResource) ScriptableObject.CreateInstance(typeof(DecalResource));
93-
decalResource.Resource = request.texture;
66+
var decalResource = ScriptableObject.CreateInstance<DecalResource>();
67+
decalResource.Resource = LoadTexture(file);
9468
decalResource.Category = category;
9569

9670
RuntimeAssetStorage.Add(new[] {
@@ -100,7 +74,14 @@ private IEnumerator WaitForRequest(WWW request) {
10074
Labels = new string[0]
10175
}
10276
});
103-
Debug.Log($"Loaded decal: {uri}.");
77+
Debug.Log($"Loaded decal: {file}.");
78+
}
79+
80+
private Texture2D LoadTexture(string file) {
81+
var fileData = File.ReadAllBytes(file);
82+
var tex = new Texture2D(1, 1);
83+
tex.LoadImage(fileData);
84+
return tex;
10485
}
10586
}
10687
}

0 commit comments

Comments
 (0)