Unity WebGL - accessing StreamingAssets folder from build uploaded in LMS /Server
Hi,
I couldn't access the files StreamingAssets folder from WebGL build which is uploaded in LMS server, I kept those files in StreamingAssets folder to update it for future use. Followed the instruction given in unity manual, working fine in editor, but with direct build run and in LMS its not working.
http://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html
Please find the script attached here for more details. Check the coroutine function named ' userDetailsXmlPath ' which called at start of the game.
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic; //allows us to list
using System.IO; //allows external file path
using System.Xml; //to read /write xml files
using System.Text;
using UnityEngine.SceneManagement;
using GAF.Core;
using System.Xml.Serialization;
public class GameControl : MonoBehaviour {
public static GameControl _main;
public GameObject globe;
public Animator globe_animator;
public GameObject initialBG;
public Camera _mainCamera;
public bool cameraZoomIn;
public GameObject fullMapView;
public Animator regionIndAnim;
public GameObject regionIndicationSet;
public GameObject regionIndication;
public bool regionIndicationZoomIn;
public float regionIndicatorZoomSize = 1.3f;
public Text hudText;
public GameObject bluePrintGObj;
public Animator bluePrint;
public GameObject bluePrintFullGObj;
public Animator bluePrintFull;
public GameObject freezeScreen;
public Animator startInstruction;
public GameObject startInsGObj;
public Animator scene1Anim;
public GameObject scene1GObj;
public Animator mainCameraAnim;
public GameObject scene1InCamGObj;
public GameObject scene3InCamGObj;
public Animator globeFullMapAnim;
public GameObject sceneInsSet;
public Animator sceneInsAnim;
public Text sceneInsText;
public TextAsset quizXml;
List<Dictionary<string, string>> quizQnALevel1 = new List<Dictionary<string, string>>();
Dictionary<string, string> objLevel1;
public string[] question;
public string[] option1;
public string[] option2;
public string[] option3;
public string[] option4;
public string[] correctOption;
public int qnaCountInXml;
private int r;
public int questionCount = 0;
public int qnaDisplayValue = 0;
public bool twoOptionQuestion;
public bool fourOptionQuestion;
public bool optionSelected;
public string[] currentOptions;
public int noOfOptions;
public int score;
public int incorrectAnswerCount;
public int sceneCount = 0;
public Text questionText;
public Text[] choiceText;
public GameObject qNaSet;
public GameObject[] choiceTickGObj;
public Animator qNaAnim;
public bool readyForAnswering;
public GameObject scoreSet;
public Animator scoreSetAnim;
public Text scoreText;
public GameObject routeSet;
public Animator routeAnim;
public GameObject routeBGSet;
public Animator routeBGAnim;
public GameObject badgeSet;
public Animator badgeAnim;
public Text badgeDetailsText;
public int noOfBadges;
public GameObject timerSet;
public Animator timerAnim;
public AudioSource aSource;
public AudioSource aSource1;
public AudioSource aSource2;
public AudioClip aClip_intro = null;
public AudioClip aClip_correctAns = null;
public AudioClip aClip_wrongAns = null;
public AudioClip aClip_selection;
public Button[] choiceButton;
public Color choiceButtonNormalColor;
public GameObject correctWrongMsgGObj;
public Animator correctWrongMsgAnim;
public Text correctWrongMsgText;
public AudioClip[] aClipCorrectMsgPack = null;
public AudioClip[] aClipWrongMsgPack = null;
public AudioClip aClipCorrectWrongMsg = null;
public AudioClip aClipCorrectWrongMsg1 = null;
public AudioClip[] aClipSceneMsgPack = null;
public AudioClip aClipSceneMsg = null;
public GameObject[] unlockScene;
public Animator scenesAnim;
public GameObject s2Set;
public GameObject s3Set;
public GameObject s4Set;
public GameObject s5Set;
public AudioClip aClip_unlock;
public Image playPauseImage = null;
public Sprite playImage;
public Sprite pauseImage;
public bool bool_playPause;
public GameObject freezeFullScreen;
public GameObject sc3BananaBasket1GObj;
public GameObject sc3BananaBasket2GObj;
public AudioClip aClip_conclusion;
public GameObject gameoverSet;
public Animator gameoverAnim;
public Text gameoverWLmsg;
public Text gameoverWLDetails;
private int totalQuestions = 15;
public bool gameCompleted;
public Color winMsgColor;
public Color loseMsgColor;
public GameObject logo;
public AudioClip aClip_globeRotation;
public GameObject narratorGObj;
public GAFBakedMovieClip _clipNarratorAnimation;
public Canvas _gameUICanvas;
public GameObject medalGObj;
public Image medalImg = null;
public Sprite bronzeMedalSprite;
public Sprite silverMedalSprite;
public Sprite goldMedalSprite;
public GameObject medalInsSet;
public Animator medalInsAnim;
public Text medalInsText;
public bool bronzeMedalGameplay;
public bool silverMedalGameplay;
public bool goldMedalGameplay;
public string currentMedal;
public GameObject container1;
public GameObject container2;
public GameObject container3;
public GameObject shipSet;
public GameObject ShipSetSc9;
public GameObject bananaSetAtImporterWH;
public AudioClip aClipCongrats;
public GameObject characterSet;
public Image maleAvatar;
public Image femaleAvatar;
public Image nextButtonInAvatar;
public bool maleAvatarSelected = false;
public bool femaleAvatarSelected = false;
public GameObject selectAvatarInstruction;
public Animator avatarNxtAnim;
public GameObject playPauseSet;
public int maxTimeInMins = 40;
public GameObject gameOverMale;
public GameObject gameOverFemale;
public Image gameOverMaleImg;
public Image gameOverFemaleImg;
public Sprite maleHappy;
public Sprite maleSad;
public Sprite femaleHappy;
public Sprite femaleSad;
public Sprite maleSadGO;
public Sprite femaleSadGO;
public Sprite maleSadTimesUp;
public Sprite femaleSadTimesUp;
public GameObject timesUpSet;
public Animator timesUpAnim;
public GameObject timesUpMale;
public GameObject timesUpFemale;
public Image timesUpMaleImg;
public Image timesUpFemaleImg;
public Text timesUpMsgText;
public AudioClip[] aClipQuestionAttendInsPack = null;
public AudioClip aClipQuestionAttendIns = null;
public Text welcomeText;
public AudioSource aSourceCamSc1;
public AudioSource aSourceCamSc3;
public AudioSource aSourceCamSc7;
public AudioSource aSourceCamSc8;
public Image correctWrongMale;
public Image correctWrongFemale;
public AudioClip aClipTimesUp;
public AudioClip[] aClipMoveFwdInsPack = null;
public AudioClip aClipMoveFwdIns = null;
public AudioSource aSource3;
public int questionSetForUser = 1;
public TextAsset userXml;
List<Dictionary<string, string>> userFullDetails = new List<Dictionary<string, string>>();
Dictionary<string, string> objUser;
public string[] userId;
public string[] questionSetOfUser;
public int userCountInXml;
public string lmsLearnerID;
//public static DataCollection XmlData;
//public static string filePath;
void Awake ()
{
_main = this;
//filePath = Path.Combine(Application.streamingAssetsPath, "UserDetails.xml");
//StartCoroutine("ParseXML");
}
/* IEnumerator ParseXML()
{
if(filePath.Contains("://"))
{
WWW www = new WWW(filePath);
yield return www;
XmlData = DataCollection.DeSerialize(www);
print ();
}
else
{
// XmlData = DataCollection.DeSerialize(filePath);
}
}*/
void Start ()
{
// userXml = Resources.Load<TextAsset> ("UserDetails");
globe_animator.Play ("Rotate");
StartCoroutine (globeRotation ());
// FetchUserDetails ();
StartCoroutine(userDetailsXmlPath ());
sceneCount = 0;
questionCount = 0;
playPauseImage.sprite = pauseImage;
bool_playPause = false;
_mainCamera.orthographic = false;
_gameUICanvas.renderMode = RenderMode.ScreenSpaceCamera;
aSource2.volume = 0.5f;
aSource2.Stop ();
aSource2.clip = aClip_globeRotation;
aSource2.Play ();
bronzeMedalGameplay = false;
silverMedalGameplay = false;
goldMedalGameplay = false;
currentMedal = "";
maleAvatarSelected = false;
femaleAvatarSelected = false;
maleAvatar.color = Color.white;
femaleAvatar.color = Color.white;
nextButtonInAvatar.color = Color.grey;
}
public void avatarSelection (string avatar)
{
if (avatar == "male") {
maleAvatarSelected = true;
femaleAvatarSelected = false;
maleAvatar.color = Color.white;
femaleAvatar.color = Color.grey;
} else if (avatar == "female") {
femaleAvatarSelected = true;
maleAvatarSelected = false;
maleAvatar.color = Color.grey;
femaleAvatar.color = Color.white;
}
selectAvatarInstruction.SetActive (false);
avatarNxtAnim.Play ("avatarNxtContinue");
aSource.Stop ();
aSource.clip = aClip_selection;
aSource.Play ();
}
void Update ()
{
if (cameraZoomIn == true) {
_mainCamera.orthographicSize -= 2 * Time.deltaTime;
}
if (cameraZoomIn == true && _mainCamera.orthographicSize <= 1) {
cameraZoomIn = false;
_mainCamera.orthographicSize = 5;
fullMapView.SetActive (true);
regionIndAnim.Play ("regionIntro");
globe.SetActive (false);
initialBG.SetActive (false);
StartCoroutine (regionIndiZoomIn ());
}
if (regionIndicationZoomIn == true) {
regionIndication.transform.localScale = Vector3.MoveTowards (regionIndication.transform.localScale, new Vector3(1.3f, 1.3f, 1.3f), 0.3f *Time.deltaTime);
}
if (regionIndicationZoomIn == true && regionIndication.transform.localScale.x >= regionIndicatorZoomSize) {
regionIndicationZoomIn = false;
bluePrintGObj.SetActive (true);
bluePrint.Play ("bpDown");
StartCoroutine (showStartInstruction ());
}
}
IEnumerator globeRotation ()
{
yield return new WaitForSeconds (2.0f);
mainCameraAnim.Play("intialCamZoomIn");
yield return new WaitForSeconds (0.8f);
_mainCamera.orthographic = true;
playPauseSet.SetActive (true);
fullMapView.SetActive (true);
regionIndAnim.Play ("regionIntro");
globe.SetActive (false);
initialBG.SetActive (false);
StartCoroutine (regionIndiZoomIn ());
}
IEnumerator regionIndiZoomIn ()
{
yield return new WaitForSeconds (4.0f);
regionIndAnim.Play ("zoomIntoARegion");
yield return new WaitForSeconds (0.8f);
bluePrintGObj.SetActive (true);
bluePrint.Play ("bpDown");
StartCoroutine (showStartInstruction ());
}
IEnumerator showStartInstruction ()
{
yield return new WaitForSeconds (2.5f);
freezeScreen.SetActive (true);
startInsGObj.SetActive (true);
welcomeText.text = "Welcome to this exciting game where you need to take the goods from the starting point to end point on the shipping cycle. " +
"How do you do this? Very simple. You need to answer 15 questions correctly. As you answer each question, you will move one step ahead in the shipping cycle. " +
"You will also earn some reward points if you answer the questions correctly." +
"\n\nYou have only 40 minutes to answer all the 15 questions. Keep a watch on the timer on your screen." +
"\n\nGo for it. Click the Play button to start.";
startInstruction.Play ("startInsShow");
narratorGObj.SetActive (true);
aSource2.volume = 1.0f;
aSource2.Stop ();
aSource1.Stop ();
aSource1.clip = aClip_intro;
aSource1.PlayDelayed (1);
StartCoroutine (playNarratorAnimation ());
}
IEnumerator playNarratorAnimation ()
{
yield return new WaitForSeconds (1.5f);
_clipNarratorAnimation.play ();
}
public void showAvatarSelection ()
{
aSource1.Stop ();
aSource.Stop ();
aSource.clip = aClip_selection;
aSource.Play ();
_gameUICanvas.renderMode = RenderMode.ScreenSpaceOverlay;
characterSet.SetActive (true);
narratorGObj.SetActive (false);
startInstruction.Play ("startInsFadeOut");
}
public void startGame ()
{
if (femaleAvatarSelected == true || maleAvatarSelected == true) {
aSource.Stop ();
aSource.clip = aClip_selection;
aSource.Play ();
characterSet.SetActive (false);
selectAvatarInstruction.SetActive (false);
_gameUICanvas.renderMode = RenderMode.ScreenSpaceOverlay;
narratorGObj.SetActive (false);
if (PlayerPrefs.HasKey ("BadgeCount")) {
noOfBadges = PlayerPrefs.GetInt ("BadgeCount");
badgeDetailsText.text = noOfBadges.ToString ();
}
startInstruction.Play ("startInsFadeOut");
bluePrint.Play ("bpFadeOut");
globeFullMapAnim.Play ("globefadeout");
scene1GObj.SetActive (true);
scene1InCamGObj.SetActive (true);
scene1Anim.Play ("s2fadein");
mainCameraAnim.Play ("sc1In");
s2Set.SetActive (true);
freezeScreen.SetActive (false);
scoreSet.SetActive (true);
scoreSetAnim.Play ("speedoFadeIn");
routeSet.SetActive (true);
routeAnim.Play ("routeFadeIn");
routeBGSet.SetActive (true);
routeBGAnim.Play ("rmBGfadeIn");
badgeSet.SetActive (true);
badgeAnim.Play ("badgeFadeIn");
timerSet.SetActive (true);
timerAnim.Play ("timerFadeIn");
logo.SetActive (true);
StartCoroutine (scene1Intro ());
} else {
selectAvatarInstruction.SetActive (true);
StartCoroutine (SelectAvatarInsDisable ());
}
}
IEnumerator SelectAvatarInsDisable ()
{
yield return new WaitForSeconds (1.5f);
selectAvatarInstruction.SetActive (false);
}
IEnumerator scene1Intro ()
{
yield return new WaitForSeconds (1.0f);
bluePrintGObj.SetActive (false);
startInsGObj.SetActive (false);
fullMapView.SetActive (false);
sceneInsSet.SetActive (true);
sceneInsText.text = "Lets begin the game at the terminal yard." +
"\n\nA customer calls to book the container. With the booking number and other booking details, " +
"he goes to the yard and picks a container.";
sceneInsAnim.Play ("insDown");
aClipSceneMsg = aClipSceneMsgPack[sceneCount];
aSource1.Stop ();
aSource1.clip = aClipSceneMsg;
aSource1.PlayDelayed (1);
}
public string filePath = Application.streamingAssetsPath + "/UserDetails.xml";
public string result = "";
IEnumerator userDetailsXmlPath()
{
print (filePath);
if (filePath.Contains ("://") || filePath.Contains (":///")) {
WWW www = new WWW (filePath);
yield return www;
result = www.text;
print (result);
FetchUserDetails ();
} else {
result = File.ReadAllText (filePath);
print (result);
FetchUserDetails ();
}
}
public void FetchUserDetails()
{
XmlDocument userXml1 = new XmlDocument ();
// userXml1.Load(Application.streamingAssetsPath + "/UserDetails.xml");
// userXml1.Load(Application.dataPath + "js/UserDetails 1.xml");
// userXml1.LoadXml(userXml.text);
userXml1.LoadXml(result);
XmlNodeList userList = userXml1.GetElementsByTagName ("user");
foreach(XmlNode userValue in userList)
{
XmlNodeList userContent = userValue.ChildNodes;
objUser = new Dictionary<string, string>();
foreach(XmlNode value in userContent)
{
objUser.Add (value.Name, value.InnerText);
}
userFullDetails.Add (objUser);
userCountInXml = userList.Count;
userId = new string[userList.Count];
questionSetOfUser = new string[userList.Count];
}
AssignUserXmlValuesToArray ();
}
void AssignUserXmlValuesToArray()
{
for (int us = 0; us < userCountInXml; )
{
userFullDetails[us].TryGetValue ("uid", out userId[us]);
userFullDetails[us].TryGetValue ("questionSet", out questionSetOfUser[us]);
us++;
}
// fetchQnABasedOnLmsLearnerId ();
}
void fetchQnABasedOnLmsLearnerId ()
{
for (int ui = 0; ui < userCountInXml;)
{
if (userId [ui] == lmsLearnerID) {
questionSetForUser = int.Parse (questionSetOfUser [ui]);
FetchQnA ();
}
ui++;
}
}
public void FetchQnA()
{
XmlDocument quizXml = new XmlDocument ();
quizXml.Load(Application.dataPath + "/StreamingAssets/QnASet"+questionSetForUser+".xml");
XmlNodeList quizQnAListLevel1 = quizXml.GetElementsByTagName ("qna_level1");
foreach(XmlNode quizValue in quizQnAListLevel1)
{
XmlNodeList quizContentL1 = quizValue.ChildNodes;
objLevel1 = new Dictionary<string, string>();
foreach(XmlNode value in quizContentL1)
{
objLevel1.Add (value.Name, value.InnerText);
}
quizQnALevel1.Add (objLevel1);
qnaCountInXml = quizQnAListLevel1.Count;
question = new string[quizQnAListLevel1.Count];
option1 = new string[quizQnAListLevel1.Count];
option2 = new string[quizQnAListLevel1.Count];
option3 = new string[quizQnAListLevel1.Count];
option4 = new string[quizQnAListLevel1.Count];
correctOption = new string[quizQnAListLevel1.Count];
}
AssignXmlValuesToArray ();
}
void AssignXmlValuesToArray()
{
for (int i = 0; i < qnaCountInXml; )
{
quizQnALevel1[i].TryGetValue ("question", out question[i]);
quizQnALevel1[i].TryGetValue ("option1", out option1[i]);
quizQnALevel1[i].TryGetValue ("option2", out option2[i]);
quizQnALevel1[i].TryGetValue ("option3", out option3[i]);
quizQnALevel1[i].TryGetValue ("option4", out option4[i]);
quizQnALevel1[i].TryGetValue ("correct", out correctOption[i]);
i++;
}
reshuffleQnA();
}
void reshuffleQnA()
{
for (int t = 0; t < qnaCountInXml; t++ )
{
string tmp = question[t];
string tmp1 = option1[t];
string tmp2 = option2[t];
string tmp3 = option3[t];
string tmp4 = option4[t];
string tmp5 = correctOption[t];
int r = Random.Range(t, qnaCountInXml);
question[t] = question[r];
question[r] = tmp;
option1[t] = option1[r];
option1[r] = tmp1;
option2[t] = option2[r];
option2[r] = tmp2;
option3[t] = option3[r];
option3[r] = tmp3;
option4[t] = option4[r];
option4[r] = tmp4;
correctOption[t] = correctOption[r];
correctOption[r] = tmp5;
question[r] = tmp;
option1[r] = tmp1;
option2[r] = tmp2;
option3[r] = tmp3;
option4[r] = tmp4;
correctOption[r] = tmp5;
questionText.text = question [r];
}
check2Or4Option();
}
void check2Or4Option()
{
if(option1 [qnaDisplayValue].Length != 0 && option2 [qnaDisplayValue].Length != 0 && option3 [qnaDisplayValue].Length != 0 && option4 [qnaDisplayValue].Length != 0)
{
fourOptionQuestion = true;
noOfOptions = 4;
currentOptions = new string[noOfOptions];
}
else if (option1 [qnaDisplayValue].Length != 0 && option2 [qnaDisplayValue].Length != 0 && option3 [qnaDisplayValue].Length == 0 && option4 [qnaDisplayValue].Length == 0)
{
twoOptionQuestion = true;
noOfOptions = 2;
currentOptions = new string[noOfOptions];
}
getCurrentOptions ();
}
void getCurrentOptions()
{
for (int j = 0; j < noOfOptions;)
{
currentOptions[0] = option1[qnaDisplayValue];
currentOptions[1] = option2[qnaDisplayValue];
if(noOfOptions == 4)
{
currentOptions[2] = option3[qnaDisplayValue];
currentOptions[3] = option4[qnaDisplayValue];
}
j++;
}
reshuffleCurrentOptions ();
}
void reshuffleCurrentOptions()
{
for (int k = 0; k < noOfOptions; k++ )
{
string tmp = currentOptions[k];
r = Random.Range(k, noOfOptions);
currentOptions[k] = currentOptions[r];
currentOptions[r] = tmp;
}
}
public void gamePlayInCurrentScene ()
{
aSource.Stop ();
aSource.clip = aClip_selection;
aSource.Play ();
aClipQuestionAttendIns = aClipQuestionAttendInsPack[sceneCount];
aSource1.Stop ();
aSource1.clip = aClipQuestionAttendIns;
aSource1.PlayDelayed (1);
aSource2.Stop ();
sceneCount += 1;
questionCount += 1;
sceneInsAnim.Play ("insFadeOut");
freezeScreen.SetActive (true);
qNaSet.SetActive (true);
for (int ct = 0; ct < choiceTickGObj.Length; ct++) {
choiceTickGObj [ct].SetActive (false);
}
questionText.text = question [questionCount - 1];
for (int l = 0; l < noOfOptions; l++) {
choiceText [l].text = currentOptions [l];
}
for (int n = 0; n < noOfOptions; n++) {
choiceButton [n].transition = Selectable.Transition.ColorTint;
choiceButton [n].image.color = Color.white;
}
qNaAnim.Play ("qnaIn");
readyForAnswering = true;
StartCoroutine (disableSceneInsSet ());
if (sceneCount == 1) {
}
}
IEnumerator disableSceneInsSet ()
{
yield return new WaitForSeconds (0.2f);
sceneInsSet.SetActive (false);
}
public void qNaSelection (int choice)
{
if (readyForAnswering == true)
{
readyForAnswering = false;
if (sceneCount >= 15) {
gameCompleted = true;
}
if (sceneCount < 15) {
aClipMoveFwdIns = aClipMoveFwdInsPack[sceneCount -1];
}
correctWrongMsgGObj.SetActive (true);
correctWrongMsgAnim.Play ("CWmsgFadeIn");
if (currentOptions [choice] == correctOption [qnaDisplayValue])
{
if (maleAvatarSelected == true) {
correctWrongMale.enabled = true;
correctWrongFemale.enabled = false;
correctWrongMale.sprite = maleHappy;
} else {
correctWrongFemale.enabled = true;
correctWrongMale.enabled = false;
correctWrongFemale.sprite = femaleHappy;
}
aSource.Stop ();
aSource.clip = aClip_correctAns;
aSource.Play ();
score += 1;
qnaDisplayValue += 1;
scoreText.text = "SCORE: "+score.ToString();
scoreSetAnim.Play ("score"+score.ToString());
choiceButton[choice].image.color = Color.green;
choiceTickGObj [choice].SetActive (true);
for (int m = 0; m < noOfOptions; m++ )
{
choiceButton [m].transition = Selectable.Transition.None;
}
aClipCorrectWrongMsg = aClipCorrectMsgPack[sceneCount -1];
if (sceneCount == 1) {
correctWrongMsgText.text = "Congratulations your answer is correct. You earned a reward point.\n\nLet us move to the next level.";
}
else if (sceneCount == 2) {
correctWrongMsgText.text = "Well done. You earned one reward point.\n\nIt is time to move forward.";
}
else if (sceneCount == 3) {
correctWrongMsgText.text = "That is quite good! You got a reward point.\n\nLet us now move forward in the shipping cycle.";
}
else if (sceneCount == 4) {
correctWrongMsgText.text = "Excellent! You got it right. You got a reward point.\n\nLet us move forward to the next level.";
}
else if (sceneCount == 5) {
correctWrongMsgText.text = "Wow! You earned a reward point.\n\nHope you are enjoying the game, let us move forward.";
}
else if (sceneCount == 6) {
correctWrongMsgText.text = "Superb! You won a reward point.\n\nIt is now time to move to the next level.";
}
else if (sceneCount == 7) {
correctWrongMsgText.text = "That's really great! You gained a reward point.\n\nLet us proceed with the game.";
}
else if (sceneCount == 8) {
correctWrongMsgText.text = "Outstanding! You won a reward point.\n\nYou are almost halfway through the game. Let us proceed.";
}
else if (sceneCount == 9) {
correctWrongMsgText.text = "You won a reward point.\n\nNow we will move forward with the game.";
}
else if (sceneCount == 10) {
correctWrongMsgText.text = "Good going. You won a reward point.\n\nLet us move forward.";
}
else if (sceneCount == 11) {
correctWrongMsgText.text = "Bingo!. You won a reward point.\n\nOk, let us move forward.";
}
else if (sceneCount == 12) {
correctWrongMsgText.text = "Good! You got a reward point.\n\nLet us go to the next step in the shipping cycle.";
}
else if (sceneCount == 13) {
correctWrongMsgText.text = "This is awesome! You won a reward point.\n\nTime to move forward.";
}
else if (sceneCount == 14) {
correctWrongMsgText.text = "Great! You earned a reward point.\n\nWe are almost at the end of the game. Let us move forward.";
}
else if (sceneCount == 15) {
correctWrongMsgText.text = "Excellent! You won a reward point.";
}
aSource1.Stop ();
aSource1.clip = aClipCorrectWrongMsg;
aSource1.PlayDelayed (1);
if (sceneCount < 15) {
aSource3.Stop ();
aSource3.clip = aClipMoveFwdIns;
aSource3.PlayDelayed (aClipCorrectWrongMsg.length + 0.5f);
}
}
else
{
if (maleAvatarSelected == true) {
correctWrongMale.enabled = true;
correctWrongFemale.enabled = false;
correctWrongMale.sprite = maleSad;
} else {
correctWrongFemale.enabled = true;
correctWrongMale.enabled = false;
correctWrongFemale.sprite = femaleSad;
}
aSource.Stop ();
aSource.clip = aClip_wrongAns;
aSource.Play ();
incorrectAnswerCount += 1;
choiceButton[choice].image.color = Color.red;
StartCoroutine (showCorrectAnswer ());
for (int m = 0; m < noOfOptions; m++ )
{
choiceButton [m].transition = Selectable.Transition.None;
}
aClipCorrectWrongMsg = aClipWrongMsgPack[sceneCount -1];
if (sceneCount == 1) {
correctWrongMsgText.text = "Sorry, your answer is incorrect. You do not get any points for this question.\n\nLet us move to the next level.";
}
else if (sceneCount == 2) {
correctWrongMsgText.text = "I am sorry! You missed it.\n\nIt is time to move forward.";
}
else if (sceneCount == 3) {
correctWrongMsgText.text = "Oh Oh! You did not get this right.\n\nLet us now move forward in the shipping cycle.";
}
else if (sceneCount == 4) {
correctWrongMsgText.text = "Sorry, your answer is incorrect.\n\nLet us move forward to the next level.";
}
else if (sceneCount == 5) {
correctWrongMsgText.text = "Oh Oh! You did not get this right.\n\nHope you are enjoying the game, let us move forward.";
}
else if (sceneCount == 6) {
correctWrongMsgText.text = "Oh No! Your choice is not the right answer.\n\nIt is now time to move to the next level.";
}
else if (sceneCount == 7) {
correctWrongMsgText.text = "Oh Oh! You did not get this right.\n\nLet us proceed with the game.";
}
else if (sceneCount == 8) {
correctWrongMsgText.text = "Sorry, that was not right.\n\nYou are almost halfway through the game. Let us proceed.";
}
else if (sceneCount == 9) {
correctWrongMsgText.text = "Sorry, your answer is incorrect.\n\nNow we will move forward with the game.";
}
else if (sceneCount == 10) {
correctWrongMsgText.text = "I am so sorry. Your answer is incorrect.\n\nLet us move forward.";
}
else if (sceneCount == 11) {
correctWrongMsgText.text = "Sorry, your answer is incorrect.\n\nOk, let us move forward.";
}
else if (sceneCount == 12) {
correctWrongMsgText.text = "Sorry, your answer is incorrect.\n\nLet us go to the next step in the shipping cycle.";
}
else if (sceneCount == 13) {
correctWrongMsgText.text = "Sorry, incorrect answer.\n\nTime to move forward.";
}
else if (sceneCount == 14) {
correctWrongMsgText.text = "Sorry, incorrect answer.\n\nWe are almost at the end of the game. Let us move forward.";
}
else if (sceneCount == 15) {
correctWrongMsgText.text = "Sorry, incorrect answer.";
}
aSource1.Stop ();
aSource1.clip = aClipCorrectWrongMsg;
aSource1.PlayDelayed (1);
if (sceneCount < 15) {
aSource3.Stop ();
aSource3.clip = aClipMoveFwdIns;
aSource3.PlayDelayed (aClipCorrectWrongMsg.length + 0.5f);
}
}
}
}
IEnumerator showCorrectAnswer ()
{
yield return new WaitForSeconds (0.5f);
if (currentOptions [0] == correctOption [qnaDisplayValue]) {
choiceButton [0].image.color = Color.green;
choiceTickGObj [0].SetActive (true);
} else if (currentOptions [1] == correctOption [qnaDisplayValue]) {
choiceButton [1].image.color = Color.green;
choiceTickGObj [1].SetActive (true);
} else if (currentOptions [2] == correctOption [qnaDisplayValue]) {
choiceButton [2].image.color = Color.green;
choiceTickGObj [2].SetActive (true);
} else if (currentOptions [3] == correctOption [qnaDisplayValue]) {
choiceButton [3].image.color = Color.green;
choiceTickGObj [3].SetActive (true);
}
qnaDisplayValue += 1;
}
public void afterAnswerSelection ()
{
aSource1.Stop ();
aSource3.Stop ();
aSource.Stop ();
aSource.clip = aClip_selection;
aSource.Play ();
correctWrongMsgAnim.Play ("CWmsgFadeOut");
qNaAnim.Play ("qnaFadeOut");
if (score == 5 && bronzeMedalGameplay == false)
{
StartCoroutine (disableObjectsAfterAnsInMedal ());
bronzeMedalGameplay = true;
medalGObj.SetActive (true);
medalImg.sprite = bronzeMedalSprite;
medalInsSet.SetActive (true);
medalInsText.text = "Congratulations! You have received a \"Bronze\" medal for answering 5 questions correclty.";
medalInsAnim.Play ("medalDown");
currentMedal = "Bronze";
aSource1.Stop ();
aSource1.clip = aClipCongrats;
aSource1.Play ();
}
else if (score == 10 && silverMedalGameplay == false)
{
StartCoroutine (disableObjectsAfterAnsInMedal ());
silverMedalGameplay = true;
medalGObj.SetActive (true);
medalImg.sprite = silverMedalSprite;
medalInsSet.SetActive (true);
medalInsText.text = "Excellent! You have received a \"Silver\" medal for answering 10 questions correclty.";
medalInsAnim.Play ("medalDown");
currentMedal = "Silver";
aSource1.Stop ();
aSource1.clip = aClipCongrats;
aSource1.Play ();
}
else if (score == 15 && goldMedalGameplay == false)
{
StartCoroutine (disableObjectsAfterAnsInMedal ());
goldMedalGameplay = true;
medalGObj.SetActive (true);
medalImg.sprite = goldMedalSprite;
medalInsSet.SetActive (true);
medalInsText.text = "Awsome! You have received a \"Gold\" medal for answering 15 questions correclty.\n\nYou are a \"Master\" in this game.";
medalInsAnim.Play ("medalDown");
currentMedal = "Gold";
aSource1.Stop ();
aSource1.clip = aClipCongrats;
aSource1.Play ();
}
else
{
bluePrintFullGObj.SetActive (true);
bluePrintFull.Play ("bpFullDown");
if (sceneCount >= 15) {
gameCompleted = true;
}
StartCoroutine (disableObjectsAfterAns ());
if (sceneCount == 13) {
StartCoroutine (enableBananaSetAtImporterWH ());
}
}
}
IEnumerator disableObjectsAfterAnsInMedal ()
{
yield return new WaitForSeconds (1.0f);
correctWrongMsgGObj.SetActive (false);
qNaSet.SetActive (false);
}
public void gamePlayAfterMedalGameplay ()
{
aSource1.Stop ();
medalInsSet.SetActive (false);
bluePrintFullGObj.SetActive (true);
bluePrintFull.Play ("bpFullDown");
if (sceneCount >= 15) {
gameCompleted = true;
}
if (sceneCount == 13) {
StartCoroutine (enableBananaSetAtImporterWH ());
}
StartCoroutine (disableObjectsAfterAns ());
}
IEnumerator disableObjectsAfterAns ()
{
yield return new WaitForSeconds (1.0f);
medalInsSet.SetActive (false);
correctWrongMsgGObj.SetActive (false);
qNaSet.SetActive (false);
unlockScene [sceneCount - 1].SetActive (true);
aSource.Stop ();
aSource.clip = aClip_unlock;
aSource.Play ();
yield return new WaitForSeconds (1.5f);
bluePrintFull.Play ("bpFullUp");
freezeScreen.SetActive (false);
yield return new WaitForSeconds (1.0f);
bluePrintFullGObj.SetActive (false);
if (sceneCount == 2) {
scene3InCamGObj.SetActive (true);
scene1InCamGObj.SetActive (false);
scene1Anim.Play ("s2fadeout");
s3Set.SetActive (true);
}
if (sceneCount == 3) {
sc3BananaBasket1GObj.SetActive (false);
sc3BananaBasket2GObj.SetActive (false);
}
if (sceneCount == 4) {
s5Set.SetActive (true);
// scenesAnim.Play ("sc4Out");
}
if (sceneCount == 7) {
container1.SetActive (false);
container2.SetActive (false);
container3.SetActive (false);
shipSet.SetActive (false);
}
if (sceneCount == 9) {
ShipSetSc9.SetActive (true);
}
if (sceneCount < 15) {
mainCameraAnim.Play ("sc" + sceneCount.ToString () + "animation");
if(sceneCount == 1 || sceneCount == 3 || sceneCount == 7 || sceneCount == 9 || sceneCount == 13)
yield return new WaitForSeconds (1.0f);
else
yield return new WaitForSeconds (0.0f);
routeAnim.Play ("route" + (sceneCount + 1).ToString ());
}
if (sceneCount == 3) {
scene1InCamGObj.SetActive (false);
s4Set.SetActive (true);
}
if (sceneCount == 7)
yield return new WaitForSeconds (5.0f);
else if (sceneCount == 8)
yield return new WaitForSeconds (4.5f);
else if (sceneCount == 9)
yield return new WaitForSeconds (2.5f);
else
yield return new WaitForSeconds (1.5f);
sceneInsSet.SetActive (true);
if (sceneCount < 15) {
aClipSceneMsg = aClipSceneMsgPack [sceneCount];
}
if (sceneCount == 1) {
sceneInsText.text = "Lets get to know the Shipper. A Shipper is a person, company or entity that is shown in all the shipping documents like the bill of lading, commercial invoice, packing list etc. He or she is partly responsible for procuring and/or placing the order for shipment, and maybe also for arranging the freight payment.";
}
else if (sceneCount == 2) {
sceneInsText.text = "You have now reached the place of origin where the container gets stuffed. This can be the customer's place or warehouse.";
}
else if (sceneCount == 3) {
sceneInsText.text = "Here you need to prepare the bill of lading., the bill of lading includes details about the content of the cargo, the cargo type, weight, vessel, voyage etc. Other necessary legal documentation is also done at this stage.";
}
else if (sceneCount == 4) {
sceneInsText.text = "Now you have reached the payment desk. At this stage, the payment is made as in the agreement with the Shipper.";
}
else if (sceneCount == 5) {
sceneInsText.text = "Now you have reached the point of the customs check. Here a customs check is done on the cargo. Then the Container is sealed, so that the cargo remains safe during transit.";
}
else if (sceneCount == 6) {
sceneInsText.text = "Great. You have now reached port of loading. Port of loading is the port terminal where the container will get loaded on vessel.";
}
else if (sceneCount == 7) {
sceneInsText.text = "You are about to reach the destination port. You will get an arrival notice now. An arrival notice is an international shipping document issued by an ocean freight carrier or an ocean freight's agent to the consignee/recipient of the internationally shipped goods (and to the notify party, if any) to inform about the arrival of international sea freight shipment.";
}
else if (sceneCount == 8) {
sceneInsText.text = "You are at the port of discharge now.\n\nOnce the vessel reaches the destination, the container will be unloaded from the vessel at the port of discharge.";
}
else if (sceneCount == 9) {
sceneInsText.text = "You need to go through the customs check again. At the discharge terminal the customs personnel will check the container with the details of container and seal.";
}
else if (sceneCount == 10) {
sceneInsText.text = "You have now reached the consignee. A consignee is the customer who has been informed of the container arrival.";
}
else if (sceneCount == 11) {
sceneInsText.text = "Now you are en-route to deliver the container to the customer. The consignee's container moves on the Land towards warehouse for de-stuffing.";
}
else if (sceneCount == 12) {
sceneInsText.text = "You have now reached the warehouse. At the warehouse the container is de-Stuffed.";
}
else if (sceneCount == 13) {
sceneInsText.text = "You have now reached the place of delivery of the customer. This is the place where the goods are finally delivered.";
}
else if (sceneCount == 14) {
sceneInsText.text = "You have now reached the terminal yard. At last, the empty container moves to the terminal yard. This completes the shipping cycle.";
}
if (sceneCount < 15)
{
sceneInsAnim.Play ("insDown");
check2Or4Option ();
yield return new WaitForSeconds (0.8f);
aSource1.Stop ();
aSource1.clip = aClipSceneMsg;
aSource1.PlayDelayed (1);
}
else
{
StartCoroutine (playFinalAnimationAndConclusion ());
}
}
IEnumerator playFinalAnimationAndConclusion ()
{
mainCameraAnim.Play ("sc14animation1");
yield return new WaitForSeconds (1.0f);
gameoverSet.SetActive (true);
if (maleAvatarSelected == true) {
gameOverMale.SetActive (true);
gameOverFemale.SetActive (false);
if (score >= 14) {
gameOverMaleImg.sprite = maleHappy;
} else {
gameOverMaleImg.sprite = maleSadGO;
}
} else {
gameOverFemale.SetActive (true);
gameOverMale.SetActive (false);
if (score >= 14) {
gameOverFemaleImg.sprite = femaleHappy;
} else {
gameOverFemaleImg.sprite = femaleSadGO;
}
}
gameoverAnim.Play ("goDown");
if (score >= 14) {
gameoverWLmsg.color = winMsgColor;
gameoverWLmsg.text = "CONGRATS, YOU WON!";
// gameoverWLDetails.text = "Hope you had a good run through the shipping cycle. Here is how you fared in the game.\n\nTotal number of correct answers: " + score.ToString () + "\n\nTotal number of incorrect answers: " + (totalQuestions - score).ToString () + "\n\nTotal points earned: " + score.ToString () + "\n\nYou earned a badge for this achievement.\nYou have completed the game in "+timer._main.displayMinutes.ToString()+" Minutes " +timer._main.displaySeconds.ToString()+ " Seconds";
gameoverWLDetails.text = "Hope you had a good run through the shipping cycle. Here is how you fared in the game.\n\nTotal number of correct answers: " + score.ToString () + "\n\nTotal number of incorrect answers: " + (totalQuestions - score).ToString () + "\n\nTotal points earned: " + score.ToString () + "\n\nYou are a \""+currentMedal+"\" medalist."+"\nYou have completed the game in "+timer._main.displayMinutes.ToString()+" Minutes " +timer._main.displaySeconds.ToString()+ " Seconds";
noOfBadges += 1;
PlayerPrefs.SetInt ("BadgeCount", noOfBadges);
badgeDetailsText.text = noOfBadges.ToString ();
} else {
gameoverWLmsg.color = loseMsgColor;
gameoverWLmsg.text = "SORRY, YOU LOSE!";
if (score >= 5) {
gameoverWLDetails.text = "Hope you had a good run through the shipping cycle. Here is how you fared in the game.\n\nTotal number of correct answers: " + score.ToString () + "\n\nTotal number of incorrect answers: " + (totalQuestions - score).ToString () + "\n\nTotal points earned: " + score.ToString () + "\n\nYou are a \"" + currentMedal + "\" medalist." + "\nYou have completed the game in " + timer._main.displayMinutes.ToString () + " Minutes " + timer._main.displaySeconds.ToString () + " Seconds";
} else {
gameoverWLDetails.text = "Hope you had a good run through the shipping cycle. Here is how you fared in the game.\n\nTotal number of correct answers: " + score.ToString () + "\n\nTotal number of incorrect answers: " + (totalQuestions - score).ToString () + "\n\nTotal points earned: " + score.ToString () + "\n\nYou have completed the game in " + timer._main.displayMinutes.ToString () + " Minutes " + timer._main.displaySeconds.ToString () + " Seconds";
}
}
aSource1.Stop ();
aSource1.clip = aClip_conclusion;
aSource1.PlayDelayed (1);
}
IEnumerator enableBananaSetAtImporterWH ()
{
yield return new WaitForSeconds (4.5f);
bananaSetAtImporterWH.SetActive (true);
}
public void playPauseGameplay ()
{
if (bool_playPause == false) {
bool_playPause = true;
aSource.mute = true;
aSource1.mute = true;
aSource2.mute = true;
aSourceCamSc1.mute = true;
aSourceCamSc3.mute = true;
aSourceCamSc7.mute = true;
aSourceCamSc8.mute = true;
aSource3.mute = true;
playPauseImage.sprite = playImage;
} else {
bool_playPause = false;
aSource.mute = false;
aSource1.mute = false;
aSource2.mute = false;
aSourceCamSc1.mute = false;
aSourceCamSc3.mute = false;
aSourceCamSc7.mute = false;
aSourceCamSc8.mute = false;
aSource3.mute = false;
playPauseImage.sprite = pauseImage;
}
}
public void replyGame ()
{
SceneManager.LoadScene ("MaerskLine");
}
public void timesUpGameplay ()
{
StopAllCoroutines ();
qNaSet.SetActive (false);
sceneInsSet.SetActive (false);
bluePrintFullGObj.SetActive (false);
correctWrongMsgGObj.SetActive (false);
medalInsSet.SetActive (false);
freezeScreen.SetActive (true);
timesUpSet.SetActive (true);
timesUpMsgText.text = "Oops your times up. Let's look at your performance.\n\nTotal number of correct answers: " + score.ToString () + "\n\nTotal number of incorrect answers: " + incorrectAnswerCount.ToString () + "\n\nTotal points earned: " + score.ToString ();
timesUpAnim.Play ("goDown");
// bool_playPause = true;
// Time.timeScale = 0.0f;
globe_animator.Stop();
regionIndAnim.Stop();
bluePrint.Stop();
bluePrintFull.Stop();
startInstruction.Stop();
scene1Anim.Stop();
mainCameraAnim.Stop();
globeFullMapAnim.Stop();
sceneInsAnim.Stop();
qNaAnim.Stop();
scoreSetAnim.Stop();
routeAnim.Stop();
routeBGAnim.Stop();
badgeAnim.Stop();
timerAnim.Stop();
correctWrongMsgAnim.Stop();
scenesAnim.Stop();
gameoverAnim.Stop();
medalInsAnim.Stop();
avatarNxtAnim.Stop();
if (maleAvatarSelected == true) {
timesUpMale.SetActive (true);
timesUpFemale.SetActive (false);
timesUpMaleImg.sprite = maleSadTimesUp;
} else {
timesUpFemale.SetActive (true);
timesUpMale.SetActive (false);
timesUpFemaleImg.sprite = femaleSadTimesUp;
}
aSource2.Stop ();
aSource1.Stop ();
aSource.Stop ();
aSource3.Stop ();
aSourceCamSc1.Stop ();
aSourceCamSc3.Stop ();
aSourceCamSc7.Stop ();
aSourceCamSc8.Stop ();
aSource1.Stop ();
aSource1.clip = aClipTimesUp;
aSource1.Play ();
}
public void closeGame ()
{
aSource2.Stop ();
aSource1.Stop ();
aSource.Stop ();
aSource3.Stop ();
aSource.Stop ();
aSource.clip = aClip_selection;
aSource.Play ();
timesUpSet.SetActive (false);
gameoverSet.SetActive (false);
Application.Quit ();
}
}
Please guild me to resolve this issue.
Answer by ben06feb · Aug 30, 2016 at 05:27 AM
public string filePath = Application.streamingAssetsPath + "/UserDetails.xml";
public string result = "";
void Awake ()
{
filePath = Application.streamingAssetsPath + "/UserDetails.xml";
}
void Start ()
{
StartCoroutine(userDetailsXmlPath() );
}
IEnumerator userDetailsXmlPath()
{
print (filePath);
if (filePath.Contains ("://") || filePath.Contains (":///")) {
WWW www = new WWW (filePath);
yield return www;
result = www.text;
print (result);
FetchUserDetails ();
} else {
result = File.ReadAllText (filePath);
print (result);
FetchUserDetails ();
}
}
public void FetchUserDetails()
{
XmlDocument userXml1 = new XmlDocument ();
userXml1.LoadXml(result);
XmlNodeList userList = userXml1.GetElementsByTagName ("user");
foreach(XmlNode userValue in userList)
{
XmlNodeList userContent = userValue.ChildNodes;
objUser = new Dictionary<string, string>();
foreach(XmlNode value in userContent)
{
objUser.Add (value.Name, value.InnerText);
}
userFullDetails.Add (objUser);
userCountInXml = userList.Count;
userId = new string[userList.Count];
questionSetOfUser = new string[userList.Count];
}
AssignUserXmlValuesToArray ();
}
Help!!!!! PLS This code loads textures from the Strea$$anonymous$$gAssets folder. It works on the editor and standalone build for PC but doesnt work on WebGL.
[System.Serializable] // To make List objects visible in the inspector public class AssetsLoader : $$anonymous$$onoBehaviour {
public List AllTextures;
public int DefaultTexture = 0; // Default texture
public GameObject ConsoleComponent;
void Start () {
StartCoroutine ("LoadAllTextures");
}
IEnumerator LoadAllTextures()
{
AllTextures = new List<Texture>();
string Folderpath= Application.strea$$anonymous$$gAssetsPath+"/ArtGalleryTextures";
string[] TextureFilePaths = Directory.GetFiles(Folderpath, "*.jpg");
for (int i = 0; i < TextureFilePaths.Length; i++)
{
UnityWebRequest www = UnityWebRequest.Get(Folderpath);
yield return www.SendWebRequest();
WWW diskTextureDir;
diskTextureDir = new WWW("file://" + TextureFilePaths[i]);
//Save the loaded texture from WWW
AllTextures.Add(diskTextureDir.texture);
}
}
}
Your answer
Follow this Question
Related Questions
Probuilder Polybrush meshes not rendering in webgl 0 Answers
Why does my toon shader not work when I build it in webgl? 0 Answers
WebGL displacement shader doesn't work in build 0 Answers
WebGL Shader compile issues 1 Answer
Pink Texture / Shader issues using the 2D lights from LWRP and building to WebGl 1 Answer