Пример #1
0
    // Use this for initialization
    void Start()
    {
        // Add prefabs to container
        // This allows us to skip the ugly if/else
        menuItemPrefabContainer.Add("rectangle", rectMenuItem);
        menuItemPrefabContainer.Add("circle", circleMenuItem);

        // Create a new instance of the ReadFromFile class
        // Allows us to access the method that turns a .json file into a string
        ReadFromFile readFromFile = new ReadFromFile();

        // Parse the .json file into a string
        string menu = readFromFile.LoadJSONResourceFile("ReferenceFiles/menu.json");

        // Turn that string into a SimpleJSON JSONNode
        _jsonNode = JSONNode.Parse(menu);

        // Use a recursive method to generate all of the Menu Items at start up
        generateMenuItems(_jsonNode["Menu"]);

        // This method "creates" the menu items
        createMenuItems(_jsonNode["Menu"]);

        // Positions the menu items correctly
        positionMenuItems(_jsonNode["Menu"]);

        // Hides the menu items
        hideAllItems(_jsonNode["Menu"]);

        // Update a reference variable
        GameObject.Find("GameManager").GetComponent <RevealMenuItems>().updateMenuItemsReference();

        // Update the top level ChildController script
        // For some reason, it is the only one that doesn't update
        GameObject.Find("MenuHolder").GetComponent <ChildController>().handleChildrenSetup();
    }