PathToUrl

This commit is contained in:
JohnCorby 2024-06-14 23:02:03 -07:00
parent 879b98bf2e
commit 396adcdbc6
3 changed files with 17 additions and 3 deletions

View File

@ -108,7 +108,7 @@ namespace NewHorizons.Utility.Files
{
DownloadHandlerAudioClip dh = new DownloadHandlerAudioClip(path, UnityEngine.AudioType.MPEG);
dh.compressed = true;
using (UnityWebRequest www = new UnityWebRequest(path, "GET", dh, null))
using (UnityWebRequest www = new UnityWebRequest(path.PathToUrl(), "GET", dh, null))
{
var result = www.SendWebRequest();
@ -127,7 +127,7 @@ namespace NewHorizons.Utility.Files
}
else
{
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(path, audioType))
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(path.PathToUrl(), audioType))
{
var result = www.SendWebRequest();

View File

@ -83,7 +83,7 @@ public class SlideReelAsyncImageLoader
yield break;
}
using UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url);
using UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url.PathToUrl());
yield return uwr.SendWebRequest();

View File

@ -1,3 +1,4 @@
using HarmonyLib;
using NewHorizons.External.Configs;
using NewHorizons.External.Modules.VariableSize;
using NewHorizons.External.SerializableData;
@ -15,6 +16,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using UnityEngine;
using UnityEngine.Networking;
using static NewHorizons.External.Modules.ParticleFieldModule;
using NomaiCoordinates = NewHorizons.External.Configs.StarSystemConfig.NomaiCoordinates;
@ -425,5 +427,17 @@ namespace NewHorizons.Utility
playerCameraEffectController._owCamera.postProcessingSettings.bloom.threshold = 0f;
playerCameraEffectController._owCamera.postProcessingSettings.eyeMaskEnabled = true;
}
/// <summary>
/// unity is STUPID and makes us use UnityWebRequest stuff.
/// so we have to do this to let it work with special characters.
/// </summary>
public static string PathToUrl(this string url) =>
$"file:///{url
.Replace('\\', '/')
.Split('/')
.Select(UnityWebRequest.EscapeURL)
.Join(delimiter: "/")
}";
}
}