Skip to content

Commit de99e72

Browse files
author
Stewart Miles
committed
Fixed PortableWebRequest to use UnityWebRequest in Unity 5.6
Unity 5.6 distributed UnityWebRequest in UnityEngine rather than the UnityEngine.UnityWebRequestModule assembly used in later versions. This was causing PortableWebRequest to display a warning when the DownloadHandler type wasn't found then fallback to the legacy WWW class instead. This changes PortableWebRequest to search both UnityEngine and UnityEngine.UnityWebRequestModule assemblies for UnityWebRequest module classes. Change-Id: Ia3988145bf627e8360475979ad04d37bf2a17666
1 parent 1d63735 commit de99e72

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

source/VersionHandlerImpl/src/PortableWebRequest.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,30 @@ private static bool FindAndCacheRequestTypeWww() {
324324
return requestType != null;
325325
}
326326

327+
/// <summary>
328+
/// Try to find a type in a list of assemblies.
329+
/// </summary>
330+
/// <param name="typeName">Fully qualified type name.</param>
331+
/// <param name="assemblyNames">Names of assemblies to search.</param>
332+
/// <returns>Type if successful, null otherwise.</returns>
333+
private static Type FindTypeInAssemblies(string typeName, IEnumerable<string> assemblyNames) {
334+
Type type = null;
335+
foreach (var assemblyName in assemblyNames) {
336+
type = Type.GetType(String.Format("{0}, {1}", typeName, assemblyName));
337+
if (type != null) break;
338+
}
339+
return type;
340+
}
341+
327342
/// <summary>
328343
/// Find and cache the UnityWebRequest type and associated classes.
329344
/// </summary>
330345
/// <returns>true if successful, false otherwise.</returns>
331346
private static bool FindAndCacheRequestTypeUnityWebRequest() {
332-
requestType = Type.GetType("UnityEngine.Networking.UnityWebRequest, " +
333-
"UnityEngine.UnityWebRequestModule");
347+
// These types moved between assemblies between Unity 5.x and Unity 2017.x
348+
var networkingAssemblyNames = new [] { "UnityEngine.UnityWebRequestModule", "UnityEngine" };
349+
requestType = FindTypeInAssemblies("UnityEngine.Networking.UnityWebRequest",
350+
networkingAssemblyNames);
334351
if (requestType != null) {
335352
postMethod = requestType.GetMethod("Post",
336353
new [] { typeof(String), typeof(WWWForm) });
@@ -357,8 +374,9 @@ private static bool FindAndCacheRequestTypeUnityWebRequest() {
357374
requestType = null;
358375
}
359376
}
360-
var downloadHandlerType = Type.GetType("UnityEngine.Networking.DownloadHandler, " +
361-
"UnityEngine.UnityWebRequestModule");
377+
378+
var downloadHandlerType = FindTypeInAssemblies("UnityEngine.Networking.DownloadHandler",
379+
networkingAssemblyNames);
362380
if (downloadHandlerType != null) {
363381
downloadHandlerDataProperty = downloadHandlerType.GetProperty("data");
364382
if (downloadHandlerDataProperty == null) {

0 commit comments

Comments
 (0)