Exemple #1
0
    /// <summary>
    /// Refreshes the content canvas.
    /// </summary>
    /// The method is used to initilize all the buttons.
    public void RefreshScroll()
    {
        //Always clean the previous items
        int child = content.childCount;

        for (int i = 0; i < child; i++)
        {
            Destroy(content.GetChild(i).gameObject);
        }

        Dictionary <string, Dictionary <string, string> > handbookDictionary = HandbookSaver.GetHandbook();

        handbookTabs = new GameObject[handbookDictionary.Count];
        int m = 0;

        //Generates new items
        foreach (string formula in handbookDictionary.Keys)
        {
            GameObject handbookItem = Instantiate(reagentButtonPrefab.gameObject) as GameObject;
            handbookItem.name = formula;

            handbookItem.GetComponentInChildren <Text>().text = handbookDictionary[formula]["formula"];
            handbookItem.gameObject.GetComponent <Button> ().onClick.AddListener(() => GoToReagent(handbookItem.name));
            handbookItem.transform.SetParent(content.transform, false);
            handbookTabs[m] = handbookItem;
            m++;
        }
    }
    public void SetValues(string formula)
    {
        Dictionary <string, Dictionary <string, string> > handbookDictionary = HandbookSaver.GetHandbook();

        if (formula != "")
        {
            reagentFormula.text     = formula;
            reagentDescription.text = handbookDictionary [formula] ["description"];
        }
    }
    //Loads the phase from a .json file, and returns a dictionary of phases
    private static Dictionary <string, Dictionary <string, string> > LoadHandbook()
    {
        JSONEditor jsonEditor = new JSONEditor("handbook", true);

        Dictionary <string, Dictionary <string, string> > handbook = new Dictionary <string, Dictionary <string, string> > ();

        for (int i = 0; i < jsonEditor.NumberOfObjects(); i++)
        {
            handbook.Add(jsonEditor.GetString(i, "formula"), HandbookSaver.LoadReagentValues(jsonEditor, i));
        }
        return(handbook);
    }
    /// <summary>
    /// Sets the values of the state according to the reagent selected
    /// </summary>
    public void OpenReagentInfo(string formula)
    {
        Dictionary <string, Dictionary <string, string> > handbookDictionary = HandbookSaver.GetHandbook();


        Debug.Log("Opening info of " + formula);
        if (formula != "")
        {
            reagentFormula.text     = formula;
            reagentDescription.text = handbookDictionary [formula] ["description"];
        }
    }
    // Use this for initialization
    public void Start()
    {
        Dictionary <string, Dictionary <string, string> > handbookDictionary = HandbookSaver.GetHandbook();

        foreach (string formula in handbookDictionary.Keys)
        {
            GameObject handbookItem = Instantiate(reagentButtonPrefab.gameObject) as GameObject;
            handbookItem.name = formula;

            handbookItem.GetComponentInChildren <Text>().text = handbookDictionary[formula]["formula"];
            handbookItem.gameObject.GetComponent <Button> ().onClick.AddListener(() => OpenReagent(handbookItem.name));
            handbookItem.transform.SetParent(content.transform, false);
        }
    }