Beispiel #1
0
    static void HandleMetadataPostprocess(string filename)
    {
        Debug.Log("WE GOT METADATA: " + filename);
        object[] meta_nodes = GameObject.FindObjectsOfType(typeof(SuperMetaNode));
        foreach (object obj in meta_nodes)
        {
            SuperMetaNode node          = (SuperMetaNode)obj;
            string        metadata_path = AssetDatabase.GetAssetPath(node.metadata);

            if (metadata_path == filename)
            {
                if (node.autoUpdate)
                {
                    Debug.Log("UPDATE METADATA FOR OBJECT " + node.gameObject.name + "(" + metadata_path + ")");
                    SuperContainerConfig.RefreshClasses();
                    SuperLabelConfig.RefreshAll();
                    SuperSpriteConfig.RefreshClasses();

                    node.ProcessMetadata();
                }
                else
                {
                    Debug.Log("SKIP " + node.gameObject.name + ": autoUpdate false");
                }
            }
        }
    }
Beispiel #2
0
    public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node, GameObject maybe_recycled_node)
    {
        string name       = (string)node["name"];
        string label_type = name.Split('_')[0];

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

        bool is_paragraph = false;

        if (label_type == "paragraph")
        {
            is_paragraph = true;
        }

        GameObject game_object = maybe_recycled_node;
        SuperLabel label       = null;
        Text       ui_text     = null;

        if (game_object == null)
        {
            game_object = new GameObject();
            label       = game_object.AddComponent(typeof(SuperLabel)) as SuperLabel;
            ui_text     = game_object.AddComponent(typeof(Text)) as Text;
        }
        else
        {
            label   = game_object.GetComponent <SuperLabel>();
            ui_text = game_object.GetComponent <Text>();
        }

        label.CreateRectTransform(game_object, node);

        label.name = name;
        label.hierarchyDescription = "LABEL";

        if (is_paragraph)
        {
            ui_text.horizontalOverflow = HorizontalWrapMode.Wrap;
        }
        else
        {
            ui_text.horizontalOverflow = HorizontalWrapMode.Overflow;
        }
        ui_text.verticalOverflow = VerticalWrapMode.Overflow;

        string font = (string)node["font"];

        if (SuperLabelConfig.GetFont(font) != null)
        {
            ui_text.font = SuperLabelConfig.GetFont(font);
        }
        else
        {
            Debug.Log("[WARNING] SuperLabelConfig not able to find " + font + " -- falling back to Arial");
        }

        //by default text shouldn't gobble clicks -- we typically embed text in other controls
        ui_text.raycastTarget = false;

        string text = (string)node["text"];

        ui_text.text = text;
        if (is_paragraph)
        {
            ui_text.text = text.Replace("\r", "\n");
        }

        int font_size = Convert.ToInt32(node["fontSize"]);

        ui_text.fontSize = font_size;

        string font_color_hex = (string)node["color"];

        ui_text.color = HexToColor(font_color_hex);

        if (node.ContainsKey("justification"))
        {
            RectTransform rect_transform = label.GetComponent <RectTransform>();

            string alignment = (string)node["justification"];
            if (alignment == "center")
            {
                if (is_paragraph)
                {
                    ui_text.alignment = TextAnchor.UpperCenter;
                }
                else
                {
                    ui_text.alignment = TextAnchor.MiddleCenter;
                }
            }
            else if (alignment == "left")
            {
                if (is_paragraph)
                {
                    ui_text.alignment = TextAnchor.UpperLeft;
                }
                else
                {
                    ui_text.alignment = TextAnchor.MiddleLeft;
                }

                rect_transform.pivot = new Vector2(0f, 0.5f);
            }
            else if (alignment == "right")
            {
                if (is_paragraph)
                {
                    ui_text.alignment = TextAnchor.UpperRight;
                }
                else
                {
                    ui_text.alignment = TextAnchor.MiddleRight;
                }

                rect_transform.pivot = new Vector2(1f, 0.5f);
            }
        }

        label.cachedMetadata = node;
        label.rootNode       = root_node;

        root_node.labelReferences.Add(new LabelReference(name, label));

        label.transform.SetParent(parent);
        label.Reset();
    }
