I’m having an issue with my webgl build. in short we are taking textures from a folder on the server and applying them using a code that is generated by an option menu that is hosted on the website. In the editor this works well, without problems but once its built it seems that the ‘WWW’ are not being called as I cannot access information from the website. I have put the code below if anyone can help?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
using System.Linq;
public class ReceveCode : MonoBehaviour {
public GameObject obj;
private Texture2D texture;
public string serverCodeURL;
public List<Material> originalMaterials;
public List<Material> objMaterials;
public GameObject testtxt;
public string CODE;
public string[] CODE2;
public string[] CODE3;
void Awake()
{
StartCoroutine(GetPublicIp());
}
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()
{
//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;
//Reads web page as text
string serverCode = guiwww.text.ToString();
print(serverCode);
//Remove stars from code
string[] splitCode1 = serverCode.Split('*');
print(splitCode1[1]);
//Splitting received code by commas
string[] testSplitCode2 = splitCode1[1].Split(',');
List<string> test = testSplitCode2.ToList<string>();
test.RemoveAt(4);
string[] splitCode2 = test.ToArray();
//TEMP JUST TO SHOW
// string[] splitCode3 = splitCode2[0].Split('/');
CODE = serverCode;
CODE2 = splitCode2;
//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++;
CODE3 = splitCode3;
}
//DISPLAY THE ARRAYS
// CODE3 = splitCode3;
//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
yield return new WaitForSeconds(1f);
Debug.Log(guiwww.text);
}
//Finds users public IP address
IEnumerator GetPublicIp()
{
//Stills form web page that displays users public IP
string pubIpAddURL = "http://stills-development.co.uk/markup/";
//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();
//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[] { "<h1>Your IP address 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];
//Setting the URL from where the code for the changes made by the user in the Stills form are kept
serverCodeURL = "http://stills-development.co.uk/markup/result-" + pubIp + ".html";
testtxt.GetComponent<Text>().text = pubIp;
}
}