public bool Delete(GameObject gameObject) { // Get file PlaylistObj playlist = FindPlaylist(gameObject); FileObj file = FindFile(gameObject); bool deleted = playlist != null ? (file != null ? DeleteFile(playlist, file) : DeletePlaylist(playlist)) : false; if (deleted) { // Unset selected file if (playlist.Files.Contains(Settings.Selected.File) && (file == null || file.Equals(Settings.Selected.File))) { Settings.Selected.File = null; } // Delete extant files FileObj[] files = file == null?playlist.Files.ToArray() : new FileObj[] { file }; foreach (FileObj f in files) { DeleteExtantFile(f, playlist); } if (file == null) { // Remove from list Playlists.Remove(playlist); // Unset active and opened playlist if (playlist.Equals(Settings.Active.Playlist)) { Settings.Active.Playlist = null; } if (playlist.Equals(Settings.Selected.Playlist)) { Settings.Selected.Playlist = null; } } else { // Remove files from playlists playlist.Files.Remove(file); if (playlist.Equals(Settings.Active.Playlist)) { Settings.Active.Playlist.Files.Remove(file); } if (playlist.Equals(Settings.Selected.Playlist)) { Settings.Selected.Playlist.Files.Remove(file); } // Toggle files if (playlist.Files.Count == 0) { ToggleFiles(playlist); } } // Display playlists Display(); } return(deleted); }
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); }