diff --git a/src/Proyecto26.RestClient/Helpers/RequestHelperExtension.cs b/src/Proyecto26.RestClient/Helpers/RequestHelperExtension.cs
index 7017a74..61f117e 100644
--- a/src/Proyecto26.RestClient/Helpers/RequestHelperExtension.cs
+++ b/src/Proyecto26.RestClient/Helpers/RequestHelperExtension.cs
@@ -106,7 +106,6 @@ public bool IsAborted
private bool _defaultContentType = true;
-
///
/// Enable or Disable Content Type JSON by default
///
@@ -117,6 +116,17 @@ public bool DefaultContentType
set { _defaultContentType = value; }
}
+ private bool _editorCoroutine = false;
+ ///
+ /// Enable to starts en editor coroutine instead
+ ///
+ /// A boolean to know if the request is working on Editor without running the game
+ public bool EditorCoroutine
+ {
+ get { return _editorCoroutine; }
+ set { _editorCoroutine = value; }
+ }
+
///
/// Abort the request manually
///
diff --git a/src/Proyecto26.RestClient/Helpers/StaticCoroutine.cs b/src/Proyecto26.RestClient/Helpers/StaticCoroutine.cs
index aea6a1c..e8b7255 100644
--- a/src/Proyecto26.RestClient/Helpers/StaticCoroutine.cs
+++ b/src/Proyecto26.RestClient/Helpers/StaticCoroutine.cs
@@ -1,5 +1,8 @@
using UnityEngine;
using System.Collections;
+#if UNITY_EDITOR
+using Unity.EditorCoroutines.Editor;
+#endif
namespace Proyecto26
{
@@ -25,5 +28,18 @@ public static Coroutine StartCoroutine(IEnumerator coroutine)
{
return Runner.StartCoroutine(coroutine);
}
+
+ public static void Start(bool useEditor, IEnumerator coroutine)
+ {
+#if UNITY_EDITOR
+ if (useEditor)
+ {
+ EditorCoroutineUtility.StartCoroutineOwnerless(coroutine);
+ return;
+ }
+#endif
+ StartCoroutine(coroutine);
+ return;
+ }
}
}
diff --git a/src/Proyecto26.RestClient/RestClient.cs b/src/Proyecto26.RestClient/RestClient.cs
index 82b0da5..f461272 100644
--- a/src/Proyecto26.RestClient/RestClient.cs
+++ b/src/Proyecto26.RestClient/RestClient.cs
@@ -90,7 +90,7 @@ public static void ClearDefaultHeaders()
/// A callback function that is executed when the request is finished.
public static void Request(RequestHelper options, Action callback)
{
- StaticCoroutine.StartCoroutine(HttpBase.DefaultUnityWebRequest(options, callback));
+ StaticCoroutine.Start(options.EditorCoroutine, HttpBase.DefaultUnityWebRequest(options, callback));
}
///
@@ -101,7 +101,7 @@ public static void Request(RequestHelper options, ActionThe element type of the response.
public static void Request(RequestHelper options, Action callback)
{
- StaticCoroutine.StartCoroutine(HttpBase.DefaultUnityWebRequest(options, callback));
+ StaticCoroutine.Start(options.EditorCoroutine, HttpBase.DefaultUnityWebRequest(options, callback));
}
///
@@ -168,7 +168,7 @@ public static void GetArray(string url, Action(RequestHelper options, Action callback)
{
options.Method = UnityWebRequest.kHttpVerbGET;
- StaticCoroutine.StartCoroutine(HttpBase.DefaultUnityWebRequest(options, callback));
+ StaticCoroutine.Start(options.EditorCoroutine, HttpBase.DefaultUnityWebRequest(options, callback));
}
///
@@ -273,7 +273,7 @@ public static void PostArray(string url, string bodyString, Action(RequestHelper options, Action callback)
{
options.Method = UnityWebRequest.kHttpVerbPOST;
- StaticCoroutine.StartCoroutine(HttpBase.DefaultUnityWebRequest(options, callback));
+ StaticCoroutine.Start(options.EditorCoroutine, HttpBase.DefaultUnityWebRequest(options, callback));
}
///