void Update() { if (oldSource != Settings.Source.Current) { // Remove all GameObjects for (int i = text.transform.childCount - 1; i >= 0; i--) { GameObject.DestroyImmediate(text.transform.GetChild(i).gameObject); } // Get current source string [] dirs = Settings.Source.Current .Replace('\\', '/') .Trim(new char [] { '/' }) .Split(new char [] { '/' }); for (int i = 0; i < dirs.Length; i++) { // Create GameObject GameObject go = new GameObject(dirs [i]); go.transform.SetParent(text.transform); // Add text Text goText = go.AddComponent <Text> (); goText.font = Resources.Load <Font> ("Fonts/FuturaStd-Book"); goText.fontSize = 20; goText.color = new Color(1, 1, 1, 0.5f); goText.text = dirs [i]; // Set RectTransform RectTransform trans = go.GetComponent <RectTransform> (); trans.localScale = Vector3.one; // Add arrow if (i < dirs.Length - 1) { GameObject arrow = new GameObject("Arrow"); arrow.transform.SetParent(text.transform); TextUnicode arrowText = arrow.AddComponent <TextUnicode> (); arrowText.font = IconFont.font; arrowText.fontSize = 15; arrowText.color = new Color(1, 1, 1, 0.5f); arrowText.alignment = TextAnchor.MiddleCenter; arrowText.text = IconFont.DROPDOWN_CLOSED; RectTransform arrowTrans = arrow.GetComponent <RectTransform> (); arrowTrans.localScale = Vector3.one; } } // Set old source oldSource = Settings.Source.Current; } }
public void DisplayColor(ColorSchemeObj colorScheme, Color color, int id) { if (colorScheme != null) { // Get Contents GameObject GameObject contents = transform.Find("#" + colorScheme.ID + "/Contents").gameObject; // Create Image GameObject GameObject image = new GameObject("#" + colorScheme.ID + "." + id); image.transform.SetParent(contents.transform); // Add image Image img = image.AddComponent <Image> (); img.color = color; if (colorScheme.Name != Settings.Selected.Visualization.Name) { // Add Event Trigger EventTrigger trigger = image.AddComponent <EventTrigger> (); // Add Click Event EventTrigger.Entry evtClick = new EventTrigger.Entry(); evtClick.eventID = EventTriggerType.PointerClick; trigger.triggers.Add(evtClick); evtClick.callback.AddListener((eventData) => { // Set active color ActiveColor = image; ActiveColorID = id; // Set current color PickerObj.CurrentColor = colorScheme.Colors [id]; // Show color picker ColorPicker.SetActive(true); }); } else { // Create Overlay GameObject GameObject overlay = new GameObject("Overlay"); overlay.transform.SetParent(image.transform); // Add RectTransform RectTransform trans = overlay.AddComponent <RectTransform> (); trans.anchorMin = Vector2.zero; trans.anchorMax = Vector2.one; trans.offsetMin = Vector2.zero; trans.offsetMax = Vector2.zero; // Add Image Image overlayImg = overlay.AddComponent <Image> (); overlayImg.color = new Color(0, 0, 0, 0.5f); // Create Text GameObject GameObject text = new GameObject("Text"); text.transform.SetParent(overlay.transform); // Add RectTransform RectTransform textTrans = text.AddComponent <RectTransform> (); textTrans.anchorMin = Vector2.zero; textTrans.anchorMax = Vector2.one; textTrans.offsetMin = Vector2.zero; textTrans.offsetMax = Vector2.zero; // Add Text TextUnicode textText = text.AddComponent <TextUnicode> (); textText.text = IconFont.LOCK; textText.color = Color.white; textText.font = IconFont.font; textText.fontSize = 24; textText.alignment = TextAnchor.MiddleCenter; } } }
public GameObject DisplayColorScheme(ColorSchemeObj colorScheme) { if (colorScheme != null) { string name = "#" + colorScheme.ID; // Create GameOject GameObject gameObject = new GameObject(name); gameObject.transform.SetParent(transform); // Create main GameObject GameObject main = new GameObject("Main"); main.transform.SetParent(gameObject.transform); // Add Vertical Layout Group VerticalLayoutGroup vlg = gameObject.AddComponent <VerticalLayoutGroup> (); vlg.spacing = 20; vlg.childForceExpandWidth = true; vlg.childForceExpandHeight = false; // Add Layout Element to GameObject LayoutElement mainLayout = main.AddComponent <LayoutElement> (); mainLayout.minHeight = 30; mainLayout.preferredHeight = mainLayout.minHeight; // Add image to GameObject Image mainImg = main.AddComponent <Image> (); mainImg.color = Color.clear; // Set transformations mainImg.rectTransform.pivot = new Vector2(0, 0.5f); // Add Horizontal Layout Group HorizontalLayoutGroup mainHlg = main.AddComponent <HorizontalLayoutGroup> (); mainHlg.spacing = 10; mainHlg.childForceExpandWidth = false; mainHlg.childForceExpandHeight = false; mainHlg.childAlignment = TextAnchor.MiddleLeft; // Set padding right of Horizontal Layout Group mainHlg.padding = new RectOffset(0, 65, 0, 0); // Create arrow text GameObject GameObject mainArrow = new GameObject("Arrow"); mainArrow.transform.SetParent(main.transform); // Add text TextUnicode mainTextArrow = mainArrow.AddComponent <TextUnicode> (); mainTextArrow.text = colorScheme.Equals(Settings.Selected.ColorScheme) ? IconFont.DROPDOWN_OPENED : IconFont.DROPDOWN_CLOSED; // Set text alignment mainTextArrow.alignment = TextAnchor.MiddleLeft; // Font settings mainTextArrow.font = IconFont.font; mainTextArrow.fontSize = 20; // Add Layout Element LayoutElement mainLayoutElementArrow = mainArrow.AddComponent <LayoutElement> (); mainLayoutElementArrow.minWidth = 22; // Create text GameObject GameObject mainText = new GameObject("Text"); mainText.transform.SetParent(main.transform); // Add text Text text = mainText.AddComponent <Text> (); text.text = colorScheme.Name; if (colorScheme.Name == Settings.Selected.Visualization.Name) { text.text += " (Standard)"; } // Set text alignment text.alignment = TextAnchor.MiddleLeft; // Set text color text.color = Color.white; // Font settings text.font = Resources.Load <Font> ("Fonts/FuturaStd-Book"); text.fontSize = 30; // Set transformations text.rectTransform.pivot = new Vector2(0.5f, 0.5f); // Add button Button buttonText = mainText.AddComponent <Button> (); buttonText.transition = Selectable.Transition.Animation; // Add Event to Button buttonText.onClick.AddListener(delegate { ToggleColors(colorScheme); }); // Add animator Animator animatorText = mainText.AddComponent <Animator> (); animatorText.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController> ("Animations/MenuButtons"); // Create active text GameObject GameObject mainActive = new GameObject("Active"); mainActive.transform.SetParent(main.transform); // Add text TextUnicode mainTextActive = mainActive.AddComponent <TextUnicode> (); if (colorScheme.Equals(Settings.Active.ColorScheme)) { mainTextActive.text = IconFont.VISUALIZATION; mainTextActive.fontSize = 30; mainTextActive.color = new Color(0.7f, 0.7f, 0.7f); } // Set text alignment mainTextActive.alignment = TextAnchor.MiddleRight; // Font settings mainTextActive.font = IconFont.font; // Add Layout Element LayoutElement mainLayoutElementListening = mainActive.AddComponent <LayoutElement> (); mainLayoutElementListening.preferredWidth = 40; if (colorScheme.Name != Settings.Selected.Visualization.Name) { // Create edit icons GameObject GameObject editIcons = new GameObject("Images"); editIcons.transform.SetParent(main.transform); // Set transformations RectTransform editIconsTrans = editIcons.AddComponent <RectTransform> (); editIconsTrans.anchoredPosition = Vector2.zero; editIconsTrans.anchorMin = new Vector2(1, 0.5f); editIconsTrans.anchorMax = new Vector2(1, 0.5f); editIconsTrans.pivot = new Vector2(1, 0.5f); // Add Layout Element LayoutElement editIconslayoutElement = editIcons.AddComponent <LayoutElement> (); editIconslayoutElement.ignoreLayout = true; // Add Content Size Fitter ContentSizeFitter editIconsCsf = editIcons.AddComponent <ContentSizeFitter> (); editIconsCsf.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; editIconsCsf.verticalFit = ContentSizeFitter.FitMode.PreferredSize; // Add Layout Group HorizontalLayoutGroup editIconsHlgImg = editIcons.AddComponent <HorizontalLayoutGroup> (); editIconsHlgImg.childAlignment = TextAnchor.MiddleRight; editIconsHlgImg.spacing = 5; editIconsHlgImg.childForceExpandWidth = false; editIconsHlgImg.childForceExpandHeight = false; // Disable edit icons GameObject editIcons.SetActive(false); // Create edit text GameObject GameObject edit = new GameObject("Edit"); edit.transform.SetParent(editIcons.transform); // Add text TextUnicode editText = edit.AddComponent <TextUnicode> (); editText.text = IconFont.EDIT; // Set text alignment editText.alignment = TextAnchor.MiddleRight; // Set transformations editText.rectTransform.sizeDelta = new Vector2(20, 30); // Font settings editText.font = IconFont.font; editText.fontSize = 30; // Add button Button buttonEditEvt = edit.AddComponent <Button> (); buttonEditEvt.transition = Selectable.Transition.Animation; // Add button onclick event buttonEditEvt.onClick.AddListener(delegate { ShowDialog("CS_EDIT", gameObject); }); // Add animator Animator animatorEditEvt = edit.AddComponent <Animator> (); animatorEditEvt.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController> ("Animations/MenuButtons"); // Create delete text GameObject GameObject delete = new GameObject("Delete"); delete.transform.SetParent(editIcons.transform); // Add text Text deleteText = delete.AddComponent <Text> (); deleteText.text = IconFont.TRASH; // Set text alignment deleteText.alignment = TextAnchor.MiddleRight; // Set transformations deleteText.rectTransform.sizeDelta = new Vector2(20, 30); // Font settings deleteText.font = IconFont.font; deleteText.fontSize = 30; // Add button Button buttonDeleteEvt = delete.AddComponent <Button> (); buttonDeleteEvt.transition = Selectable.Transition.Animation; // Add button onclick event buttonDeleteEvt.onClick.AddListener(delegate { ShowDialog("CS_DEL", gameObject); }); // Add animator Animator animatorDeleteEvt = delete.AddComponent <Animator> (); animatorDeleteEvt.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController> ("Animations/MenuButtons"); // Create GameObject Event Triggers EventTrigger evtWrapper = gameObject.AddComponent <EventTrigger> (); // Add Hover Enter Event EventTrigger.Entry evtHover = new EventTrigger.Entry(); evtHover.eventID = EventTriggerType.PointerEnter; evtWrapper.triggers.Add(evtHover); evtHover.callback.AddListener((eventData) => { editIcons.SetActive(true); }); // Add Hover Exit Event EventTrigger.Entry evtExit = new EventTrigger.Entry(); evtExit.eventID = EventTriggerType.PointerExit; evtWrapper.triggers.Add(evtExit); evtExit.callback.AddListener((eventData) => { editIcons.SetActive(false); }); } // Add Event Trigger EventTrigger evtMain = main.AddComponent <EventTrigger> (); // Add Click Event EventTrigger.Entry evtClick = new EventTrigger.Entry(); evtClick.eventID = EventTriggerType.PointerClick; evtMain.triggers.Add(evtClick); evtClick.callback.AddListener((eventData) => { ToggleColors(colorScheme); }); // Add Contents GameObject GameObject contents = new GameObject("Contents"); contents.transform.SetParent(gameObject.transform); // Add Grid Layout Group GridLayoutGroup glg = contents.AddComponent <GridLayoutGroup> (); // Set Grid Layout glg.cellSize = new Vector2(53.5f, 53.5f); glg.spacing = new Vector2(25, 25); glg.constraint = GridLayoutGroup.Constraint.FixedColumnCount; glg.constraintCount = 10; return(gameObject); } return(null); }
public void Display() { if (Visualizations != null) { // Remove all GameObjects for (int i = transform.childCount - 1; i >= 0; i--) { GameObject.DestroyImmediate(transform.GetChild(i).gameObject); } foreach (VisualizationObj viz in Visualizations) { // Create GameObject GameObject gameObject = new GameObject("#" + viz.ID); gameObject.transform.SetParent(transform); RectTransform trans = gameObject.AddComponent <RectTransform> (); trans.pivot = new Vector2(0, 0.5f); // Add Layout Element LayoutElement layoutElement = gameObject.AddComponent <LayoutElement> (); layoutElement.minHeight = 30; layoutElement.preferredHeight = 30; // Add Horizontal Layout Group HorizontalLayoutGroup hlg = gameObject.AddComponent <HorizontalLayoutGroup> (); hlg.childForceExpandWidth = false; hlg.childForceExpandHeight = false; hlg.spacing = 10; hlg.childAlignment = TextAnchor.MiddleLeft; // Create arrow text GameObject GameObject mainArrow = new GameObject("Arrow"); mainArrow.transform.SetParent(gameObject.transform); // Add text TextUnicode mainTextArrow = mainArrow.AddComponent <TextUnicode> (); mainTextArrow.text = viz.Equals(Settings.Selected.Visualization) ? IconFont.DROPDOWN_CLOSED : ""; // Set text alignment mainTextArrow.alignment = TextAnchor.MiddleLeft; // Font settings mainTextArrow.font = IconFont.font; mainTextArrow.fontSize = 20; // Add Layout Element LayoutElement mainLayoutElementArrow = mainArrow.AddComponent <LayoutElement> (); mainLayoutElementArrow.minWidth = 22; // Create Text GameObject GameObject mainText = new GameObject("Text"); mainText.transform.SetParent(gameObject.transform); // Add Text Text text = mainText.AddComponent <Text> (); text.color = Color.white; text.font = Resources.Load <Font> ("Fonts/FuturaStd-Book"); text.text = viz.Name; text.fontSize = 30; // Add Button Button button = mainText.AddComponent <Button> (); button.transition = Selectable.Transition.Animation; // Add OnClick Handler VisualizationObj currentViz = viz; button.onClick.AddListener(delegate { if (!currentViz.Equals(Settings.Selected.Visualization)) { Settings.Selected.Visualization = currentViz; if (Settings.Selected.Visualization.Equals(Settings.Active.Visualization)) { Settings.Selected.ColorScheme = Settings.Active.ColorScheme; } else { Settings.Selected.ColorScheme = ColorScheme.GetDefault(currentViz); } ColorSchemes.Display(); Display(); // Show or hide start button MenuManager.ToggleStart(); } }); // Add Animator Animator animator = mainText.AddComponent <Animator> (); animator.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController> ("Animations/MenuButtons"); // Create active text GameObject GameObject mainActive = new GameObject("Active"); mainActive.transform.SetParent(gameObject.transform); // Add text TextUnicode mainTextActive = mainActive.AddComponent <TextUnicode> (); if (viz.Equals(Settings.Active.Visualization)) { mainTextActive.text = IconFont.VISUALIZATION; mainTextActive.fontSize = 30; mainTextActive.color = new Color(0.7f, 0.7f, 0.7f); } // Set text alignment mainTextActive.alignment = TextAnchor.MiddleRight; // Font settings mainTextActive.font = IconFont.font; // Add Layout Element LayoutElement mainLayoutElementActive = mainActive.AddComponent <LayoutElement> (); mainLayoutElementActive.preferredWidth = 40; mainLayoutElementActive.preferredHeight = 30; // Set scaling gameObject.GetComponent <RectTransform> ().localScale = Vector3.one; } } }
public void ToggleFiles(PlaylistObj playlist, bool forceOpen) { // Show or hide playlist files bool opened = false; foreach (PlaylistObj p in Playlists) { // Get GameObject for current file Transform contents = transform.Find("#" + p.ID + "/Contents"); GameObject main = contents != null ? contents.gameObject : null; // Get arrow Text arr = transform.Find("#" + p.ID + "/Main/Arrow").GetComponent <Text>(); // Toggle files for GameObject if (main != null) { if (p == playlist && p.Files.Count > 0) { main.SetActive(!forceOpen ? !main.activeSelf : true); opened = main.activeSelf; } else { main.SetActive(false); if (arr.text == IconFont.DROPDOWN_OPENED) { arr.text = IconFont.DROPDOWN_CLOSED; } } } else if (p == playlist) { opened = true; } // Change arrows if (!forceOpen && p != playlist) { arr.text = IconFont.DROPDOWN_CLOSED; } } // Change arrow image TextUnicode arrow = transform.Find("#" + playlist.ID + "/Main/Arrow").GetComponent <TextUnicode>(); if (arrow != null) { arrow.text = opened ? IconFont.DROPDOWN_OPENED : IconFont.DROPDOWN_CLOSED; } if (!opened && Settings.Selected.File != null) { // Remove icon from selected file Transform file = transform.Find("#" + Settings.Selected.Playlist.ID + "/Contents/#" + Settings.Selected.Playlist.ID + "." + Settings.Selected.File.ID + "/Listening"); if (file != null) { file.GetComponent <Text>().text = ""; } // Unset selected file Settings.Selected.File = null; } if ((opened && Settings.Selected.Playlist != playlist) || forceOpen) { // Set selected playlist Settings.Selected.Playlist = playlist; // Set selected file if (Settings.Selected.Playlist.Files.Count > 0) { UpdateSelectedFile(Settings.Selected.Playlist.Files.First(), Settings.Active.File == null || Settings.Active.Playlist == null || (Settings.Active.File != null && !Settings.Active.Playlist.Equals(Settings.Selected.Playlist))); } else { Settings.Selected.File = null; } } // Unset selected playlist if (!opened && !forceOpen) { Settings.Selected.Playlist = null; } // Scroll to top if scrollbar is hidden ScrollToTop(); // Toggle start button MenuManager.ToggleStart(); }
public GameObject DisplayPlaylistOrFile(PlaylistObj playlist, FileObj file) { if (playlist != null) { // Navigation for buttons Navigation nav = new Navigation(); nav.mode = Navigation.Mode.None; // Set name string name = "#" + playlist.ID + (file != null ? ("." + file.ID) : ""); // Create main GameObject GameObject main = new GameObject("Main"); if (file != null) { main.name = "Contents"; } // Check if Contents GameObject already exists Transform contents = transform.Find("#" + playlist.ID + "/Contents"); bool contentsExists = !ReferenceEquals(contents, null); if (contentsExists && file != null) { DestroyImmediate(main); main = contents.gameObject; } // Set parent of GameObject Transform parent = transform; if (file != null) { parent = main.transform; } // Create GameOject GameObject gameObject = new GameObject(name); gameObject.transform.SetParent(parent); // Add Vertical Layout Group if (!contentsExists || file == null) { VerticalLayoutGroup vlg = (file == null ? gameObject : main).AddComponent <VerticalLayoutGroup>(); vlg.spacing = 20; vlg.childForceExpandWidth = true; vlg.childForceExpandHeight = false; } // Set GameObject for return GameObject goReturn = gameObject; // Set parent of main GameObject parent = gameObject.transform; if (file != null) { parent = transform.Find("#" + playlist.ID); } main.transform.SetParent(parent); // Change GameObjects if file is displayed to inherit from different GameObject if (file != null) { main = gameObject; } // Add Layout Element to GameObject LayoutElement mainLayout = main.AddComponent <LayoutElement>(); mainLayout.minHeight = 30; mainLayout.preferredHeight = mainLayout.minHeight; // Add image to GameObject Image mainImg = main.AddComponent <Image>(); mainImg.color = Color.clear; // Set transformations mainImg.rectTransform.pivot = new Vector2(0, 0.5f); // Add Horizontal Layout Group HorizontalLayoutGroup mainHlg = main.AddComponent <HorizontalLayoutGroup>(); mainHlg.spacing = 10; mainHlg.childForceExpandWidth = false; mainHlg.childForceExpandHeight = false; mainHlg.childAlignment = TextAnchor.MiddleLeft; // Set padding right of Horizontal Layout Group mainHlg.padding = new RectOffset(0, (file == null ? 65 : 30), 0, 0); // Add Drop Handler script if (file == null) { //gameObject.AddComponent<DropHandler> (); gameObject.AddComponent <Image>().color = Color.clear; } // Create arrow text GameObject GameObject mainArrow = new GameObject("Arrow"); mainArrow.transform.SetParent(main.transform); // Add text TextUnicode mainTextArrow = mainArrow.AddComponent <TextUnicode>(); mainTextArrow.color = Color.white; if (file == null) { mainTextArrow.text = playlist.Equals(Settings.Selected.Playlist) ? IconFont.DROPDOWN_OPENED : IconFont.DROPDOWN_CLOSED; } // Set text alignment mainTextArrow.alignment = TextAnchor.MiddleLeft; // Font settings mainTextArrow.font = IconFont.font; mainTextArrow.fontSize = 20; // Add Layout Element LayoutElement mainLayoutElementArrow = mainArrow.AddComponent <LayoutElement>(); mainLayoutElementArrow.minWidth = 22; // Create listening text GameObject GameObject mainListening = new GameObject("Listening"); if (file != null) { mainListening.transform.SetParent(main.transform); } // Add text TextUnicode mainTextListening = mainListening.AddComponent <TextUnicode>(); if (playlist.Equals(Settings.Active.Playlist) && (file == null || (file != null && file.Equals(Settings.Active.File)))) { mainTextListening.text = IconFont.LISTENING; mainTextListening.fontSize = 30; mainTextListening.color = file == null ? Color.white : Settings.GetColorFromRgb(180, 180, 180); } else if (file != null && playlist.Equals(Settings.Selected.Playlist) && file.Equals(Settings.Selected.File)) { mainTextListening.text = IconFont.DROPDOWN_CLOSED; mainTextListening.fontSize = 20; mainTextListening.color = Color.gray; } // Set text alignment mainTextListening.alignment = file == null ? TextAnchor.MiddleRight : TextAnchor.MiddleLeft; // Font settings mainTextListening.font = IconFont.font; // Add Layout Element LayoutElement mainLayoutElementListening = mainListening.AddComponent <LayoutElement>(); mainLayoutElementListening.minWidth = file == null ? 40 : 32; // Create text GameObject GameObject mainText = new GameObject("Text"); mainText.transform.SetParent(main.transform); // Add text Text text = mainText.AddComponent <Text>(); // Set text alignment text.alignment = TextAnchor.MiddleLeft; // Set text color if (file == null) { text.color = Color.white; } else if (playlist.Equals(Settings.Active.Playlist) && file.Equals(Settings.Active.File)) { text.color = Settings.GetColorFromRgb(180, 180, 180); } else { text.color = Color.gray; } // Font settings text.font = Resources.Load <Font>("Fonts/FuturaStd-Book"); text.fontSize = 30; // Set transformations text.rectTransform.pivot = new Vector2(0.5f, 0.5f); // Add button Button buttonText = mainText.AddComponent <Button>(); buttonText.transition = Selectable.Transition.Animation; buttonText.navigation = nav; // Add animator Animator animatorText = mainText.AddComponent <Animator>(); animatorText.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>("Animations/MenuButtons"); // Add listening element if (file == null) { mainListening.transform.SetParent(main.transform); } // Create edit icons GameObject GameObject editIcons = new GameObject("Images"); editIcons.transform.SetParent(main.transform); // Set transformations RectTransform editIconsTrans = editIcons.AddComponent <RectTransform>(); editIconsTrans.anchoredPosition = Vector2.zero; editIconsTrans.anchorMin = new Vector2(1, 0.5f); editIconsTrans.anchorMax = new Vector2(1, 0.5f); editIconsTrans.pivot = new Vector2(1, 0.5f); // Add Layout Element LayoutElement editIconslayoutElement = editIcons.AddComponent <LayoutElement>(); editIconslayoutElement.ignoreLayout = true; // Add Content Size Fitter ContentSizeFitter editIconsCsf = editIcons.AddComponent <ContentSizeFitter>(); editIconsCsf.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; editIconsCsf.verticalFit = ContentSizeFitter.FitMode.PreferredSize; // Add Layout Group HorizontalLayoutGroup editIconsHlgImg = editIcons.AddComponent <HorizontalLayoutGroup>(); editIconsHlgImg.childAlignment = TextAnchor.MiddleRight; editIconsHlgImg.spacing = 5; editIconsHlgImg.childForceExpandWidth = false; editIconsHlgImg.childForceExpandHeight = false; // Disable edit icons GameObject editIcons.SetActive(false); if (file == null) { // Create edit text GameObject GameObject edit = new GameObject("Edit"); edit.transform.SetParent(editIcons.transform); // Add text TextUnicode editText = edit.AddComponent <TextUnicode>(); editText.text = IconFont.EDIT; editText.color = Color.white; // Set text alignment editText.alignment = TextAnchor.MiddleRight; // Set transformations editText.rectTransform.sizeDelta = new Vector2(20, 30); // Font settings editText.font = IconFont.font; editText.fontSize = 30; // Add button Button buttonEditEvt = edit.AddComponent <Button>(); buttonEditEvt.transition = Selectable.Transition.Animation; buttonEditEvt.navigation = nav; // Add button onclick event buttonEditEvt.onClick.AddListener(delegate { ShowDialog("PL_EDIT", gameObject); }); // Add animator Animator animatorEditEvt = edit.AddComponent <Animator>(); animatorEditEvt.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>("Animations/MenuButtons"); } // Create delete text GameObject GameObject delete = new GameObject("Delete"); delete.transform.SetParent(editIcons.transform); // Add text Text deleteText = delete.AddComponent <Text>(); deleteText.text = IconFont.TRASH; deleteText.color = Color.white; // Set text alignment deleteText.alignment = TextAnchor.MiddleRight; // Set transformations deleteText.rectTransform.sizeDelta = new Vector2(20, 30); // Font settings deleteText.font = IconFont.font; deleteText.fontSize = 30; // Add button Button buttonDeleteEvt = delete.AddComponent <Button>(); buttonDeleteEvt.transition = Selectable.Transition.Animation; buttonDeleteEvt.navigation = nav; // Add button onclick event buttonDeleteEvt.onClick.AddListener(delegate { if (FindFile(gameObject) == null) { ShowDialog("PL_DEL", gameObject); } else { Delete(gameObject); } }); // Add animator Animator animatorDeleteEvt = delete.AddComponent <Animator>(); animatorDeleteEvt.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>("Animations/MenuButtons"); // Create GameObject Event Triggers EventTrigger evtWrapper = gameObject.AddComponent <EventTrigger>(); // Add Hover Enter Event EventTrigger.Entry evtHover = new EventTrigger.Entry(); evtHover.eventID = EventTriggerType.PointerEnter; evtWrapper.triggers.Add(evtHover); evtHover.callback.AddListener((eventData) => { editIcons.SetActive(true); }); // Add Hover Exit Event EventTrigger.Entry evtExit = new EventTrigger.Entry(); evtExit.eventID = EventTriggerType.PointerExit; evtWrapper.triggers.Add(evtExit); evtExit.callback.AddListener((eventData) => { editIcons.SetActive(false); }); return(goReturn); } return(null); }
public static void Display(List <string> Directories, List <string> Files, bool FromSearch) { // Delete all previous created GameObjects DestroyAll(); // Scroll to top if (!FromSearch) { GameObject.Find("Files").GetComponent <ScrollRect> ().verticalScrollbar.value = 1; } // Combine directories and folders List <string> results = new List <string> (Directories); int lastDirectory = results.Count; results.AddRange(Files); // Get current GameObject GameObject gameObject = GameObject.Find("FileContent"); // Create item for ech entry in results foreach (string item in results) { // Test if item is directory bool isDir = Directory.Exists(item); // Create GameObject GameObject obj = new GameObject(item); obj.transform.SetParent(gameObject.transform); // Add Horizontal Layout Group HorizontalLayoutGroup hlg = obj.AddComponent <HorizontalLayoutGroup> (); hlg.spacing = 20; hlg.childAlignment = TextAnchor.MiddleLeft; hlg.childForceExpandWidth = false; hlg.childForceExpandHeight = true; // Set RectTransform RectTransform trans = obj.GetComponent <RectTransform> (); trans.localScale = Vector3.one; // Create image GameObject GameObject goImage = new GameObject("Image"); goImage.transform.SetParent(obj.transform); // Add text TextUnicode textImage = goImage.AddComponent <TextUnicode> (); textImage.color = Settings.GetColorFromRgb(180, 180, 180); textImage.text = isDir ? IconFont.FOLDER : IconFont.MUSIC; textImage.alignment = TextAnchor.MiddleLeft; textImage.font = IconFont.font; textImage.fontSize = 30; // Add RectTransform RectTransform imageTrans = goImage.GetComponent <RectTransform> (); imageTrans.localScale = Vector3.one; // Add Layout Element LayoutElement imageLayout = goImage.AddComponent <LayoutElement> (); imageLayout.minWidth = 30; // Create text GameObject GameObject goText = new GameObject("Text"); goText.transform.SetParent(obj.transform); // Add RectTransform element RectTransform textTrans = goText.AddComponent <RectTransform> (); textTrans.pivot = new Vector2(0.5f, 0.5f); textTrans.localScale = Vector3.one; // Add Layout Element LayoutElement layoutElement = goText.AddComponent <LayoutElement> (); layoutElement.minHeight = 30; layoutElement.preferredHeight = 30; // Add Drag Handler if (!isDir) { goText.AddComponent <DragHandler> (); } // Add Button Button button = goText.AddComponent <Button> (); button.transition = Selectable.Transition.Animation; Navigation nav = new Navigation(); nav.mode = Navigation.Mode.None; button.navigation = nav; // Add OnClick Handler string currentItem = item; if (isDir) { button.onClick.AddListener(delegate { Initialize(currentItem); }); } else { string currentFile = item; button.onClick.AddListener(delegate { // Get reference to playlist object Playlist pl = GameObject.Find("PlaylistContent").GetComponent <Playlist> (); // Get file object if available FileObj file = pl.GetFile(currentItem); // Get source folder object SourceFolder sf = GameObject.Find("FileContent").GetComponent <SourceFolder> (); if (sf.DoubleClicked(goText)) { // Get drop area GameObject dropObj = GameObject.FindGameObjectWithTag("PlaylistDrop"); // Insert file DropHandler.InsertFile(currentFile, dropObj, dropObj); } }); } // Add Animator Animator animator = goText.AddComponent <Animator> (); animator.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController> ("Animations/MenuButtons"); // Add Text Text text = goText.AddComponent <Text> (); text.color = Color.white; text.font = Resources.Load <Font> ("Fonts/FuturaStd-Book"); text.text = Path.GetFileName(item); text.fontSize = 30; text.alignment = TextAnchor.MiddleLeft; } }