Merged in zhdiv/unity-ui-extensions-i1 (pull request #35)

Master

Approved-by: Simon Jackson <darkside@xna-uk.net>
pull/413/head
Ivan Zhdanov 2018-10-04 13:07:17 +00:00 committed by Simon Jackson
commit c844807864
3 changed files with 29 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -0,0 +1,15 @@
namespace UnityEngine.UI.Extensions
{
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;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed85e09a894358f4782be8df50a1221a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: