Update release from development

pull/413/head
Simon (Darkside) Jackson 2021-05-10 19:36:52 +01:00
commit f1f3f8fda9
16 changed files with 500 additions and 274 deletions

View File

@ -806,7 +806,8 @@ namespace UnityEditor.UI
//Setup Template
itemTemplate.name = "ItemTemplate";
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
itemTemplateRT.sizeDelta = cbbRT.sizeDelta;
itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10,0);
itemTemplateRT.anchoredPosition = new Vector2(-5, 0);
var itemTemplateButton = itemTemplate.GetComponent<Button>();
itemTemplateButton.transition = Selectable.Transition.None;
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();
@ -902,7 +903,8 @@ namespace UnityEditor.UI
//Setup Template
itemTemplate.name = "ItemTemplate";
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
itemTemplateRT.sizeDelta = cbbRT.sizeDelta;
itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10, 0);
itemTemplateRT.anchoredPosition = new Vector2(-5, 0);
var itemTemplateButton = itemTemplate.GetComponent<Button>();
itemTemplateButton.transition = Selectable.Transition.None;
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();
@ -1002,7 +1004,8 @@ namespace UnityEditor.UI
//Setup Template
itemTemplate.name = "ItemTemplate";
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
itemTemplateRT.sizeDelta = cbbRT.sizeDelta;
itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10, 0);
itemTemplateRT.anchoredPosition = new Vector2(-5, 0);
var itemTemplateButton = itemTemplate.GetComponent<Button>();
itemTemplateButton.transition = Selectable.Transition.None;
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();

View File

@ -63,7 +63,7 @@ namespace UnityEngine.UI.Extensions
LayoutElement le = this.gameObject.GetComponent<LayoutElement>();
if (le != null)
if (le != null && m_Accordion != null)
{
if (this.isOn)
{
@ -99,7 +99,7 @@ namespace UnityEngine.UI.Extensions
Accordion.Transition transition = (this.m_Accordion != null) ? this.m_Accordion.transition : Accordion.Transition.Instant;
if (transition == Accordion.Transition.Instant)
if (transition == Accordion.Transition.Instant && m_Accordion != null)
{
if (state)
{

View File

@ -19,6 +19,11 @@ namespace UnityEngine.UI.Extensions
public Color disabledTextColor;
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
/// <summary>
/// Contains the included items. To add and remove items to/from this list, use the <see cref="AddItem(string)"/>,
/// <see cref="RemoveItem(string)"/> and <see cref="SetAvailableOptions(List{string})"/> methods as these also execute
/// the required methods to update to the current collection.
/// </summary>
public List<string> AvailableOptions;
//private bool isInitialized = false;
@ -36,7 +41,7 @@ namespace UnityEngine.UI.Extensions
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT;
private RectTransform _scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
@ -104,6 +109,9 @@ namespace UnityEngine.UI.Extensions
public AutoCompleteSearchType autocompleteSearchType = AutoCompleteSearchType.Linq;
[SerializeField]
private bool _displayPanelAbove = false;
private bool _selectionIsValid = false;
[System.Serializable]
@ -129,13 +137,15 @@ namespace UnityEngine.UI.Extensions
{
Initialize();
}
public void Start()
{
if (SelectFirstItemOnStart && AvailableOptions.Count > 0) {
ToggleDropdownPanel (false);
OnItemClicked (AvailableOptions [0]);
}
}
RedrawPanel();
}
private bool Initialize()
{
@ -155,7 +165,7 @@ namespace UnityEngine.UI.Extensions
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
_scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
@ -182,39 +192,75 @@ namespace UnityEngine.UI.Extensions
_panelItems = new List<string>();
RebuildPanel();
//RedrawPanel(); - causes an initialisation failure in U5
return success;
}
/// <summary>
/// Adds the item to <see cref="this.AvailableOptions"/> if it is not a duplicate and rebuilds the panel.
/// </summary>
/// <param name="item">Item to add.</param>
public void AddItem(string item)
{
AvailableOptions.Add(item);
RebuildPanel();
if (!this.AvailableOptions.Contains(item))
{
this.AvailableOptions.Add(item);
this.RebuildPanel();
}
else
{
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(AddItem)}: items may only exists once. '{item}' can not be added.");
}
}
/// <summary>
/// Removes the item from <see cref="this.AvailableOptions"/> and rebuilds the panel.
/// </summary>
/// <param name="item">Item to remove.</param>
public void RemoveItem(string item)
{
AvailableOptions.Remove(item);
RebuildPanel();
if (this.AvailableOptions.Contains(item))
{
this.AvailableOptions.Remove(item);
this.RebuildPanel();
}
}
/// <summary>
/// Sets the given items as new content for the comboBox. Previous entries will be cleared.
/// </summary>
/// <param name="newOptions">New entries.</param>
public void SetAvailableOptions(List<string> newOptions)
{
AvailableOptions.Clear();
AvailableOptions = newOptions;
RebuildPanel();
}
public void SetAvailableOptions(string[] newOptions)
{
AvailableOptions.Clear();
for (int i = 0; i < newOptions.Length; i++)
var uniqueOptions = newOptions.Distinct().ToList();
if (newOptions.Count != uniqueOptions.Count)
{
AvailableOptions.Add(newOptions[i]);
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(SetAvailableOptions)}: items may only exists once. {newOptions.Count - uniqueOptions.Count} duplicates.");
}
RebuildPanel();
this.AvailableOptions.Clear();
this.AvailableOptions = uniqueOptions;
this.RebuildPanel();
}
/// <summary>
/// Sets the given items as new content for the comboBox. Previous entries will be cleared.
/// </summary>
/// <param name="newOptions">New entries.</param>
public void SetAvailableOptions(string[] newOptions)
{
var uniqueOptions = newOptions.Distinct().ToList();
if (newOptions.Length != uniqueOptions.Count)
{
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(SetAvailableOptions)}: items may only exists once. {newOptions.Length - uniqueOptions.Count} duplicates.");
}
this.AvailableOptions.Clear();
for (int i = 0; i < newOptions.Length; i++)
{
this.AvailableOptions.Add(newOptions[i]);
}
this.RebuildPanel();
}
public void ResetItems()
@ -264,7 +310,7 @@ namespace UnityEngine.UI.Extensions
if (i < AvailableOptions.Count)
{
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = _panelItems[i]; //set the text value
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
Button itemBtn = itemObjs[i].GetComponent<Button>();
itemBtn.onClick.RemoveAllListeners();
@ -331,7 +377,9 @@ namespace UnityEngine.UI.Extensions
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
new Vector2(0, DropdownOffset + _rectTransform.sizeDelta.y * _panelItems.Count - 1) :
new Vector2(0, -_rectTransform.sizeDelta.y);
//make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
@ -354,6 +402,7 @@ namespace UnityEngine.UI.Extensions
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);

View File

@ -21,8 +21,12 @@ namespace UnityEngine.UI.Extensions
[SerializeField]
private int _itemsToDisplay;
//Sorting disabled as it causes issues.
//[SerializeField]
//private bool _sortItems = true;
[SerializeField]
private bool _sortItems = true;
private bool _displayPanelAbove = false;
[System.Serializable]
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string>
@ -45,7 +49,7 @@ namespace UnityEngine.UI.Extensions
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT;
private RectTransform _scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
@ -88,6 +92,11 @@ namespace UnityEngine.UI.Extensions
Initialize();
}
public void Start()
{
RedrawPanel();
}
private bool Initialize()
{
bool success = true;
@ -104,7 +113,7 @@ namespace UnityEngine.UI.Extensions
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
_scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
@ -181,7 +190,7 @@ namespace UnityEngine.UI.Extensions
{
_panelItems.Add(option.ToLower());
}
if(_sortItems) _panelItems.Sort();
//if(_sortItems) _panelItems.Sort();
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
panelObjects.Clear();
@ -202,7 +211,7 @@ namespace UnityEngine.UI.Extensions
if (i < AvailableOptions.Count)
{
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = _panelItems[i]; //set the text value
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
Button itemBtn = itemObjs[i].GetComponent<Button>();
itemBtn.onClick.RemoveAllListeners();
@ -268,7 +277,9 @@ namespace UnityEngine.UI.Extensions
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
new Vector2(0, _rectTransform.sizeDelta.y * ItemsToDisplay - 1) :
new Vector2(0, -_rectTransform.sizeDelta.y);
//make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
@ -291,6 +302,7 @@ namespace UnityEngine.UI.Extensions
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);

View File

@ -31,7 +31,7 @@ namespace UnityEngine.UI.Extensions
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT;
private RectTransform _scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
@ -57,7 +57,6 @@ namespace UnityEngine.UI.Extensions
// private int scrollOffset; //offset of the selected item
private int _selectedIndex = -1;
[SerializeField]
private int _itemsToDisplay;
public int ItemsToDisplay
@ -72,6 +71,9 @@ namespace UnityEngine.UI.Extensions
public bool SelectFirstItemOnStart = false;
[SerializeField]
private bool _displayPanelAbove = false;
[System.Serializable]
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<int> {
}
@ -86,6 +88,7 @@ namespace UnityEngine.UI.Extensions
ToggleDropdownPanel (false);
OnItemClicked (0);
}
RedrawPanel();
}
private bool Initialize()
@ -103,7 +106,7 @@ namespace UnityEngine.UI.Extensions
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
_scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
@ -332,7 +335,9 @@ namespace UnityEngine.UI.Extensions
_mainButton.txt.rectTransform.offsetMax = new Vector2(4, 0);
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
new Vector2(0, _rectTransform.sizeDelta.y * ItemsToDisplay - 1) :
new Vector2(0, -_rectTransform.sizeDelta.y);
//make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
@ -355,6 +360,7 @@ namespace UnityEngine.UI.Extensions
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);

View File

