FancyScrollView control updated to add an event when the page is changed / Selected
Thanks to @ChongHann (Hann Chong) for the fix Resolves #157release
parent
adb09d3481
commit
b4a2e81aae
|
@ -4,7 +4,6 @@ namespace UnityEngine.UI.Extensions.Examples
|
||||||
{
|
{
|
||||||
public class Example01ScrollView : FancyScrollView<Example01CellDto>
|
public class Example01ScrollView : FancyScrollView<Example01CellDto>
|
||||||
{
|
{
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
ScrollPositionController scrollPositionController;
|
ScrollPositionController scrollPositionController;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@ namespace UnityEngine.UI.Extensions.Examples
|
||||||
new void Awake()
|
new void Awake()
|
||||||
{
|
{
|
||||||
scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition);
|
scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition);
|
||||||
|
// Add OnItemSelected event listener
|
||||||
|
scrollPositionController.OnItemSelected.AddListener(CellSelected);
|
||||||
|
|
||||||
SetContext(new Example02ScrollViewContext { OnPressedCell = OnPressedCell });
|
SetContext(new Example02ScrollViewContext { OnPressedCell = OnPressedCell });
|
||||||
base.Awake();
|
base.Awake();
|
||||||
}
|
}
|
||||||
|
@ -27,5 +30,13 @@ namespace UnityEngine.UI.Extensions.Examples
|
||||||
context.SelectedIndex = cell.DataIndex;
|
context.SelectedIndex = cell.DataIndex;
|
||||||
UpdateContents();
|
UpdateContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An event triggered when a cell is selected.
|
||||||
|
void CellSelected(int cellIndex)
|
||||||
|
{
|
||||||
|
// Update context.SelectedIndex and call UpdateContents for updating cell's content.
|
||||||
|
context.SelectedIndex = cellIndex;
|
||||||
|
UpdateContents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,10 @@ namespace UnityEngine.UI.Extensions.Examples
|
||||||
new void Awake()
|
new void Awake()
|
||||||
{
|
{
|
||||||
scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition);
|
scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition);
|
||||||
|
|
||||||
|
// Add OnItemSelected event listener
|
||||||
|
scrollPositionController.OnItemSelected.AddListener(CellSelected);
|
||||||
|
|
||||||
SetContext(new Example03ScrollViewContext { OnPressedCell = OnPressedCell });
|
SetContext(new Example03ScrollViewContext { OnPressedCell = OnPressedCell });
|
||||||
base.Awake();
|
base.Awake();
|
||||||
}
|
}
|
||||||
|
@ -28,5 +32,12 @@ namespace UnityEngine.UI.Extensions.Examples
|
||||||
UpdateContents();
|
UpdateContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An event triggered when a cell is selected.
|
||||||
|
void CellSelected(int cellIndex)
|
||||||
|
{
|
||||||
|
// Update context.SelectedIndex and call UpdateContents for updating cell's content.
|
||||||
|
context.SelectedIndex = cellIndex;
|
||||||
|
UpdateContents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue