-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from cs-util-com/feature/debugUis
Feature/debug uis
- Loading branch information
Showing
117 changed files
with
6,304 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
CsCore/CsCoreUnity/Plugins/CsCoreUnity/com/csutil/http/UnityRestFactoryV2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
using UnityEngine.Networking; | ||
|
||
namespace com.csutil.http { | ||
|
||
public class UnityRestFactoryV2 : RestFactory { | ||
|
||
public override RestRequest SendRequest(Uri uri, HttpMethod method) { | ||
if (ApplicationV2.platform.IsAnyOf(RuntimePlatform.WebGLPlayer)) { | ||
return MainThread.instance.ExecuteOnMainThread(() => { | ||
if (method.ToString() == "GET") { | ||
return new UnityRestRequest(UnityWebRequest.Get(uri)); | ||
} | ||
return new UnityRestRequest(new UnityWebRequest(uri, method.ToString())); | ||
}); | ||
} | ||
return base.SendRequest(uri, method); | ||
} | ||
|
||
public override async Task<long> GetCurrentPing(string ipOrUrl = DEFAULT_PING_IP, int timeoutInMs = DEFAULT_PING_TIMEOUT) { | ||
if (ApplicationV2.platform.IsAnyOf(RuntimePlatform.WebGLPlayer) && ApplicationV2.isPlaying) { | ||
return await GetCurrentPingViaHeadRequest(ipOrUrl, timeoutInMs); | ||
} | ||
#if !UNITY_WEBGL | ||
var ping = await GetCurrentPingViaUnityPing(ipOrUrl, timeoutInMs); | ||
if (ping > 0) { return ping; } | ||
#endif | ||
// If Unity.Ping did not work, eg because a URL was used instead of an IP fallback to default ping approach: | ||
return await base.GetCurrentPing(ipOrUrl, timeoutInMs); | ||
} | ||
|
||
public static async Task<long> GetCurrentPingViaHeadRequest(string ipOrUrl, int timeoutInMs = DEFAULT_PING_TIMEOUT) { | ||
if (!ipOrUrl.StartsWith("http")) { ipOrUrl = "https://" + ipOrUrl; } | ||
Stopwatch timer = Stopwatch.StartNew(); | ||
var result = await new Uri(ipOrUrl).SendHEAD().GetResult<HttpStatusCode>().WithTimeout(timeoutInMs); | ||
AssertV2.AreEqual(HttpStatusCode.OK, result); | ||
return timer.ElapsedMilliseconds; | ||
} | ||
|
||
#if !UNITY_WEBGL | ||
private static async Task<long> GetCurrentPingViaUnityPing(string ip, int timeoutInMs = DEFAULT_PING_TIMEOUT) { | ||
var ping = new UnityEngine.Ping(ip); | ||
var timer = Stopwatch.StartNew(); | ||
while (!ping.isDone && timer.ElapsedMilliseconds < timeoutInMs) { await TaskV2.Delay(10); } | ||
return ping.isDone ? ping.time : -1; | ||
} | ||
#endif | ||
|
||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
CsCore/CsCoreUnity/Plugins/CsCoreUnity/com/csutil/http/UnityRestFactoryV2.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.