@ -563,7 +563,10 @@ namespace UnityEngine.UI.Extensions
{
//outside the handles, move the entire slider along
UpdateDrag(eventData, eventData.pressEventCamera);
interactionState = InteractionState.Bar;
if (eventData.pointerCurrentRaycast.gameObject == m_FillRect.gameObject)
{
interactionState = InteractionState.Bar;
}
if (transition == Transition.ColorTint)
{
targetGraphic = m_FillImage;
@ -578,6 +581,7 @@ namespace UnityEngine.UI.Extensions
{
return;
}
UpdateDrag(eventData, eventData.pressEventCamera);
}

View File

@ -73,6 +73,11 @@ namespace UnityEngine.UI.Extensions
value = Math.Max(value, -1);
value = Math.Min(value, segments.Length - 1);
if (m_selectedSegmentIndex == value)
{
return;
}
m_selectedSegmentIndex = value;
if (selectedSegment)

View File

@ -103,7 +103,7 @@ namespace UnityEngine.UI.Extensions
private ScrollRect scrollRect = null;
private RectTransform scrollRectTransform = null;
private RectTransform contentTransform = null;
private List<Vector3> contentPositions = null;
private List<Vector3> contentPositions = new List<Vector3>();
private Vector3 lerpTarget = Vector3.zero;
private float totalScrollableWidth = 0;
private DrivenRectTransformTracker tracker ;
@ -514,6 +514,11 @@ namespace UnityEngine.UI.Extensions
#region Behind the Scenes Movement stuff
public void OnBeginDrag(PointerEventData ped)
{
if (contentPositions.Count < 2)
{
return;
}
StopMovement();
if (!Moving)
{
@ -523,6 +528,11 @@ namespace UnityEngine.UI.Extensions
public void OnEndDrag(PointerEventData ped)
{
if (contentPositions.Count <= 1)
{
return;
}
if (IsScrollRectAvailable)
{
StartCoroutine("SlideAndLerp");

View File

@ -359,11 +359,12 @@ namespace UnityEngine.UI.Extensions
/// *Note, this is based on a 0 starting index - 0 to x
/// </summary>
/// <param name="screenIndex">0 starting index of page to jump to</param>
public void GoToScreen(int screenIndex)
/// <param name="pagination">Override the screen movement if driven from a pagination control</param>
public void GoToScreen(int screenIndex, bool pagination = false)
{
if (screenIndex <= _screens - 1 && screenIndex >= 0)
{
if (!_lerp) StartScreenChange();
if (!_lerp || pagination) StartScreenChange();
_lerp = true;
CurrentPage = screenIndex;

View File

@ -83,9 +83,17 @@ namespace UnityEngine.UI.Extensions
}
}
var topCanvas = menuInstance.GetComponent<Canvas>();
var previousCanvas = menuStack.Peek().GetComponent<Canvas>();
topCanvas.sortingOrder = previousCanvas.sortingOrder + 1;
Canvas topCanvas = menuInstance.GetComponent<Canvas>();
if (topCanvas != null)
{
Canvas previousCanvas = menuStack.Peek().GetComponent<Canvas>();
if(previousCanvas != null)
{
topCanvas.sortingOrder = previousCanvas.sortingOrder + 1;
}
}
}
menuStack.Push(menuInstance);

View File

@ -178,6 +178,7 @@ namespace UnityEngine.UI.Extensions
// Generate the quads that make up the wide line
var segments = new List<UIVertex[]> ();
if (lineList) {
//Loop through list in line pairs, skipping drawing between lines
for (var i = 1; i < pointsToDraw.Length; i += 2) {
var start = pointsToDraw [i - 1];
var end = pointsToDraw [i];
@ -188,13 +189,15 @@ namespace UnityEngine.UI.Extensions
segments.Add (CreateLineCap (start, end, SegmentType.Start));
}
segments.Add(CreateLineSegment(start, end, SegmentType.Middle, segments.Count > 1 ? segments[segments.Count - 2] : null));
// Originally, UV's had to be wrapped per segment to ensure textures rendered correctly, however when tested in 2019.4, this no longer seems to be an issue.
segments.Add(CreateLineSegment(start, end, SegmentType.Middle));
if (lineCaps) {
segments.Add (CreateLineCap (start, end, SegmentType.End));
}
}
} else {
//Draw full lines
for (var i = 1; i < pointsToDraw.Length; i++) {
var start = pointsToDraw [i - 1];
var end = pointsToDraw [i];
@ -459,5 +462,14 @@ namespace UnityEngine.UI.Extensions
float t = Mathf.Clamp01(dot);
return p1 + from_p1_to_p2 * t;
}
protected override void OnEnable()
{
base.OnEnable();
if (m_points.Length == 0)
{
m_points = new Vector2[1];
}
}
}
}

View File

@ -76,7 +76,7 @@ namespace UnityEngine.UI.Extensions
/// <param name="pageNo"></param>
public void GoToScreen(int pageNo)
{
scrollSnap.GoToScreen(pageNo);
scrollSnap.GoToScreen(pageNo, true);
}

View File

@ -1,10 +1,14 @@
/// Credit SimonDarksideJ
/// Sourced from: https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/348/menu-manager-does-not-work-with-the-new
#if UNITY_2019_1_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
#define NEW_INPUT_SYSTEM
#endif
using System;
using System.Collections.Generic;
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
#endif
@ -13,7 +17,7 @@ namespace UnityEngine.UI.Extensions
{
public static class UIExtensionsInputManager
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
private static bool[] mouseButtons = new bool[3] { false, false, false };
private static Dictionary<KeyCode, bool> keys = new Dictionary<KeyCode, bool>();
private static Dictionary<String, bool> buttons = new Dictionary<String, bool>();
@ -21,7 +25,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetMouseButton(int button)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
if (Mouse.current == null)
{
return false;
@ -35,7 +39,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetMouseButtonDown(int button)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
if (Mouse.current == null)
{
return false;
@ -57,7 +61,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetMouseButtonUp(int button)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
if (Mouse.current == null)
{
return false;
@ -76,7 +80,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetButton(string input)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
ButtonControl buttonPressed = GetButtonControlFromString(input);
if (!buttons.ContainsKey(input))
@ -90,7 +94,7 @@ namespace UnityEngine.UI.Extensions
#endif
}
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
private static ButtonControl GetButtonControlFromString(string input)
{
if (Gamepad.current == null)
@ -112,7 +116,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetButtonDown(string input)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
ButtonControl buttonPressed = GetButtonControlFromString(input);
if (buttonPressed.isPressed)
@ -140,7 +144,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetButtonUp(string input)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
ButtonControl buttonPressed = GetButtonControlFromString(input);
if (buttons[input] && !buttonPressed.isPressed)
@ -156,7 +160,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetKey(KeyCode key)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
KeyControl keyPressed = GetKeyControlFromKeyCode(key);
if (!keys.ContainsKey(key))
{
@ -169,7 +173,7 @@ namespace UnityEngine.UI.Extensions
#endif
}
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
private static KeyControl GetKeyControlFromKeyCode(KeyCode key)
{
if (Keyboard.current == null)
@ -203,7 +207,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetKeyDown(KeyCode key)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
KeyControl keyPressed = GetKeyControlFromKeyCode(key);
if (keyPressed.isPressed)
{
@ -230,7 +234,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetKeyUp(KeyCode key)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
KeyControl keyPressed = GetKeyControlFromKeyCode(key);
if (keys[key] && !keyPressed.isPressed)
{
@ -245,7 +249,7 @@ namespace UnityEngine.UI.Extensions
public static float GetAxisRaw(string axis)
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
if (Gamepad.current == null)
{
return 0f;
@ -269,7 +273,7 @@ namespace UnityEngine.UI.Extensions
{
get
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
return Mouse.current.position.ReadValue();
#else
return Input.mousePosition;
@ -281,7 +285,7 @@ namespace UnityEngine.UI.Extensions
{
get
{
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER
#if NEW_INPUT_SYSTEM
return Mouse.current.position.ReadValue();
#else
return Input.mouseScrollDelta;

View File

@ -11,7 +11,7 @@ namespace UnityEngine.UI.Extensions
// The elements between which line segments should be drawn
public RectTransform[] transforms;
private Vector2[] previousPositions;
private Vector3[] previousPositions;
private RectTransform canvas;
private RectTransform rt;
private UILineRenderer lr;
@ -36,7 +36,7 @@ namespace UnityEngine.UI.Extensions
bool updateLine = false;
for (int i = 0; i < transforms.Length; i++)
{
if (!updateLine && previousPositions[i] != transforms[i].anchoredPosition)
if (!updateLine && previousPositions[i] != transforms[i].position)
{
updateLine = true;
}
@ -76,10 +76,10 @@ namespace UnityEngine.UI.Extensions
lr.RelativeSize = false;
lr.drivenExternally = true;
previousPositions = new Vector2[transforms.Length];
previousPositions = new Vector3[transforms.Length];
for (int i = 0; i < transforms.Length; i++)
{
previousPositions[i] = transforms[i].anchoredPosition;
previousPositions[i] = transforms[i].position;
}
}
}

View File

@ -2,225 +2,302 @@
/// sourced from: http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2011648
/*USAGE:
Simply place the script on the ScrollRect that contains the selectable children we'll be scrolling to
and drag'n'drop the RectTransform of the options "container" that we'll be scrolling.*/
Simply place the script on the ScrollRect that contains the selectable children you will be scrolling
*/
using System.Collections.Generic;
using System;
using System.Collections;
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(ScrollRect))]
[AddComponentMenu("UI/Extensions/UIScrollToSelection")]
public class UIScrollToSelection : MonoBehaviour
{
[RequireComponent(typeof(ScrollRect))]
[AddComponentMenu("UI/Extensions/UIScrollToSelection")]
public class UIScrollToSelection : MonoBehaviour
{
#region MEMBERS
//*** ATTRIBUTES ***//
[Header("[ Settings ]")]
[SerializeField]
private ScrollType scrollDirection = ScrollType.BOTH;
[SerializeField]
private float scrollSpeed = 10f;
[Header("[ References ]")]
[SerializeField, Tooltip("View (boundaries/mask) rect transform. Used to check if automatic scroll to selection is required.")]
private RectTransform viewportRectTransform;
[SerializeField, Tooltip("Scroll rect used to reach selected element.")]
private ScrollRect targetScrollRect;
[Header("[ Input ]")]
[SerializeField]
private bool cancelScrollOnInput = false;
[SerializeField]
private List<KeyCode> cancelScrollKeycodes = new List<KeyCode>();
[Header("[ Scrolling ]")]
[SerializeField, Tooltip("Allow automatic scrolling only on these axes.")]
private Axis scrollAxes = Axis.ANY;
[SerializeField, Tooltip("MOVE_TOWARDS: stiff movement, LERP: smoothed out movement")]
private ScrollMethod usedScrollMethod = ScrollMethod.MOVE_TOWARDS;
[SerializeField]
private float scrollSpeed = 50;
//*** PROPERTIES ***//
// REFERENCES
protected RectTransform LayoutListGroup
{
get { return TargetScrollRect != null ? TargetScrollRect.content : null; }
}
[Space(5)]
[SerializeField, Tooltip("Scroll speed used when element to select is out of \"JumpOffsetThreshold\" range")]
private float endOfListJumpScrollSpeed = 150;
[SerializeField, Range(0, 1), Tooltip("If next element to scroll to is located over this screen percentage, use \"EndOfListJumpScrollSpeed\" to reach this element faster.")]
private float jumpOffsetThreshold = 1;
// SETTINGS
protected ScrollType ScrollDirection
{
get { return scrollDirection; }
}
protected float ScrollSpeed
{
get { return scrollSpeed; }
}
[Header("[ Input ]")]
[SerializeField]
private MouseButton cancelScrollMouseButtons = MouseButton.ANY;
[SerializeField]
private KeyCode[] cancelScrollKeys = new KeyCode[0];
// INPUT
protected bool CancelScrollOnInput
{
get { return cancelScrollOnInput; }
}
protected List<KeyCode> CancelScrollKeycodes
{
get { return cancelScrollKeycodes; }
}
// INTERNAL - MEMBERS ONLY
private Vector3[] viewRectCorners = new Vector3[4];
private Vector3[] selectedElementCorners = new Vector3[4];
// CACHED REFERENCES
protected RectTransform ScrollWindow { get; set; }
protected ScrollRect TargetScrollRect { get; set; }
#endregion
// SCROLLING
protected EventSystem CurrentEventSystem
{
get { return EventSystem.current; }
}
protected GameObject LastCheckedGameObject { get; set; }
protected GameObject CurrentSelectedGameObject
{
get { return EventSystem.current.currentSelectedGameObject; }
}
protected RectTransform CurrentTargetRectTransform { get; set; }
protected bool IsManualScrollingAvailable { get; set; }
#region PROPERTIES
//*** METHODS - PUBLIC ***//
// REFERENCES
public RectTransform ViewRectTransform
{
get { return viewportRectTransform; }
set { viewportRectTransform = value; }
}
public ScrollRect TargetScrollRect
{
get { return targetScrollRect; }
set { targetScrollRect = value; }
}
// SCROLLING
public Axis ScrollAxes => scrollAxes;
public ScrollMethod UsedScrollMethod => usedScrollMethod;
public float ScrollSpeed => scrollSpeed;
public float EndOfListJumpScrollSpeed => endOfListJumpScrollSpeed;
public float JumpOffsetThreshold => jumpOffsetThreshold;
//*** METHODS - PROTECTED ***//
protected virtual void Awake()
{
TargetScrollRect = GetComponent<ScrollRect>();
ScrollWindow = TargetScrollRect.GetComponent<RectTransform>();
}
// INPUT
public MouseButton CancelScrollMouseButtons => cancelScrollMouseButtons;
public KeyCode[] CancelScrollKeys => cancelScrollKeys;
protected virtual void Start()
{
// VARIABLES
private RectTransform scrollRectContentTransform;
private GameObject lastCheckedSelection;
}
// COROUTINES
private Coroutine animationCoroutine;
protected virtual void Update()
{
UpdateReferences();
CheckIfScrollingShouldBeLocked();
ScrollRectToLevelSelection();
}
#endregion
//*** METHODS - PRIVATE ***//
private void UpdateReferences()
{
// update current selected rect transform
if (CurrentSelectedGameObject != LastCheckedGameObject)
#region FUNCTIONS
protected void Awake()
{
ValidateReferences();
}
protected void LateUpdate()
{
TryToScrollToSelection();
}
protected void Reset()
{
TargetScrollRect = gameObject.GetComponentInParent<ScrollRect>() ?? gameObject.GetComponentInChildren<ScrollRect>();
ViewRectTransform = gameObject.GetComponent<RectTransform>();
}
private void ValidateReferences()
{
if (!targetScrollRect)
{
CurrentTargetRectTransform = (CurrentSelectedGameObject != null) ?
CurrentSelectedGameObject.GetComponent<RectTransform>() :
null;
// unlock automatic scrolling
if (CurrentSelectedGameObject != null &&
CurrentSelectedGameObject.transform.parent == LayoutListGroup.transform)
{
IsManualScrollingAvailable = false;
}
targetScrollRect = GetComponent<ScrollRect>();
}
LastCheckedGameObject = CurrentSelectedGameObject;
}
private void CheckIfScrollingShouldBeLocked()
{
if (CancelScrollOnInput == false || IsManualScrollingAvailable == true)
if (!targetScrollRect)
{
return;
}
Debug.LogError("[UIScrollToSelection] No ScrollRect found. Either attach this script to a ScrollRect or assign on in the 'Target Scroll Rect' property");
gameObject.SetActive(false);
return;
}
for (int i = 0; i < CancelScrollKeycodes.Count; i++)
{
if (UIExtensionsInputManager.GetKeyDown(CancelScrollKeycodes[i]) == true)
{
IsManualScrollingAvailable = true;
if (ViewRectTransform == null)
{
ViewRectTransform = TargetScrollRect.GetComponent<RectTransform>();
}
break;
}
}
}
if (TargetScrollRect != null)
{
scrollRectContentTransform = TargetScrollRect.content;
}
private void ScrollRectToLevelSelection()
{
// check main references
bool referencesAreIncorrect = (TargetScrollRect == null || LayoutListGroup == null || ScrollWindow == null);
if (EventSystem.current == null)
{
Debug.LogError("[UIScrollToSelection] Unity UI EventSystem not found. It is required to check current selected object.");
gameObject.SetActive(false);
return;
}
}
if (referencesAreIncorrect == true || IsManualScrollingAvailable == true)
{
return;
}
private void TryToScrollToSelection()
{
// update references if selection changed
GameObject selection = EventSystem.current.currentSelectedGameObject;
RectTransform selection = CurrentTargetRectTransform;
if (selection == null || selection.activeInHierarchy == false || selection == lastCheckedSelection ||
selection.transform.IsChildOf(transform) == false)
{
return;
}
// check if scrolling is possible
if (selection == null || selection.transform.parent != LayoutListGroup.transform)
{
return;
}
RectTransform selectionRect = selection.GetComponent<RectTransform>();
// depending on selected scroll direction move the scroll rect to selection
switch (ScrollDirection)
{
case ScrollType.VERTICAL:
UpdateVerticalScrollPosition(selection);
break;
case ScrollType.HORIZONTAL:
UpdateHorizontalScrollPosition(selection);
break;
case ScrollType.BOTH:
UpdateVerticalScrollPosition(selection);
UpdateHorizontalScrollPosition(selection);
break;
}
}
ViewRectTransform.GetWorldCorners(viewRectCorners);
selectionRect.GetWorldCorners(selectedElementCorners);
private void UpdateVerticalScrollPosition(RectTransform selection)
{
// move the current scroll rect to correct position
float selectionPosition = -selection.anchoredPosition.y - (selection.rect.height * (1 - selection.pivot.y));
ScrollToSelection(selection);
float elementHeight = selection.rect.height;
float maskHeight = ScrollWindow.rect.height;
float listAnchorPosition = LayoutListGroup.anchoredPosition.y;
lastCheckedSelection = selection;
}
// get the element offset value depending on the cursor move direction
float offlimitsValue = GetScrollOffset(selectionPosition, listAnchorPosition, elementHeight, maskHeight);
private void ScrollToSelection(GameObject selection)
{
// initial check if we can scroll at all
if (selection == null)
{
return;
}
// move the target scroll rect
TargetScrollRect.verticalNormalizedPosition +=
(offlimitsValue / LayoutListGroup.rect.height) * Time.unscaledDeltaTime * scrollSpeed;
}
// this is just to make names shorter a bit
Vector3[] corners = viewRectCorners;
Vector3[] selectionCorners = selectedElementCorners;
private void UpdateHorizontalScrollPosition(RectTransform selection)
{
// move the current scroll rect to correct position
float selectionPosition = -selection.anchoredPosition.x - (selection.rect.width * (1 - selection.pivot.x));
// calculate scroll offset
Vector2 offsetToSelection = Vector2.zero;
float elementWidth = selection.rect.width;
float maskWidth = ScrollWindow.rect.width;
float listAnchorPosition = -LayoutListGroup.anchoredPosition.x;
offsetToSelection.x =
(selectionCorners[0].x < corners[0].x ? selectionCorners[0].x - corners[0].x : 0) +
(selectionCorners[2].x > corners[2].x ? selectionCorners[2].x - corners[2].x : 0);
offsetToSelection.y =
(selectionCorners[0].y < corners[0].y ? selectionCorners[0].y - corners[0].y : 0) +
(selectionCorners[1].y > corners[1].y ? selectionCorners[1].y - corners[1].y : 0);
// get the element offset value depending on the cursor move direction
float offlimitsValue = -GetScrollOffset(selectionPosition, listAnchorPosition, elementWidth, maskWidth);
// calculate final scroll speed
float finalScrollSpeed = ScrollSpeed;
// move the target scroll rect
TargetScrollRect.horizontalNormalizedPosition +=
(offlimitsValue / LayoutListGroup.rect.width) * Time.unscaledDeltaTime * scrollSpeed;
}
if (Math.Abs(offsetToSelection.x) / Screen.width >= JumpOffsetThreshold || Math.Abs(offsetToSelection.y) / Screen.height >= JumpOffsetThreshold)
{
finalScrollSpeed = EndOfListJumpScrollSpeed;
}
private float GetScrollOffset(float position, float listAnchorPosition, float targetLength, float maskLength)
{
if (position < listAnchorPosition + (targetLength / 2))
{
return (listAnchorPosition + maskLength) - (position - targetLength);
}
else if (position + targetLength > listAnchorPosition + maskLength)
{
return (listAnchorPosition + maskLength) - (position + targetLength);
}
// initiate animation coroutine
Vector2 targetPosition = (Vector2)scrollRectContentTransform.localPosition - offsetToSelection;
return 0;
}
if (animationCoroutine != null)
{
StopCoroutine(animationCoroutine);
}
//*** ENUMS ***//
public enum ScrollType
{
VERTICAL,
HORIZONTAL,
BOTH
}
}
animationCoroutine = StartCoroutine(ScrollToPosition(targetPosition, finalScrollSpeed));
}
private IEnumerator ScrollToPosition(Vector2 targetPosition, float speed)
{
Vector3 startPosition = scrollRectContentTransform.localPosition;
// cancel movement on axes not specified in ScrollAxes mask
targetPosition.x = ((ScrollAxes | Axis.HORIZONTAL) == ScrollAxes) ? targetPosition.x : startPosition.x;
targetPosition.y = ((ScrollAxes | Axis.VERTICAL) == ScrollAxes) ? targetPosition.y : startPosition.y;
// move to target position
Vector2 currentPosition2D = startPosition;
float horizontalSpeed = (Screen.width / Screen.dpi) * speed;
float verticalSpeed = (Screen.height / Screen.dpi) * speed;
while (currentPosition2D != targetPosition && CheckIfScrollInterrupted() == false)
{
currentPosition2D.x = MoveTowardsValue(currentPosition2D.x, targetPosition.x, horizontalSpeed, UsedScrollMethod);
currentPosition2D.y = MoveTowardsValue(currentPosition2D.y, targetPosition.y, verticalSpeed, UsedScrollMethod);
scrollRectContentTransform.localPosition = currentPosition2D;
yield return null;
}
scrollRectContentTransform.localPosition = currentPosition2D;
}
private bool CheckIfScrollInterrupted()
{
bool mouseButtonClicked = false;
// check mouse buttons
switch (CancelScrollMouseButtons)
{
case MouseButton.LEFT:
mouseButtonClicked |= Input.GetMouseButtonDown(0);
break;
case MouseButton.RIGHT:
mouseButtonClicked |= Input.GetMouseButtonDown(1);
break;
case MouseButton.MIDDLE:
mouseButtonClicked |= Input.GetMouseButtonDown(2);
break;
}
if (mouseButtonClicked == true)
{
return true;
}
// check keyboard buttons
for (int i = 0; i < CancelScrollKeys.Length; i++)
{
if (Input.GetKeyDown(CancelScrollKeys[i]) == true)
{
return true;
}
}
return false;
}
private float MoveTowardsValue(float from, float to, float delta, ScrollMethod method)
{
switch (method)
{
case ScrollMethod.MOVE_TOWARDS:
return Mathf.MoveTowards(from, to, delta * Time.unscaledDeltaTime);
case ScrollMethod.LERP:
return Mathf.Lerp(from, to, delta * Time.unscaledDeltaTime);
default:
return from;
}
}
#endregion
#region CLASS_ENUMS
[Flags]
public enum Axis
{
NONE = 0x00000000,
HORIZONTAL = 0x00000001,
VERTICAL = 0x00000010,
ANY = 0x00000011
}
[Flags]
public enum MouseButton
{
NONE = 0x00000000,
LEFT = 0x00000001,
RIGHT = 0x00000010,
MIDDLE = 0x00000100,
ANY = 0x00000111
}
public enum ScrollMethod
{
MOVE_TOWARDS,
LERP
}
#endregion
}
}

View File

@ -27,6 +27,7 @@ namespace UnityEngine.UI.Extensions
{
//if true user will need to call Init() method manually (in case the contend of the scrollview is generated from code or requires special initialization)
public bool InitByUser = false;
private bool _initialised = false;
private ScrollRect _scrollRect;
private ContentSizeFitter _contentSizeFitter;
private VerticalLayoutGroup _verticalLayoutGroup;
@ -36,8 +37,9 @@ namespace UnityEngine.UI.Extensions
private bool _isHorizontal = false;
private float _disableMarginX = 0;
private float _disableMarginY = 0;
private bool hasDisabledGridComponents = false;
private List<RectTransform> items = new List<RectTransform>();
private bool _hasDisabledGridComponents = false;
private List<RectTransform> _items = new List<RectTransform>();
private bool _reset = false;
void Awake()
{
@ -45,13 +47,19 @@ namespace UnityEngine.UI.Extensions
return;
Init();
}
public void Init()
{
if (_initialised)
{
Debug.LogError("Control already initialized\nYou have to enable the InitByUser setting on the control in order to use Init() when running");
return;
}
if (GetComponent<ScrollRect>() != null)
{
_initialised = true;
_scrollRect = GetComponent<ScrollRect>();
_scrollRect.onValueChanged.AddListener(OnScroll);
@ -60,7 +68,7 @@ namespace UnityEngine.UI.Extensions
for (int i = 0; i < _scrollRect.content.childCount; i++)
{
items.Add(_scrollRect.content.GetChild(i).GetComponent<RectTransform>());
_items.Add(_scrollRect.content.GetChild(i).GetComponent<RectTransform>());
}
if (_scrollRect.content.GetComponent<VerticalLayoutGroup>() != null)
{
@ -78,7 +86,6 @@ namespace UnityEngine.UI.Extensions
{
_contentSizeFitter = _scrollRect.content.GetComponent<ContentSizeFitter>();
}
}
else
{
@ -86,80 +93,108 @@ namespace UnityEngine.UI.Extensions
}
}
void DisableGridComponents()
void ToggleGridComponents(bool toggle)
{
if (_isVertical)
_disableMarginY = _scrollRect.GetComponent<RectTransform>().rect.height / 2 + items[0].sizeDelta.y;
_disableMarginY = _scrollRect.GetComponent<RectTransform>().rect.height / 2 + _items[0].sizeDelta.y;
if (_isHorizontal)
_disableMarginX = _scrollRect.GetComponent<RectTransform>().rect.width / 2 + items[0].sizeDelta.x;
_disableMarginX = _scrollRect.GetComponent<RectTransform>().rect.width / 2 + _items[0].sizeDelta.x;
if (_verticalLayoutGroup)
{
_verticalLayoutGroup.enabled = false;
_verticalLayoutGroup.enabled = toggle;
}
if (_horizontalLayoutGroup)
{
_horizontalLayoutGroup.enabled = false;
_horizontalLayoutGroup.enabled = toggle;
}
if (_contentSizeFitter)
{
_contentSizeFitter.enabled = false;
_contentSizeFitter.enabled = toggle;
}
if (_gridLayoutGroup)
{
_gridLayoutGroup.enabled = false;
_gridLayoutGroup.enabled = toggle;
}
hasDisabledGridComponents = true;
_hasDisabledGridComponents = !toggle;
}
public void OnScroll(Vector2 pos)
{
if (_reset)
{
return;
}
if (!hasDisabledGridComponents)
DisableGridComponents();
if (!_hasDisabledGridComponents)
{
ToggleGridComponents(false);
}
for (int i = 0; i < items.Count; i++)
for (int i = 0; i < _items.Count; i++)
{
if (_isVertical && _isHorizontal)
{
if (_scrollRect.transform.InverseTransformPoint(items[i].position).y < -_disableMarginY || _scrollRect.transform.InverseTransformPoint(items[i].position).y > _disableMarginY
|| _scrollRect.transform.InverseTransformPoint(items[i].position).x < -_disableMarginX || _scrollRect.transform.InverseTransformPoint(items[i].position).x > _disableMarginX)
if (_scrollRect.transform.InverseTransformPoint(_items[i].position).y < -_disableMarginY || _scrollRect.transform.InverseTransformPoint(_items[i].position).y > _disableMarginY
|| _scrollRect.transform.InverseTransformPoint(_items[i].position).x < -_disableMarginX || _scrollRect.transform.InverseTransformPoint(_items[i].position).x > _disableMarginX)
{
items[i].gameObject.SetActive(false);
_items[i].gameObject.SetActive(false);
}
else
{
items[i].gameObject.SetActive(true);
_items[i].gameObject.SetActive(true);
}
}
else
{
if (_isVertical)
{
if (_scrollRect.transform.InverseTransformPoint(items[i].position).y < -_disableMarginY || _scrollRect.transform.InverseTransformPoint(items[i].position).y > _disableMarginY)
if (_scrollRect.transform.InverseTransformPoint(_items[i].position).y < -_disableMarginY || _scrollRect.transform.InverseTransformPoint(_items[i].position).y > _disableMarginY)
{
items[i].gameObject.SetActive(false);
_items[i].gameObject.SetActive(false);
}
else
{
items[i].gameObject.SetActive(true);
_items[i].gameObject.SetActive(true);
}
}
if (_isHorizontal)
{
if (_scrollRect.transform.InverseTransformPoint(items[i].position).x < -_disableMarginX || _scrollRect.transform.InverseTransformPoint(items[i].position).x > _disableMarginX)
if (_scrollRect.transform.InverseTransformPoint(_items[i].position).x < -_disableMarginX || _scrollRect.transform.InverseTransformPoint(_items[i].position).x > _disableMarginX)
{
items[i].gameObject.SetActive(false);
_items[i].gameObject.SetActive(false);
}
else
{
items[i].gameObject.SetActive(true);
_items[i].gameObject.SetActive(true);
}
}
}
}
}
public void SetDirty()
{
_reset = true;
}
private void LateUpdate()
{
if (_reset)
{
_reset = false;
_items.Clear();
for (int i = 0; i < _scrollRect.content.childCount; i++)
{
_items.Add(_scrollRect.content.GetChild(i).GetComponent<RectTransform>());
_items[i].gameObject.SetActive(true);
}
ToggleGridComponents(true);
}
}
}
}