I currently have a small scene with a single object of witch I am changing the texture. The textures are held on the server and assessed by the Script below. The issue is that this works fine in Firefox and in Edge but not in Chrome. If I delete Cached Images through chrome the texture changes will take effect. I need this to work without having the user delete their history. It will also work when its left for an unspecified time.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
using System.Linq;
public class ReceveCode : MonoBehaviour {
public GameObject obj;
public Texture2D texture;
public string serverCodeURL;
public List<Material> originalMaterials;
public List<Material> objMaterials;
public GameObject testtxt;
public string userID;
public string serverCode;
public string[] splitCode1;
public string[] testSplitCode2;
void Awake()
{
for (int i = 0; i < 8; i++) {
double randNum = UnityEngine.Random.Range(0.0f, 1.0f);
randNum = randNum * 9;
userID += Convert.ToInt32(randNum).ToString();
}
print(userID);
Application.ExternalCall("SetID", userID);
serverCodeURL = "http://stills-development.co.uk/markup/" + userID + ".php";
testtxt.GetComponent<Text>().text = userID;
// StartCoroutine(PostUserID());
StartCoroutine(LoadText());
}
void Start()
{
//Defining customisable object
obj = GameObject.FindGameObjectWithTag("Custom");
//Creating a list of materials stored for future reference
originalMaterials = new List<Material>(Resources.LoadAll("Materials", typeof(Material)).Cast<Material>());
//Getting materials array from customisable object
objMaterials = new List<Material>(obj.GetComponent<Renderer>().materials);
}
//Button function to refresh chair materials
public void TextLoad()
{
StartCoroutine(LoadText());
}
IEnumerator LoadText()
{
while (true)
{
//The URL of the web page where the textures are stored
string materialsURL = "http://stills-development.co.uk/markup/fabrics/";
//Start download of webpage
WWW guiwww = new WWW(serverCodeURL);
//Wait for web page to be downloaded
yield return guiwww;
if (guiwww.error == null)
{
//Reads web page as text
serverCode = guiwww.text.ToString();
print("test" + serverCode);
//Remove stars from code
splitCode1 = serverCode.Split('*');
print(splitCode1[1]);
//Splitting received code by commas
testSplitCode2 = splitCode1[1].Split(',');
print(testSplitCode2[0]);
List<string> test = testSplitCode2.ToList<string>();
test.RemoveAt(4);
string[] splitCode2 = test.ToArray();
Debug.Log(serverCode);
//Initialising counter to determine which material array element is being created
int counter = 0;
foreach (string codePart in splitCode2)
{
//Splitting code again to read material and texture
string[] splitCode3 = codePart.Split('/');
//Reading the chosen material from the code
Material chosenMaterial = Instantiate<Material>(originalMaterials.Find(mat => mat.name == splitCode3[0]));
//Downloading the chosen texture from the database
WWW tex = new WWW(materialsURL + splitCode3[1] + ".jpg");
yield return tex;
texture = tex.texture;
//Applying the chosen texture to the chosen material
chosenMaterial.mainTexture = texture;
print(counter.ToString());
//Adding the finished material to a materials array
objMaterials[counter] = chosenMaterial;
//Incrementing counter
counter++;
}
//Replacing the chairs material array with the newly generated one from above
obj.GetComponent<Renderer>().materials = objMaterials.ToArray();
//Add delay so as to not overload the system
Debug.Log(guiwww.text);
}
else
{
print(guiwww.error);
}
yield return new WaitForSeconds(1f);
}
}
//Finds users public IP address
IEnumerator GetPublicIp()
{
//Stills form web page that displays users public IP
string pubIpAddURL = "http://stills-development.co.uk/markup/index.php";
//Start download of webpage
WWW pubIpAdd = new WWW(pubIpAddURL);
//Wait for web page to be downloaded
yield return pubIpAdd;
//Reads whole web page as text
string pubIpAddPage = pubIpAdd.text.ToString();
print(pubIpAddPage);
//Split web page text to find the public ip address located between "<h1>Your IP address is " and "</h1>"
//To see where this is, visit pubIpAddURL and hit F12 to read code of page, you will find what this is referring to there
string[] splitString1 = pubIpAddPage.Split(new string[] { "Your User ID is " }, StringSplitOptions.None);
string[] splitString2 = splitString1[1].Split(new string[] { "</h1>" }, StringSplitOptions.None);
//Users public IP address being pulled from website
string pubIp = splitString2[0];
pubIp = pubIp.Trim(' ', '\n');
//Setting the URL from where the code for the changes made by the user in the Stills form are kep
// testtxt.GetComponent<Text>().text = pubIp;
serverCodeURL = "http://stills-development.co.uk/markup/" + userID + ".php";
Debug.Log(pubIp);
StartCoroutine(LoadText());
}
IEnumerator PostUserID()
{
string databaseURL = "http://stills-development.co.uk/markup/index.php?userID=" + userID;
WWWForm databaseForm = new WWWForm();
databaseForm.AddField("userID", userID);
WWW databaseWWW = new WWW(databaseURL, databaseForm);
yield return databaseWWW;
if (databaseWWW.error == null)
{
Debug.Log("www OK" + databaseWWW.text);
}
else
{
Debug.Log("www error" + databaseWWW.error);
}
serverCodeURL = "http://stills-development.co.uk/markup/" + userID + ".php";
StartCoroutine(LoadText());
}
}