public bool Delete(GameObject gameObject, ColorSchemeObj colorScheme) { if (Delete(colorScheme)) { // Remove from interface DestroyImmediate(gameObject); // Remove from list ColorSchemes.Remove(colorScheme); // Unset active and opened color scheme if (colorScheme.Equals(Settings.Active.ColorScheme)) { Settings.Active.ColorScheme = null; } if (colorScheme.Equals(Settings.Selected.ColorScheme)) { Settings.Selected.ColorScheme = null; } return(true); } return(false); }
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); }