diff --git a/Editor/UIExtensionsMenuOptions.cs b/Editor/UIExtensionsMenuOptions.cs index 9c718c8..19048fc 100644 --- a/Editor/UIExtensionsMenuOptions.cs +++ b/Editor/UIExtensionsMenuOptions.cs @@ -6,11 +6,11 @@ using UnityEngine.UI.Extensions; namespace UnityEditor.UI { - /// - /// This script adds the Extensions UI menu options to the Unity Editor. - /// + /// + /// This script adds the Extensions UI menu options to the Unity Editor. + /// - static internal class ExtensionMenuOptions + static internal class ExtensionMenuOptions { #region Unity Builder section - Do not change unless UI Source (Editor\MenuOptions) changes #region Unity Builder properties - Do not change unless UI Source (Editor\MenuOptions) changes @@ -467,119 +467,119 @@ namespace UnityEditor.UI { FixedScrollSnapBase(menuCommand, "Scroll Snap Vertical Multiple", ScrollSnap.ScrollDirection.Vertical, 3, 15, new Vector2(100, 100)); } - #endregion + #endregion - #region ContentScrollSnapHorizontal - [MenuItem("GameObject/UI/Extensions/Content Scroll Snap Horizontal", false)] - static public void AddContentScrollSnapHorizontal(MenuCommand menuCommand) - { - GameObject contentScrollSnapRoot = CreateUIElementRoot("Content Scroll Snap Horizontal", menuCommand, s_ThickGUIElementSize); + #region ContentScrollSnapHorizontal + [MenuItem("GameObject/UI/Extensions/Content Scroll Snap Horizontal", false)] + static public void AddContentScrollSnapHorizontal(MenuCommand menuCommand) + { + GameObject contentScrollSnapRoot = CreateUIElementRoot("Content Scroll Snap Horizontal", menuCommand, s_ThickGUIElementSize); - GameObject childContent = CreateUIObject("Content", contentScrollSnapRoot); + GameObject childContent = CreateUIObject("Content", contentScrollSnapRoot); - GameObject childPage01 = CreateUIObject("Position 1", childContent); + GameObject childPage01 = CreateUIObject("Position 1", childContent); - GameObject childPage02 = CreateUIObject("Position 2", childContent); + GameObject childPage02 = CreateUIObject("Position 2", childContent); - GameObject childPage03 = CreateUIObject("Position 3", childContent); + GameObject childPage03 = CreateUIObject("Position 3", childContent); - GameObject childPage04 = CreateUIObject("Position 4", childContent); + GameObject childPage04 = CreateUIObject("Position 4", childContent); - GameObject childPage05 = CreateUIObject("Position 5", childContent); + GameObject childPage05 = CreateUIObject("Position 5", childContent); - //setup root - RectTransform contentScrollSnapRectTransform = ((RectTransform)contentScrollSnapRoot.transform); - contentScrollSnapRectTransform.anchorMin = new Vector2(0.5f, 0.5f); - contentScrollSnapRectTransform.anchorMax = new Vector2(0.5f, 0.5f); - contentScrollSnapRectTransform.anchoredPosition = Vector2.zero; - contentScrollSnapRectTransform.sizeDelta = new Vector2(100, 200); + //setup root + RectTransform contentScrollSnapRectTransform = ((RectTransform)contentScrollSnapRoot.transform); + contentScrollSnapRectTransform.anchorMin = new Vector2(0.5f, 0.5f); + contentScrollSnapRectTransform.anchorMax = new Vector2(0.5f, 0.5f); + contentScrollSnapRectTransform.anchoredPosition = Vector2.zero; + contentScrollSnapRectTransform.sizeDelta = new Vector2(100, 200); - Image image = contentScrollSnapRoot.AddComponent(); - image.sprite = null; - image.color = new Color(1, 0, 0, .5f); + Image image = contentScrollSnapRoot.AddComponent(); + image.sprite = null; + image.color = new Color(1, 0, 0, .5f); - ScrollRect sr = contentScrollSnapRoot.AddComponent(); - sr.vertical = false; - sr.horizontal = true; + ScrollRect sr = contentScrollSnapRoot.AddComponent(); + sr.vertical = false; + sr.horizontal = true; - //setup content container - RectTransform contentTransform = ((RectTransform)childContent.transform); - contentTransform.anchorMin = new Vector2(.5f, .5f); - contentTransform.anchorMax = new Vector2(.5f, .5f); - contentTransform.pivot = new Vector2(.5f, .5f); - contentTransform.sizeDelta = new Vector2(200, 300); + //setup content container + RectTransform contentTransform = ((RectTransform)childContent.transform); + contentTransform.anchorMin = new Vector2(.5f, .5f); + contentTransform.anchorMax = new Vector2(.5f, .5f); + contentTransform.pivot = new Vector2(.5f, .5f); + contentTransform.sizeDelta = new Vector2(200, 300); - Image contentImage = childContent.AddComponent(); - contentImage.sprite = null; - contentImage.color = new Color(0, 0, 1, .5f); + Image contentImage = childContent.AddComponent(); + contentImage.sprite = null; + contentImage.color = new Color(0, 0, 1, .5f); - sr.content = contentTransform; + sr.content = contentTransform; - //setup child 1 - RectTransform childPage01Transform = (RectTransform)childPage01.transform; - childPage01Transform.anchorMin = new Vector2(0, 1); - childPage01Transform.anchorMax = new Vector2(0, 1); - childPage01Transform.pivot = new Vector2(0, 1); - childPage01Transform.anchoredPosition = new Vector2(0, -125); + //setup child 1 + RectTransform childPage01Transform = (RectTransform)childPage01.transform; + childPage01Transform.anchorMin = new Vector2(0, 1); + childPage01Transform.anchorMax = new Vector2(0, 1); + childPage01Transform.pivot = new Vector2(0, 1); + childPage01Transform.anchoredPosition = new Vector2(0, -125); - Image childPage01Image = childPage01.AddComponent(); - childPage01Image.sprite = null; - childPage01Image.color = Color.white; + Image childPage01Image = childPage01.AddComponent(); + childPage01Image.sprite = null; + childPage01Image.color = Color.white; - //setup child 2 - RectTransform childPage02Transform = (RectTransform)childPage02.transform; - childPage02Transform.anchorMin = new Vector2(0, 1); - childPage02Transform.anchorMax = new Vector2(0, 1); - childPage02Transform.pivot = new Vector2(0, 1); - childPage02Transform.anchoredPosition = new Vector2(175, -150); + //setup child 2 + RectTransform childPage02Transform = (RectTransform)childPage02.transform; + childPage02Transform.anchorMin = new Vector2(0, 1); + childPage02Transform.anchorMax = new Vector2(0, 1); + childPage02Transform.pivot = new Vector2(0, 1); + childPage02Transform.anchoredPosition = new Vector2(175, -150); - Image childPage02Image = childPage02.AddComponent(); - childPage02Image.sprite = null; - childPage02Image.color = Color.white; + Image childPage02Image = childPage02.AddComponent(); + childPage02Image.sprite = null; + childPage02Image.color = Color.white; - //setup child 3 - RectTransform childPage03Transform = (RectTransform)childPage03.transform; - childPage03Transform.anchorMin = new Vector2(0, 1); - childPage03Transform.anchorMax = new Vector2(0, 1); - childPage03Transform.pivot = new Vector2(0, 1); - childPage03Transform.anchoredPosition = new Vector2(315, -125); - childPage03Transform.sizeDelta = new Vector2(50, 100); + //setup child 3 + RectTransform childPage03Transform = (RectTransform)childPage03.transform; + childPage03Transform.anchorMin = new Vector2(0, 1); + childPage03Transform.anchorMax = new Vector2(0, 1); + childPage03Transform.pivot = new Vector2(0, 1); + childPage03Transform.anchoredPosition = new Vector2(315, -125); + childPage03Transform.sizeDelta = new Vector2(50, 100); - Image childPage03Image = childPage03.AddComponent(); - childPage03Image.sprite = null; - childPage03Image.color = Color.white; + Image childPage03Image = childPage03.AddComponent(); + childPage03Image.sprite = null; + childPage03Image.color = Color.white; - //setup child 4 - RectTransform childPage04Transform = (RectTransform)childPage04.transform; - childPage04Transform.anchorMin = new Vector2(0, 1); - childPage04Transform.anchorMax = new Vector2(0, 1); - childPage04Transform.pivot = new Vector2(0, 1); - childPage04Transform.anchoredPosition = new Vector2(490, -110); + //setup child 4 + RectTransform childPage04Transform = (RectTransform)childPage04.transform; + childPage04Transform.anchorMin = new Vector2(0, 1); + childPage04Transform.anchorMax = new Vector2(0, 1); + childPage04Transform.pivot = new Vector2(0, 1); + childPage04Transform.anchoredPosition = new Vector2(490, -110); - Image childPage04Image = childPage04.AddComponent(); - childPage04Image.sprite = null; - childPage04Image.color = Color.white; + Image childPage04Image = childPage04.AddComponent(); + childPage04Image.sprite = null; + childPage04Image.color = Color.white; - //setup child 5 - RectTransform childPage05Transform = (RectTransform)childPage05.transform; - childPage05Transform.anchorMin = new Vector2(0, 1); - childPage05Transform.anchorMax = new Vector2(0, 1); - childPage05Transform.pivot = new Vector2(0, 1); - childPage05Transform.anchoredPosition = new Vector2(630, -180); + //setup child 5 + RectTransform childPage05Transform = (RectTransform)childPage05.transform; + childPage05Transform.anchorMin = new Vector2(0, 1); + childPage05Transform.anchorMax = new Vector2(0, 1); + childPage05Transform.pivot = new Vector2(0, 1); + childPage05Transform.anchoredPosition = new Vector2(630, -180); - Image childPage05Image = childPage05.AddComponent(); - childPage05Image.sprite = null; - childPage05Image.color = Color.white; + Image childPage05Image = childPage05.AddComponent(); + childPage05Image.sprite = null; + childPage05Image.color = Color.white; - //add scroll snap after we've added the content & items - contentScrollSnapRoot.AddComponent(); - } - #endregion + //add scroll snap after we've added the content & items + contentScrollSnapRoot.AddComponent(); + } + #endregion - #endregion + #endregion - #region UIVertical Scroller - [MenuItem("GameObject/UI/Extensions/UI Vertical Scroller", false)] + #region UIVertical Scroller + [MenuItem("GameObject/UI/Extensions/UI Vertical Scroller", false)] static public void AddUIVerticallScroller(MenuCommand menuCommand) { GameObject uiVerticalScrollerRoot = CreateUIElementRoot("UI Vertical Scroller", menuCommand, s_ThickGUIElementSize); @@ -657,10 +657,10 @@ namespace UnityEditor.UI Selection.activeGameObject = uiVerticalScrollerRoot; } - #endregion + #endregion - #region UI Button - [MenuItem("GameObject/UI/Extensions/UI Button", false)] + #region UI Button + [MenuItem("GameObject/UI/Extensions/UI Button", false)] static public void AddUIButton(MenuCommand menuCommand) { GameObject uiButtonRoot = CreateUIElementRoot("UI Button", menuCommand, s_ThickGUIElementSize); @@ -687,10 +687,10 @@ namespace UnityEditor.UI Selection.activeGameObject = uiButtonRoot; } - #endregion + #endregion - #region UI Flippable - [MenuItem("GameObject/UI/Extensions/UI Flippable", false)] + #region UI Flippable + [MenuItem("GameObject/UI/Extensions/UI Flippable", false)] static public void AddUIFlippableImage(MenuCommand menuCommand) { GameObject go = CreateUIElementRoot("UI Flippable", menuCommand, s_ImageGUIElementSize); @@ -698,10 +698,10 @@ namespace UnityEditor.UI go.AddComponent(); Selection.activeGameObject = go; } - #endregion + #endregion - #region UI WindowBase - [MenuItem("GameObject/UI/Extensions/UI Window Base", false)] + #region UI WindowBase + [MenuItem("GameObject/UI/Extensions/UI Window Base", false)] static public void AddUIWindowBase(MenuCommand menuCommand) { GameObject go = CreateUIElementRoot("UI Window Base", menuCommand, s_ThickGUIElementSize); @@ -717,8 +717,8 @@ namespace UnityEditor.UI { GameObject go = CreateUIElementRoot("Accordion Group", menuCommand, s_ThickGUIElementSize); CreateAccordionGroup(go); - for (int i = 0; i < 3; i++) - { + for (int i = 0; i < 3; i++) + { GameObject child = CreateUIObject($"Accordion Element {i}", go); CreateAccordionElement(child); } @@ -727,60 +727,60 @@ namespace UnityEditor.UI [MenuItem("GameObject/UI/Extensions/Accordion/Accordion Group", false)] static public void AddAccordionGroup(MenuCommand menuCommand) - { - GameObject go = CreateUIElementRoot("Accordion Group", menuCommand, s_ThickGUIElementSize); - CreateAccordionGroup(go); - Selection.activeGameObject = go; - } + { + GameObject go = CreateUIElementRoot("Accordion Group", menuCommand, s_ThickGUIElementSize); + CreateAccordionGroup(go); + Selection.activeGameObject = go; + } - private static void CreateAccordionGroup(GameObject go) - { - var vlg = go.AddComponent(); - vlg.childControlHeight = true; - vlg.childControlWidth = true; - vlg.childForceExpandHeight = false; - vlg.childForceExpandHeight = true; - var csf = go.AddComponent(); - csf.verticalFit = ContentSizeFitter.FitMode.PreferredSize; - go.AddComponent(); - go.AddComponent(); - } + private static void CreateAccordionGroup(GameObject go) + { + var vlg = go.AddComponent(); + vlg.childControlHeight = true; + vlg.childControlWidth = true; + vlg.childForceExpandHeight = false; + vlg.childForceExpandHeight = true; + var csf = go.AddComponent(); + csf.verticalFit = ContentSizeFitter.FitMode.PreferredSize; + go.AddComponent(); + go.AddComponent(); + } - [MenuItem("GameObject/UI/Extensions/Accordion/Accordion Element", false)] + [MenuItem("GameObject/UI/Extensions/Accordion/Accordion Element", false)] static public void AddAccordionElement(MenuCommand menuCommand) - { - GameObject go = CreateUIElementRoot("Accordion Element", menuCommand, s_ThickGUIElementSize); - CreateAccordionElement(go); + { + GameObject go = CreateUIElementRoot("Accordion Element", menuCommand, s_ThickGUIElementSize); + CreateAccordionElement(go); - Selection.activeGameObject = go; - } + Selection.activeGameObject = go; + } - private static void CreateAccordionElement(GameObject go) - { - var vlg = go.AddComponent(); - vlg.childControlHeight = true; - vlg.childControlWidth = true; - vlg.childForceExpandHeight = false; - vlg.childForceExpandHeight = true; - go.AddComponent(); - var accordionElement = go.AddComponent(); + private static void CreateAccordionElement(GameObject go) + { + var vlg = go.AddComponent(); + vlg.childControlHeight = true; + vlg.childControlWidth = true; + vlg.childForceExpandHeight = false; + vlg.childForceExpandHeight = true; + go.AddComponent(); + var accordionElement = go.AddComponent(); - // Header - GameObject headergo = CreateUIObject("Header", go); - var headerLayout = headergo.AddComponent(); - headerLayout.minHeight = accordionElement.MinHeight; - var headerText = headergo.AddComponent(); - headerText.text = "This is an Accordion header"; + // Header + GameObject headergo = CreateUIObject("Header", go); + var headerLayout = headergo.AddComponent(); + headerLayout.minHeight = accordionElement.MinHeight; + var headerText = headergo.AddComponent(); + headerText.text = "This is an Accordion header"; - // Text - GameObject textgo = CreateUIObject("Text", go); - var textText = textgo.AddComponent(); - textText.text = "This is an example of text in an accordion element\nLots of information can be put here for selection\nIf you like"; - } - #endregion + // Text + GameObject textgo = CreateUIObject("Text", go); + var textText = textgo.AddComponent(); + textText.text = "This is an example of text in an accordion element\nLots of information can be put here for selection\nIf you like"; + } + #endregion - #region Drop Down controls - [MenuItem("GameObject/UI/Extensions/AutoComplete ComboBox", false)] + #region Drop Down controls + [MenuItem("GameObject/UI/Extensions/AutoComplete ComboBox", false)] static public void AddAutoCompleteComboBox(MenuCommand menuCommand) { GameObject autoCompleteComboBoxRoot = CreateUIElementRoot("AutoCompleteComboBox", menuCommand, s_ThickGUIElementSize); @@ -807,7 +807,7 @@ namespace UnityEditor.UI //Setup Template itemTemplate.name = "ItemTemplate"; var itemTemplateRT = itemTemplate.GetComponent(); - itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10,0); + itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10, 0); itemTemplateRT.anchoredPosition = new Vector2(-5, 0); var itemTemplateButton = itemTemplate.GetComponent