public MyScrollBar(Sprite sprite) : base("ScrollBar") { var trans = Element.AddComponent<RectTransform>(); trans.sizeDelta = new Vector2(0, 0); SetSize(trans, new Vector2(20, 0)); SetAnchor(new Vector2(1, 0), new Vector2(1, 1)); trans.anchoredPosition3D = new Vector3(0, 0, 0); trans.anchoredPosition = new Vector2(0, 0); trans.localPosition = new Vector3(-10, 0, 0); trans.localScale = new Vector3(1f, 1f, 1.0f); Element.AddComponent<CanvasRenderer>(); var slidingArea = new UIElement("Sliding Area"); var rectSlidingArea = slidingArea.Element.AddComponent<RectTransform>(); slidingArea.SetAnchor(new Vector2(0, 0), new Vector2(1, 1)); rectSlidingArea.sizeDelta = new Vector2(0, 0); rectSlidingArea.localScale = new Vector3(1, 1, 1); var Handle = new UIElement("Handle"); var rectHandle = Handle.Element.AddComponent<RectTransform>(); SetSize(rectHandle, new Vector2(0, 0)); rectHandle.anchorMin = new Vector2(0, 0.5f); rectHandle.anchorMax = new Vector2(1, 1); rectHandle.localScale = new Vector3(1f, 1f, 1f); Handle.Element.AddComponent<CanvasRenderer>(); var imageHandle = Handle.Element.AddComponent<Image>(); imageHandle.sprite = sprite; imageHandle.type = Image.Type.Sliced; slidingArea.AddElement(Handle); AddElement(slidingArea); var image = Element.AddComponent<Image>(); image.sprite = sprite; image.type = Image.Type.Sliced; image.color = new Color32(120, 120, 120, 180); var scrollBarScript = Element.AddComponent<Scrollbar>(); scrollBarScript.interactable = true; scrollBarScript.handleRect = rectHandle; scrollBarScript.direction = Scrollbar.Direction.BottomToTop; }
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); }