fixed adding component ScrollSnapScrollbarHelper multiple times
parent
ee391cab7f
commit
16df45eea3
|
@ -136,12 +136,13 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
if (_scroll_rect.horizontalScrollbar != null && _scroll_rect.horizontal)
|
||||
{
|
||||
var hscroll = _scroll_rect.horizontalScrollbar.gameObject.AddComponent<ScrollSnapScrollbarHelper>();
|
||||
|
||||
var hscroll = _scroll_rect.horizontalScrollbar.gameObject.GetOrAddComponent<ScrollSnapScrollbarHelper>();
|
||||
hscroll.ss = this;
|
||||
}
|
||||
if (_scroll_rect.verticalScrollbar != null && _scroll_rect.vertical)
|
||||
{
|
||||
var vscroll = _scroll_rect.verticalScrollbar.gameObject.AddComponent<ScrollSnapScrollbarHelper>();
|
||||
var vscroll = _scroll_rect.verticalScrollbar.gameObject.GetOrAddComponent<ScrollSnapScrollbarHelper>();
|
||||
vscroll.ss = this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
|
||||
public static class ExtentionMethods
|
||||
{
|
||||
public static T GetOrAddComponent<T>(this GameObject child) where T : Component
|
||||
{
|
||||
T result = child.GetComponent<T>();
|
||||
if (result == null)
|
||||
{
|
||||
result = child.AddComponent<T>();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ed85e09a894358f4782be8df50a1221a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue