public void Create(FileBrowseProp prop, FileBrowser browser) { this.prop = prop; this.browser = browser; this.okBtn = prop.CreateButton(this.transform, "OK"); this.okImg = this.okBtn.image; this.okBtn.onClick.AddListener(() => { this.browser.OK(); }); RectTransform rtOK = this.okImg.rectTransform; rtOK.anchorMin = new Vector2(0.5f, 0.0f); rtOK.anchorMax = new Vector2(1.0f, 1.0f); rtOK.pivot = new Vector2(0.0f, 1.0f); rtOK.offsetMin = Vector2.zero; rtOK.offsetMax = Vector2.zero; //////////////////////////////////////////////////////////////////////////////// this.cancelBtn = prop.CreateButton(this.transform, "Cancel"); this.cancelImg = this.cancelBtn.image; this.cancelBtn.onClick.AddListener(() => { this.browser.Cancel(); }); RectTransform rtC = this.cancelImg.rectTransform; rtC.anchorMin = new Vector2(0.0f, 0.0f); rtC.anchorMax = new Vector2(0.5f, 1.0f); rtC.pivot = new Vector2(0.0f, 1.0f); rtC.offsetMin = Vector2.zero; rtC.offsetMax = Vector2.zero; //this.prop.confirmButtons.Apply(this.cancelBtn, this.cancelImg); }
public void Create(FileBrowseProp prop, FileBrowser browser) { this.prop = prop; this.browser = browser; // // NAV BUTTONS //////////////////////////////////////////////////////////////////////////////// this.backBtn = this.prop.CreateButton(this.transform, ""); if (this.prop.navBackSprite != null) { FileBrowseProp.CreateCenteredImage(this.prop.navBackSprite, backBtn.transform, Vector2.zero); } this.backBtn.onClick.AddListener(() => { this.browser.HistoryGoBack(); }); this.fwdBtn = this.prop.CreateButton(this.transform, ""); if (this.prop.navForwardSprite != null) { FileBrowseProp.CreateCenteredImage(this.prop.navForwardSprite, fwdBtn.transform, Vector2.zero); } this.fwdBtn.onClick.AddListener(() => { this.browser.HistoryGoForward(); }); this.upBtn = this.prop.CreateButton(this.transform, "UpButton"); if (this.prop.navUpSprite != null) { FileBrowseProp.CreateCenteredImage(this.prop.navUpSprite, upBtn.transform, Vector2.zero); } this.upBtn.onClick.AddListener(() => { this.browser.NavigateParent(); }); // // Edit Location //////////////////////////////////////////////////////////////////////////////// GameObject goLoc = new GameObject("EditLoc"); goLoc.transform.SetParent(this.transform); goLoc.transform.localRotation = Quaternion.identity; goLoc.transform.localScale = Vector3.one; UnityEngine.UI.Image editPlate = goLoc.AddComponent <UnityEngine.UI.Image>(); editPlate.sprite = this.prop.inputPlateSprite; editPlate.type = UnityEngine.UI.Image.Type.Sliced; RectTransform rtEditPlate = editPlate.rectTransform; rtEditPlate.anchorMin = Vector2.zero; rtEditPlate.anchorMax = Vector2.one; rtEditPlate.pivot = new Vector2(0.0f, 1.0f); rtEditPlate.offsetMin = Vector2.zero; rtEditPlate.offsetMax = Vector2.zero; this.prop.inputText.Create(goLoc.transform, out this.textInput, "", "InputText"); this.textInput.alignment = TextAnchor.MiddleLeft; RectTransform rtInputTxt = this.textInput.rectTransform; rtInputTxt.anchorMin = Vector2.zero; rtInputTxt.anchorMax = Vector2.one; rtInputTxt.pivot = new Vector2(0.0f, 1.0f); rtInputTxt.offsetMin = new Vector2(this.prop.inputPadding, 0.0f); rtInputTxt.offsetMax = new Vector2(-this.prop.inputPadding, 0.0f); this.editInput = goLoc.AddComponent <UnityEngine.UI.InputField>(); this.editInput.targetGraphic = editPlate; this.editInput.textComponent = this.textInput; this.editInput.onEndEdit.AddListener( (x) => { this.OnInput_PathEndEdit(x); }); this.editInput.lineType = UnityEngine.UI.InputField.LineType.MultiLineSubmit; this.DisableInput(); UnityEngine.EventSystems.EventTrigger et = goLoc.AddComponent <UnityEngine.EventSystems.EventTrigger>(); et.triggers = new List <UnityEngine.EventSystems.EventTrigger.Entry>(); UnityEngine.EventSystems.EventTrigger.Entry evtMDown = new UnityEngine.EventSystems.EventTrigger.Entry(); evtMDown.eventID = UnityEngine.EventSystems.EventTriggerType.PointerClick; evtMDown.callback.AddListener( (x) => { this.OnButton_PathClick((UnityEngine.EventSystems.PointerEventData)x); }); et.triggers.Add(evtMDown); this.created = true; this.RefreshNavigationButtonsInteractivity(); }
public void Create(FileBrowseSpawner spawner, FileBrowseProp properties, string startingDir, string extensions, bool saving) { this.spawner = spawner; this.properties = properties; this.fileFilters = FileFilter.ParseFilterString(extensions); if (this.fileFilters.Length > 0) { this.filterIndex = 0; } this.saving = saving; if (System.IO.Directory.Exists(startingDir) == false) { // https://stackoverflow.com/questions/1143706/getting-the-path-of-the-home-directory-in-c startingDir = UnityEngine.Application.persistentDataPath; } //////////////////////////////////////////////////////////////////////////////// GameObject goCrumb = new GameObject("Crumb"); goCrumb.transform.SetParent(this.transform, false); FileBrowserCrumbRgn frCrumb = goCrumb.AddComponent <FileBrowserCrumbRgn>(); RectTransform rtCrumb = frCrumb.gameObject.AddComponent <RectTransform>(); rtCrumb.anchorMin = new Vector2(0.0f, 1.0f); rtCrumb.anchorMax = new Vector2(1.0f, 1.0f); rtCrumb.pivot = new Vector2(0.0f, 1.0f); rtCrumb.offsetMin = new Vector2(10.0f, -60.0f); rtCrumb.offsetMax = new Vector2(-10.0f, -10.0f); frCrumb.Create(properties, this); this.browserAreas.Add(frCrumb); //////////////////////////////////////////////////////////////////////////////// GameObject goFR = new GameObject("FilesRegion"); goFR.transform.SetParent(this.transform, false); FileBrowseFileListRgn frRgn = goFR.AddComponent <FileBrowseFileListRgn>(); RectTransform rtRgn = frRgn.gameObject.AddComponent <RectTransform>(); rtRgn.anchorMin = Vector2.zero; rtRgn.anchorMax = Vector2.one; rtRgn.pivot = new Vector2(0.0f, 1.0f); rtRgn.offsetMin = new Vector2(10.0f, 40.0f); rtRgn.offsetMax = new Vector2(-10.0f, -60.0f); frRgn.Create(properties, this); this.region = frRgn; this.browserAreas.Add(frRgn); //////////////////////////////////////////////////////////////////////////////// GameObject goPath = new GameObject("FilesPath"); goPath.transform.SetParent(this.transform, false); this.pathRgn = goPath.AddComponent <FileBrowserPathRgn>(); RectTransform rtPath = this.pathRgn.gameObject.AddComponent <RectTransform>(); rtPath.anchorMin = new Vector2(0.0f, 0.0f); rtPath.anchorMax = new Vector2(1.0f, 0.0f); rtPath.pivot = new Vector2(0.0f, 1.0f); rtPath.offsetMin = new Vector2(10.0f, 0.0f); rtPath.offsetMax = new Vector2(-10.0f, 40.0f); this.pathRgn.Create(properties, this); this.browserAreas.Add(this.pathRgn); //////////////////////////////////////////////////////////////////////////////// /// //GameObject goConfirm = new GameObject("Confirm"); //goConfirm.transform.SetParent(this.transform); //goConfirm.transform.localScale = Vector3.one; //goConfirm.transform.localRotation = Quaternion.identity; // //FileBrowserConfirmRgn confirmRgn = goConfirm.AddComponent<FileBrowserConfirmRgn>(); //RectTransform rtConf = confirmRgn.rectTransform; //rtConf.anchorMin = new Vector2(1.0f, 0.0f); //rtConf.anchorMax = new Vector2(1.0f, 0.0f); //rtConf.pivot = new Vector2(0.0f, 1.0f); //rtConf.offsetMin = new Vector2(-210.0f, 60.0f); //rtConf.offsetMax = new Vector2(-10.0f, 100.0f); // //confirmRgn.Create(this.properties, this); //this.browserAreas.Add(confirmRgn); this.ViewDirectory(startingDir, NavigationType.Misc); }
public void Create(PxPre.FileBrowse.FileBrowseProp prop, FileBrowser browser) { this.prop = prop; this.browser = browser; GameObject goLabel = new GameObject("FontLabel"); goLabel.transform.SetParent(this.transform); goLabel.transform.localScale = Vector3.one; goLabel.transform.localRotation = Quaternion.identity; UnityEngine.UI.Text txtLabel = goLabel.AddComponent <UnityEngine.UI.Text>(); this.prop.inputLabel.Apply(txtLabel); txtLabel.horizontalOverflow = HorizontalWrapMode.Overflow; txtLabel.verticalOverflow = VerticalWrapMode.Overflow; txtLabel.alignment = TextAnchor.MiddleLeft; txtLabel.text = "Filename"; RectTransform rtLabel = txtLabel.rectTransform; TextGenerationSettings tgsLabel = txtLabel.GetGenerationSettings(new Vector2(float.PositiveInfinity, float.PositiveInfinity)); tgsLabel.scaleFactor = 1.0f; TextGenerator tgLabel = txtLabel.cachedTextGenerator; float labelWidth = tgLabel.GetPreferredWidth(txtLabel.text, tgsLabel); rtLabel.pivot = new Vector2(0.0f, 0.5f); rtLabel.anchorMin = new Vector2(0.0f, 0.0f); rtLabel.anchorMax = new Vector2(0.0f, 1.0f); rtLabel.offsetMin = new Vector2(0.0f, 0.0f); rtLabel.offsetMax = new Vector2(labelWidth, 0.0f); GameObject goInput = new GameObject("Input"); goInput.transform.SetParent(this.transform); goInput.transform.localScale = Vector3.one; goInput.transform.localRotation = Quaternion.identity; UnityEngine.UI.Image imgInput = goInput.AddComponent <UnityEngine.UI.Image>(); imgInput.type = UnityEngine.UI.Image.Type.Sliced; imgInput.sprite = this.prop.inputPlateSprite; RectTransform rtInput = imgInput.rectTransform; rtInput.anchorMin = Vector2.zero; rtInput.anchorMax = Vector2.one; rtInput.offsetMin = new Vector2(labelWidth + this.prop.inputLabelInputPadding, 0.0f); rtInput.offsetMax = Vector2.zero; GameObject goInputText = new GameObject("InputText"); goInputText.transform.SetParent(goInput.transform); goInputText.transform.localScale = Vector3.one; goInputText.transform.localRotation = Quaternion.identity; UnityEngine.UI.Text textInput = goInputText.AddComponent <UnityEngine.UI.Text>(); this.prop.inputText.Apply(textInput); textInput.alignment = TextAnchor.MiddleLeft; textInput.verticalOverflow = VerticalWrapMode.Overflow; RectTransform rtText = textInput.rectTransform; rtText.anchorMin = Vector2.zero; rtText.anchorMax = Vector2.one; rtText.pivot = new Vector2(0.0f, 0.5f); rtText.offsetMin = new Vector2(this.prop.inputPadding, 0.0f); rtText.offsetMax = new Vector2(-this.prop.inputPadding, 0.0f); this.input = goInput.AddComponent <UnityEngine.UI.InputField>(); this.input.textComponent = textInput; this.input.onValidateInput += this.OnValidateInput; this.input.lineType = UnityEngine.UI.InputField.LineType.MultiLineNewline; }