Hi Guys.
Im working on app wihich is comunicating with server database through php. Problem is when i want to
make progress bar for this communication. From what i know and read all over unity forums and internet… my code is right… from first i thought problem is in content-header which i was missing… but nothing changed when i added it.
Problem is that progress variable is 0 and when its complete its jump to 1. better yet… Debug.Log indicates that progress is nothing… not even 0… so no progress at all… as if unity coudnt get how many bytes was downloaded so far and thus cant make float number like bytesDownloaded/bytesTotal …
So where is problem ? In my server ? or some missing info from header ? or bug in unity ?
here is my C# which makes Loading bar…
using UnityEngine;
using UnityEngine.UI;
public class LoadingBar : MonoBehaviour
{
public GameObject progressRadial;
private bool inProgress;
private float progress;
[SerializeField]
private Text progressText;
[SerializeField]
private Image progressCircle;
void Start ()
{
progressRadial.SetActive (false);
progressCircle.fillAmount = 0f;
InProgress = false;
Progress = 0f;
progressText.text = "0%";
}
void Update ()
{
if (InProgress) {
progressRadial.SetActive (true);
progressText.text = (Progress * 100).ToString ("#") + "%";
progressCircle.fillAmount = Progress;
Debug.Log ("DOWNLOAD PROGRESS : " + (Progress * 100).ToString("#") + "%");
} else {
progressRadial.SetActive (false);
}
}
public bool InProgress
{
get
{
return inProgress;
}
set
{
inProgress = value;
}
}
public float Progress
{
get
{
return progress;
}
set
{
progress = value;
}
}
}
And here is one testing method which handles download from server
public IEnumerator getListUsers(Action<string> result)
{
Debug.Log("DatabaseHandler.GETLISTUSERS: START");
string hash = md5(secretKey);
WWWForm frm = new WWWForm();
frm.AddField("list_users","true");
frm.AddField("hash", hash);
WWW hs = new WWW("web adress", frm);
Debug.Log("DatabaseHandler.GETLISTUSERS: DOWNLOADING");
loadbar.InProgress = true;
int count = 1;
while (!hs.isDone)
{
loadbar.Progress = hs.progress;
Debug.Log(count + " - " + hs.bytesDownloaded);
count++;
}
yield return hs;
loadbar.InProgress = false;
Debug.Log("DatabaseHandler.GETLISTUSERS: DOWNLOAD FINISHED");
if (hs.responseHeaders.ContainsKey("CONTENT-LENGTH"))
{
Debug.Log(hs.responseHeaders["CONTENT-LENGTH"]);
}
if (!string.IsNullOrEmpty(hs.error))
{
Debug.Log("DatabaseHandler.GETLISTUSERS: ERROR" + hs.error);
}
else
{
Debug.Log("HSTEXT: " + hs.text);
result(hs.text);
}
Debug.Log("DatabaseHandler.GETLISTUSERS: STOP");
}
Sooo… my only solution so far is to make just indicator for internet activity without any loading… but this should work or not ? I tested on android also… no change.