예제 #1
0
    public MyWindow(Sprite sprite, string title, Rect rect)
        : base()
    {
        isOpen = true;
        Head = new MyPanel(sprite, rect);
        Head.Element.name = "Window" + title;
        var trans = Head.Element.GetComponent<RectTransform>();
        Head.SetAnchor(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f));

        trans.anchoredPosition3D = new Vector3(0, 0, 0);
        trans.anchoredPosition = new Vector2(0, 0);
        trans.localPosition = new Vector3(0, 0, 0);
        trans.localScale = new Vector3(1, 1, 1);
        SetSize(trans, rect.size);

        var header = new MyPanel(sprite, rect);

        trans = header.Element.GetComponent<RectTransform>();
        header.Element.GetComponent<Image>().color = new Color32(230, 230, 230, 200);
        header.SetAnchor(new Vector2(0, 1), new Vector2(1, 1));
        trans.anchoredPosition3D = new Vector3(0, 0, 0);
        trans.anchoredPosition = new Vector2(0, 0);
        trans.offsetMin = new Vector2(0, 0);
        trans.offsetMax = new Vector2(0, 0);
        trans.localPosition = new Vector3(0, -10, 0);
        trans.sizeDelta = new Vector2(0, 20);
        trans.localScale = new Vector3(1, 1, 1);

        var titleWindow = new MyText(title);
        header.AddElement(titleWindow);

        var buttonClosed = new MyButton(() => SetActive(false), sprite, new Rect(0, 0, 64, 48), "X");
        var rectButton = buttonClosed.Element.GetComponent<RectTransform>();
        buttonClosed.SetAnchor(new Vector2(1, 1), new Vector2(1, 1));
        rectButton.sizeDelta = new Vector2(50, 20);
        rectButton.localPosition = new Vector3(-25, -10, 0);
        //rectButton.pivot = new Vector2(1, 1);
        var buttonScript = buttonClosed.Element.GetComponent<Button>();
        buttonScript.transition = Selectable.Transition.ColorTint;
        var selColor = new ColorBlock();
        selColor.normalColor = buttonClosed.Element.GetComponent<Button>().colors.normalColor;
        selColor.pressedColor = new Color32(255, 80, 80, 255);
        selColor.highlightedColor = new Color32(255, 0, 0, 255);
        selColor.colorMultiplier = 1;
        selColor.fadeDuration = 0.2f;

        buttonClosed.Element.GetComponent<Button>().colors = selColor;

        Element = new MyPanel(sprite, rect).Element;
        var transM = Element.GetComponent<RectTransform>();

        SetAnchor(new Vector2(0, 0), new Vector2(1, 1));
        transM.anchoredPosition3D = new Vector3(0, 0, 0);
        transM.anchoredPosition = new Vector2(0, 0);

        transM.sizeDelta = new Vector2(0, 0);
        transM.localPosition = new Vector3(0, -20, 0);
        transM.offsetMin = new Vector2(transM.offsetMin.x, 0);

        transM.localScale = new Vector3(1, 1, 1);

        header.AddElement(buttonClosed);
        Head.AddElement(header);
        Head.AddElement(this);
    }