public static void SetTextWithScales(Text t, string msg) { IFontSetter.SetFont(t); RectTransform trans = t.rectTransform; TextGenerationSettings s = t.GetGenerationSettings(trans.rect.size); float slotSize = t.cachedTextGenerator.GetPreferredHeight(msg, s); trans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize); t.text = msg; }
public void InitializeNode() { if (dialog.current_index < 0 || dialog.nodes.Length < 1) { dialog.has_ended = true; control.OutDialog(); switch (dialog.current_index) { case -2: // to trade menu break; case -3: //spetialAction dialog.onAction.Invoke(); break; } dialog.current_index = 0; } else { Button[] bts = parent.GetComponentsInChildren <Button> (); for (int i = 0; i < bts.Length; i++) { GameObject.Destroy(bts [i].gameObject); } float end_Scale = 0; Button[] bN = new Button[dialog.currentNode.answers.Length]; for (int i = 0; i < dialog.currentNode.answers.Length; i++) { Button bt = null; GameObject bPref = (GameObject)Resources.Load("Prefabs/DialogSlot"); bt = Button.Instantiate(bPref, parent).GetComponent <Button> (); RectTransform trans = bt.GetComponent <RectTransform> (); trans.anchoredPosition = -Vector2.up * end_Scale + new Vector2(10, -10); Text t = bt.GetComponent <Text> (); IFontSetter.SetFont(t); IControl.SetTextWithScales(t, dialog.currentNode.answers [i]); float scale = trans.rect.height; end_Scale += scale + 15; bt.onClick.RemoveAllListeners(); int node_next = dialog.currentNode.answersTr[i].nextNode; bt.onClick.AddListener(delegate { dialog.current_index = node_next; InitializeNode(); }); bN [i] = bt; } parent.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, end_Scale + 10); IFontSetter.SetFont(for_answer); IControl.SetTextWithScales(for_answer, dialog.currentNode.npc_text); } }
public InventorySlot[] FillItemsTo(RectTransform parent, int[] items) { GameObject prefab = (GameObject)Resources.Load("Prefabs/Slot"); Button[] buttons = parent.GetComponentsInChildren <Button>(); for (int i = 0; i < buttons.Length; i++) { Destroy(buttons[i].gameObject); } List <InventorySlot> bts = new List <InventorySlot> (); List <int> has = new List <int> (); List <ISlot> upd = new List <ISlot> (); for (int i = 0; i < items.Length; i++) { if (!HasInt(has.ToArray(), items[i])) { upd.Add(new ISlot(items [i])); has.Add(items [i]); } else { int index = -1; for (int n = 0; n < upd.Count; n++) { if (upd[n].id == items[i]) { index = n; break; } } if (index > -1) { upd [index].Add(); } } } float slotSize = prefab.GetComponent <RectTransform>().rect.height; for (int i = 0; i < upd.Count; i++) { RectTransform trans = ((GameObject)Instantiate(prefab)).GetComponent <RectTransform> (); trans.SetParent(parent); trans.anchoredPosition = -Vector2.up * slotSize * i; trans.GetComponentInChildren <RawImage>().texture = IItemAsset.LoadTexture(upd[i].id); string num = ""; if (upd[i].count > 1) { num = "(" + upd [i].count + ")"; } Text t = trans.GetComponentInChildren <Text> (); IFontSetter.SetFont(t); t.text = IItemAsset.items[upd[i].id].name + num; trans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, parent.rect.width); Button bt = trans.GetComponent <Button>(); Color c = Color.white; if (!character.status.CanUseItem(upd[i].id)) { c = new Color(1f, 0.5f, 0.5f); } bt.image.color = c; bts.Add(new InventorySlot(upd[i].id, bt)); } parent.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize * upd.Count); return(bts.ToArray()); }