void MakeBetterSceneLoader() { UISystem = UIUtility.CreateNewUISystem("BetterSceneLoaderCanvas"); UISystem.GetComponent <CanvasScaler>().referenceResolution = new Vector2(1920f / UIScale, 1080f / UIScale); UISystem.gameObject.SetActive(false); UISystem.gameObject.transform.SetParent(transform); mainPanel = UIUtility.CreatePanel("Panel", UISystem.transform); mainPanel.color = backgroundColor; UIUtility.AddOutlineToObject(mainPanel.transform, outlineColor); var drag = UIUtility.CreatePanel("Draggable", mainPanel.transform); drag.transform.SetRect(0f, 1f, 1f, 1f, 0f, -headerSize); drag.color = dragColor; UIUtility.MakeObjectDraggable(drag.rectTransform, mainPanel.rectTransform); nametext = UIUtility.CreateText("Nametext", drag.transform, "Scenes"); nametext.transform.SetRect(0f, 0f, 1f, 1f, 340f, 0f, -buttonSize * 2f); nametext.alignment = TextAnchor.MiddleCenter; var close = UIUtility.CreateButton("CloseButton", drag.transform, ""); close.transform.SetRect(1f, 0f, 1f, 1f, -buttonSize * 2f); close.onClick.AddListener(() => UISystem.gameObject.SetActive(false)); Utils.AddCloseSymbol(close); category = UIUtility.CreateDropdown("Dropdown", drag.transform, "Categories"); category.transform.SetRect(0f, 0f, 0f, 1f, 0f, 0f, 100f); category.captionText.transform.SetRect(0f, 0f, 1f, 1f, 0f, 2f, -15f, -2f); category.captionText.alignment = TextAnchor.MiddleCenter; category.options = GetCategories(); category.onValueChanged.AddListener((x) => { imagelist.content.GetComponentInChildren <Image>().gameObject.SetActive(false); imagelist.content.anchoredPosition = new Vector2(0f, 0f); PopulateGrid(); }); var refresh = UIUtility.CreateButton("RefreshButton", drag.transform, "Refresh"); refresh.transform.SetRect(0f, 0f, 0f, 1f, 100f, 0f, 180f); refresh.onClick.AddListener(() => ReloadImages()); var save = UIUtility.CreateButton("SaveButton", drag.transform, "Save"); save.transform.SetRect(0f, 0f, 0f, 1f, 180f, 0f, 260f); save.onClick.AddListener(() => SaveScene()); var folder = UIUtility.CreateButton("FolderButton", drag.transform, "Folder"); folder.transform.SetRect(0f, 0f, 0f, 1f, 260f, 0f, 340f); folder.onClick.AddListener(() => Process.Start(scenePath)); var loadingPanel = UIUtility.CreatePanel("LoadingIconPanel", drag.transform); loadingPanel.transform.SetRect(0f, 0f, 0f, 1f, 340f, 0f, 340f + headerSize); loadingPanel.color = new Color(0f, 0f, 0f, 0f); var loadingIcon = UIUtility.CreatePanel("LoadingIcon", loadingPanel.transform); loadingIcon.transform.SetRect(0.1f, 0.1f, 0.9f, 0.9f); var texture = Utils.LoadTexture(Properties.Resources.loadicon); loadingIcon.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); LoadingIcon.Init(loadingIcon, -5f); imagelist = UIUtility.CreateScrollView("Imagelist", mainPanel.transform); imagelist.transform.SetRect(0f, 0f, 1f, 1f, marginSize, marginSize, -marginSize, -headerSize - marginSize / 2f); imagelist.gameObject.AddComponent <Mask>(); imagelist.content.gameObject.AddComponent <VerticalLayoutGroup>(); imagelist.content.gameObject.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize; imagelist.verticalScrollbar.GetComponent <RectTransform>().offsetMin = new Vector2(scrollOffsetX, 0f); imagelist.viewport.offsetMax = new Vector2(scrollOffsetX, 0f); imagelist.movementType = ScrollRect.MovementType.Clamped; optionspanel = UIUtility.CreatePanel("ButtonPanel", imagelist.transform); optionspanel.gameObject.SetActive(false); confirmpanel = UIUtility.CreatePanel("ConfirmPanel", imagelist.transform); confirmpanel.gameObject.SetActive(false); yesbutton = UIUtility.CreateButton("YesButton", confirmpanel.transform, "Y"); yesbutton.transform.SetRect(0f, 0f, 0.5f, 1f); yesbutton.onClick.AddListener(() => DeleteScene(currentPath)); nobutton = UIUtility.CreateButton("NoButton", confirmpanel.transform, "N"); nobutton.transform.SetRect(0.5f, 0f, 1f, 1f); nobutton.onClick.AddListener(() => confirmpanel.gameObject.SetActive(false)); var loadbutton = UIUtility.CreateButton("LoadButton", optionspanel.transform, "Load"); loadbutton.transform.SetRect(0f, 0f, 0.3f, 1f); loadbutton.onClick.AddListener(() => LoadScene(currentPath)); var importbutton = UIUtility.CreateButton("ImportButton", optionspanel.transform, "Import"); importbutton.transform.SetRect(0.35f, 0f, 0.65f, 1f); importbutton.onClick.AddListener(() => ImportScene(currentPath)); var deletebutton = UIUtility.CreateButton("DeleteButton", optionspanel.transform, "Delete"); deletebutton.transform.SetRect(0.7f, 0f, 1f, 1f); deletebutton.onClick.AddListener(() => confirmpanel.gameObject.SetActive(true)); PopulateGrid(); }
void MakeBetterSceneLoader() { UISystem = UIUtility.CreateNewUISystem("BetterSceneLoaderCanvas"); UISystem.GetComponent <CanvasScaler>().referenceResolution = new Vector2(1920f / UIScale, 1080f / UIScale); UISystem.gameObject.SetActive(false); UISystem.gameObject.transform.SetParent(transform); mainPanel = UIUtility.CreatePanel("Panel", UISystem.transform); mainPanel.color = backgroundColor; UIUtility.AddOutlineToObject(mainPanel.transform, outlineColor); var drag = UIUtility.CreatePanel("Draggable", mainPanel.transform); drag.transform.SetRect(0f, 1f, 1f, 1f, 0f, -headerSize); drag.color = dragColor; UIUtility.MakeObjectDraggable(drag.rectTransform, mainPanel.rectTransform); nametext = UIUtility.CreateText("Nametext", drag.transform, "Scenes"); nametext.transform.SetRect(0.87f, 0f, 0.98f, 1f, 340f, 0f, -buttonSize * 2f); nametext.alignment = TextAnchor.MiddleCenter; var close = UIUtility.CreateButton("CloseButton", drag.transform, ""); close.transform.SetRect(1f, 0f, 1f, 1f, -buttonSize * 2f); close.onClick.AddListener(() => UISystem.gameObject.SetActive(false)); Utils.AddCloseSymbol(close); category = UIUtility.CreateDropdown("Dropdown", drag.transform, "Categories"); category.transform.SetRect(0f, 0f, 0f, 1f, 0f, 0f, 200f); category.captionText.transform.SetRect(0f, 0f, 1f, 1f, 0f, 2f, -15f, -2f); category.captionText.alignment = TextAnchor.MiddleCenter; category.onValueChanged.AddListener((x) => { imagelist.content.GetComponentInChildren <Image>().gameObject.SetActive(false); imagelist.content.anchoredPosition = new Vector2(0f, 0f); PopulateGrid(); }); // Увеличиваем область выпадающего списка и чувствительность скролла. ScrollRect categoryListRect = category.transform.Find("Template").GetComponent <ScrollRect>(); categoryListRect.scrollSensitivity = 45f; categoryListRect.transform.SetRect(0f, 0f, 1f, 1f, 0f, -330f, 0f, 0f); GetCategories(); var refresh = UIUtility.CreateButton("RefreshButton", drag.transform, "Refresh"); refresh.transform.SetRect(0f, 0f, 0f, 1f, 200f, 0f, 280f); refresh.onClick.AddListener(() => ReloadImages()); var save = UIUtility.CreateButton("SaveButton", drag.transform, "Save"); save.transform.SetRect(0f, 0f, 0f, 1f, 280f, 0f, 360f, 15f); save.onClick.AddListener(() => SaveScene()); var loadingPanel = UIUtility.CreatePanel("LoadingIconPanel", drag.transform); loadingPanel.transform.SetRect(0f, 0f, 0f, 1f, 380f, 0f, 380f + headerSize); loadingPanel.color = new Color(0f, 0f, 0f, 0f); var loadingIcon = UIUtility.CreatePanel("LoadingIcon", loadingPanel.transform); loadingIcon.transform.SetRect(0.1f, 0.1f, 0.9f, 0.9f); var texture = Utils.LoadTexture(Properties.Resources.loadicon); loadingIcon.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); LoadingIcon.Init(loadingIcon, -5f); var folder = UIUtility.CreateButton("FolderButton", drag.transform, "Folder"); folder.transform.SetRect(0f, 0f, 0f, 1f, 360f, 0f, 440f); folder.onClick.AddListener(() => openFolder()); var oneColumn = UIUtility.CreateButton("oneColumn", drag.transform, "1"); oneColumn.transform.SetRect(0f, 0f, 0f, 1f, 450f, 0f, 470f, 0f); oneColumn.onClick.AddListener(() => setColums(1)); var twoColumn = UIUtility.CreateButton("twoColumn", drag.transform, "2"); twoColumn.transform.SetRect(0f, 0f, 0f, 1f, 470f, 0f, 490f, 0f); twoColumn.onClick.AddListener(() => setColums(2)); imagelist = UIUtility.CreateScrollView("Imagelist", mainPanel.transform); imagelist.transform.SetRect(0f, 0f, 1f, 1f, marginSize, marginSize, -marginSize, -headerSize - marginSize / 2f); imagelist.gameObject.AddComponent <Mask>(); imagelist.content.gameObject.AddComponent <VerticalLayoutGroup>(); imagelist.content.gameObject.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize; imagelist.verticalScrollbar.GetComponent <RectTransform>().offsetMin = new Vector2(scrollOffsetX, 0f); imagelist.viewport.offsetMax = new Vector2(scrollOffsetX, 0f); imagelist.movementType = ScrollRect.MovementType.Clamped; lastLoadedMark_Panel = UIUtility.CreatePanel("lastLoadedMark_Panel", imagelist.transform); lastLoadedMark_Panel.color = new Color(1f, .5f, 1f, 1f); UIUtility.AddOutlineToObject(lastLoadedMark_Panel.transform, outlineColor); lastLoadedMark_Panel.gameObject.SetActive(false); var lastLoadedMark_Text = UIUtility.CreateText("confirmPanelText", lastLoadedMark_Panel.transform, "Current"); lastLoadedMark_Text.color = new Color(.1f, .1f, .1f, 1f); lastLoadedMark_Text.transform.SetRect(.05f, .02f, .95f, .98f); lastLoadedMark_Text.alignment = TextAnchor.MiddleCenter; optionspanel = UIUtility.CreatePanel("ButtonPanel", imagelist.transform); optionspanel.gameObject.SetActive(false); confirmpanel = UIUtility.CreatePanel("ConfirmPanel", imagelist.transform); confirmpanel.gameObject.SetActive(false); var confirmPanelText = UIUtility.CreateText("confirmPanelText", confirmpanel.transform, "confirmText"); confirmPanelText.text = "Delete scene?"; confirmPanelText.color = Color.red; confirmPanelText.fontStyle = FontStyle.Bold; confirmPanelText.transform.SetRect(-1f, 1f, 2f, 2f); confirmPanelText.alignment = TextAnchor.MiddleCenter; yesbutton = UIUtility.CreateButton("YesButton", confirmpanel.transform, "Y"); yesbutton.transform.SetRect(0f, 0f, 0.5f, 1f); yesbutton.onClick.AddListener(() => DeleteScene(currentPath)); nobutton = UIUtility.CreateButton("NoButton", confirmpanel.transform, "N"); nobutton.transform.SetRect(0.5f, 0f, 1f, 1f); nobutton.onClick.AddListener(() => { confirmpanel.gameObject.SetActive(false); confirmpanel2.gameObject.SetActive(false); }); confirmpanel2 = UIUtility.CreatePanel("ConfirmPanel2", imagelist.transform); confirmpanel2.gameObject.SetActive(false); var confirmPanelText2 = UIUtility.CreateText("confirmPanelText2", confirmpanel2.transform, "confirmText2"); confirmPanelText2.text = "ReSave scene?"; confirmPanelText2.color = Color.magenta; confirmPanelText2.fontStyle = FontStyle.Bold; confirmPanelText2.transform.SetRect(-1f, 1f, 2f, 2f); confirmPanelText2.alignment = TextAnchor.MiddleCenter; yesbutton2 = UIUtility.CreateButton("YesButton2", confirmpanel2.transform, "Y"); yesbutton2.transform.SetRect(0f, 0f, 0.5f, 1f); yesbutton2.onClick.AddListener(() => { StartCoroutine(ResaveScene()); }); nobutton2 = UIUtility.CreateButton("NoButton2", confirmpanel2.transform, "N"); nobutton2.transform.SetRect(0.5f, 0f, 1f, 1f); nobutton2.onClick.AddListener(() => { confirmpanel.gameObject.SetActive(false); confirmpanel2.gameObject.SetActive(false); }); var filenamePanel = UIUtility.CreatePanel("filenamePanel", optionspanel.transform); filenamePanel.color = new Color(0f, 0f, 0f, .8f); filenamePanel.transform.SetRect(0f, 5.2f, 1f, 6.6f); fileNameText = UIUtility.CreateText("FileNameText", filenamePanel.transform, "filename"); fileNameText.color = new Color(.95f, .95f, .95f, 1f); fileNameText.transform.SetRect(0.05f, 0f, 0.95f, 1f); fileNameText.alignment = TextAnchor.MiddleCenter; var resavebutton = UIUtility.CreateButton("ReSaveButton", optionspanel.transform, "ReSave"); resavebutton.transform.SetRect(0.68f, 4f, 0.98f, 5f); resavebutton.onClick.AddListener(() => { confirmpanel.gameObject.SetActive(false); confirmpanel2.gameObject.SetActive(true); }); var loadbutton = UIUtility.CreateButton("LoadButton", optionspanel.transform, "Load"); loadbutton.transform.SetRect(0f, 0f, 0.3f, 1f); loadbutton.onClick.AddListener(() => LoadScene(currentPath)); var importbutton = UIUtility.CreateButton("ImportButton", optionspanel.transform, "Import"); importbutton.transform.SetRect(0.35f, 0f, 0.65f, 1f); importbutton.onClick.AddListener(() => ImportScene(currentPath)); var deletebutton = UIUtility.CreateButton("DeleteButton", optionspanel.transform, "Delete"); deletebutton.transform.SetRect(0.7f, 0f, 1f, 1f); deletebutton.onClick.AddListener(() => { confirmpanel.gameObject.SetActive(true); confirmpanel2.gameObject.SetActive(false); }); PopulateGrid(); }