public override void  OnInspectorGUI()
    {
        base.OnInspectorGUI();
        VerticalLayoutCustom vlc = (VerticalLayoutCustom)target;

        if (GUILayout.Button("Resize TMPros"))
        {
            vlc.ResizeTextContainers();
        }


        if (GUILayout.Button("Align elements"))
        {
            vlc.AlignElements();
        }

        if (GUILayout.Button("Resize container"))
        {
            vlc.ResizeContainer();
        }
    }
Esempio n. 2
0
    void SetContent(ref Paragraph[] paragraphs, VerticalLayoutCustom vlc)
    {
        foreach (Transform child in vlc.transform)
        {
            GameObject child_to_delete = child.gameObject;
            if (!child_to_delete.name.Equals("Image_header"))
            {
//                print("Destroying " + child_to_delete.name);
                Destroy(child_to_delete);
            }
            else
            {
                header_image = child_to_delete;
            }
        }



        List <Transform> added_objects = new List <Transform>();


        foreach (Paragraph p in paragraphs)
        {
            if (!p.title.Equals("SKIP"))
            {
                GameObject p_title = Instantiate(title_prefab, Vector3.zero, Quaternion.identity);
                p_title.transform.GetChild(0).GetComponent <TextMeshProUGUI>().SetText(p.title);
                p_title.transform.SetParent(vlc.transform);

                added_objects.Add(p_title.transform);
            }

            if (p.image == null)
            {
                GameObject p_text = Instantiate(text_prefab, Vector3.zero, Quaternion.identity, vlc.GetComponent <RectTransform>());

                p_text.GetComponent <TextMeshProUGUI>().SetText(p.text);
                added_objects.Add(p_text.transform);
            }
            else
            {
                GameObject p_image = Instantiate(image_prefab, Vector3.zero, Quaternion.identity, vlc.GetComponent <RectTransform>());
                p_image.GetComponent <Image>().sprite = p.image;
                p_image.GetComponent <Image>().SetNativeSize();

                added_objects.Add(p_image.transform);
            }
        }


        foreach (Transform t in added_objects)
        {
            //t.SetAsFirstSibling();
            t.localScale = Vector3.one;
        }

        header_image.transform.SetAsFirstSibling();

        vlc.ResizeTextContainers();
        vlc.AlignElements();
        vlc.ResizeContainer();

        vlc.updateNeeded = true;
    }