public MyList(Sprite sprite, Rect rect) : base("List") { Element = new MyPanel(sprite, rect).Element; Element.AddComponent<Mask>(); var scrollRect = Element.AddComponent<ScrollRect>(); var panelIn = new MyPanel(sprite, new Rect(0, 0, 0, 200)); var panelInRect = panelIn.Element.GetComponent<RectTransform>(); panelInRect.pivot = new Vector2(0.5f, 1); panelIn.SetAnchor(new Vector2(0, 0), new Vector2(1, 1)); panelIn.Element.AddComponent<VerticalLayoutGroup>(); AddElement(panelIn); MainElement = panelIn; scrollRect.content = MainElement.Element.GetComponent<RectTransform>(); }
public static MyPanel TestButton(object test, Sprite sprite, LoadingData data, Sprite backgroundTest) { var headPanel = new MyPanel(sprite, new Rect(0, 0, 0, 0)); Destroy(headPanel.Element.GetComponent<Image>()); headPanel.SetAnchor(new Vector2(0, 0), new Vector2(1, 1)); headPanel.Element.AddComponent<VerticalLayoutGroup>(); var headPanelContentSizeFilter = headPanel.Element.AddComponent<ContentSizeFitter>(); headPanelContentSizeFilter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; if ((test as Folder) != null) { var mainPanel = new MyPanel(sprite, new Rect(0, 0, 0, 0)); Destroy(mainPanel.Element.GetComponent<Image>()); mainPanel.Element.SetActive(((Folder)test).IsOpen); mainPanel.SetAnchor(new Vector2(0, 0), new Vector2(1, 1)); mainPanel.Element.AddComponent<LayoutElement>(); mainPanel.Element.AddComponent<VerticalLayoutGroup>().padding.left = 20; var buttonArea = new MyPanel(sprite, new Rect(0, 0, 0, 0)); UIElement.SetSize(buttonArea.Element.GetComponent<RectTransform>(), new Vector2(60, 32)); buttonArea.SetAnchor(new Vector2(0, 0), new Vector2(1, 1)); buttonArea.Element.AddComponent<HorizontalLayoutGroup>(); var button = new MyButton( () => { mainPanel.Element.SetActive(!mainPanel.Element.activeSelf); ((Folder)test).IsOpen = !((Folder)test).IsOpen; Debug.Log(((Folder)test).Name + " : " + mainPanel.Element.activeSelf); } , sprite, new Rect(0, 0, 0, 0), " <color=#00000060>►</color> " + ((Folder)test).Name); button.Element.AddComponent<LayoutElement>(); var buttonRunTestIn = new MyButton( () => { TestDispatcher.RunAnyTests(((Folder)test).GetChildrenTests().Select(e => e.NameTest), data); foreach(var e in ((Folder)test).GetChildrenTests().Select(e => e.NameTest)) ((Test) test).State = TestDispatcher.LastTestExecution[e] ? 1 : -1; } , sprite, new Rect(0, 0, 0, 0), " <color=#00ff0060>►</color> "); buttonRunTestIn.Element.AddComponent<LayoutElement>(); buttonArea.AddElement(button); buttonArea.AddElement(buttonRunTestIn); button.Element.GetComponentInChildren<Text>().alignment = TextAnchor.MiddleLeft; UIElement.SetSize(button.Element.GetComponent<RectTransform>(), new Vector2(60, 32)); button.SetAnchor(new Vector2(0, 0), new Vector2(1, 1)); var layoutElement = button.Element.AddComponent<LayoutElement>(); layoutElement.minHeight = 30; headPanel.AddElement(buttonArea); foreach (var e in ((Folder)test).GetChildren()) mainPanel.AddElement(TestButton(e, sprite, data, backgroundTest)); headPanel.AddElement(mainPanel); } else { var testName = ((Test)test).NameTest; var button = new MyButton( () => { TestDispatcher.RunOneTest(data, testName); if (TestDispatcher.LastTestExecution.ContainsKey(testName)) if (TestDispatcher.LastTestExecution[testName]) ((Test)test).State = 1; else ((Test)test).State = -1; else ((Test)test).State = 0; ((Test)test).State = TestDispatcher.LastTestExecution[testName] ? 1 : -1; }, sprite, new Rect(0, 0, 0, 0), testName.Split('_').Last()); button.SetAnchor(new Vector2(0, 0), new Vector2(1, 1)); button.Element.AddComponent<LayoutElement>(); var testStateImage = new MyPanel(backgroundTest, new Rect(0, 0, 0, 0)); testStateImage.SetAnchor(new Vector2(0, 0), new Vector2(1, 1)); button.AddElement(testStateImage); testStateImage.Element.transform.SetAsFirstSibling(); //testStateImage.Element.GetComponent<Image>().color = new Color32(0, 0, 0, 100); testStateImage.Element.GetComponent<Image>().color = GetTestColor(testName); button.Element.GetComponent<Button>().onClick.AddListener(() => testStateImage.Element.GetComponent<Image>().color = GetTestColor(testName)); headPanel.AddElement(button); UIElement.SetSize(button.Element.GetComponent<RectTransform>(), new Vector2(60, 32)); button.SetAnchor(new Vector2(0, 0), new Vector2(1, 1)); var layoutElement = button.Element.AddComponent<LayoutElement>(); layoutElement.minHeight = 30; } return headPanel; }
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); }