From d89d80f9680962c1c1b10bf7bba5ed27b1cae249 Mon Sep 17 00:00:00 2001 From: "Simon (darkside) Jackson" Date: Thu, 29 Oct 2015 21:11:00 +0000 Subject: [PATCH] Back-ported the Reorderable List control from 5.2 --HG-- branch : develop_4.6 --- Scripts/Editor/UIExtensionsMenuOptions.cs | 965 ++++++++++++------ Scripts/ReorderableList.meta | 5 + Scripts/ReorderableList/ReorderableList.cs | 99 ++ .../ReorderableList/ReorderableList.cs.meta | 12 + Scripts/ReorderableList/ReorderableList.unity | Bin 0 -> 90216 bytes .../ReorderableList.unity.meta | 8 + .../ReorderableList/ReorderableListContent.cs | 63 ++ .../ReorderableListContent.cs.meta | 12 + .../ReorderableList/ReorderableListDebug.cs | 29 + .../ReorderableListDebug.cs.meta | 12 + .../ReorderableList/ReorderableListElement.cs | 240 +++++ .../ReorderableListElement.cs.meta | 12 + 12 files changed, 1165 insertions(+), 292 deletions(-) create mode 100644 Scripts/ReorderableList.meta create mode 100644 Scripts/ReorderableList/ReorderableList.cs create mode 100644 Scripts/ReorderableList/ReorderableList.cs.meta create mode 100644 Scripts/ReorderableList/ReorderableList.unity create mode 100644 Scripts/ReorderableList/ReorderableList.unity.meta create mode 100644 Scripts/ReorderableList/ReorderableListContent.cs create mode 100644 Scripts/ReorderableList/ReorderableListContent.cs.meta create mode 100644 Scripts/ReorderableList/ReorderableListDebug.cs create mode 100644 Scripts/ReorderableList/ReorderableListDebug.cs.meta create mode 100644 Scripts/ReorderableList/ReorderableListElement.cs create mode 100644 Scripts/ReorderableList/ReorderableListElement.cs.meta diff --git a/Scripts/Editor/UIExtensionsMenuOptions.cs b/Scripts/Editor/UIExtensionsMenuOptions.cs index 96d2209..fe68e7d 100644 --- a/Scripts/Editor/UIExtensionsMenuOptions.cs +++ b/Scripts/Editor/UIExtensionsMenuOptions.cs @@ -14,19 +14,19 @@ namespace UnityEditor.UI #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 private const string kUILayerName = "UI"; - private const float kWidth = 160f; - private const float kThickHeight = 30f; - private const float kThinHeight = 20f; - private const string kStandardSpritePath = "UI/Skin/UISprite.psd"; + private const float kWidth = 160f; + private const float kThickHeight = 30f; + private const float kThinHeight = 20f; + private const string kStandardSpritePath = "UI/Skin/UISprite.psd"; private const string kBackgroundSpriteResourcePath = "UI/Skin/Background.psd"; - private const string kInputFieldBackgroundPath = "UI/Skin/InputFieldBackground.psd"; - private const string kKnobPath = "UI/Skin/Knob.psd"; - private const string kCheckmarkPath = "UI/Skin/Checkmark.psd"; + private const string kInputFieldBackgroundPath = "UI/Skin/InputFieldBackground.psd"; + private const string kKnobPath = "UI/Skin/Knob.psd"; + private const string kCheckmarkPath = "UI/Skin/Checkmark.psd"; - private static Vector2 s_ThickGUIElementSize = new Vector2(kWidth, kThickHeight); - private static Vector2 s_ThinGUIElementSize = new Vector2(kWidth, kThinHeight); - private static Vector2 s_ImageGUIElementSize = new Vector2(100f, 100f); - private static Color s_DefaultSelectableColor = new Color(1f, 1f, 1f, 1f); + private static Vector2 s_ThickGUIElementSize = new Vector2(kWidth, kThickHeight); + private static Vector2 s_ThinGUIElementSize = new Vector2(kWidth, kThinHeight); + private static Vector2 s_ImageGUIElementSize = new Vector2(100f, 100f); + private static Color s_DefaultSelectableColor = new Color(1f, 1f, 1f, 1f); private static Color s_TextColor = new Color(50f / 255f, 50f / 255f, 50f / 255f, 1f); #endregion #region Unity Builder methods - Do not change unless UI Source (Editor\MenuOptions) changes @@ -97,7 +97,7 @@ namespace UnityEditor.UI Selection.activeGameObject = child; return child; } - + static GameObject CreateUIObject(string name, GameObject parent) { GameObject go = new GameObject(name); @@ -207,6 +207,7 @@ namespace UnityEditor.UI #region UI Extensions "Create" Menu items + #region Scroll Snap controls [MenuItem("GameObject/UI/Extensions/Horizontal Scroll Snap", false)] static public void AddHorizontalScrollSnap(MenuCommand menuCommand) { @@ -224,7 +225,7 @@ namespace UnityEditor.UI rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; rectTransformScrollSnapRoot.sizeDelta = new Vector2(300f, 150f); - + Image image = horizontalScrollSnapRoot.AddComponent(); image.sprite = AssetDatabase.GetBuiltinExtraResource(kBackgroundSpriteResourcePath); @@ -240,7 +241,6 @@ namespace UnityEditor.UI RectTransform rectTransformContent = childContent.GetComponent(); rectTransformContent.anchorMin = Vector2.zero; rectTransformContent.anchorMax = new Vector2(1f, 1f); - //rectTransformContent.anchoredPosition = Vector2.zero; rectTransformContent.sizeDelta = Vector2.zero; sr.content = rectTransformContent; @@ -249,15 +249,13 @@ namespace UnityEditor.UI Image pageImage = childPage01.AddComponent(); pageImage.sprite = AssetDatabase.GetBuiltinExtraResource(kStandardSpritePath); pageImage.type = Image.Type.Sliced; - pageImage.color = s_DefaultSelectableColor; - + pageImage.color = s_DefaultSelectableColor; + RectTransform rectTransformPage01 = childPage01.GetComponent(); rectTransformPage01.anchorMin = new Vector2(0f, 0.5f); rectTransformPage01.anchorMax = new Vector2(0f, 0.5f); - //rectTransformPage01.anchoredPosition = Vector2.zero; - //rectTransformPage01.sizeDelta = Vector2.zero; - rectTransformPage01.pivot = new Vector2(0f, 0.5f); - + rectTransformPage01.pivot = new Vector2(0f, 0.5f); + //Setup Text on Page01 Text text = childText.AddComponent(); text.text = "Page_01"; @@ -268,13 +266,10 @@ namespace UnityEditor.UI RectTransform rectTransformPage01Text = childText.GetComponent(); rectTransformPage01Text.anchorMin = new Vector2(0.5f, 0.5f); rectTransformPage01Text.anchorMax = new Vector2(0.5f, 0.5f); - //rectTransformPage01Text.anchoredPosition = Vector2.zero; - //rectTransformPage01Text.sizeDelta = Vector2.zero; rectTransformPage01Text.pivot = new Vector2(0.5f, 0.5f); //Need to add example child components like in the Asset (SJ) - Selection.activeGameObject = horizontalScrollSnapRoot; } @@ -350,6 +345,131 @@ namespace UnityEditor.UI Selection.activeGameObject = verticalScrollSnapRoot; } + #region New ScrollSnapCode + static public void FixedScrollSnapBase(MenuCommand menuCommand, string name, ScrollSnap.ScrollDirection direction, int itemVisible, int itemCount, Vector2 itemSize) + { + GameObject scrollSnapRoot = CreateUIElementRoot(name, menuCommand, s_ThickGUIElementSize); + GameObject itemList = CreateUIObject("List", scrollSnapRoot); + + // Set RectTransform to stretch + RectTransform rectTransformScrollSnapRoot = scrollSnapRoot.GetComponent(); + rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; + + if (direction == ScrollSnap.ScrollDirection.Horizontal) + { + rectTransformScrollSnapRoot.sizeDelta = new Vector2(itemVisible * itemSize.x, itemSize.y); + } + else + { + rectTransformScrollSnapRoot.sizeDelta = new Vector2(itemSize.x, itemVisible * itemSize.y); + } + + Image image = scrollSnapRoot.AddComponent(); + image.sprite = AssetDatabase.GetBuiltinExtraResource(kBackgroundSpriteResourcePath); + image.type = Image.Type.Sliced; + image.color = new Color(1f, 1f, 1f, 1f); + + Mask listMask = scrollSnapRoot.AddComponent(); + listMask.showMaskGraphic = false; + + ScrollRect scrollRect = scrollSnapRoot.AddComponent(); + scrollRect.vertical = direction == ScrollSnap.ScrollDirection.Vertical; + scrollRect.horizontal = direction == ScrollSnap.ScrollDirection.Horizontal; + + ScrollSnap scrollSnap = scrollSnapRoot.AddComponent(); + scrollSnap.direction = direction; + scrollSnap.itemsVisibleAtOnce = itemVisible; + + //Setup Content container + RectTransform rectTransformContent = itemList.GetComponent(); + rectTransformContent.anchorMin = Vector2.zero; + rectTransformContent.anchorMax = new Vector2(1f, 1f); + rectTransformContent.sizeDelta = Vector2.zero; + scrollRect.content = rectTransformContent; + + //Setup Item list container + if (direction == ScrollSnap.ScrollDirection.Horizontal) + { + itemList.AddComponent(); + ContentSizeFitter sizeFitter = itemList.AddComponent(); + sizeFitter.horizontalFit = ContentSizeFitter.FitMode.MinSize; + } + else + { + itemList.AddComponent(); + ContentSizeFitter sizeFitter = itemList.AddComponent(); + sizeFitter.verticalFit = ContentSizeFitter.FitMode.MinSize; + } + + //Setup children + for (var i = 0; i < itemCount; i++) + { + GameObject item = CreateUIObject(string.Format("Item_{0:00}", i), itemList); + GameObject childText = CreateUIObject("Text", item); + + Image pageImage = item.AddComponent(); + pageImage.sprite = AssetDatabase.GetBuiltinExtraResource(kStandardSpritePath); + pageImage.type = Image.Type.Sliced; + pageImage.color = s_DefaultSelectableColor; + + LayoutElement elementLayout = item.AddComponent(); + if (direction == ScrollSnap.ScrollDirection.Horizontal) + { + elementLayout.minWidth = itemSize.x; + } + else + { + elementLayout.minHeight = itemSize.y; + } + + RectTransform rectTransformPage01 = item.GetComponent(); + rectTransformPage01.anchorMin = new Vector2(0f, 0.5f); + rectTransformPage01.anchorMax = new Vector2(0f, 0.5f); + rectTransformPage01.pivot = new Vector2(0f, 0.5f); + + //Setup Text on Page01 + Text text = childText.AddComponent(); + text.text = item.name; + text.alignment = TextAnchor.MiddleCenter; + text.color = new Color(0.196f, 0.196f, 0.196f); + + //Setup Text 1st Child + RectTransform rectTransformPage01Text = childText.GetComponent(); + rectTransformPage01Text.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformPage01Text.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformPage01Text.pivot = new Vector2(0.5f, 0.5f); + } + Selection.activeGameObject = scrollSnapRoot; + } + + [MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Horizontal Single Item", false)] + static public void AddFixedItemScrollSnapHorizontalSingle(MenuCommand menuCommand) + { + FixedScrollSnapBase(menuCommand, "Scroll Snap Horizontal Single", ScrollSnap.ScrollDirection.Horizontal, 1, 3, new Vector2(100, 100)); + } + + [MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Horizontal Multiple Items", false)] + static public void AddFixedItemScrollSnapHorizontalMultiple(MenuCommand menuCommand) + { + FixedScrollSnapBase(menuCommand, "Scroll Snap Horizontal Multiple", ScrollSnap.ScrollDirection.Horizontal, 3, 15, new Vector2(100, 100)); + } + + [MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Vertical Single Item", false)] + static public void AddFixedItemScrollSnapVerticalSingle(MenuCommand menuCommand) + { + FixedScrollSnapBase(menuCommand, "Scroll Snap Vertical Multiple", ScrollSnap.ScrollDirection.Vertical, 1, 3, new Vector2(100, 100)); + } + + [MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Vertical Multiple Items", false)] + static public void AddFixedItemScrollSnapVerticalMultiple(MenuCommand menuCommand) + { + FixedScrollSnapBase(menuCommand, "Scroll Snap Vertical Multiple", ScrollSnap.ScrollDirection.Vertical, 3, 15, new Vector2(100, 100)); + } + #endregion + + #endregion [MenuItem("GameObject/UI/Extensions/UI Button", false)] static public void AddUIButton(MenuCommand menuCommand) @@ -397,6 +517,7 @@ namespace UnityEditor.UI Selection.activeGameObject = go; } + #region Accordian [MenuItem("GameObject/UI/Extensions/Accordion/Accordion Group", false)] static public void AddAccordionGroup(MenuCommand menuCommand) { @@ -417,7 +538,9 @@ namespace UnityEditor.UI Selection.activeGameObject = go; } +#endregion + #region Drop Down controls [MenuItem("GameObject/UI/Extensions/AutoComplete ComboBox", false)] static public void AddAutoCompleteComboBox(MenuCommand menuCommand) { @@ -437,7 +560,7 @@ namespace UnityEditor.UI //Create Arrow Button GameObject arrowButton = AddButtonAsChild(autoCompleteComboBoxRoot); - + //Setup ComboBox var autoCompleteComboBox = autoCompleteComboBoxRoot.AddComponent(); var cbbRT = autoCompleteComboBoxRoot.GetComponent(); @@ -671,8 +794,8 @@ namespace UnityEditor.UI mainButtonTextRT.anchorMin = Vector2.zero; mainButtonTextRT.anchorMin = Vector2.zero; mainButtonTextRT.pivot = new Vector2(0f, 1f); - mainButtonTextRT.offsetMin = new Vector2(10f,0f); - mainButtonTextRT.offsetMax = new Vector2(-4f,0f); + mainButtonTextRT.offsetMin = new Vector2(10f, 0f); + mainButtonTextRT.offsetMax = new Vector2(-4f, 0f); //Main Button Image var mainButtonImageRT = mainButtonImage.GetComponent(); mainButtonImageRT.anchorMin = Vector2.zero; @@ -682,7 +805,7 @@ namespace UnityEditor.UI mainButtonImageRT.offsetMin = new Vector2(4f, 4f); mainButtonImageRT.offsetMax = new Vector2(22f, -4f); mainButtonImageRT.GetComponent().color = new Color(1, 1, 1, 0); - + //Setup Overlay var overlayRT = overlay.GetComponent(); @@ -741,7 +864,9 @@ namespace UnityEditor.UI arrowTextCanvasGroup.blocksRaycasts = false; Selection.activeGameObject = dropDownListRoot; } +#endregion + #region RTS Selection box [MenuItem("GameObject/UI/Extensions/Selection Box", false)] static public void AddSelectionBox(MenuCommand menuCommand) { @@ -773,7 +898,9 @@ namespace UnityEditor.UI Selection.activeGameObject = go; } +#endregion + #region Bound Tooltip [MenuItem("GameObject/UI/Extensions/Bound Tooltip/Tooltip", false)] static public void AddBoundTooltip(MenuCommand menuCommand) { @@ -781,7 +908,7 @@ namespace UnityEditor.UI var tooltip = go.AddComponent(); tooltip.text = "This is my Tooltip Text"; var boundTooltip = go.AddComponent(); - boundTooltip.sprite = AssetDatabase.GetBuiltinExtraResource(kBackgroundSpriteResourcePath); + boundTooltip.sprite = AssetDatabase.GetBuiltinExtraResource(kBackgroundSpriteResourcePath); // if there is no ToolTipItem add one... CreateToolTipItem(false, go); @@ -804,7 +931,7 @@ namespace UnityEditor.UI boundTooltipItemCanvasGroup.interactable = false; boundTooltipItemCanvasGroup.blocksRaycasts = false; var boundTooltipItemImage = boundTooltipItem.AddComponent(); - boundTooltipItemImage.sprite = AssetDatabase.GetBuiltinExtraResource(kBackgroundSpriteResourcePath); + boundTooltipItemImage.sprite = AssetDatabase.GetBuiltinExtraResource(kBackgroundSpriteResourcePath); var boundTooltipItemText = CreateUIObject("Text", boundTooltipItem); var boundTooltipItemTextRT = boundTooltipItemText.GetComponent(); boundTooltipItemTextRT.anchorMin = Vector2.zero; @@ -821,6 +948,9 @@ namespace UnityEditor.UI } } +#endregion + + #region Progress bar [MenuItem("GameObject/UI/Extensions/Progress Bar", false)] static public void AddSlider(MenuCommand menuCommand) { @@ -865,6 +995,9 @@ namespace UnityEditor.UI slider.direction = Slider.Direction.LeftToRight; SetDefaultColorTransitionValues(slider); } +#endregion + + #region Primitives [MenuItem("GameObject/UI/Extensions/Primitives/UI Line Renderer", false)] static public void AddUILineRenderer(MenuCommand menuCommand) @@ -881,7 +1014,7 @@ namespace UnityEditor.UI go.AddComponent(); Selection.activeGameObject = go; } - + [MenuItem("GameObject/UI/Extensions/Primitives/UI Circle", false)] static public void AddUICircle(MenuCommand menuCommand) { @@ -889,6 +1022,516 @@ namespace UnityEditor.UI go.AddComponent(); Selection.activeGameObject = go; } +#endregion + + #region Re-Orderable Lists + + [MenuItem("GameObject/UI/Extensions/Re-orderable Lists/Re-orderable Vertical Scroll Rect", false)] + static public void AddReorderableScrollRectVertical(MenuCommand menuCommand) + { + GameObject reorderableScrollRoot = CreateUIElementRoot("Re-orderable Vertical ScrollRect", menuCommand, s_ThickGUIElementSize); + + GameObject childContent = CreateUIObject("List_Content", reorderableScrollRoot); + + GameObject Element01 = CreateUIObject("Element_01", childContent); + GameObject Element02 = CreateUIObject("Element_02", childContent); + GameObject Element03 = CreateUIObject("Element_03", childContent); + + + // Set RectTransform to stretch + RectTransform rectTransformScrollSnapRoot = reorderableScrollRoot.GetComponent(); + rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; + rectTransformScrollSnapRoot.sizeDelta = new Vector2(150f, 150f); + + + Image image = reorderableScrollRoot.AddComponent(); + image.color = new Color(1f, 1f, 1f, 0.392f); + + ScrollRect sr = reorderableScrollRoot.AddComponent(); + sr.vertical = true; + sr.horizontal = false; + + LayoutElement reorderableScrollRootLE = reorderableScrollRoot.AddComponent(); + reorderableScrollRootLE.preferredHeight = 300; + + reorderableScrollRoot.AddComponent(); + ReorderableList reorderableScrollRootRL = reorderableScrollRoot.AddComponent(); + + //Setup Content container + RectTransform rectTransformContent = childContent.GetComponent(); + rectTransformContent.anchorMin = Vector2.zero; + rectTransformContent.anchorMax = new Vector2(1f, 1f); + rectTransformContent.sizeDelta = Vector2.zero; + VerticalLayoutGroup childContentVLG = childContent.AddComponent(); + ContentSizeFitter childContentCSF = childContent.AddComponent(); + childContentCSF.verticalFit = ContentSizeFitter.FitMode.PreferredSize; + + sr.content = rectTransformContent; + reorderableScrollRootRL.ContentLayout = childContentVLG; + + //Setup 1st Child + Image Element01Image = Element01.AddComponent(); + Element01Image.color = Color.green; + + RectTransform rectTransformElement01 = Element01.GetComponent(); + rectTransformElement01.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement01.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement01.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement01 = Element01.AddComponent(); + LEElement01.minHeight = 50; + + //Setup 2nd Child + Image Element02Image = Element02.AddComponent(); + Element02Image.color = Color.red; + + RectTransform rectTransformElement02 = Element02.GetComponent(); + rectTransformElement02.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement02.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement02.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement02 = Element02.AddComponent(); + LEElement02.minHeight = 50; + + //Setup 2nd Child + Image Element03Image = Element03.AddComponent(); + Element03Image.color = Color.blue; + + RectTransform rectTransformElement03 = Element03.GetComponent(); + rectTransformElement03.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement03.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement03.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement03 = Element03.AddComponent(); + LEElement03.minHeight = 50; + + + //Need to add example child components like in the Asset (SJ) + Selection.activeGameObject = reorderableScrollRoot; + } + + [MenuItem("GameObject/UI/Extensions/Re-orderable Lists/Re-orderable Horizontal Scroll Rect", false)] + static public void AddReorderableScrollRectHorizontal(MenuCommand menuCommand) + { + GameObject reorderableScrollRoot = CreateUIElementRoot("Re-orderable Horizontal ScrollRect", menuCommand, s_ThickGUIElementSize); + + GameObject childContent = CreateUIObject("List_Content", reorderableScrollRoot); + + GameObject Element01 = CreateUIObject("Element_01", childContent); + GameObject Element02 = CreateUIObject("Element_02", childContent); + GameObject Element03 = CreateUIObject("Element_03", childContent); + + + // Set RectTransform to stretch + RectTransform rectTransformScrollSnapRoot = reorderableScrollRoot.GetComponent(); + rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; + rectTransformScrollSnapRoot.sizeDelta = new Vector2(150f, 150f); + + + Image image = reorderableScrollRoot.AddComponent(); + image.color = new Color(1f, 1f, 1f, 0.392f); + + ScrollRect sr = reorderableScrollRoot.AddComponent(); + sr.vertical = false; + sr.horizontal = true; + + LayoutElement reorderableScrollRootLE = reorderableScrollRoot.AddComponent(); + reorderableScrollRootLE.preferredHeight = 300; + + reorderableScrollRoot.AddComponent(); + ReorderableList reorderableScrollRootRL = reorderableScrollRoot.AddComponent(); + + //Setup Content container + RectTransform rectTransformContent = childContent.GetComponent(); + rectTransformContent.anchorMin = Vector2.zero; + rectTransformContent.anchorMax = new Vector2(1f, 1f); + rectTransformContent.sizeDelta = Vector2.zero; + HorizontalLayoutGroup childContentHLG = childContent.AddComponent(); + ContentSizeFitter childContentCSF = childContent.AddComponent(); + childContentCSF.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; + + sr.content = rectTransformContent; + reorderableScrollRootRL.ContentLayout = childContentHLG; + + //Setup 1st Child + Image Element01Image = Element01.AddComponent(); + Element01Image.color = Color.green; + + RectTransform rectTransformElement01 = Element01.GetComponent(); + rectTransformElement01.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement01.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement01.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement01 = Element01.AddComponent(); + LEElement01.minWidth = 50; + + //Setup 2nd Child + Image Element02Image = Element02.AddComponent(); + Element02Image.color = Color.red; + + RectTransform rectTransformElement02 = Element02.GetComponent(); + rectTransformElement02.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement02.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement02.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement02 = Element02.AddComponent(); + LEElement02.minWidth = 50; + + //Setup 2nd Child + Image Element03Image = Element03.AddComponent(); + Element03Image.color = Color.blue; + + RectTransform rectTransformElement03 = Element03.GetComponent(); + rectTransformElement03.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement03.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement03.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement03 = Element03.AddComponent(); + LEElement03.minWidth = 50; + + + //Need to add example child components like in the Asset (SJ) + Selection.activeGameObject = reorderableScrollRoot; + } + + [MenuItem("GameObject/UI/Extensions/Re-orderable Lists/Re-orderable Grid Scroll Rect", false)] + static public void AddReorderableScrollRectGrid(MenuCommand menuCommand) + { + GameObject reorderableScrollRoot = CreateUIElementRoot("Re-orderable Grid ScrollRect", menuCommand, s_ThickGUIElementSize); + + GameObject childContent = CreateUIObject("List_Content", reorderableScrollRoot); + + GameObject Element01 = CreateUIObject("Element_01", childContent); + GameObject Element02 = CreateUIObject("Element_02", childContent); + GameObject Element03 = CreateUIObject("Element_03", childContent); + + + // Set RectTransform to stretch + RectTransform rectTransformScrollSnapRoot = reorderableScrollRoot.GetComponent(); + rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; + rectTransformScrollSnapRoot.sizeDelta = new Vector2(150f, 150f); + + + Image image = reorderableScrollRoot.AddComponent(); + image.color = new Color(1f, 1f, 1f, 0.392f); + + ScrollRect sr = reorderableScrollRoot.AddComponent(); + sr.vertical = true; + sr.horizontal = false; + + LayoutElement reorderableScrollRootLE = reorderableScrollRoot.AddComponent(); + reorderableScrollRootLE.preferredHeight = 300; + + reorderableScrollRoot.AddComponent(); + ReorderableList reorderableScrollRootRL = reorderableScrollRoot.AddComponent(); + + //Setup Content container + RectTransform rectTransformContent = childContent.GetComponent(); + rectTransformContent.anchorMin = Vector2.zero; + rectTransformContent.anchorMax = new Vector2(1f, 1f); + rectTransformContent.sizeDelta = Vector2.zero; + GridLayoutGroup childContentGLG = childContent.AddComponent(); + childContentGLG.cellSize = new Vector2(30, 30); + childContentGLG.spacing = new Vector2(10, 10); + ContentSizeFitter childContentCSF = childContent.AddComponent(); + childContentCSF.verticalFit = ContentSizeFitter.FitMode.PreferredSize; + + sr.content = rectTransformContent; + reorderableScrollRootRL.ContentLayout = childContentGLG; + + //Setup 1st Child + Image Element01Image = Element01.AddComponent(); + Element01Image.color = Color.green; + + RectTransform rectTransformElement01 = Element01.GetComponent(); + rectTransformElement01.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement01.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement01.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement01 = Element01.AddComponent(); + LEElement01.minHeight = 50; + + //Setup 2nd Child + Image Element02Image = Element02.AddComponent(); + Element02Image.color = Color.red; + + RectTransform rectTransformElement02 = Element02.GetComponent(); + rectTransformElement02.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement02.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement02.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement02 = Element02.AddComponent(); + LEElement02.minHeight = 50; + + //Setup 2nd Child + Image Element03Image = Element03.AddComponent(); + Element03Image.color = Color.blue; + + RectTransform rectTransformElement03 = Element03.GetComponent(); + rectTransformElement03.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement03.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement03.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement03 = Element03.AddComponent(); + LEElement03.minHeight = 50; + + + //Need to add example child components like in the Asset (SJ) + Selection.activeGameObject = reorderableScrollRoot; + } + + [MenuItem("GameObject/UI/Extensions/Re-orderable Lists/Re-orderable Vertical List", false)] + static public void AddReorderableVerticalList(MenuCommand menuCommand) + { + GameObject reorderableScrollRoot = CreateUIElementRoot("Re-orderable Vertial List", menuCommand, s_ThickGUIElementSize); + + GameObject childContent = CreateUIObject("List_Content", reorderableScrollRoot); + + GameObject Element01 = CreateUIObject("Element_01", childContent); + GameObject Element02 = CreateUIObject("Element_02", childContent); + GameObject Element03 = CreateUIObject("Element_03", childContent); + + + // Set RectTransform to stretch + RectTransform rectTransformScrollSnapRoot = reorderableScrollRoot.GetComponent(); + rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; + rectTransformScrollSnapRoot.sizeDelta = new Vector2(150f, 150f); + + Image image = reorderableScrollRoot.AddComponent(); + image.color = new Color(1f, 1f, 1f, 0.392f); + + LayoutElement reorderableScrollRootLE = reorderableScrollRoot.AddComponent(); + reorderableScrollRootLE.preferredHeight = 300; + + reorderableScrollRoot.AddComponent(); + ReorderableList reorderableScrollRootRL = reorderableScrollRoot.AddComponent(); + + //Setup Content container + RectTransform rectTransformContent = childContent.GetComponent(); + rectTransformContent.anchorMin = Vector2.zero; + rectTransformContent.anchorMax = new Vector2(1f, 1f); + rectTransformContent.sizeDelta = Vector2.zero; + VerticalLayoutGroup childContentVLG = childContent.AddComponent(); + ContentSizeFitter childContentCSF = childContent.AddComponent(); + childContentCSF.verticalFit = ContentSizeFitter.FitMode.PreferredSize; + + reorderableScrollRootRL.ContentLayout = childContentVLG; + + //Setup 1st Child + Image Element01Image = Element01.AddComponent(); + Element01Image.color = Color.green; + + RectTransform rectTransformElement01 = Element01.GetComponent(); + rectTransformElement01.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement01.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement01.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement01 = Element01.AddComponent(); + LEElement01.minHeight = 50; + + //Setup 2nd Child + Image Element02Image = Element02.AddComponent(); + Element02Image.color = Color.red; + + RectTransform rectTransformElement02 = Element02.GetComponent(); + rectTransformElement02.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement02.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement02.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement02 = Element02.AddComponent(); + LEElement02.minHeight = 50; + + //Setup 2nd Child + Image Element03Image = Element03.AddComponent(); + Element03Image.color = Color.blue; + + RectTransform rectTransformElement03 = Element03.GetComponent(); + rectTransformElement03.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement03.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement03.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement03 = Element03.AddComponent(); + LEElement03.minHeight = 50; + + + //Need to add example child components like in the Asset (SJ) + Selection.activeGameObject = reorderableScrollRoot; + } + + [MenuItem("GameObject/UI/Extensions/Re-orderable Lists/Re-orderable Horizontal List", false)] + static public void AddReorderableHorizontalList(MenuCommand menuCommand) + { + GameObject reorderableScrollRoot = CreateUIElementRoot("Re-orderable Horizontal List", menuCommand, s_ThickGUIElementSize); + + GameObject childContent = CreateUIObject("List_Content", reorderableScrollRoot); + + GameObject Element01 = CreateUIObject("Element_01", childContent); + GameObject Element02 = CreateUIObject("Element_02", childContent); + GameObject Element03 = CreateUIObject("Element_03", childContent); + + + // Set RectTransform to stretch + RectTransform rectTransformScrollSnapRoot = reorderableScrollRoot.GetComponent(); + rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; + rectTransformScrollSnapRoot.sizeDelta = new Vector2(150f, 150f); + + + Image image = reorderableScrollRoot.AddComponent(); + image.color = new Color(1f, 1f, 1f, 0.392f); + + LayoutElement reorderableScrollRootLE = reorderableScrollRoot.AddComponent(); + reorderableScrollRootLE.preferredHeight = 300; + + reorderableScrollRoot.AddComponent(); + ReorderableList reorderableScrollRootRL = reorderableScrollRoot.AddComponent(); + + //Setup Content container + RectTransform rectTransformContent = childContent.GetComponent(); + rectTransformContent.anchorMin = Vector2.zero; + rectTransformContent.anchorMax = new Vector2(1f, 1f); + rectTransformContent.sizeDelta = Vector2.zero; + HorizontalLayoutGroup childContentHLG = childContent.AddComponent(); + ContentSizeFitter childContentCSF = childContent.AddComponent(); + childContentCSF.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; + + reorderableScrollRootRL.ContentLayout = childContentHLG; + + //Setup 1st Child + Image Element01Image = Element01.AddComponent(); + Element01Image.color = Color.green; + + RectTransform rectTransformElement01 = Element01.GetComponent(); + rectTransformElement01.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement01.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement01.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement01 = Element01.AddComponent(); + LEElement01.minWidth = 50; + + //Setup 2nd Child + Image Element02Image = Element02.AddComponent(); + Element02Image.color = Color.red; + + RectTransform rectTransformElement02 = Element02.GetComponent(); + rectTransformElement02.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement02.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement02.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement02 = Element02.AddComponent(); + LEElement02.minWidth = 50; + + //Setup 2nd Child + Image Element03Image = Element03.AddComponent(); + Element03Image.color = Color.blue; + + RectTransform rectTransformElement03 = Element03.GetComponent(); + rectTransformElement03.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement03.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement03.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement03 = Element03.AddComponent(); + LEElement03.minWidth = 50; + + + //Need to add example child components like in the Asset (SJ) + Selection.activeGameObject = reorderableScrollRoot; + } + + [MenuItem("GameObject/UI/Extensions/Re-orderable Lists/Re-orderable Grid", false)] + static public void AddReorderableGrid(MenuCommand menuCommand) + { + GameObject reorderableScrollRoot = CreateUIElementRoot("Re-orderable Grid", menuCommand, s_ThickGUIElementSize); + + GameObject childContent = CreateUIObject("List_Content", reorderableScrollRoot); + + GameObject Element01 = CreateUIObject("Element_01", childContent); + GameObject Element02 = CreateUIObject("Element_02", childContent); + GameObject Element03 = CreateUIObject("Element_03", childContent); + + + // Set RectTransform to stretch + RectTransform rectTransformScrollSnapRoot = reorderableScrollRoot.GetComponent(); + rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; + rectTransformScrollSnapRoot.sizeDelta = new Vector2(150f, 150f); + + + Image image = reorderableScrollRoot.AddComponent(); + image.color = new Color(1f, 1f, 1f, 0.392f); + + LayoutElement reorderableScrollRootLE = reorderableScrollRoot.AddComponent(); + reorderableScrollRootLE.preferredHeight = 300; + + reorderableScrollRoot.AddComponent(); + ReorderableList reorderableScrollRootRL = reorderableScrollRoot.AddComponent(); + + //Setup Content container + RectTransform rectTransformContent = childContent.GetComponent(); + rectTransformContent.anchorMin = Vector2.zero; + rectTransformContent.anchorMax = new Vector2(1f, 1f); + rectTransformContent.sizeDelta = Vector2.zero; + GridLayoutGroup childContentGLG = childContent.AddComponent(); + childContentGLG.cellSize = new Vector2(30, 30); + childContentGLG.spacing = new Vector2(10, 10); + ContentSizeFitter childContentCSF = childContent.AddComponent(); + childContentCSF.verticalFit = ContentSizeFitter.FitMode.PreferredSize; + + reorderableScrollRootRL.ContentLayout = childContentGLG; + + //Setup 1st Child + Image Element01Image = Element01.AddComponent(); + Element01Image.color = Color.green; + + RectTransform rectTransformElement01 = Element01.GetComponent(); + rectTransformElement01.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement01.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement01.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement01 = Element01.AddComponent(); + LEElement01.minHeight = 50; + + //Setup 2nd Child + Image Element02Image = Element02.AddComponent(); + Element02Image.color = Color.red; + + RectTransform rectTransformElement02 = Element02.GetComponent(); + rectTransformElement02.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement02.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement02.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement02 = Element02.AddComponent(); + LEElement02.minHeight = 50; + + //Setup 2nd Child + Image Element03Image = Element03.AddComponent(); + Element03Image.color = Color.blue; + + RectTransform rectTransformElement03 = Element03.GetComponent(); + rectTransformElement03.anchorMin = new Vector2(0f, 0.5f); + rectTransformElement03.anchorMax = new Vector2(0f, 0.5f); + rectTransformElement03.pivot = new Vector2(0.5f, 0.5f); + + LayoutElement LEElement03 = Element03.AddComponent(); + LEElement03.minHeight = 50; + + + //Need to add example child components like in the Asset (SJ) + Selection.activeGameObject = reorderableScrollRoot; + } + + + #endregion #endregion @@ -1024,268 +1667,6 @@ namespace UnityEditor.UI } #endregion - - #region New ScrollSnapCode - static public void FixedScrollSnapBase(MenuCommand menuCommand, string name, ScrollSnap.ScrollDirection direction, int itemVisible, int itemCount, Vector2 itemSize) - { - - GameObject scrollSnapRoot = CreateUIElementRoot(name, menuCommand, s_ThickGUIElementSize); - - - - GameObject itemList = CreateUIObject("List", scrollSnapRoot); - - - - // Set RectTransform to stretch - - RectTransform rectTransformScrollSnapRoot = scrollSnapRoot.GetComponent(); - - rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f); - - rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); - - rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; - - - - if (direction == ScrollSnap.ScrollDirection.Horizontal) - - { - - rectTransformScrollSnapRoot.sizeDelta = new Vector2(itemVisible * itemSize.x, itemSize.y); - - } - - else - - { - - rectTransformScrollSnapRoot.sizeDelta = new Vector2(itemSize.x, itemVisible * itemSize.y); - - } - - - - Image image = scrollSnapRoot.AddComponent(); - - image.sprite = AssetDatabase.GetBuiltinExtraResource(kBackgroundSpriteResourcePath); - - image.type = Image.Type.Sliced; - - image.color = new Color(1f, 1f, 1f, 1f); - - - - Mask listMask = scrollSnapRoot.AddComponent(); - - listMask.showMaskGraphic = false; - - - - ScrollRect scrollRect = scrollSnapRoot.AddComponent(); - - scrollRect.vertical = direction == ScrollSnap.ScrollDirection.Vertical; - - scrollRect.horizontal = direction == ScrollSnap.ScrollDirection.Horizontal; - - - - ScrollSnap scrollSnap = scrollSnapRoot.AddComponent(); - - scrollSnap.direction = direction; - - scrollSnap.itemsVisibleAtOnce = itemVisible; - - - - //Setup Content container - - RectTransform rectTransformContent = itemList.GetComponent(); - - rectTransformContent.anchorMin = Vector2.zero; - - rectTransformContent.anchorMax = new Vector2(1f, 1f); - - //rectTransformContent.anchoredPosition = Vector2.zero; - - rectTransformContent.sizeDelta = Vector2.zero; - - scrollRect.content = rectTransformContent; - - - - //Setup Item list container - - if (direction == ScrollSnap.ScrollDirection.Horizontal) - - { - - itemList.AddComponent (); - - ContentSizeFitter sizeFitter = itemList.AddComponent(); - - sizeFitter.horizontalFit = ContentSizeFitter.FitMode.MinSize; - - } - - else - - { - - itemList.AddComponent (); - - ContentSizeFitter sizeFitter = itemList.AddComponent(); - - sizeFitter.verticalFit = ContentSizeFitter.FitMode.MinSize; - - } - - - - //Setup children - - - - for (var i = 0; i < itemCount; i ++) - - { - - GameObject item = CreateUIObject (string.Format("Item_{0:00}", i), itemList); - - - - GameObject childText = CreateUIObject ("Text", item); - - - - Image pageImage = item.AddComponent (); - - pageImage.sprite = AssetDatabase.GetBuiltinExtraResource (kStandardSpritePath); - - pageImage.type = Image.Type.Sliced; - - pageImage.color = s_DefaultSelectableColor; - - - - LayoutElement elementLayout = item.AddComponent (); - - if (direction == ScrollSnap.ScrollDirection.Horizontal) - - { - - elementLayout.minWidth = itemSize.x; - - } - - else - - { - - elementLayout.minHeight = itemSize.y; - - } - - - - RectTransform rectTransformPage01 = item.GetComponent (); - - rectTransformPage01.anchorMin = new Vector2 (0f, 0.5f); - - rectTransformPage01.anchorMax = new Vector2 (0f, 0.5f); - - //rectTransformPage01.anchoredPosition = Vector2.zero; - - //rectTransformPage01.sizeDelta = Vector2.zero; - - rectTransformPage01.pivot = new Vector2 (0f, 0.5f); - - - - //Setup Text on Page01 - - Text text = childText.AddComponent (); - - text.text = item.name; - - text.alignment = TextAnchor.MiddleCenter; - - text.color = new Color (0.196f, 0.196f, 0.196f); - - - - //Setup Text 1st Child - - RectTransform rectTransformPage01Text = childText.GetComponent (); - - rectTransformPage01Text.anchorMin = new Vector2 (0.5f, 0.5f); - - rectTransformPage01Text.anchorMax = new Vector2 (0.5f, 0.5f); - - //rectTransformPage01Text.anchoredPosition = Vector2.zero; - - //rectTransformPage01Text.sizeDelta = Vector2.zero; - - rectTransformPage01Text.pivot = new Vector2 (0.5f, 0.5f); - - } - - - - Selection.activeGameObject = scrollSnapRoot; - - } - - - - [MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Horizontal Single Item", false)] - - static public void AddFixedItemScrollSnapHorizontalSingle(MenuCommand menuCommand) - - { - - FixedScrollSnapBase (menuCommand, "Scroll Snap Horizontal Single", ScrollSnap.ScrollDirection.Horizontal, 1, 3, new Vector2(100, 100)); - - } - - - - [MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Horizontal Multiple Items", false)] - - static public void AddFixedItemScrollSnapHorizontalMultiple(MenuCommand menuCommand) - - { - - FixedScrollSnapBase (menuCommand, "Scroll Snap Horizontal Multiple", ScrollSnap.ScrollDirection.Horizontal, 3, 15, new Vector2(100, 100)); - - } - - - - [MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Vertical Single Item", false)] - - static public void AddFixedItemScrollSnapVerticalSingle(MenuCommand menuCommand) - - { - - FixedScrollSnapBase (menuCommand, "Scroll Snap Vertical Multiple", ScrollSnap.ScrollDirection.Vertical, 1, 3, new Vector2(100, 100)); - - } - - - - [MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Vertical Multiple Items", false)] - - static public void AddFixedItemScrollSnapVerticalMultiple(MenuCommand menuCommand) - - { - - FixedScrollSnapBase (menuCommand, "Scroll Snap Vertical Multiple", ScrollSnap.ScrollDirection.Vertical, 3, 15, new Vector2(100, 100)); - - } - - #endregion } } diff --git a/Scripts/ReorderableList.meta b/Scripts/ReorderableList.meta new file mode 100644 index 0000000..2f25e85 --- /dev/null +++ b/Scripts/ReorderableList.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 2172bd77b99a4a9409c147b803ae67df +folderAsset: yes +DefaultImporter: + userData: diff --git a/Scripts/ReorderableList/ReorderableList.cs b/Scripts/ReorderableList/ReorderableList.cs new file mode 100644 index 0000000..df876d7 --- /dev/null +++ b/Scripts/ReorderableList/ReorderableList.cs @@ -0,0 +1,99 @@ +/// Credit Ziboo +/// Sourced from - http://forum.unity3d.com/threads/free-reorderable-list.364600/ + +using System; +using UnityEngine.Events; + +namespace UnityEngine.UI.Extensions +{ + [RequireComponent(typeof(RectTransform)), DisallowMultipleComponent] + [AddComponentMenu("UI/Extensions/Re-orderable list")] + public class ReorderableList : MonoBehaviour + { + [Tooltip("Child container with re-orderable items in a layout group")] + public LayoutGroup ContentLayout; + [Tooltip("Parent area to draw the dragged element on top of containers. Defaults to the root Canvas")] + public RectTransform DraggableArea; + + [Tooltip("Can items be dragged from the container?")] + public bool IsDraggable = true; + [Tooltip("Should the draggable components be removed or cloned?")] + public bool CloneDraggedObject = false; + + [Tooltip("Can new draggable items be dropped in to the container?")] + public bool IsDropable = true; + + + [Header("UI Re-orderable Events")] + public ReorderableListHandler OnElementDropped = new ReorderableListHandler(); + public ReorderableListHandler OnElementGrabbed = new ReorderableListHandler(); + public ReorderableListHandler OnElementRemoved = new ReorderableListHandler(); + + private RectTransform _content; + private ReorderableListContent _listContent; + + public RectTransform Content + { + get + { + if (_content == null) + { + _content = ContentLayout.GetComponent(); + } + return _content; + } + } + + private void Awake() + { + + if (ContentLayout == null) + { + Debug.LogError("You need to have a child LayoutGroup content set for the list: " + name, gameObject); + return; + } + if (DraggableArea == null) + { + DraggableArea = transform.root.GetComponentInChildren().GetComponent(); + } + if (IsDropable && !GetComponent()) + { + Debug.LogError("You need to have a Graphic control (such as an Image) for the list [" + name + "] to be droppable", gameObject); + return; + } + _listContent = ContentLayout.gameObject.AddComponent(); + _listContent.Init(this); + } + + #region Nested type: ReorderableListEventStruct + + [Serializable] + public struct ReorderableListEventStruct + { + public GameObject DroppedObject; + public int FromIndex; + public ReorderableList FromList; + public bool IsAClone; + public GameObject SourceObject; + public int ToIndex; + public ReorderableList ToList; + } + + #endregion + + #region Nested type: ReorderableListHandler + + [Serializable] + public class ReorderableListHandler : UnityEvent + { + } + + public void TestReOrderableListTarget(ReorderableListEventStruct item) + { + Debug.Log("Event Received"); + Debug.Log("Hello World, is my item a clone? [" + item.IsAClone + "]"); + } + + #endregion + } +} \ No newline at end of file diff --git a/Scripts/ReorderableList/ReorderableList.cs.meta b/Scripts/ReorderableList/ReorderableList.cs.meta new file mode 100644 index 0000000..0c82a31 --- /dev/null +++ b/Scripts/ReorderableList/ReorderableList.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6b333d67eb08d464d823874f6a1666c2 +timeCreated: 1446072130 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/ReorderableList/ReorderableList.unity b/Scripts/ReorderableList/ReorderableList.unity new file mode 100644 index 0000000000000000000000000000000000000000..2be9c022e800913ae3fa0b6b649b3e8b02998c8e GI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Pwhxrz@`K;dEQRuk_(p?r$Ou?T5Z8an+k|c=2@- zkMu)jnwNb@=!eVIefjl$9o4V!^O0D|?N<3wy1d7a1A5jE#nJDsA1ail_sz?yJPKuu zhFm{t&kJ8&z!a*#LnW^IySEqLOXAeuZ847BL+FRO?p}X&T`c@u(OAj)tNd&${f(pF zmHzhjajeRtXw3oP>aV`TuKGLt*0l@ytm<#27e7$q)Zd+OO-{~lU&zh<2$#dx8Yc8X z&iQq(zxtkq>Y07me~!?>HTY92n{2n}n>8p&w zMV-(xB8XoH_HqTmm@#8ath+xdr&7~tUd$uzd==HZuIQO(C4u(8s<--{vBr0M`}VV$ zlycaX>kC69A7M*wz8*4eFUp<2udG;qgbf9O`b3N$_31t&?kIhI!L?`lZ5Op?b7$_qn1xh5IL(WnDsk#X=sn0X z&1=jN`mQ|7>A%I%@2dZ!e)Q&jO)3x8c~`&qbj91L($e*7+MW`ACHYCN{@(ljY94=( z_b2a@xa#lMz4%&*Z!7)1N9c#k+P$3ApDd@G$b<5;t=dx@{q4CusXW5#jP*q z#j7`;uM#Jh?(CZDQ>s3_pUx*xo_M!@bYZ*&P?tZIN0*6!)O2oM#r-$V!SO2Xyh*p; z*K^|4ZoahZB(vX0?dI>j`0pf6J4pLm?)O_dg??B*#qFS`)As{3-p#!v+eaG8PxtlE zv;C=Y^t);wy?q`@<M z@m?_={@&@u@9^SZ z_2RdC@w+4*>i28P*YDpZ^uy&XuJ5Xc?l?`)VJv6AuY75K#rkD^k4@A4yY$O``N)4y z`sFw}as9GeU(AbFZ|;}lX4s!zS8Usid9+j%sm>9qX3$M-in*BYL0{eSYH B{IUQ5 literal 0 HcmV?d00001 diff --git a/Scripts/ReorderableList/ReorderableList.unity.meta b/Scripts/ReorderableList/ReorderableList.unity.meta new file mode 100644 index 0000000..47431b0 --- /dev/null +++ b/Scripts/ReorderableList/ReorderableList.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9b8d590979bc3264ab9a7df11a0e8c3c +timeCreated: 1446061891 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/ReorderableList/ReorderableListContent.cs b/Scripts/ReorderableList/ReorderableListContent.cs new file mode 100644 index 0000000..9d5b47c --- /dev/null +++ b/Scripts/ReorderableList/ReorderableListContent.cs @@ -0,0 +1,63 @@ +/// Credit Ziboo +/// Sourced from - http://forum.unity3d.com/threads/free-reorderable-list.364600/ + +using System.Collections; +using System.Collections.Generic; + +namespace UnityEngine.UI.Extensions +{ + public class ReorderableListContent : MonoBehaviour + { + private List _cachedChildren; + private List _cachedListElement; + private ReorderableListElement _ele; + private ReorderableList _extList; + private RectTransform _rect; + + public void OnTransformChildrenChanged() + { + StartCoroutine(RefreshChildren()); + } + + public void Init(ReorderableList extList) + { + _extList = extList; + _rect = GetComponent(); + _cachedChildren = new List(); + _cachedListElement = new List(); + + StartCoroutine(RefreshChildren()); + } + + private IEnumerator RefreshChildren() + { + //Handle new chilren + for (int i = 0; i < _rect.childCount; i++) + { + if (_cachedChildren.Contains(_rect.GetChild(i))) + continue; + + //Get or Create ReorderableListElement + _ele = _rect.GetChild(i).gameObject.GetComponent() ?? + _rect.GetChild(i).gameObject.AddComponent(); + _ele.Init(_extList); + + _cachedChildren.Add(_rect.GetChild(i)); + _cachedListElement.Add(_ele); + } + + //HACK a little hack, if I don't wait one frame I don't have the right deleted children + yield return 0; + + //Remove deleted child + for (int i = _cachedChildren.Count - 1; i >= 0; i--) + { + if (_cachedChildren[i] == null) + { + _cachedChildren.RemoveAt(i); + _cachedListElement.RemoveAt(i); + } + } + } + } +} \ No newline at end of file diff --git a/Scripts/ReorderableList/ReorderableListContent.cs.meta b/Scripts/ReorderableList/ReorderableListContent.cs.meta new file mode 100644 index 0000000..513644a --- /dev/null +++ b/Scripts/ReorderableList/ReorderableListContent.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 252dd148b2c1dbe40b7d938a553e3caf +timeCreated: 1446062045 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/ReorderableList/ReorderableListDebug.cs b/Scripts/ReorderableList/ReorderableListDebug.cs new file mode 100644 index 0000000..b051c88 --- /dev/null +++ b/Scripts/ReorderableList/ReorderableListDebug.cs @@ -0,0 +1,29 @@ +/// Credit Ziboo +/// Sourced from - http://forum.unity3d.com/threads/free-reorderable-list.364600/ + +namespace UnityEngine.UI.Extensions +{ + public class ReorderableListDebug : MonoBehaviour + { + public Text DebugLabel; + + void Awake() + { + foreach (var list in FindObjectsOfType()) + { + list.OnElementDropped.AddListener(ElementDropped); + } + } + + private void ElementDropped(ReorderableList.ReorderableListEventStruct droppedStruct) + { + DebugLabel.text = ""; + DebugLabel.text += "Dropped Object: " + droppedStruct.DroppedObject.name + "\n"; + DebugLabel.text += "Is Clone ?: " + droppedStruct.IsAClone + "\n"; + if (droppedStruct.IsAClone) + DebugLabel.text += "Source Object: " + droppedStruct.SourceObject.name + "\n"; + DebugLabel.text += string.Format("From {0} at Index {1} \n", droppedStruct.FromList.name, droppedStruct.FromIndex); + DebugLabel.text += string.Format("To {0} at Index {1} \n", droppedStruct.ToList.name, droppedStruct.ToIndex); + } + } +} \ No newline at end of file diff --git a/Scripts/ReorderableList/ReorderableListDebug.cs.meta b/Scripts/ReorderableList/ReorderableListDebug.cs.meta new file mode 100644 index 0000000..d9e54ed --- /dev/null +++ b/Scripts/ReorderableList/ReorderableListDebug.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 86c224aef3e999140b78d1d7135ba33f +timeCreated: 1446072313 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/ReorderableList/ReorderableListElement.cs b/Scripts/ReorderableList/ReorderableListElement.cs new file mode 100644 index 0000000..6d964be --- /dev/null +++ b/Scripts/ReorderableList/ReorderableListElement.cs @@ -0,0 +1,240 @@ +/// Credit Ziboo +/// Sourced from - http://forum.unity3d.com/threads/free-reorderable-list.364600/ + +using System.Collections.Generic; +using UnityEngine.EventSystems; + +namespace UnityEngine.UI.Extensions +{ + + [RequireComponent(typeof(RectTransform))] + public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler + { + private readonly List _raycastResults = new List(); + private ReorderableList _currentReorderableListRaycasted; + private RectTransform _draggingObject; + private LayoutElement _draggingObjectLE; + private Vector2 _draggingObjectOriginalSize; + private RectTransform _fakeElement; + private LayoutElement _fakeElementLE; + private int _fromIndex; + private bool _isDragging; + private RectTransform _rect; + private ReorderableList _reorderableList; + + #region IBeginDragHandler Members + + 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(); + } + + //Put _dragging object into the draggin area + _draggingObjectOriginalSize = gameObject.GetComponent().rect.size; + _draggingObjectLE = _draggingObject.GetComponent(); + _draggingObject.SetParent(_reorderableList.DraggableArea, false); + _draggingObject.SetAsLastSibling(); + + //Create a fake element for previewing placement + _fakeElement = new GameObject("Fake").AddComponent(); + _fakeElementLE = _fakeElement.gameObject.AddComponent(); + + + 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; + } + + #endregion + + #region IDragHandler Members + + public void OnDrag(PointerEventData eventData) + { + if (!_isDragging) + return; + + //Set dragging object on cursor + _draggingObject.position = eventData.position; + + //Check everything under the cursor to find a ReorderableList + EventSystem.current.RaycastAll(eventData, _raycastResults); + for (int i = 0; i < _raycastResults.Count; i++) + { + _currentReorderableListRaycasted = _raycastResults[i].gameObject.GetComponent(); + if (_currentReorderableListRaycasted != null) + { + break; + } + } + + //If nothing found or the list is not dropable, put the fake element outsite + if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false) + { + RefreshSizes(); + _fakeElement.transform.SetParent(_reorderableList.DraggableArea, false); + + } + //Else find the best position on the list and put fake element on the right index + else + { + if (_fakeElement.parent != _currentReorderableListRaycasted) + _fakeElement.SetParent(_currentReorderableListRaycasted.Content, false); + + float minDistance = float.PositiveInfinity; + int targetIndex = 0; + float dist = 0; + for (int j = 0; j < _currentReorderableListRaycasted.Content.childCount; j++) + { + var c = _currentReorderableListRaycasted.Content.GetChild(j).GetComponent(); + + if (_currentReorderableListRaycasted.ContentLayout is VerticalLayoutGroup) + dist = Mathf.Abs(c.position.y - eventData.position.y); + else if (_currentReorderableListRaycasted.ContentLayout is HorizontalLayoutGroup) + dist = Mathf.Abs(c.position.x - eventData.position.x); + else if (_currentReorderableListRaycasted.ContentLayout is GridLayoutGroup) + dist = (Mathf.Abs(c.position.x - eventData.position.x) + Mathf.Abs(c.position.y - eventData.position.y)); + + if (dist < minDistance) + { + minDistance = dist; + targetIndex = j; + } + } + + RefreshSizes(); + _fakeElement.SetSiblingIndex(targetIndex); + _fakeElement.gameObject.SetActive(true); + + } + } + + #endregion + + #region IEndDragHandler Members + + public void OnEndDrag(PointerEventData eventData) + { + _isDragging = false; + + if (_draggingObject != null) + { + //If we have a, ReorderableList that is dropable + //Put the dragged object into the content and at the right index + if (_currentReorderableListRaycasted != null && _currentReorderableListRaycasted.IsDropable) + { + RefreshSizes(); + _draggingObject.SetParent(_currentReorderableListRaycasted.Content, false); + _draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex()); + + + //Send OnelementDropped Event + if (_reorderableList.OnElementDropped != null) + { + _reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct + { + DroppedObject = _draggingObject.gameObject, + IsAClone = _reorderableList.CloneDraggedObject, + SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject, + FromList = _reorderableList, + FromIndex = _fromIndex, + ToList = _currentReorderableListRaycasted, + ToIndex = _fakeElement.GetSiblingIndex() - 1 + }); + } + } + //We don't have an ReorderableList + else + { + //If it's a clone, delete it + if (_reorderableList.CloneDraggedObject) + { + Destroy(_draggingObject.gameObject); + } + //Else replace the draggedObject to his first place + else + { + RefreshSizes(); + _draggingObject.SetParent(_reorderableList.Content, false); + _draggingObject.SetSiblingIndex(_fromIndex); + } + } + } + + //Delete fake element + if (_fakeElement != null) + Destroy(_fakeElement.gameObject); + } + + #endregion + + private void RefreshSizes() + { + Vector2 size = _draggingObjectOriginalSize; + + if (_currentReorderableListRaycasted != null && _currentReorderableListRaycasted.IsDropable) + { + var firstChild = _currentReorderableListRaycasted.Content.GetChild(0); + if (firstChild != null) + { + size = firstChild.GetComponent().rect.size; + } + } + + _draggingObject.sizeDelta = size; + _fakeElementLE.preferredHeight = _draggingObjectLE.preferredHeight = size.y; + _fakeElementLE.preferredWidth = _draggingObjectLE.preferredWidth = size.x; + } + + public void Init(ReorderableList reorderableList) + { + _reorderableList = reorderableList; + _rect = GetComponent(); + } + } +} \ No newline at end of file diff --git a/Scripts/ReorderableList/ReorderableListElement.cs.meta b/Scripts/ReorderableList/ReorderableListElement.cs.meta new file mode 100644 index 0000000..cd587fb --- /dev/null +++ b/Scripts/ReorderableList/ReorderableListElement.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 916e98f1b982a9a4082fcc45c87b66c5 +timeCreated: 1446072130 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: