Exemplo n.º 1
0
    public void OnEnable()
    {
        Initialisation.Start();
        actions = Controls.actions;
        //Debug.Log("ACTION0!");
        //Debug.Log(actions[0]);
        //Debug.Log("ACTION0\\!");
        foreach (Action a in actions)
        {
            //Debug.Log("ACTION!");


            try
            {
                actionByCategory[a.category.name].Add(a);
            }
            catch (KeyNotFoundException e)
            {
                List <Action> l = new List <Action> {
                    a
                };
                actionByCategory.Add(a.category.name, l);
                categories.Add(new Category(a.category.name, a.category.description));
            }
        }

        GameObject mainControlMenu = CreateMenu();

        //mainControlMenu.transform.SetAsFirstSibling();
        mainControlMenu.transform.SetParent(transform.parent);
        mainControlMenu.transform.localPosition = new Vector2(0, 0);
        mainControlMenu.name = "Menu Control";

        ControlOption.menu = mainControlMenu;//new
        GameObject selected = mainControlMenu.GetComponent <Menu>().selected;

        for (int k = 0; k < categories.Count; k++)
        {
            Category c = categories[k];

            GameObject catMenu = CreateMenuCategory(actionByCategory[c.name]);

            catMenu.name = "Menu " + actionByCategory[c.name][0].category;

            GameObject catOption = CreateOptionCategory(actionByCategory[c.name], catMenu);
            catOption.transform.SetParent(mainControlMenu.transform);
            catOption.name = "Option " + actionByCategory[c.name][0].category;


            //catMenu.transform.SetAsFirstSibling();
            catMenu.transform.SetParent(transform.parent);
            catMenu.transform.localPosition = k * sep * Vector2.down;


            if (selected.transform.parent == null)
            {
                //selected.transform.SetParent(catMenu.transform, false);
                selected.transform.parent        = catMenu.transform;//MODIFIED
                selected.transform.localPosition = Vector2.zero;
            }


            //Debug.Log("Aah");
        }
        gameObject.AddComponent <Controls>();
    }