Esempio n. 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");
                }
            }
        }
    }
Esempio n. 2
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;
            }
        }
    }
Esempio n. 3
0
    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();
        }
    }