I'm trying to obtain a binary file through UnityWebRequest (Only way of obtaining a file in Android platform, which is a file added to the StreamingAssets folder). How can i deserialize the contents of the response into one of my game's Class?..
↧
UnityWebRequest deserialize content
↧
Curl error 28: Operation timed out after 5000 milliseconds with 0 bytes received
When I'm starting the game in unity, sometimes **Unity 2018.4.16f1** crashes and I don't know why.
In the last editor log I see this:
Curl error 28: Operation timed out after 5000 milliseconds with 0 bytes received
0x000000014145EFF8 (Unity) StackWalker::GetCurrentCallstack
0x00000001414654A6 (Unity) StackWalker::ShowCallstack
0x0000000141347B6B (Unity) GetStacktrace
0x000000014014B4C8 (Unity) DebugStringToFile
0x0000000141DF149B (Unity) TransportCurl::TransformCurlErrorToWebError
0x0000000141DEED16 (Unity) CurlExecutor::CurlExecute
0x00000001408D6D18 (Unity) JobQueue::Exec
0x00000001408D8C5D (Unity) JobQueue::Steal
0x00000001408D6FA2 (Unity) JobQueue::ExecuteJobFromQueue
0x00000001408D73A2 (Unity) JobQueue::ProcessJobs
0x00000001408D93E3 (Unity) JobQueue::WorkLoop
0x0000000140AAB9E0 (Unity) Thread::RunThreadWrapper
0x00007FFA5F307BD4 (KERNEL32) BaseThreadInitThunk
0x00007FFA5F5CCED1 (ntdll) RtlUserThreadStart
(Filename: C:\buildslave\unity\build\Modules/UnityWebRequest/Implementations/TransportCurl.cpp Line: 757)
* Assertion at ..\mono\metadata\threads.c:1780, condition `internal' not met
I see the problem is in **UnityWebRequest**, but I'm using it in many parts of code and I don't know, what I'm should to show in code example...
And I'm sure, what the problem is not in the code.
↧
↧
How to get UnityWebRequest data early when using php flush()
Hi, I'm using UnityWebRequest.Post to communicate with my php server. I want to use flush() in PHP to send partial data to the game as soon as possible but the WebRequest is set to be done only after the whole thing finishes.
Is there any way to check if a flush happened on the other end and get the data early?
here is the code I'm using:
IEnumerator DoPostRequest( string route, WWWForm formData,
UnityAction OnSuccess, UnityAction OnFailure )
{
using( var request = UnityWebRequest.Post( GamePrefs.SERVER + route, formData ) )
{
yield return request.SendWebRequest();
if( request.isNetworkError || request.isHttpError )
{
Debug.LogError( "POST_ERROR:" + route + " - " + request.error );
}
else
{
if( request.responseCode == 200 )
{
RESULTTYPE result = default;
bool success = true;
try
{
result = JsonUtility.FromJson( request.downloadHandler.text );
}
catch( System.Exception e )
{
Debug.LogError( "Exception When parsing " + route + " as json :: " + e.ToString() + "\nResponse:" + request.downloadHandler.text );
success = false;
}
if( success )
{
OnSuccess( result );
}
}
else
{
Debug.LogWarning( "POST_ABORT:" + route + " " + request.downloadHandler.text );
OnFailure?.Invoke();
}
}
}
}
the php part:
if (ob_get_level() == 0) ob_start();
echo GetJsonFromResult( $result, "games" );
ob_flush();
flush();
sleep(2);
echo "Post flush echo";
the php works fine when run in the browser, but I can't get unity to receive the data early.
Thanks! :)
↧
Why am I unable to locate font files(.ttf) in unity android game in persistentDataPath?
Can somebody guide me in the right direction? My android game that I made on unity 2018.4.9 using C# on VS 2017 is unable to detect files at persistent data path.
The two font files are located in the persistent data path directory
![alt text][1]
[1]: /storage/temp/153495-whatsapp-image-2020-03-02-at-030144.jpeg
This is my code which locates the two font files.
string fontpath1 = Application.streamingAssetsPath + "/LEOPALMHINDI15K710.TTF";
string fontpath2 = Application.streamingAssetsPath + "/LEOPALMHINDI14K240.TTF";
//Check Font 1 existence
if (File.Exists(fontpath1))
{
Debugtext.text += "true1\r\n";
}
else if (!File.Exists(fontpath1))
{
Debugtext.text += "false1\r\n";
}
//Check Font 2 existence
if (File.Exists(fontpath2))
{
Debugtext.text += "true2\r\n";
}
else if (!File.Exists(fontpath2))
{
Debugtext.text += "false2\r\n";
}
//Third File(Image file existence)
if (File.Exists(Application.persistentDataPath + "/FullShot.jpg"))
{
Debugtext.text += "trueIM\r\n";
}
else if (!File.Exists(Application.persistentDataPath + "/FullShot.jpg"))
{
Debugtext.text += "falseIM\r\n";
}
Debugtext.text += Application.persistentDataPath;
Debugtext.text is a textbox which shows the result of three files: a) Font File 1 b) Font File 2 c) An Image File
The debug traces for files 1 and 2 are always false, whereas the image file returns true when it's present.
These fonts files are downloaded using UnityWebRequest from streaming path to persistent path using the following code:
string fontpath1 = Application.streamingAssetsPath + "/LEOPALMHINDI15K710.TTF";
string fontpath2 = Application.streamingAssetsPath + "/LEOPALMHINDI14K240.TTF";
//Request Font1
UnityWebRequest request = UnityWebRequest.Get(fontpath1);
request.SendWebRequest();
while (!request.isDone)
{
}
System.IO.File.WriteAllBytes(Application.persistentDataPath + "/LEOPALMHINDI15K710.TTF", request.downloadHandler.data);
//Request Font2
UnityWebRequest font2 = UnityWebRequest.Get(fontpath2);
font2.SendWebRequest();
while (!font2.isDone)
{
}
System.IO.File.WriteAllBytes(Application.persistentDataPath + "/LEOPALMHINDI14K240.TTF", font2.downloadHandler.data);
The files are downloaded and written properly to the Persistent data path which is storage/emulated/0/Android/data/com.appname.com/files(cross-checked in traces.)
Why are these two font files not being located and returning false while other files in same path returns true?
Please, anyone, help me fix it. I gotta locate these two font files.
↧
Json data isn't being parsed
I have the following JSON data and this is how it appears in the Visual Studio watch window:
"{\"TestResponse\":\"[{isValid:false,errorMessage:\'\',mainPath:~/yourName/yourfolder/,fileName:\'tempFile.txt\'}]\"}"
So I made two classes:
[System.Serializable]
public class ResponseData
{
public bool isValid;
public string errorMessage;
public string mainPath;
public string fileName;
}
[System.Serializable]
public class ResponseDataList
{
public List TestResponse;
}
And here's how I'm parsing it:
ResponseDataList responseDataList = JsonUtility.FromJson(jsonData);
I'm always getting zero elements in the `responseDataList` though. I tried changing the bool to a string, and the errorMessage to a character (because it looks like it an empty character '\') but no luck.
↧
↧
OAuth 2.0 Capture Redirect
Hello,
I am currently trying to implement OAuth 2.0 into my Windows application to access a third party API. It requires me to open a Webpage for the user to login and then redirects to a custom URL with the access token in it.
I first tried to get it wokring over UnityWebRequest, but that does not seem to work when the user has to manually enter his/her login details on the third party website before the redirect (or at least it never opened the browser in my initial tests).
So my current plan would be to have that redirect URL beeing a local php script that stores the access token in a seperate file, which I could then read in Unity again. Unfortunately, my php skills are not existent, so I was wondering whether someone could help me out :)
↧
Same png file import from asset and download with Unitywebrequest got different result
I got a png file to use as an image mask, the color on the mask is queried in by a shader to decide which part of the mask will be used. I put this mask into asset to develop and test, and everything goes well, then i tried to move this file to a remote server and download with UnityWebRequest, but this time the color on the downloaded texture went slightly off than the one i got from local asset. I tried encode the downloaded texture into a png file and compare it with the original one from the server using BeyondCompare , the software shows color change all over the image. Why?![alt text][1]
[1]: /storage/temp/155011-test.png
↧
How to check if DownloadHelperAudioClip still has internet connection for streaming during playback?
Hi, i use a DownloadhelperAudioClip and UnityWebRequests in order to access audio files on a web server from mobile. Now, thinking about stability with WiFi or even Mobile Networt (i create an Android App) i wonder how to check during playback, if the stream is still available? Does anyone know an answer? Thank you. Here is the Method for my Audio Streaming:
public static IEnumerator GetAudioClipAsWebStream(string mp3Url, AudioSource audioSource,AudioType audioType)
{
var downloadHandler = new DownloadHandlerAudioClip(mp3Url,audioType);
downloadHandler.compressed = false;
downloadHandler.streamAudio = true;
UnityWebRequest www = new UnityWebRequest(mp3Url,UnityWebRequest.kHttpVerbGET,downloadHandler,null);
www.SendWebRequest();
while (www.downloadProgress<0.01)
{
yield return new WaitForSeconds(0.1f);
}
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
var clip = downloadHandler.audioClip;
if (clip)
{
audioSource.clip = clip;
audioSource.Play();
}
}
}
↧
What is the problem with my code?
my json code :
{
"vuser": {
"id": "1",
"email": "mohsensd1373@gmail.com ",
"tel": "000000",
"fname": "kingblack",
"username": "mohsensd1373",
"password": "000000",
"nfarm": "mohsensd1373"
},
"vfarms": {
"id": "1",
"name": "mohsensd1373",
"gift": "0",
"Planting": "10",
"power": "0"
},
"vPlanting": [
{
"id": "1",
"nfarm": "mohsensd1373",
"type": "flower",
"sprite": "flower",
"timer": "60",
"result": "flower",
"posx": "1",
"posy": "1"
},
{
"id": "2",
"nfarm": "mohsensd1373",
"type": "flower",
"sprite": "flower",
"timer": "60",
"result": "flower",
"posx": "2",
"posy": "2"
}
]
}
this code for get json from url and convert to class object:
using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
class httprequest : MonoBehaviour
{
void Start() { }
public string GET(string url)
{
RootObject myObject = new RootObject();
StartCoroutine(GetText(url, (result) =>{
PlayerPrefs.SetString("sdall", result);
//Debug.Log(result);
}));
Debug.Log(PlayerPrefs.GetString("sdall"));
myObject = JsonUtility.FromJson(PlayerPrefs.GetString("sdall"));
Debug.Log(myObject.vuser.email);
return myObject.vuser.email;
}
[Serializable]
public class VUser
{
public string id { get; set; }
public string email { get; set; }
public string tel { get; set; }
public string fname { get; set; }
public string username { get; set; }
public string password { get; set; }
public string nfarm { get; set; }
}
public class VFarms
{
public string id { get; set; }
public string name { get; set; }
public string gift { get; set; }
public string Planting { get; set; }
public string power { get; set; }
}
public class VPlanting
{
public string id { get; set; }
public string nfarm { get; set; }
public string type { get; set; }
public string sprite { get; set; }
public string timer { get; set; }
public string result { get; set; }
public string posx { get; set; }
public string posy { get; set; }
}
public class RootObject
{
public VUser vuser { get; set; }
public VFarms vfarms { get; set; }
public List vPlanting { get; set; }
}
IEnumerator GetText(string url, Action result)
{
UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
if (result != null)
result(www.error);
}
else
{
//Debug.Log(www.downloadHandler.data);
if (result != null)
result(www.downloadHandler.text);
}
}
}
returned this error:
ArgumentException: JSON parse error: Invalid escape character in string.
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at <1386288601af43018501cce2912f52f4>:0)
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at <1386288601af43018501cce2912f52f4>:0)
httprequest.GET (System.String url) (at Assets/myscript 1/httprequest.cs:21)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <437ba245d8404784b9fbab9b439ac908>:0)
FlowCanvas.Nodes.PureReflectedMethodNode.Call () (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Nodes/Functions/Reflected/Internal/Method/PureReflectedMethodNode.cs:54)
FlowCanvas.Nodes.PureReflectedMethodNode+<>c__DisplayClass12_1.b__2 (FlowCanvas.Flow flow) (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Nodes/Functions/Reflected/Internal/Method/PureReflectedMethodNode.cs:80)
FlowCanvas.FlowOutput.Continue (FlowCanvas.Flow f) (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Ports.cs:272)
UnityEngine.Logger:LogException(Exception)
ParadoxNotion.Services.Logger:ForwardToUnity(LogType, Object, String, Object) (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:114)
ParadoxNotion.Services.Logger:Internal_Log(LogType, Object, String, Object) (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:108)
ParadoxNotion.Services.Logger:LogException(Exception, String, Object) (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:66)
NodeCanvas.Framework.Node:Error(Object) (at Assets/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Node.cs:326)
FlowCanvas.FlowOutput:Continue(Flow) (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Ports.cs:276)
FlowCanvas.FlowOutput:Call(Flow) (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Ports.cs:250)
FlowCanvas.Nodes.StartEvent:OnStartCallback() (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Nodes/Events/Graph/StartEvent.cs:33)
NodeCanvas.Framework.GraphOwner:InvokeStartEvent() (at Assets/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/GraphOwner.cs:384)
NodeCanvas.Framework.GraphOwner:Start() (at Assets/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/GraphOwner.cs:375)
↧
↧
Texture2D.GetPixels().Length is smaller on iOS build than in Editor
Hello, I am using the paintcraft asset from the asset store. I want to combine the region texture with the outline texture so I retrieve the region texture from the files and merge them one pixel at a time with the outline texture. On iOS the region texture.GetPixels().Length is smaller on iOS than in the editor.
I tried to make them completely uncompressed and there was no change. Here is my code below
public void SaveImageAsync() { if (canvasController.OutlineTexture != null && canvasController.RegionTexture != null) { tempOutline = new Texture2D(OutlineTex.width, OutlineTex.height, OutlineTex.format, false); tempRegion = new Texture2D(RegionTex.width, RegionTex.height, RegionTex.format, false); Graphics.CopyTexture(OutlineTex, 0, 0, tempOutline, 0, 0); if (File.Exists(SaveFilePath) && !string.IsNullOrEmpty(currentPage.name)) { StartCoroutine(LoadTexture()); } } } private IEnumerator LoadTexture() { UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("file://" + SaveFilePath); yield return uwr.SendWebRequest(); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); } else { // Get downloaded asset bundle tempRegion = DownloadHandlerTexture.GetContent(uwr); tempRegion.Apply(); } Texture2D mergedTex = MergeTexture(tempRegion, tempOutline); //Save image merged image NativeGallery.SaveImageToGallery(mergedTex.EncodeToPNG(), "Album Name", currentPage.UniqueId + ".png"); } public Texture2D MergeTexture(Texture2D region, Texture2D outline) { var cols1 = (region as Texture2D).GetPixels(); var cols2 = (outline as Texture2D).GetPixels(); for (int i = 0; i < cols1.Length; i++) { //If the image isn't transparent if (cols2[i].a != 0) { //Color Multiply cols1[i] *= cols2[i]; } } (region as Texture2D).SetPixels(cols1); (region as Texture2D).Apply(); return (region as Texture2D); } Below is what the image links like in the editor(Correct) vs what it looks like on iOS(Super messed up) ![CorrectUnicorn][1] ![MessedUpUnicorn][2] [1]: /storage/temp/157679-unicorncorrect.png [2]: /storage/temp/157680-unicornmessedup.png
I tried to make them completely uncompressed and there was no change. Here is my code below
public void SaveImageAsync() { if (canvasController.OutlineTexture != null && canvasController.RegionTexture != null) { tempOutline = new Texture2D(OutlineTex.width, OutlineTex.height, OutlineTex.format, false); tempRegion = new Texture2D(RegionTex.width, RegionTex.height, RegionTex.format, false); Graphics.CopyTexture(OutlineTex, 0, 0, tempOutline, 0, 0); if (File.Exists(SaveFilePath) && !string.IsNullOrEmpty(currentPage.name)) { StartCoroutine(LoadTexture()); } } } private IEnumerator LoadTexture() { UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("file://" + SaveFilePath); yield return uwr.SendWebRequest(); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); } else { // Get downloaded asset bundle tempRegion = DownloadHandlerTexture.GetContent(uwr); tempRegion.Apply(); } Texture2D mergedTex = MergeTexture(tempRegion, tempOutline); //Save image merged image NativeGallery.SaveImageToGallery(mergedTex.EncodeToPNG(), "Album Name", currentPage.UniqueId + ".png"); } public Texture2D MergeTexture(Texture2D region, Texture2D outline) { var cols1 = (region as Texture2D).GetPixels(); var cols2 = (outline as Texture2D).GetPixels(); for (int i = 0; i < cols1.Length; i++) { //If the image isn't transparent if (cols2[i].a != 0) { //Color Multiply cols1[i] *= cols2[i]; } } (region as Texture2D).SetPixels(cols1); (region as Texture2D).Apply(); return (region as Texture2D); } Below is what the image links like in the editor(Correct) vs what it looks like on iOS(Super messed up) ![CorrectUnicorn][1] ![MessedUpUnicorn][2] [1]: /storage/temp/157679-unicorncorrect.png [2]: /storage/temp/157680-unicornmessedup.png
↧
AWS WebGL Securly Get Images?
So AWS SDK is not compatable with WebGL.
Is there any way to securly pull images from an S3 bucket?
Myabe using the http get to authenticate with cognito then pull the images?
Any suggesstions would be very helpful, I just need some way of getting images securly from an S3 bucket on a Unity WebGL project.
↧
Can't Send a form to a server(POST) due to CORS error in a WEBGL build
At the beginning i am not fully understanding http and web request so correct me if i am wrong.
I am currently working on a game and it will be hosted on a server as a webgl build
at the very beginning of the game the player sends some information to an API. The API has an ip whiteList ( i guess it is set via CORS ). but when i send a request i get a response code = 0 and i cannot connect to the server. Although my host domain is added to the whitelist.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://domain.com
my questions are.
- when i send the request in an webgl build what is the ip and the host that sends that request? is it the server that hosts the webgl or the device that runs it(browser based) ?
- If so, how to establish a connection and fix this problem?
Thanks in avance.
↧
What is the ip when sending a webrequest in webgl build
what is the ip when a webgl build sends a webrequest to another server ( is it my browser or the server hosts the game) ?
↧
↧
Stream while simultaneously downloading video from URL using video player
Hi, I'm wanting to use a video clip as the background in my menu scene for one of my games.
Setting the video player's URL to the URL I want to play works, however, each time the game is launched, it re-downloads the video. This causes unnecessary data usage, especially on mobile.
Instead, I tried downloading the video using a UnityWebRequest and saving it to a file. This works, and the video only has to be downloaded once, however, the video then needs to be fully downloaded before playback can commence, meaning there is a delay before the video starts playing.
So, my question is: is there any way to stream a video from a URL directly using the video player, but also cache the download in the persistent data path, so the video is only downloaded once?
The only other way I can think of achieving this is by playing the video via the URL of the video player, while also downloading the file using a web request. This is better than downloading it every time the game is launched, however, it still downloads the video twice which is not ideal.
Thanks.
↧
How to free memory of UnityWebRequest?
How can I free the data of UnityWebRequest at Unity WebGL?
I am using it to load AssetBundle for most of the data but still unable to release the memory of UnityWebRequest.data because JavaScript.ArrayBuffer is increasing everytime i make a request.
using (UnityWebRequest webReq = UnityWebRequest.Get(_filePath));
.
.
webReq.Dispose()
Everytime I unload the scene, i will call the dispose function
AssetBundle.UnloadAllAssetBundles(true)
Nothing is happens. Is there something i did wrong? Do I have to do the loading at JavaScript followed by releasing the memory of that data?
I was thinking of doing something like this for JavaScript side but it will always result in memory out of bound for obvious reasons.
function FreePointer(_arrayOfBytes, _byteLength)
{
console.log("free array of bytes: " + _arrayOfBytes);
gameInstance.Module._free(_arrayOfBytes);
console.log("Delete array");
delete _arrayOfBytes;
}
s
↧
Making an interface for web requests
I have some web requests that are working correctly, but I'm trying to extract them out into an interface to tidy up my code.
I'm having trouble with the return statements for these calls, because the async request needs a return and it doesn't match the type I'm passing back. I'm 90% sure this problem stems from my lack of understanding of asynchronous operations, but I'm hoping someone will be able to help me out.
public interface IWebRequest
{
IEnumerable Register(WWWForm form);
}
public class WebResult
{
public long ResponseCode { get; set; }
public bool IsError { get; set; }
public string Value { get; set; }
}
I've defined an interface `IWebRequest` and a return object `WebResult`.
When I try to implement these functions, I get an error due to the `yield return www.SendWebRequest()` call not being a type of `IEnumerable`
public class WebRequestSender : IWebRequest
{
public IEnumerable Register(WWWForm form)
{
using (UnityWebRequest www = UnityWebRequest.Post("REGISTER_URL", form))
{
www.certificateHandler = new SelfSignedCertificateHandler();
yield return www.SendWebRequest();
if (www.isHttpError || www.isNetworkError)
{
yield return new WebResult
{
IsError = true,
ResponseCode = www.responseCode,
Value = null
};
}
else
{
yield return new WebResult
{
IsError = false,
ResponseCode = www.responseCode,
Value = www.downloadHandler.text
};
}
}
}
}
Does anyone know the proper way to code this so I can have my return type object and still make the asynchronous call?
Thank you for any help.
↧
UnityWebRequest work only on odd tries
I am downloading an obj runtime, but the download call work only on odd tries. if I try to download first time it work, second time is not working (don't go after yield return uwr.SendWebRequest();) the third time is working again and so on... anyone can help me?
IEnumerator GetObjectRoutine(Action callback)
{
GameObject loadedObj = null;
UnityWebRequest.ClearCookieCache();
using (UnityWebRequest uwr = new UnityWebRequest("http://127.0.0.1:8887/Models/174-l2.obj", UnityWebRequest.kHttpVerbGET))
{
string path = Path.Combine(Application.persistentDataPath, "model.obj");
uwr.downloadHandler = new DownloadHandlerFile(path);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
Debug.LogError(uwr.error);
else
{
Debug.Log("File successfully downloaded and saved to " + path);
objectPath = path;
loadedObj = new OBJLoader().Load(path);
downloadedObj = loadedObj;
uwr.Dispose();
}
}
if(loadedObj != null)
callback?.Invoke(loadedObj);
Debug.Log("EXIT FROM GETOBJECT");
}
↧
↧
Switching from localhost to actual domain breaks cookies,Switching from localhost to actual domain breaks cookies?
so I recently tried launching my game on the website with WebGL. I had tested it a number of times on XAMPP with localhost, and everything worked out perfectly. See, I sent UnityWebRequest forms to my php scripts, and those scripts would encrypt/create a cookie or decrypt/retrieve a cookie. It all worked out astoundingly well, to the point where I could set and retrieve cookies on the localhost from my Unity editor.
When I put the game on my domain through namecheap, though, the game was still able to communicate with the php scripts but the scripts weren't setting/retrieving cookies. Why is that?
I do have an SSH certificate with the domain, is it a problem of security?,So I recently tried launching my game on the website with WebGL. I had tested it a number of times on XAMPP with localhost, and everything worked out perfectly. See, I sent UnityWebRequest forms to my php scripts, and those scripts would encrypt/create a cookie or decrypt/retrieve a cookie. It all worked out well to the point where I could set and retrieve cookies on the localhost from my Unity editor.
When I put the game on my domain through namecheap, though, the game was still able to communicate with the php scripts but the scripts weren't setting/retrieving cookies. Why is that?
I do have an SSH certificate with the domain, is it a problem of security?
↧
Getting Localization data in Android with streamingAssets and UnityWebRequest
Hi I used Unity localization tutorial to localize text in my app - In editor it works fine, but in Android it works partly (first canvas it doesn't find strings - shows missingTextString and other canvas is translated fine(buttons)).
In the code I use missingTextString to debug errors too. It's more handy.
Unity version is 2019.2.0f1 and I'm testing it in Android is 8.1
So the code:
IEnumerator LoadLocalizedTextOnAndroid(string fileName)
{
localizedText = new Dictionary();
string filePath;
filePath = Path.Combine(Application.streamingAssetsPath + "/", fileName);
missingTextString = "Android filePath: "+filePath;
string dataAsJson;
if (filePath.Contains("://") || filePath.Contains(":///"))
{
UnityWebRequest uwr = UnityWebRequest.Get(filePath);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.Log(uwr.error);
dataAsJson = "error";
missingTextString += uwr.error;
}
else
{
dataAsJson = uwr.downloadHandler.text;
missingTextString = missingTextString+" - "+ uwr.downloadHandler.text+" Juhuu";
}
}
else
{
dataAsJson = File.ReadAllText(filePath);
Debug.Log("DataAsJson = "+dataAsJson);
missingTextString += dataAsJson;
}
LocalizationData loadedData = JsonUtility.FromJson(dataAsJson);
for (int i = 0; i < loadedData.items.Length; i++)
{
localizedText.Add(loadedData.items[i].key, loadedData.items[i].value);
Debug.Log("KEYS:" + loadedData.items[i].key);
}
isReady = true;
}
↧
UnityWebRequest setup
I'm new to web communication. I'm trying to get to the authenticated url with the following setup:
'Content-Type: application/json'
'Authorization: Basic '.base64_encode("$username:$password")
Here is my code:
string authenticate(string username, string password)
{
string auth = username + ":" + password;
auth = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(auth));
auth = "Basic " + auth;
return auth;
}
IEnumerator makeRequest()
{
string authorization = authenticate(username, password);
string url = "http://testweb14.webland.cz/api/user/login.php";
var request = new UnityWebRequest(url, "POST");
request.SetRequestHeader("Authorization", authorization);
request.SetRequestHeader("Content-Type", "application/json");
Debug.Log(request.url);
yield return request.SendWebRequest();
Debug.Log("Status Code: " + request.responseCode);
}
It returns "401" which means unauthorized. Can you tell me what's wrong?
Also is there a way to Debug.Log the whole request before sending so I see the whole header line of the request?
Thanks for your help.
↧