public void SetSuccessorChances(List <int> newChances)
    {
        int counter = 0;

        foreach (Transform child in transformOfObjects)
        {
            Destroy(child.gameObject);
        }
        foreach (ProductionRule prod in productionRuleOrganiser.productionRules)
        {
            Succesors.StochasticSuccesor succ = (prod.succesorObject as Succesors.StochasticSuccesor);
            if (succ)
            {
                GameObject      obj        = Instantiate <GameObject>(parameterTextShowValues, transformOfObjects);
                TextMeshProUGUI textHolder = obj.GetComponent <TextMeshProUGUI>();
                textHolder.text = succ.name + ": ";
                for (int i = 0; i < succ.chances.Length; i++)
                {
                    succ.chances[i]  = newChances[counter];
                    textHolder.text += succ.chances[i] + ", ";
                    counter++;
                }
            }
        }
    }
    public List <int> GetSuccessorChances()
    {
        List <int> chances = new List <int>();

        foreach (ProductionRule prod in productionRuleOrganiser.productionRules)
        {
            Succesors.StochasticSuccesor succ = (prod.succesorObject as Succesors.StochasticSuccesor);

            if (succ)
            {
                chances.AddRange(succ.chances);
            }
        }
        return(chances);
    }
Ejemplo n.º 3
0
    static public Succesors.Successor ReadSuccessor(string path)
    {
        string jsonText   = HandleTextFile.ReadString(path);
        var    parsedJson = JSON.Parse(jsonText);

        if (parsedJson["type"] == "single")
        {
            Succesors.ContextFreeSuccesor single = ScriptableObject.CreateInstance <Succesors.ContextFreeSuccesor>();
            single.SetSuccesor(parsedJson["successor"].Value);

            return(single);
        }
        else if (parsedJson["type"] == "stochastic")
        {
            Succesors.StochasticSuccesor stochastic = ScriptableObject.CreateInstance <Succesors.StochasticSuccesor>();
            stochastic.name = parsedJson["name"];
            //Get all the successors from the array in the JSON
            List <string> listOfSuccessors = new List <string>();
            foreach (JSONNode node in parsedJson["successors"])
            {
                listOfSuccessors.Add(node.Value);
            }
            stochastic.succesors = listOfSuccessors.ToArray();

            //Get all the chances from the array in the JSON
            List <int> listOfChances = new List <int>();

            foreach (JSONNode node in parsedJson["chances"])
            {
                listOfChances.Add((int)Convert.ToInt32(node.Value));
            }
            stochastic.chances = listOfChances.ToArray();

            stochastic.CalculateChances();

            Debug.Log(stochastic.ToString());
            return(stochastic);
        }
        Debug.Log("The JSON " + path + " of type " + parsedJson["type"] + " was badly formed");
        return(null);
    }