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"); } } } }
public void Refresh() { metaNode = GetComponent <SuperMetaNode>(); metaNode.Get <SuperTab>("tab_front_sushi").currentState = sushi.name; metaNode.Get <SuperTab>("tab_back_sushi").currentState = sushi.name; fishLabel.text = sushi.fish + " NIGIRI"; countLabel.text = count + "/2"; priceLabel.text = "$" + sushi.nigiriPrice; }
public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node, GameObject maybe_recycled_node) { #if UNITY_EDITOR string image_name = (string)node["name"]; string image_type = image_name.Split('_')[0]; if (spriteClasses.ContainsKey(image_type)) { object[] args = new object[4]; args[0] = root_node; args[1] = parent; args[2] = node; args[3] = maybe_recycled_node; spriteClasses[image_type].GetMethod("ProcessNode").Invoke(null, args); return; } GameObject game_object = maybe_recycled_node; SuperSprite sprite = null; Image image = null; if (game_object == null) { game_object = new GameObject(); image = game_object.AddComponent(typeof(Image)) as Image; sprite = game_object.AddComponent(typeof(SuperSprite)) as SuperSprite; } else { image = game_object.GetComponent <Image>(); sprite = game_object.GetComponent <SuperSprite>(); } sprite.CreateRectTransform(game_object, node); sprite.name = image_name; sprite.hierarchyDescription = "SPRITE"; image.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(root_node.imagePath + "/" + image_name + ".png"); if (image_type == "flipX") { sprite.flipX = true; } sprite.cachedMetadata = node; sprite.rootNode = root_node; root_node.spriteReferences.Add(new SpriteReference(image_name, sprite)); game_object.transform.SetParent(parent); sprite.Reset(); #endif }
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>); }
//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(); }
//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! }
// Use this for initialization void Start() { orders = new List <SushiPrefab>(); metaNode = GetComponent <SuperMetaNode>(); queueContainer = metaNode.ContainerWithName("order_queue"); inventory = new Dictionary <Sushi, int>(); foreach (Sushi fish in sushi) { inventory[fish] = 0; } inventory[rice] = 0; AddSushiToQueue(); AddSushiToQueue(); AddSushiToQueue(); AddSushiToQueue(); foreach (SuperButtonBase button in metaNode.buttons.Values) { button.onClick += HandleButton; } Refresh(); selected = new List <int>(); activeIngredients = new Dictionary <int, Sushi>(); for (var i = 1; i <= 9; i++) { activeIngredients[i] = null; } Fill(); }
//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 }
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(); }
public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node) { ProcessNode(root_node, parent, node, null); }
// Use this for initialization void Start() { metaNode = GetComponent <SuperMetaNode>(); }
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(); } }
//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) { #if UNITY_EDITOR string name = (string)node["name"]; GameObject game_object = maybe_recycled_node; SuperScale9Sprite sprite = null; Image image = null; if (game_object == null) { game_object = new GameObject(); image = game_object.AddComponent(typeof(Image)) as Image; sprite = game_object.AddComponent(typeof(SuperScale9Sprite)) as SuperScale9Sprite; } else { image = game_object.GetComponent <Image>(); sprite = game_object.GetComponent <SuperScale9Sprite>(); } sprite.CreateRectTransform(game_object, node); //SCALE9 Container has 3 children: // an image (any name) // placeholder_center (the center cutout of the scale9) // placeholder_size (the size the image should stretch to fill) bool has_image = false; bool has_center = false; bool has_size = false; List <object> children = node["children"] as List <object>; foreach (object raw_node in children) { Dictionary <string, object> child_node = raw_node as Dictionary <string, object>; string node_type = (string)child_node["type"]; string child_name = (string)child_node["name"]; switch (node_type) { case "image": has_image = true; //we discard the "scale9_whatever" and just use the image name name = child_name; image.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(root_node.imagePath + "/" + child_name + ".png"); sprite.imageRect = SuperMetaNode.ProcessPlaceholderNode(child_node); break; case "placeholder": if (child_name == "center") { has_center = true; sprite.centerRect = SuperMetaNode.ProcessPlaceholderNode(child_node); } else if (child_name == "size") { has_size = true; sprite.sizeRect = SuperMetaNode.ProcessPlaceholderNode(child_node); } else { Debug.Log("UH OH -- SCALE9 HAS A PLACEHOLDER NAMED " + child_name); } break; default: Debug.Log("UH OH -- SCALE9 NODE HAD SOMETHING IT SHOULDN'T HAVE: " + node_type); break; } } if (!has_image) { Debug.Log("[ERROR] NO IMAGE FOUND FOR PLACEHOLDER " + name); } if (!has_size) { Debug.Log("[ERROR] NO SIZE PLACEHOLDER FOUND FOR PLACEHOLDER " + name); } if (!has_center) { Debug.Log("[ERROR] NO CENTER PLACEHOLDER FOUND FOR PLACEHOLDER " + name); } Sprite original = image.sprite; sprite.CalculateBorder(); //most commonly, the border will be Vector4.zero... but also want to warn when the underlying asset has changed if (image.sprite.border != sprite.borderLBRT) { Debug.Log("[WARNING] sprite " + name + " has no border or doesn't match! This can't be automated..."); Debug.Log("... duplicating the sprite, which will split your sprite batching. To fix this..."); Debug.Log("... set the sprite's border LBRT to " + sprite.borderLBRT); Rect rect = new Rect(0, 0, original.texture.width, original.texture.height); Sprite replacement = Sprite.Create(original.texture, rect, new Vector2(0.5f, 0.5f), 100, 1, SpriteMeshType.FullRect, sprite.borderLBRT); image.sprite = replacement; } image.type = Image.Type.Sliced; // image.hasBorder = true; sprite.name = name; sprite.hierarchyDescription = "SCALE9"; sprite.cachedMetadata = node; sprite.rootNode = root_node; root_node.spriteReferences.Add(new SpriteReference(name, sprite)); game_object.transform.SetParent(parent); sprite.Reset(); #endif }