public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node, GameObject maybe_recycled_node)
    {
        string name           = (string)node["name"];
        string container_type = name.Split('_')[0];

        if (containerClasses.ContainsKey(container_type))
        {
            object[] args = new object[4];
            args[0] = root_node;
            args[1] = parent;
            args[2] = node;
            args[3] = maybe_recycled_node;
            containerClasses[container_type].GetMethod("ProcessNode").Invoke(null, args);
            return;
        }

        GameObject     game_object = maybe_recycled_node;
        SuperContainer container   = null;

        if (game_object == null)
        {
            game_object = new GameObject();
            container   = game_object.AddComponent(typeof(SuperContainer)) as SuperContainer;
        }
        else
        {
            container = game_object.GetComponent <SuperContainer>();
        }

        container.CreateRectTransform(game_object, node);

        root_node.containerReferences.Add(new ContainerReference(name, container));
        container.name = name;
        container.hierarchyDescription = "";

        container.cachedMetadata = node;
        container.rootNode       = root_node;

        game_object.transform.SetParent(parent);
        container.Reset();

        root_node.ProcessChildren(container.transform, node["children"] as List <object>);
    }
Beispiel #2
0
    //Custom classes don't need to create a ProcessNode that doesn't take maybe_recycled_node, since
    //the only way to get here is through the Container/Label/Sprite configs passing it through
    public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node, GameObject maybe_recycled_node)
    {
        string name = (string)node["name"];

        GameObject  game_object = maybe_recycled_node;
        SuperButton button      = null;

        if (game_object == null)
        {
            game_object = new GameObject();
            button      = game_object.AddComponent(typeof(SuperButton)) as SuperButton;

            button.createAnimation();
        }
        else
        {
            button = game_object.GetComponent <SuperButton>();

            //TODO: should probably verify that we still have our UpState/HighlightedState/PressedState/DisabledState
            //but for now just assume we're not changing classes
        }

        button.CreateRectTransform(game_object, node);
        button.name                 = name;
        button.rootNode             = root_node;
        button.cachedMetadata       = node;
        button.hierarchyDescription = "BUTTON";

        root_node.buttonReferences.Add(new ButtonReference(name, button));

        game_object.transform.SetParent(parent);
        button.Reset();

        //image nodes don't have children
        if (node.ContainsKey("children"))
        {
            root_node.ProcessChildren(game_object.transform, node["children"] as List <object>);
        }

        //we post process our children into our state objects so they can turn on/off correctly
        button.sortChildren();
    }
Beispiel #3
0
    //Custom classes don't need to create a ProcessNode that doesn't take maybe_recycled_node, since
    //the only way to get here is through the Container/Label/Sprite configs passing it through
    public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node, GameObject maybe_recycled_node)
    {
        string name = (string)node["name"];

        GameObject game_object = maybe_recycled_node;
        SuperTab   tab         = null;

        if (game_object == null)
        {
            game_object = new GameObject();
            tab         = game_object.AddComponent(typeof(SuperTab)) as SuperTab;
        }
        else
        {
            tab = game_object.GetComponent <SuperTab>();
        }

        tab.CreateRectTransform(game_object, node);
        tab.name                 = name;
        tab.rootNode             = root_node;
        tab.cachedMetadata       = node;
        tab.hierarchyDescription = "TAB";

        root_node.controlReferences.Add(new ControlReference(name, tab));

        game_object.transform.SetParent(parent);
        tab.Reset();

        //image nodes don't have children
        if (node.ContainsKey("children"))
        {
            root_node.ProcessChildren(game_object.transform, node["children"] as List <object>);
        }

        //this is cosmetic only... the states won't persist into runtime, but it will hide all but the last
        //found state in the editor so our states dont look like hot garbage
        tab.CreateStates();

        //make sure to call CreateStates in Start() or we won't know what to do!
    }
Beispiel #4
0
    //SuperScaleButton takes two inputs:
    //  a contaner named scalebtn_
    //  a single sprite named scalebtn_
    //  the end result is the same!
    //  but if we're just an image... let's fake being an image inside a container
    public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node, GameObject maybe_recycled_node)
    {
        #if UNITY_EDITOR
        string node_type = (string)node["type"];
        string name      = (string)node["name"];

        GameObject       game_object = maybe_recycled_node;
        SuperScaleButton button      = null;
        if (game_object == null)
        {
            game_object = new GameObject();
            button      = game_object.AddComponent(typeof(SuperScaleButton)) as SuperScaleButton;
            button.createAnimation();
        }
        else
        {
            button = game_object.GetComponent <SuperScaleButton>();
            //TODO: should probably verify that our animation is still set up properly
            //but for now just assume we're not changing classes
        }

        button.CreateRectTransform(game_object, node);
        button.name                 = name;
        button.rootNode             = root_node;
        button.cachedMetadata       = node;
        button.hierarchyDescription = "BUTTON";

        root_node.buttonReferences.Add(new ButtonReference(name, button));

        game_object.transform.SetParent(parent);
        button.Reset();

        if (node_type == "image")
        {
            SuperSprite sprite = game_object.GetComponent <SuperSprite>();
            Image       image  = null;
            if (sprite == null)
            {
                sprite = game_object.AddComponent(typeof(SuperSprite)) as SuperSprite;
                image  = game_object.AddComponent(typeof(Image)) as Image;
            }
            else
            {
                image = game_object.GetComponent <Image>();
            }

            sprite.name           = name;
            sprite.rootNode       = root_node;
            sprite.cachedMetadata = node;

            image.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(root_node.imagePath + "/" + name + ".png");

            sprite.resetX = button.resetX;
            sprite.resetY = button.resetY;

            root_node.spriteReferences.Add(new SpriteReference(name, sprite));
            game_object.transform.SetParent(parent);

            sprite.Reset();
        }

        //image nodes don't have children
        if (node.ContainsKey("children"))
        {
            root_node.ProcessChildren(game_object.transform, node["children"] as List <object>);
        }
        #endif
    }