private void btnAdd_Click(object sender, EventArgs e) { LayoutElement elem = new LayoutElement(); elem.Title = "New item " + (layoutBindingSource.Count + 1); elem.Data = new DataElement(EntryDataType.UserName); elem.Filter = new Filter(); layoutBindingSource.Add(elem); }
protected override void Awake() { base.Awake(); base.transition = Transition.None; base.toggleTransition = ToggleTransition.None; this.m_Accordion = this.gameObject.GetComponentInParent<Accordion>(); this.m_RectTransform = this.transform as RectTransform; this.m_LayoutElement = this.gameObject.GetComponent<LayoutElement>(); this.onValueChanged.AddListener(OnValueChanged); }
public void Cloning() { try { LayoutElement[] layoutElement = new LayoutElement[8]; layoutElement[0] = new LayoutElement(); layoutElement[0].Data = new DataElement(EntryDataType.Notes); layoutElement[0].Title = "Notes for me"; layoutElement[0].Width = 123; layoutElement[0].Filter = new Filter(); Assert.Equals(layoutElement[0], layoutElement[0].Clone(), "Clone()"); layoutElement[1] = layoutElement[0].Clone(); layoutElement[1].Data = new DataElement(EntryDataType.Notes); Assert.Equals(layoutElement[0], layoutElement[1], "Data same meaning, different object."); layoutElement[1].Data = new DataElement(EntryDataType.Empty); Assert.NotEquals(layoutElement[0], layoutElement[1], "Different Data"); layoutElement[1] = layoutElement[0].Clone(); layoutElement[1].Title = "Different title"; Assert.NotEquals(layoutElement[0], layoutElement[1], "Different Title"); layoutElement[1] = layoutElement[0].Clone(); layoutElement[1].Width = 999; Assert.NotEquals(layoutElement[0], layoutElement[1], "Different Width"); Filter filter; layoutElement[1] = layoutElement[0].Clone(); filter = new Filter(); filter.Comparator = "<="; layoutElement[1].Filter = filter; Assert.NotEquals(layoutElement[0], layoutElement[1], "Different Filter"); layoutElement[1] = layoutElement[0].Clone(); filter = new Filter(); layoutElement[1].Filter = filter; Assert.Equals(layoutElement[0], layoutElement[1], "Same Filter"); } catch (Exception e) { Assert.Fail("Exception: " + e.GetType().Name + "\n" + e.Message + "\n" + e.StackTrace); } }
public void Serialization() { try { LayoutElement[] layoutElement = new LayoutElement[3]; layoutElement[0] = new LayoutElement(); layoutElement[0].Data = new DataElement(EntryDataType.Notes); layoutElement[0].Title = "Notes for me"; layoutElement[0].Width = 123; layoutElement[0].Filter = new Filter(); layoutElement[1] = new LayoutElement(); layoutElement[1].Data = new DataElement(new StrengthReport.Measuring.BasicStrengthMeasure()); layoutElement[1].Title = "Abcdeűáéúőóöüö"; layoutElement[1].Width = 999; layoutElement[1].Filter = new Filter(); layoutElement[2] = new LayoutElement(); layoutElement[2].Data = new DataElement(EntryDataType.Empty); layoutElement[2].Title = ""; layoutElement[2].Width = 0; layoutElement[2].Filter = new Filter(); for (int i = 0; i < layoutElement.Length; i++) { StringWriter stringWriter = new StringWriter(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(LayoutElement)); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); xmlSerializer.Serialize(xmlTextWriter, layoutElement[i]); LayoutElement result = (LayoutElement)xmlSerializer.Deserialize(new StringReader(stringWriter.ToString())); Assert.Equals(layoutElement[i], result, "Not equals: index: "+i); } } catch (Exception e) { Assert.Fail("Exception: " + e.GetType().Name + "\n" + e.Message + "\n" + e.StackTrace); } }
internal void ConstructUI() { GameObject parent = MainMenu.Instance.PageViewport; Content = UIFactory.CreateVerticalGroup(parent, new Color(0.15f, 0.15f, 0.15f)); var mainGroup = Content.GetComponent <VerticalLayoutGroup>(); mainGroup.padding.left = 4; mainGroup.padding.right = 4; mainGroup.padding.top = 4; mainGroup.padding.bottom = 4; mainGroup.spacing = 5; mainGroup.childForceExpandHeight = false; mainGroup.childForceExpandWidth = true; mainGroup.childControlHeight = true; mainGroup.childControlWidth = true; // ~~~~~ Title ~~~~~ GameObject titleObj = UIFactory.CreateLabel(Content, TextAnchor.UpperLeft); Text titleLabel = titleObj.GetComponent <Text>(); titleLabel.text = "Options"; titleLabel.fontSize = 20; LayoutElement titleLayout = titleObj.AddComponent <LayoutElement>(); titleLayout.minHeight = 30; titleLayout.flexibleHeight = 0; // ~~~~~ Actual options ~~~~~ var optionsGroupObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f)); var optionsGroup = optionsGroupObj.GetComponent <VerticalLayoutGroup>(); optionsGroup.childForceExpandHeight = false; optionsGroup.childForceExpandWidth = true; optionsGroup.childControlWidth = true; optionsGroup.childControlHeight = true; optionsGroup.spacing = 5; optionsGroup.padding.top = 5; optionsGroup.padding.left = 5; optionsGroup.padding.right = 5; optionsGroup.padding.bottom = 5; ConstructKeycodeOpt(optionsGroupObj); ConstructMouseUnlockOpt(optionsGroupObj); ConstructPageLimitOpt(optionsGroupObj); ConstructOutputPathOpt(optionsGroupObj); ConstructHideOnStartupOpt(optionsGroupObj); var applyBtnObj = UIFactory.CreateButton(Content, new Color(0.2f, 0.2f, 0.2f)); var applyText = applyBtnObj.GetComponentInChildren <Text>(); applyText.text = "Apply and Save"; var applyLayout = applyBtnObj.AddComponent <LayoutElement>(); applyLayout.minHeight = 30; applyLayout.flexibleWidth = 1000; var applyBtn = applyBtnObj.GetComponent <Button>(); var applyColors = applyBtn.colors; applyColors.normalColor = new Color(0.3f, 0.7f, 0.3f); applyBtn.colors = applyColors; applyBtn.onClick.AddListener(OnApply); }
public void OnBeginDrag(PointerEventData eventData) { isValid = true; if (_reorderableList == null) { return; } //Can't drag, return... if (!_reorderableList.IsDraggable || !this.IsGrabbable) { _draggingObject = null; return; } //If CloneDraggedObject just set draggingObject to this gameobject if (_reorderableList.CloneDraggedObject == false) { _draggingObject = _rect; _fromIndex = _rect.GetSiblingIndex(); //Send OnElementRemoved Event if (_reorderableList.OnElementRemoved != null) { _reorderableList.OnElementRemoved.Invoke(new ReorderableList.ReorderableListEventStruct { DroppedObject = _draggingObject.gameObject, IsAClone = _reorderableList.CloneDraggedObject, SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject, FromList = _reorderableList, FromIndex = _fromIndex, }); } if (isValid == false) { _draggingObject = null; return; } } //Else Duplicate else { GameObject clone = (GameObject)Instantiate(gameObject); _draggingObject = clone.GetComponent <RectTransform>(); } //Put _dragging object into the dragging area _draggingObjectOriginalSize = gameObject.GetComponent <RectTransform>().rect.size; _draggingObjectLE = _draggingObject.GetComponent <LayoutElement>(); _draggingObject.SetParent(_reorderableList.DraggableArea, true); _draggingObject.SetAsLastSibling(); //Create a fake element for previewing placement _fakeElement = new GameObject("Fake").AddComponent <RectTransform>(); _fakeElementLE = _fakeElement.gameObject.AddComponent <LayoutElement>(); RefreshSizes(); //Send OnElementGrabbed Event if (_reorderableList.OnElementGrabbed != null) { _reorderableList.OnElementGrabbed.Invoke(new ReorderableList.ReorderableListEventStruct { DroppedObject = _draggingObject.gameObject, IsAClone = _reorderableList.CloneDraggedObject, SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject, FromList = _reorderableList, FromIndex = _fromIndex, }); if (!isValid) { CancelDrag(); return; } } _isDragging = true; }
private bool CanExecuteFloatCommand(object anchorable) { return(LayoutElement != null && LayoutElement.CanFloat && LayoutElement.FindParent <LayoutFloatingWindow>() == null); }
private void Awake() { scrollRect = GetComponent <ScrollRect>(); layout = GetComponent <LayoutElement>(); }
private void AddObjectListButton() { int thisIndex = m_shortListTexts.Count(); GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(m_pageContent, new Color(0.1f, 0.1f, 0.1f)); HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent <HorizontalLayoutGroup>(); btnGroup.childForceExpandWidth = true; btnGroup.childControlWidth = true; btnGroup.childForceExpandHeight = false; btnGroup.childControlHeight = true; LayoutElement btnLayout = btnGroupObj.AddComponent <LayoutElement>(); btnLayout.flexibleWidth = 320; btnLayout.minHeight = 25; btnLayout.flexibleHeight = 0; btnGroupObj.AddComponent <Mask>(); var toggleObj = UIFactory.CreateToggle(btnGroupObj, out Toggle toggle, out Text toggleText, new Color(0.1f, 0.1f, 0.1f)); var toggleLayout = toggleObj.AddComponent <LayoutElement>(); toggleLayout.minHeight = 25; toggleLayout.minWidth = 25; toggleText.text = ""; toggle.isOn = false; m_shortListToggles.Add(toggle); toggle.onValueChanged.AddListener((bool val) => { OnToggleClicked(thisIndex, val); }); GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj); LayoutElement mainBtnLayout = mainButtonObj.AddComponent <LayoutElement>(); mainBtnLayout.minHeight = 25; mainBtnLayout.flexibleHeight = 0; mainBtnLayout.minWidth = 230; mainBtnLayout.flexibleWidth = 0; Button mainBtn = mainButtonObj.GetComponent <Button>(); ColorBlock mainColors = mainBtn.colors; mainColors.normalColor = new Color(0.1f, 0.1f, 0.1f); mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1); mainBtn.colors = mainColors; mainBtn.onClick.AddListener(() => { SceneListObjectClicked(thisIndex); }); Text mainText = mainButtonObj.GetComponentInChildren <Text>(); mainText.alignment = TextAnchor.MiddleLeft; mainText.horizontalOverflow = HorizontalWrapMode.Overflow; m_shortListTexts.Add(mainText); GameObject inspectBtnObj = UIFactory.CreateButton(btnGroupObj); LayoutElement inspectBtnLayout = inspectBtnObj.AddComponent <LayoutElement>(); inspectBtnLayout.minWidth = 60; inspectBtnLayout.flexibleWidth = 0; inspectBtnLayout.minHeight = 25; inspectBtnLayout.flexibleHeight = 0; Text inspectText = inspectBtnObj.GetComponentInChildren <Text>(); inspectText.text = "Inspect"; inspectText.color = Color.white; Button inspectBtn = inspectBtnObj.GetComponent <Button>(); ColorBlock inspectColors = inspectBtn.colors; inspectColors.normalColor = new Color(0.15f, 0.15f, 0.15f); mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 0.5f); inspectBtn.colors = inspectColors; inspectBtn.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_shortList[thisIndex]); }); }
protected override void modifyShownElement(int index, GameObject element) { LayoutElement componentInParent = element.GetComponentInParent <LayoutElement>(); componentInParent.minWidth = 185f; }
public static Tweener DOPreferredSize(this LayoutElement target, Vector2 endValue, float duration) => DG.Tweening.DOTween.To(() => new Vector2(target.preferredWidth, target.preferredHeight), vec => { target.preferredWidth = vec.x; target.preferredHeight = vec.y; }, endValue, duration) .SetTarget(target);
private void Awake() { m_rectTransform = GetComponent <RectTransform>(); m_layoutElement = GetComponent <LayoutElement>(); AwakeOverride(); }
private void CreateEndPlaceHolderWithTransform(Transform transform) { endPlaceholder = CreatePlaceHolderWithIdentifier(endPlaceHolderIdentifier); endPlaceholder.transform.SetParent(transform, false); endPlaceholder.gameObject.SetActive(false); }
public void PushLayoutElement(LayoutElement element) { element.transform.SetParent(content.transform, false); SetContentSize(LayoutElementCount()); }
//--------------------------------------------------------------------------------------------------------------------------------------------- void Awake() { txt = this.GetComponentInChildren <Text>(); img = this.GetComponent <Image>(); le = this.GetComponent <LayoutElement>(); }
/// <summary> /// Sets the custom rect transforms by .MinSize/.PreferredSize, Returns the custom rect transforms, And populates highestCellInRows/widestCellInColumns // I made it in 1 function so i wont need to iterate twice :P /// </summary> /// <returns>The custom rect transforms</returns> private List <RectTransform> calculateCustomRectTransformsAndAdditionalData() { highestCellInRows.Clear(); widestCellInColumns.Clear(); for (int i = 0; i < rectChildren.Count; i++) { int rowPosition = calculateRowPosition(i); int columnPosition = calculateColumnPosition(i); float highestCellInRow; if (!highestCellInRows.TryGetValue(rowPosition, out highestCellInRow)) { highestCellInRow = 0; highestCellInRows[rowPosition] = highestCellInRow; } float widestCellInColumn; if (!widestCellInColumns.TryGetValue(columnPosition, out widestCellInColumn)) { widestCellInColumn = 0; widestCellInColumns[columnPosition] = widestCellInColumn; } RectTransform rectChild = rectChildren[i]; LayoutElement layoutElement = rectChild.GetComponent <LayoutElement>(); Vector2 cellSize = Vector2.zero; if (layoutElement != null) { if (horizontalSizePreference == ContentSizeFitter.FitMode.MinSize) { cellSize.x = layoutElement.minWidth; } else if (horizontalSizePreference == ContentSizeFitter.FitMode.PreferredSize) { cellSize.x = layoutElement.preferredWidth; } if (verticalSizePreference == ContentSizeFitter.FitMode.MinSize) { cellSize.y = layoutElement.minHeight; } else if (verticalSizePreference == ContentSizeFitter.FitMode.PreferredSize) { cellSize.y = layoutElement.preferredHeight; } if (cellSize.x > widestCellInColumn) { widestCellInColumns[columnPosition] = cellSize.x; } if (cellSize.y > highestCellInRow) { highestCellInRows[rowPosition] = cellSize.y; } } rectChild.sizeDelta = cellSize; } return(rectChildren); }
public static void SetUniqueElementName(IEnumerable <LayoutElement> elements, LayoutElement le) { var list = elements.ToList(); string leName = le.Name + " 1"; int i = 2; while (list.Any(o => o.Name == leName)) { leName = le.Name + " " + i; i++; } le.Name = leName; }
public ActionUiPreferredHeight(GameObject go, float end, float duration, Ease ease = null) : base(go, end, duration, ease) { Name = "UiPreferredHeight"; LE = go?.GetComponent <LayoutElement>(); }
internal void OnLayoutElementRemoved(LayoutElement element) { if (element.Descendents().OfType<LayoutContent>().Any(c => Equals(c, LastFocusedDocument))) LastFocusedDocument = null; if (element.Descendents().OfType<LayoutContent>().Any(c => Equals(c, ActiveContent))) ActiveContent = null; ElementRemoved?.Invoke(this, new LayoutElementEventArgs(element)); }
protected override void setUpEmptyCell(GameObject cell) { LayoutElement layoutElement = cell.AddComponent <LayoutElement>(); layoutElement.preferredHeight = preferredHeight; }
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 override GameObject InitializeElement() { GameObject element = GetFluidHorizontalBaseElement("InputField", true, false, TextAnchor.MiddleLeft, 10); Text text = CreateText(option.name, true); text.transform.SetParent(element.transform); value = getValue(); fieldElement = CreateInputField(value); fieldElement.transform.SetParent(element.transform); fieldElement.textComponent.alignment = TextAnchor.MiddleCenter; fieldElement.onValueChanged.AddListener( (string v) => { if (v != value) { valueChanged = true; value = v; } }); LayoutElement layout = fieldElement.gameObject.AddComponent <LayoutElement>(); layout.minWidth = 60; layout.minHeight = 30; string verification = this.parameterData.ContainsKey("Verification") ? this.parameterData["Verification"].ToString() : "Standard"; switch (verification) { case "PositiveInteger": fieldElement.onValidateInput += ValidateInputForPositiveNumber; break; case "Integer": fieldElement.contentType = InputField.ContentType.IntegerNumber; break; case "Alphanumeric": fieldElement.contentType = InputField.ContentType.Alphanumeric; break; case "Decimal": fieldElement.contentType = InputField.ContentType.DecimalNumber; break; case "Pin": fieldElement.contentType = InputField.ContentType.Pin; break; case "Password": fieldElement.contentType = InputField.ContentType.Password; break; case "Name": fieldElement.contentType = InputField.ContentType.Name; break; case "EmailAddress": fieldElement.contentType = InputField.ContentType.EmailAddress; break; case "Autocorrected": fieldElement.contentType = InputField.ContentType.Autocorrected; break; } return(element); }
void Awake() { _LayoutElement = GetComponent<LayoutElement>(); }
private void checkFilter_CheckedChanged(object sender, EventArgs e) { LayoutElement element = (LayoutElement)layoutBindingSource.Current; element.Filter.Enabled = checkFilter.Checked; }
protected override void Awake() { base.Awake(); _layoutElement = this.GetComponent <LayoutElement>(); }
private void Awake() { m_group = GetComponent <HorizontalOrVerticalLayoutGroup>(); m_element = GetComponent <LayoutElement>(); }
public void ConstructScenePane() { GameObject leftPane = UIFactory.CreateVerticalGroup(HomePage.Instance.Content, new Color(72f / 255f, 72f / 255f, 72f / 255f)); LayoutElement leftLayout = leftPane.AddComponent <LayoutElement>(); leftLayout.minWidth = 350; leftLayout.flexibleWidth = 0; VerticalLayoutGroup leftGroup = leftPane.GetComponent <VerticalLayoutGroup>(); leftGroup.padding.left = 4; leftGroup.padding.right = 4; leftGroup.padding.top = 8; leftGroup.padding.bottom = 4; leftGroup.spacing = 4; leftGroup.childControlWidth = true; leftGroup.childControlHeight = true; leftGroup.childForceExpandWidth = true; leftGroup.childForceExpandHeight = true; GameObject titleObj = UIFactory.CreateLabel(leftPane, TextAnchor.UpperLeft); Text titleLabel = titleObj.GetComponent <Text>(); titleLabel.text = "Scene Explorer"; titleLabel.fontSize = 20; LayoutElement titleLayout = titleObj.AddComponent <LayoutElement>(); titleLayout.minHeight = 30; titleLayout.flexibleHeight = 0; GameObject sceneDropdownObj = UIFactory.CreateDropdown(leftPane, out m_sceneDropdown); LayoutElement dropdownLayout = sceneDropdownObj.AddComponent <LayoutElement>(); dropdownLayout.minHeight = 40; dropdownLayout.flexibleHeight = 0; dropdownLayout.minWidth = 320; dropdownLayout.flexibleWidth = 2; m_sceneDropdownText = m_sceneDropdown.transform.Find("Label").GetComponent <Text>(); m_sceneDropdown.onValueChanged.AddListener((int val) => { SetSceneFromDropdown(val); }); void SetSceneFromDropdown(int val) { //string scene = m_sceneDropdown.options[val].text; SetTargetScene(m_currentScenes[val]); } GameObject scenePathGroupObj = UIFactory.CreateHorizontalGroup(leftPane, new Color(1, 1, 1, 0f)); HorizontalLayoutGroup scenePathGroup = scenePathGroupObj.GetComponent <HorizontalLayoutGroup>(); scenePathGroup.childControlHeight = true; scenePathGroup.childControlWidth = true; scenePathGroup.childForceExpandHeight = true; scenePathGroup.childForceExpandWidth = true; scenePathGroup.spacing = 5; LayoutElement scenePathLayout = scenePathGroupObj.AddComponent <LayoutElement>(); scenePathLayout.minHeight = 20; scenePathLayout.minWidth = 335; scenePathLayout.flexibleWidth = 0; m_backButtonObj = UIFactory.CreateButton(scenePathGroupObj); Text backButtonText = m_backButtonObj.GetComponentInChildren <Text>(); backButtonText.text = "◄"; LayoutElement backButtonLayout = m_backButtonObj.AddComponent <LayoutElement>(); backButtonLayout.minWidth = 40; backButtonLayout.flexibleWidth = 0; Button backButton = m_backButtonObj.GetComponent <Button>(); var colors = backButton.colors; colors.normalColor = new Color(0.12f, 0.12f, 0.12f); backButton.colors = colors; backButton.onClick.AddListener(() => { SetSceneObjectParent(); }); void SetSceneObjectParent() { if (!m_selectedSceneObject || !m_selectedSceneObject.transform.parent?.gameObject) { m_selectedSceneObject = null; SetTargetScene(m_currentScene); } else { SetTargetObject(m_selectedSceneObject.transform.parent.gameObject); } } GameObject scenePathLabel = UIFactory.CreateHorizontalGroup(scenePathGroupObj); Image image = scenePathLabel.GetComponent <Image>(); image.color = Color.white; LayoutElement scenePathLabelLayout = scenePathLabel.AddComponent <LayoutElement>(); scenePathLabelLayout.minWidth = 210; scenePathLabelLayout.minHeight = 20; scenePathLabelLayout.flexibleHeight = 0; scenePathLabelLayout.flexibleWidth = 120; scenePathLabel.AddComponent <Mask>().showMaskGraphic = false; GameObject scenePathLabelText = UIFactory.CreateLabel(scenePathLabel, TextAnchor.MiddleLeft); m_scenePathText = scenePathLabelText.GetComponent <Text>(); m_scenePathText.text = "Scene root:"; m_scenePathText.fontSize = 15; m_scenePathText.horizontalOverflow = HorizontalWrapMode.Overflow; LayoutElement textLayout = scenePathLabelText.gameObject.AddComponent <LayoutElement>(); textLayout.minWidth = 210; textLayout.flexibleWidth = 120; textLayout.minHeight = 20; textLayout.flexibleHeight = 0; m_mainInspectBtn = UIFactory.CreateButton(scenePathGroupObj); Text inspectButtonText = m_mainInspectBtn.GetComponentInChildren <Text>(); inspectButtonText.text = "Inspect"; LayoutElement inspectButtonLayout = m_mainInspectBtn.AddComponent <LayoutElement>(); inspectButtonLayout.minWidth = 65; inspectButtonLayout.flexibleWidth = 0; Button inspectButton = m_mainInspectBtn.GetComponent <Button>(); colors = inspectButton.colors; colors.normalColor = new Color(0.12f, 0.12f, 0.12f); inspectButton.colors = colors; inspectButton.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_selectedSceneObject); }); GameObject scrollObj = UIFactory.CreateScrollView(leftPane, out m_pageContent, out SliderScrollbar scroller, new Color(0.1f, 0.1f, 0.1f)); m_pageHandler = new PageHandler(scroller); m_pageHandler.ConstructUI(leftPane); m_pageHandler.OnPageChanged += OnSceneListPageTurn; // hide button var hideButtonObj = UIFactory.CreateButton(leftPane); var hideBtn = hideButtonObj.GetComponent <Button>(); var hideColors = hideBtn.colors; hideColors.normalColor = new Color(0.15f, 0.15f, 0.15f); hideBtn.colors = hideColors; var hideText = hideButtonObj.GetComponentInChildren <Text>(); hideText.text = "Hide Scene Explorer"; hideText.fontSize = 13; var hideLayout = hideButtonObj.AddComponent <LayoutElement>(); hideLayout.minWidth = 20; hideLayout.minHeight = 20; hideBtn.onClick.AddListener(OnHide); void OnHide() { if (!Hiding) { Hiding = true; hideText.text = "►"; titleObj.SetActive(false); sceneDropdownObj.SetActive(false); scenePathGroupObj.SetActive(false); scrollObj.SetActive(false); m_pageHandler.Hide(); leftLayout.minWidth = 15; } else { Hiding = false; hideText.text = "Hide Scene Explorer"; titleObj.SetActive(true); sceneDropdownObj.SetActive(true); scenePathGroupObj.SetActive(true); scrollObj.SetActive(true); leftLayout.minWidth = 350; Update(); } OnToggleShow?.Invoke(); } }
/// <summary> /// Removes the specified layoutElement from the selection /// </summary> internal void RemoveFromSelection(LayoutElement le) { _selectedLayoutElements.Remove(le); DoInvalidate(new Region(PaperToScreen(le.Rectangle))); FireSelectionChanged(); }
void ResetChildrenWidth(LayoutElement element, int index) { element.preferredWidth = widths[index]; }
void Awake() { rect = GetComponent <RectTransform> (); layoutElem = GetComponent <LayoutElement> (); }
protected virtual void Awake() { LayoutElement = GetComponent <LayoutElement>(); InputField = GetComponent <TMP_InputField>(); }
public void Start() { _layoutElement = GetComponent <LayoutElement>(); UpdateLayout(); }
public void OnBeginDrag(PointerEventData eventData) { if (_reorderableList == null) return; //Can't drag, return... if (!_reorderableList.IsDraggable) { _draggingObject = null; return; } //If CloneDraggedObject just set draggingObject to this gameobject if (_reorderableList.CloneDraggedObject == false) { _draggingObject = _rect; _fromIndex = _rect.GetSiblingIndex(); //Send OnElementRemoved Event if (_reorderableList.OnElementRemoved != null) { _reorderableList.OnElementRemoved.Invoke(new ReorderableList.ReorderableListEventStruct { DroppedObject = _draggingObject.gameObject, IsAClone = _reorderableList.CloneDraggedObject, SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject, FromList = _reorderableList, FromIndex = _fromIndex, }); } } //Else Duplicate else { GameObject clone = (GameObject)Instantiate(gameObject); _draggingObject = clone.GetComponent<RectTransform>(); } //Put _dragging object into the draggin area _draggingObjectOriginalSize = gameObject.GetComponent<RectTransform>().rect.size; _draggingObjectLE = _draggingObject.GetComponent<LayoutElement>(); _draggingObject.SetParent(_reorderableList.DraggableArea, false); _draggingObject.SetAsLastSibling(); //Create a fake element for previewing placement _fakeElement = new GameObject("Fake").AddComponent<RectTransform>(); _fakeElementLE = _fakeElement.gameObject.AddComponent<LayoutElement>(); RefreshSizes(); //Send OnElementGrabbed Event if (_reorderableList.OnElementGrabbed != null) { _reorderableList.OnElementGrabbed.Invoke(new ReorderableList.ReorderableListEventStruct { DroppedObject = _draggingObject.gameObject, IsAClone = _reorderableList.CloneDraggedObject, SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject, FromList = _reorderableList, FromIndex = _fromIndex, }); } _isDragging = true; }
void OnEnable() { layout = GetComponent <LayoutElement>(); }
public LayoutElementEventArgs(LayoutElement element) { Element = element; }
public void ConstructUI(GameObject parent) { var mainObj = UIFactory.CreateVerticalGroup(parent, new Color(0.1f, 0.1f, 0.1f, 1.0f)); var mainGroup = mainObj.GetComponent <VerticalLayoutGroup>(); mainGroup.childControlHeight = true; mainGroup.childControlWidth = true; mainGroup.childForceExpandHeight = true; mainGroup.childForceExpandWidth = true; var mainImage = mainObj.GetComponent <Image>(); mainImage.maskable = true; var mask = mainObj.AddComponent <Mask>(); mask.showMaskGraphic = true; var mainLayout = mainObj.AddComponent <LayoutElement>(); mainLayout.minHeight = 190; mainLayout.flexibleHeight = 0; #region LOG AREA var logAreaObj = UIFactory.CreateHorizontalGroup(mainObj); var logAreaGroup = logAreaObj.GetComponent <HorizontalLayoutGroup>(); logAreaGroup.childControlHeight = true; logAreaGroup.childControlWidth = true; logAreaGroup.childForceExpandHeight = true; logAreaGroup.childForceExpandWidth = true; var logAreaLayout = logAreaObj.AddComponent <LayoutElement>(); logAreaLayout.preferredHeight = 190; logAreaLayout.flexibleHeight = 0; var inputScrollerObj = UIFactory.CreateSrollInputField(logAreaObj, out InputFieldScroller inputScroll, 14, new Color(0.05f, 0.05f, 0.05f)); inputScroll.inputField.textComponent.font = UIManager.ConsoleFont; inputScroll.inputField.readOnly = true; m_textInput = inputScroll.inputField; #endregion #region BOTTOM BAR var bottomBarObj = UIFactory.CreateHorizontalGroup(mainObj); LayoutElement topBarLayout = bottomBarObj.AddComponent <LayoutElement>(); topBarLayout.minHeight = 30; topBarLayout.flexibleHeight = 0; var bottomGroup = bottomBarObj.GetComponent <HorizontalLayoutGroup>(); bottomGroup.padding.left = 10; bottomGroup.padding.right = 10; bottomGroup.padding.top = 2; bottomGroup.padding.bottom = 2; bottomGroup.spacing = 10; bottomGroup.childForceExpandHeight = true; bottomGroup.childForceExpandWidth = false; bottomGroup.childControlWidth = true; bottomGroup.childControlHeight = true; bottomGroup.childAlignment = TextAnchor.MiddleLeft; // Debug Console label var bottomLabel = UIFactory.CreateLabel(bottomBarObj, TextAnchor.MiddleLeft); var topBarLabelLayout = bottomLabel.AddComponent <LayoutElement>(); topBarLabelLayout.minWidth = 100; topBarLabelLayout.flexibleWidth = 0; var topBarText = bottomLabel.GetComponent <Text>(); topBarText.fontStyle = FontStyle.Bold; topBarText.text = "Debug Console"; topBarText.fontSize = 14; // Hide button var hideButtonObj = UIFactory.CreateButton(bottomBarObj); var hideBtnText = hideButtonObj.GetComponentInChildren <Text>(); hideBtnText.text = "Hide"; var hideButton = hideButtonObj.GetComponent <Button>(); hideButton.onClick.AddListener(HideCallback); void HideCallback() { if (logAreaObj.activeSelf) { logAreaObj.SetActive(false); hideBtnText.text = "Show"; mainLayout.minHeight = 30; } else { logAreaObj.SetActive(true); hideBtnText.text = "Hide"; mainLayout.minHeight = 190; } } var hideBtnColors = hideButton.colors; //hideBtnColors.normalColor = new Color(160f / 255f, 140f / 255f, 40f / 255f); hideButton.colors = hideBtnColors; var hideBtnLayout = hideButtonObj.AddComponent <LayoutElement>(); hideBtnLayout.minWidth = 80; hideBtnLayout.flexibleWidth = 0; // Clear button var clearButtonObj = UIFactory.CreateButton(bottomBarObj); var clearBtnText = clearButtonObj.GetComponentInChildren <Text>(); clearBtnText.text = "Clear"; var clearButton = clearButtonObj.GetComponent <Button>(); clearButton.onClick.AddListener(ClearCallback); void ClearCallback() { m_textInput.text = ""; AllMessages.Clear(); } var clearBtnColors = clearButton.colors; //clearBtnColors.normalColor = new Color(160f/255f, 140f/255f, 40f/255f); clearButton.colors = clearBtnColors; var clearBtnLayout = clearButtonObj.AddComponent <LayoutElement>(); clearBtnLayout.minWidth = 80; clearBtnLayout.flexibleWidth = 0; // Unity log toggle var unityToggleObj = UIFactory.CreateToggle(bottomBarObj, out Toggle unityToggle, out Text unityToggleText); unityToggle.onValueChanged.AddListener(ToggleLogUnity); unityToggle.isOn = LogUnity; unityToggleText.text = "Print Unity Debug?"; unityToggleText.alignment = TextAnchor.MiddleLeft; void ToggleLogUnity(bool val) { LogUnity = val; ModConfig.Instance.Log_Unity_Debug = val; ModConfig.SaveSettings(); } var unityToggleLayout = unityToggleObj.AddComponent <LayoutElement>(); unityToggleLayout.minWidth = 170; unityToggleLayout.flexibleWidth = 0; var unityToggleRect = unityToggleObj.transform.Find("Background").GetComponent <RectTransform>(); var pos = unityToggleRect.localPosition; pos.y = -4; unityToggleRect.localPosition = pos; // // Save to disk button // var saveToDiskObj = UIFactory.CreateToggle(bottomBarObj, out Toggle diskToggle, out Text diskToggleText); // diskToggle.onValueChanged.AddListener(ToggleDisk); // diskToggle.isOn = SaveToDisk; // diskToggleText.text = "Save logs to 'Mods\\UnityExplorer\\Logs'?"; // diskToggleText.alignment = TextAnchor.MiddleLeft; // void ToggleDisk(bool val) // { // SaveToDisk = val; // ModConfig.Instance.Save_Logs_To_Disk = val; // ModConfig.SaveSettings(); // } // var diskToggleLayout = saveToDiskObj.AddComponent<LayoutElement>(); // diskToggleLayout.minWidth = 340; // diskToggleLayout.flexibleWidth = 0; // var saveToDiskRect = saveToDiskObj.transform.Find("Background").GetComponent<RectTransform>(); // pos = unityToggleRect.localPosition; // pos.y = -8; // saveToDiskRect.localPosition = pos; #endregion }
private void CreateStartPlaceHolderWithTransform(Transform transform) { startPlaceHolder = CreatePlaceHolderWithIdentifier(startPlaceHolderIdentifier); startPlaceHolder.transform.SetParent(transform, false); startPlaceHolder.gameObject.SetActive(false); }
internal void OnLayoutElementAdded(LayoutElement element) { ElementAdded?.Invoke(this, new LayoutElementEventArgs(element)); }