Пример #1
0
    public void init(TypeChallenge tc, MinorIsland island, Building myBuilding)
    {
        this.Client = GameObject.Find("Network").GetComponent<Client>();

        canvasChallenge = this.transform.parent.GetComponent<Canvas>();

        this.building = myBuilding;
        this.minorIsland = island;

        this.typeChallenge = tc;
        if (typeChallenge == TypeChallenge.QCM)
            this.nbPropositions = 3;
        else
            this.nbPropositions = 2;

        //CSV part
        //row[0] : question ; row[1] : answer ; row[2] : explainations ; after : propositions
        //VraiFaux : answer = Proposition0 ou answer = Proposition1
        //QCM : answer = Proposition0 ou answer = Proposition1 ou answer = Proposition2

        //ENCODAGE : UTF8-16-LE
        //last line of file usually blank --> to be removed!
        //csv = Resources.Load<TextAsset>("Challenges/ChallengesFiles/" + typeChallenge.ToString() + "/" + typeChallenge.ToString() + "_" + myBuilding.TypeBuilding.ToString());
        if (RegisterScene.level == 0)   //collège
            csv = Resources.Load<TextAsset>("Challenges/ChallengesFiles/College/" + typeChallenge.ToString() + "/" + typeChallenge.ToString() + "_" + myBuilding.TypeBuilding.ToString());
        else
            csv = Resources.Load<TextAsset>("Challenges/ChallengesFiles/Lycee/" + typeChallenge.ToString() + "/" + typeChallenge.ToString() + "_" + myBuilding.TypeBuilding.ToString());

        Debug.Log("File : " + typeChallenge.ToString() + "_" + myBuilding.TypeBuilding.ToString());

        string[] row = CSV_reader.GetRandomLine(csv.text);

        try
        {
            this.question = row[0];
        }
        catch
        {
            error = true;
        }
        finally
        {
            if (!error)
            {
                addLineBreaks();
                this.answer = row[1];
                this.explainations = row[2];
                this.propositions = new string[nbPropositions];
                this.propositions[0] = row[3];
                this.propositions[1] = row[4];
                if (this.nbPropositions == 3)
                    this.propositions[2] = row[5];

                foreach (Text text in canvasChallenge.GetComponentsInChildren<Text>())
                {
                    switch (text.name)
                    {
                        case "Question":
                            text.text = this.question;
                            break;
                        case "Result":
                            resultText = text;
                            break;
                        case "Proposition0":
                            if (typeChallenge == TypeChallenge.QCM)
                                text.text = this.propositions[0];
                            break;
                        case "Proposition1":
                            if (typeChallenge == TypeChallenge.QCM)
                                text.text = this.propositions[1];
                            break;
                        case "Proposition2":
                            if (typeChallenge == TypeChallenge.QCM)
                                text.text = this.propositions[2];
                            break;
                    }
                }

                foreach (SpriteRenderer sp in canvasChallenge.GetComponentsInChildren<SpriteRenderer>())
                {
                    if (sp.name == "background")
                        this.background = sp;
                }
            }
            else
            {
                minorIsland.displayPopup("Oups ! Une erreur s'eest produite, veuillez ré-essayer ...", 3);
                Destroy(GameObject.Find("Challenge_" + typeChallenge + "_" + minorIsland.nameMinorIsland));
            }
        }
    }
Пример #2
0
 //for objects (expect background) which have not been initialized
 private void refreshAttributes()
 {
     background = this.transform.parent.Find("background").gameObject.GetComponent<SpriteRenderer>();
     ChallengeUpgrade backgroundChallengeUpgrade = this.transform.parent.Find("background").gameObject.GetComponent<ChallengeUpgrade>();
     this.question = backgroundChallengeUpgrade.question;
     this.answer = backgroundChallengeUpgrade.answer;
     this.explainations = backgroundChallengeUpgrade.explainations;
     this.propositions = backgroundChallengeUpgrade.propositions;
     this.nbPropositions = backgroundChallengeUpgrade.nbPropositions;
     this.typeChallenge = backgroundChallengeUpgrade.typeChallenge;
     this.resultText = backgroundChallengeUpgrade.resultText;
     this.minorIsland = backgroundChallengeUpgrade.minorIsland;
     this.goodAnswer = backgroundChallengeUpgrade.goodAnswer;
     this.canvasChallenge = backgroundChallengeUpgrade.canvasChallenge;
     this.building = backgroundChallengeUpgrade.building;
     this.Client = backgroundChallengeUpgrade.Client;
 }
Пример #3
0
 //for objects (expect background) which have not been initialized
 private void refreshAttributes()
 {
     background = this.transform.parent.Find("background").gameObject.GetComponent<SpriteRenderer>();
     ChallengeBuild backgroundChallengeBuild = this.transform.parent.Find("background").gameObject.GetComponent<ChallengeBuild>();
     this.question = backgroundChallengeBuild.question;
     this.answer = backgroundChallengeBuild.answer;
     this.explainations = backgroundChallengeBuild.explainations;
     this.propositions = backgroundChallengeBuild.propositions;
     this.nbPropositions = backgroundChallengeBuild.nbPropositions;
     this.typeChallenge = backgroundChallengeBuild.typeChallenge;
     this.resultText = backgroundChallengeBuild.resultText;
     this.minorIsland = backgroundChallengeBuild.minorIsland;
     this.goodAnswer = backgroundChallengeBuild.goodAnswer;
     this.canvasChallenge = backgroundChallengeBuild.canvasChallenge;
 }