Beispiel #3
0
    // this one is weird... ideally i'd like to move it out of SuperMetaNode since
    // theoretically only a Container can have children... but maybe containers
    // don't need to know about images/labels/placeholders?
    public void ProcessChildren(Transform parent, List <object> children)
    {
        foreach (object raw_node in children)
        {
            Dictionary <string, object> node = raw_node as Dictionary <string, object>;
            string node_type = (string)node["type"];
            string name      = (string)node["name"];
            switch (node_type)
            {
            case "container":
                if (editorObjectCache.ContainsKey(name))
                {
                    SuperContainerConfig.ProcessNode(this, parent, node, editorObjectCache[name]);
                    editorObjectCache.Remove(name);
                }
                else
                {
                    SuperContainerConfig.ProcessNode(this, parent, node);
                }
                break;

            case "text":
                if (editorObjectCache.ContainsKey(name))
                {
                    SuperLabelConfig.ProcessNode(this, parent, node, editorObjectCache[name]);
                    editorObjectCache.Remove(name);
                }
                else
                {
                    SuperLabelConfig.ProcessNode(this, parent, node);
                }

                break;

            case "image":
                if (editorObjectCache.ContainsKey(name))
                {
                    SuperSpriteConfig.ProcessNode(this, parent, node, editorObjectCache[name]);
                    editorObjectCache.Remove(name);
                }
                else
                {
                    SuperSpriteConfig.ProcessNode(this, parent, node);
                }
                break;

            case "placeholder":
                Rect placeholder = ProcessPlaceholderNode(node);
                placeholderReferences.Add(new PlaceholderReference(name, placeholder));

                if (name == "modal")
                {
                    Debug.Log("ADD A MODAL TO " + parent.name);
                    parent.GetComponent <SuperContainer>().AddModal();
                }
                break;

            default:
                Debug.Log("UH OH -- INVALID NODE FOUND: " + node_type);
                break;
            }
        }
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        SuperMetaNode node = (SuperMetaNode)target;


        if (node.metadata != null)
        {
            if (node.metadata.text != cachedMetadata)
            {
                cachedMetadata = node.metadata.text;

                var json = Json.Deserialize(node.metadata.text) as Dictionary <string, object>;
                cachedOptions = new List <String>()
                {
                    "(root)"
                };

                if (json.ContainsKey("children"))
                {
                    List <object> children = json["children"] as List <object>;
                    for (int i = 0; i < children.Count; i++)
                    {
                        Dictionary <string, object> raw_node = children[i] as Dictionary <string, object>;
                        string node_type = (string)raw_node["type"];
                        string node_name = (string)raw_node["name"];

                        if (node_type == "container")
                        {
                            cachedOptions.Add(node_name);
                        }
                    }
                }


                //grab this when we assign our metadata so we don't have to keep figuring it out
                string path = AssetDatabase.GetAssetPath(node.metadata);
                string dir  = Path.GetDirectoryName(path);
                node.imagePath = dir;
            }



            var current_choice = cachedOptions.IndexOf(node.rootContainer);
            if (current_choice < 0)
            {
                current_choice     = 0;
                node.rootContainer = "(root)";
            }

            // Choose an option from the list
            var choice = EditorGUILayout.Popup("Choose Root Node", current_choice, cachedOptions.ToArray());
            // Update the selected option on the underlying instance of SomeClass
            node.rootContainer = cachedOptions[choice];

            EditorGUILayout.BeginHorizontal();

            //ONLY SHOW THESE BUTTONS IF WE HAVE METADATA
            if (GUILayout.Button("Construct Node"))
            {
                Debug.Log("MAKE IT FROM " + node.metadata);

                SuperContainerConfig.RefreshClasses();
                SuperLabelConfig.RefreshAll();
                SuperSpriteConfig.RefreshClasses();

                node.ProcessMetadata();
            }

            if (GUILayout.Button("Update Node"))
            {
                SuperContainerConfig.RefreshClasses();
                SuperLabelConfig.RefreshAll();
                SuperSpriteConfig.RefreshClasses();

                node.ProcessMetadata();
            }

            EditorGUILayout.EndHorizontal();
        }
    }