/// <summary> /// Called internally in <see cref="SRIA{TParams, TItemViewsHolder}.Init()"/> and every time the scrollview's size changes. /// This makes sure the content and viewport have valid values. It can also be overridden to initialize custom data /// </summary> public virtual void InitIfNeeded(ISRIA sria) { // Commented: null-coalescing operator doesn't work with unity's Object //content = content ?? scrollRect.content; if (!scrollRect) { scrollRect = sria.AsMonoBehaviour.GetComponent <ScrollRect>(); } if (!scrollRect) { throw new UnityException("Can't find ScrollRect component!"); } if (!viewport) { viewport = scrollRect.transform as RectTransform; } if (!content) { content = scrollRect.content; } if (!Snapper) { Snapper = scrollRect.GetComponent <Snapper8>(); } }
internal void InitWithAdapter(ISRIA adapterImpl) { if (_AdapterImpl != null && !allowReinitializationWithOtherAdapter) { return; } _AdapterImpl = adapterImpl; Button b; transform.GetComponentAtPath("ComputeNowButton", out b); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => Call("ComputeVisibilityForCurrentPosition", true, true, false)); transform.GetComponentAtPath("ComputeNowButton_PlusDelta", out b); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => Call("ComputeVisibilityForCurrentPosition", true, true, false, .1f)); transform.GetComponentAtPath("ComputeNowButton_MinusDelta", out b); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => Call("ComputeVisibilityForCurrentPosition", true, true, false, -.1f)); transform.GetComponentAtPath("CorrectNowButton", out b); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => Call("CorrectPositionsOfVisibleItems", true)); }
/// <inheritdoc/> public override void InitIfNeeded(ISRIA sria) { base.InitIfNeeded(sria); _PrefabSize = -1f; // so the prefab's size will be recalculated _DefaultItemSize = ItemPrefabSize; }
/// <inheritdoc/> public override void InitIfNeeded(ISRIA sria) { base.InitIfNeeded(sria); if (Data == null) // this will only be null at init. When scrollview's size changes, the data should remain the same { Data = new LazyList <TData>(NewModelCreator, 0); } }
public void Init( ISRIA adapter, bool addGravityCommand = true, bool addItemEdgeFreezeCommand = true, bool addContentEdgeFreezeCommand = true, bool addServerDelaySetting = true, bool addOneItemAddRemovePanel = true ) { Init(new ISRIA[] { adapter }, addGravityCommand, addItemEdgeFreezeCommand, addContentEdgeFreezeCommand, addServerDelaySetting, addOneItemAddRemovePanel); }
/// <inheritdoc/> public override void InitIfNeeded(ISRIA sria) { base.InitIfNeeded(sria); if (!cellPrefab) { throw new UnityException("SRIA: " + typeof(GridParams) + ": the prefab was not set. Please set it through inspector or in code"); } if (numCellsPerGroup < 1) { throw new UnityException("SRIA: numCellsPerGroup = " + numCellsPerGroup); } _DefaultItemSize = scrollRect.horizontal ? cellPrefab.rect.width : cellPrefab.rect.height; // Hotfix 12.10.2017 14:45: There's a bug in Unity on some versions: creating a new GameObject at runtime and adding it a RectTransform cannot be done in Awake() or OnEnabled(). // See: https://issuetracker.unity3d.com/issues/error-when-creating-a-recttransform-component-in-an-awake-call-of-an-instantiated-monobehaviour // The bug was initially found in a project where the initial count is 0 (when Start() is called), then the scrollview is disabled, set a non-zero count, then enabled back, // and in OnEnable() the user called ResetItems(), which triggered the lazy-instantiation of the group prefab - since it's created in the first GetGroupPrefab() call. // Solved it by creating the prefab here, because InitIfNeeded(ISRIA) is called at Init time (in MonoBehaviour.Start()) CreateCellGroupPrefab(); }