//float _LastItemSize = float.MinValue * 1.1f; //float _LastVPSize = float.MinValue * 1.1f; #region Unity void Awake() { enabled = false; _IOSA = GetComponent(typeof(IOSA)) as IOSA; if (_IOSA == null) { Debug.Log(typeof(OSAPercentageContentPaddingSetter).Name + " needs to be attached to a game object containing an OSA component"); return; } if (_IOSA.IsInitialized) { Debug.Log(typeof(OSAPercentageContentPaddingSetter).Name + " needs the OSA component to not be initialized before it"); return; } var parameters = _IOSA.BaseParameters; _UseDefaultItemSize = _ItemSizeCustomSource == null; _IsHorizontal = _IOSA.BaseParameters.IsHorizontal; _IOSA.ScrollViewSizeChanged += OnScrollViewSizeChanged; //_IOSA.ItemsRefreshed += OnItemsRefreshed; parameters.PrepareForInit(true); parameters.InitIfNeeded(_IOSA); UpdatePadding(); }
void Start() { _Adapter = GetComponentInParent <IOSA>(); _HandleRT = transform as RectTransform; //_HandleRT = _Scrollbar.handleRect; _SrollbarPivotOnInit = _HandleRT.pivot; }
public void InitIfNeeded(IOSA iAdapter) { string sceneObjectErrSuffix = " should be non-null, and a scene object that's active in hierarchy (i.e. not directly assigned from project view)"; if (TuplePrefab == null || !TuplePrefab.gameObject.activeInHierarchy) { throw new OSAException("TuplePrefab" + sceneObjectErrSuffix); } if (ColumnsTuplePrefab == null || !ColumnsTuplePrefab.gameObject.activeInHierarchy) { throw new OSAException("ColumnsTuplePrefab" + sceneObjectErrSuffix); } _IsHorizontal = iAdapter.IsHorizontal; if (_ColumnsTupleSize == -1f) { _ColumnsTupleSize = _TuplePrefab.rect.size[_IsHorizontal ? 0 : 1]; } var adapterParams = iAdapter.BaseParameters; if (TuplePrefab.parent != adapterParams.ScrollViewRT) { LayoutRebuilder.ForceRebuildLayoutImmediate(TuplePrefab.parent as RectTransform); } else { LayoutRebuilder.ForceRebuildLayoutImmediate(TuplePrefab); } adapterParams.AssertValidWidthHeight(TuplePrefab); _TuplePrefabSize = -1f; // so the prefab's size will be recalculated next time is accessed }
public override void InitIfNeeded(IOSA iAdapter) { if (ItemPrefab == null || !ItemPrefab.gameObject.activeInHierarchy) { throw new OSAException( "A Tuple's value prefab should be non-null, and a scene object (i.e. not directly assigned from project view) active in hierarchy." + "This error may be caused by the Tuple prefab itself not being an object present in scene"); } base.InitIfNeeded(iAdapter); var tupleAdapter = iAdapter as ITupleAdapter; if (tupleAdapter == null) { throw new OSAException(typeof(TupleParams).Name + ": No script implementing " + typeof(ITupleAdapter).Name + " found on TuplePrefab"); } bool prefabRebuildNeeded = InitResizingNeeded(tupleAdapter); if (prefabRebuildNeeded) { InitItemPrefab(); } else { AssertValidWidthHeight(ItemPrefab); } if (ContentPadding.left == -1 || ContentPadding.right == -1 || ContentPadding.top == -1 || ContentPadding.bottom == -1) { throw new OSAException(typeof(TupleParams).Name + ": A Tuple's ContentPadding isn't allowed to have negative components in any direction. Set them to zero or positive values"); } }
public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); AssertValidWidthHeight(bidirectionalPrefab); AssertValidWidthHeight(expandablePrefab); }
public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); AssertValidWidthHeight(orangePrefab); AssertValidWidthHeight(greenPrefab); AssertValidWidthHeight(adPrefab); }
/// <inheritdoc/> public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); _PrefabSize = -1f; // so the prefab's size will be recalculated DefaultItemSize = ItemPrefabSize; }
public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); AssertValidWidthHeight(commandPrefab); AssertValidWidthHeight(chatPrefab); AssertValidWidthHeight(phasePrefab); }
/// <inheritdoc/> public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); 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); } }
/// <summary> /// Only to be called if OSA is initialized manually via <see cref="OSA{TParams, TItemViewsHolder}.Init"/>. Call it before that. /// With the default setup, where OSA initializes itself in its Start(), you don't need to call this, as it's called from this.Awake() /// </summary> public void Init() { _RT = transform as RectTransform; _ParentRT = _RT.parent as RectTransform; if (_OSA == null) { _OSA = _ParentRT.GetComponentInParent(typeof(IOSA)) as IOSA; if (_OSA == null) { throw new OSAException("Component implementing IOSA not found in parents"); } } else { _OSA = _OSATransform.GetComponent(typeof(IOSA)) as IOSA; if (_OSA == null) { throw new OSAException("Component implementing IOSA not found on the specified object '" + _OSATransform.name + "'"); } } if (_OSA.BaseParameters.Viewport != _ParentRT) { throw new OSAException(typeof(OSAContentDecorator).Name + " can only work when attached to a direct child of OSA's Viewport."); } if (_ControlOSAPaddingAtInsetEdge != ControlOSAPaddingMode.DONT_CONTROL) { if (_OSA.IsInitialized) { Debug.Log( "OSA's content padding can't be set after OSA was initialized. " + "You're most probably calling OSA.Init manually(), in which case make sure to also manually call Init() on this decorator, before OSA.Init()" ); } else { if (_Inset != 0f) { Debug.Log( "OSA's content padding can't be controlled if Inset (" + _Inset + ") is not 0 . " ); } SetOSAPadding(); } } _OSA.ScrollPositionChanged += OSAScrollPositionChanged; var aPos = _RT.localPosition; _RT.anchorMin = _RT.anchorMax = new Vector2(0f, 1f); // top-right _RT.localPosition = aPos; _Initialized = true; }
public void Init( IOSA adapter, bool addGravityCommand = true, bool addItemEdgeFreezeCommand = true, bool addContentEdgeFreezeCommand = true, bool addServerDelaySetting = true, bool addOneItemAddRemovePanel = true, bool addInsertRemoveAtIndexPanel = true ) { Init(new IOSA[] { adapter }, addGravityCommand, addItemEdgeFreezeCommand, addContentEdgeFreezeCommand, addServerDelaySetting, addOneItemAddRemovePanel, addInsertRemoveAtIndexPanel); }
/// <inheritdoc/> public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); if (optimization.ScaleToZeroInsteadOfDisable) { Debug.Log(typeof(TableParams).Name + ": optimization.ScaleToZeroInsteadOfDisable is true, but this is not supported with a TableView. Setting back to false..."); optimization.ScaleToZeroInsteadOfDisable = false; } Table.InitIfNeeded(iAdapter); DefaultItemSize = Table.TuplePrefabSize; }
internal void InitWithAdapter(IOSA adapterImpl) { if (_AdapterImpl != null && !allowReinitializationWithOtherAdapter || onlyAcceptedGameObjects && acceptedGameObjectsNames != null && Array.IndexOf(acceptedGameObjectsNames, adapterImpl.gameObject.name) == -1 ) { return; } _AdapterImpl = adapterImpl; Button b; transform.GetComponentAtPath("ComputePanel/ComputeNowButton", out b); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => Call("ComputeVisibilityForCurrentPosition", true, false)); transform.GetComponentAtPath("ComputePanel/ComputeNowButton_PlusDelta", out b); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => Call("ComputeVisibilityForCurrentPositionRawParams", true, false, .1f)); transform.GetComponentAtPath("ComputePanel/ComputeNowButton_MinusDelta", out b); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => Call("ComputeVisibilityForCurrentPositionRawParams", true, false, -.1f)); transform.GetComponentAtPath("ComputePanel/CorrectNowButton", out b); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => Call("CorrectPositionsOfVisibleItems", true, true)); transform.GetComponentAtPath("DataManipPanel/EndStationaryToggle", out _EndStationary); transform.GetComponentAtPath("DataManipPanel/AmountInputField", out _AmountInputField); transform.GetComponentAtPath("DataManipPanel/head", out b); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => AddOrRemove(true)); transform.GetComponentAtPath("DataManipPanel/tail", out b); b.onClick.AddListener(() => AddOrRemove(false)); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => Call("RemoveItems", adapterImpl.GetItemsCount() - 2, int.Parse(_AmountInputField.text), _EndStationary.isOn, false)); }
/// <inheritdoc/> public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); AssertValidWidthHeight(itemPrefab); if (itemPrefab.parent != ScrollViewRT) { LayoutRebuilder.ForceRebuildLayoutImmediate(itemPrefab.parent as RectTransform); } else { LayoutRebuilder.ForceRebuildLayoutImmediate(itemPrefab); } _PrefabSize = -1f; // so the prefab's size will be recalculated DefaultItemSize = ItemPrefabSize; }
public void ConfigureNewAdapter(IOSA adapter) { var tableAdapter = adapter as ITableAdapter; var p = tableAdapter.TableParameters; var transform = tableAdapter.AsMonoBehaviour.transform; p.Viewport = transform.Find("Viewport") as RectTransform; p.Content = p.Viewport.Find("Content") as RectTransform; var pTable = p.Table; var prefabsParent = transform.Find("Prefabs-Hidden"); var tuplePrefabsParent = prefabsParent.Find("Tuple") as RectTransform; var columnsTuplePrefabsParent = prefabsParent.Find("ColumnsTuple") as RectTransform; var paths = CWiz.TV.Paths; // Some recommended spacing values p.ContentSpacing = 2; if (!p.IsHorizontal) { p.ContentPadding.bottom = 320; } pTable.ColumnsTupleSize = 60f; pTable.ColumnsTupleSpacing = 5f; // Only children scroll on X axis p.ScrollSensivityOnXAxis = 0f; // Scrollbar var sbTR = transform.Find("Scrollbar"); if (sbTR) { p.Scrollbar = sbTR.GetComponent <Scrollbar>(); OSAUtil.ConfigureDinamicallyCreatedScrollbar(p.Scrollbar, adapter, p.Viewport); } // Columns Scrollbar var csbTR = transform.Find("ColumnsScrollbar"); if (csbTR) { pTable.ColumnsScrollbar = csbTR.GetComponent <Scrollbar>(); } // Instantiate the tuple prefab & its value prefab pTable.TuplePrefab = InstantiateFromRes(paths.TUPLE_PREFAB, tuplePrefabsParent); var tupleAdapter = pTable.TuplePrefab.GetComponent(typeof(ITupleAdapter)) as ITupleAdapter; tupleAdapter.TupleParameters.ItemPrefab = InstantiateFromRes(paths.TUPLE_VALUE_PREFAB, tuplePrefabsParent); // Allowing resizing of individual tuples manually, by default tupleAdapter.TupleParameters.ResizingMode = TableResizingMode.MANUAL_TUPLES; // Instantiate the columns tuple prefab & its value prefab pTable.ColumnsTuplePrefab = InstantiateFromRes(paths.COLUMNS_TUPLE_PREFAB, columnsTuplePrefabsParent); var hTupleAdapter = pTable.ColumnsTuplePrefab.GetComponent(typeof(ITupleAdapter)) as ITupleAdapter; var hTupleValuePrefab = hTupleAdapter.TupleParameters.ItemPrefab = InstantiateFromRes(paths.COLUMNS_TUPLE_VALUE_PREFAB, columnsTuplePrefabsParent); DisableLayoutComponentsInTupleValuePrefab(hTupleValuePrefab); // Assign the floating text input and dropdown pTable.FloatingDropdownPrefab = Resources.Load <GameObject>(paths.INPUT__FLOATING_DROPDOWN).transform as RectTransform; pTable.TextInputControllerPrefab = Resources.Load <GameObject>(paths.INPUT__FLOATING_TEXT).GetComponent <TableViewTextInputController>(); // Assign the options panel pTable.OptionsPanel = transform.Find("OptionsPanel") as RectTransform; Debug.Log("TableView instantiated. Resize mode was set to " + tupleAdapter.TupleParameters.ResizingMode + ". If you don't plan to have individual rows resizeable, " + "go over the tuple & column prefabs and their associated value prefabs and remove " + "all Layout components, as they won't be needed. And set ResizeMode to NONE in inspector. " + "This will boost scrolling performance.", adapter.AsMonoBehaviour.gameObject ); }
public SimpleDataHelper(IOSA iAdapter, bool keepVelocityOnCountChange = true) { _Adapter = iAdapter; _DataList = new List <T>(); _KeepVelocityOnCountChange = keepVelocityOnCountChange; }
public LazyDataHelper(IOSA iAdapter, Func <int, T> newModelCreator, bool keepVelocityOnCountChange = true) { _Adapter = iAdapter; _DataList = new LazyList <T>(newModelCreator, 0); _KeepVelocityOnCountChange = keepVelocityOnCountChange; }
/// <inheritdoc/> public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); if (!grid.cellPrefab) { throw new UnityException("OSA: " + typeof(GridParams) + ": the prefab was not set. Please set it through inspector or in code"); } _CellPrefabLayoutElement = grid.cellPrefab.GetComponent <LayoutElement>(); if (!_CellPrefabLayoutElement) { throw new UnityException("OSA: " + typeof(GridParams) + ": no LayoutElement found on the cellPrefab: you should add one to configure how the cell's parent LayoutGroup should position/size it"); } if (grid.spacingInGroup == -1f) { grid.spacingInGroup = ContentSpacing; } if (!grid.UseDefaulfItemSizeForCellGroupSize) { // DefaultItemSize refers to the group's size here, so we're also adding the groupPadding to it if (IsHorizontal) { DefaultItemSize = _CellPrefabLayoutElement.preferredWidth; if (DefaultItemSize < 0) { DefaultItemSize = _CellPrefabLayoutElement.minWidth; if (DefaultItemSize < 0) { if (_CellPrefabLayoutElement.flexibleWidth == -1) { throw new UnityException( "OSA: " + typeof(GridParams) + ".cellPrefab.LayoutElement: Could not determine the cell group's width(UseDefaulfItemSizeForCellGroupSize=false). " + "Please specify at least preferredWidth, minWidth or flexibleWidth(case in which the current width of the cell will be used as the group's width)" ); } DefaultItemSize = _CellPrefab.rect.width; } } DefaultItemSize += grid.groupPadding.horizontal; } else { DefaultItemSize = _CellPrefabLayoutElement.preferredHeight; if (DefaultItemSize < 0) { DefaultItemSize = _CellPrefabLayoutElement.minHeight; if (DefaultItemSize < 0) { if (_CellPrefabLayoutElement.flexibleHeight == -1) { throw new UnityException( "OSA: " + typeof(GridParams) + ".cellPrefab.LayoutElement: Could not determine the cell group's height(UseDefaulfItemSizeForCellGroupSize=false). " + "Please specify at least preferredHeight, minHeight or flexibleHeight(case in which the current height of the cell will be used as the group's height)" ); } DefaultItemSize = _CellPrefab.rect.height; } } DefaultItemSize += grid.groupPadding.vertical; } } if (_MaxCellsPerGroup == 0) { _MaxCellsPerGroup = -1; } _CurrentUsedNumCellsPerGroup = CalculateCurrentNumCellsPerGroup(); // 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(IOSA) is called at Init time (in MonoBehaviour.Start()) CreateOrReinitCellGroupPrefab(); }
/// <summary> /// Called internally in <see cref="OSA{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(IOSA iAdapter) { _ScrollViewRT = iAdapter.AsMonoBehaviour.transform as RectTransform; LayoutRebuilder.ForceRebuildLayoutImmediate(ScrollViewRT); AssertValidWidthHeight(ScrollViewRT); var sr = ScrollViewRT.GetComponent <ScrollRect>(); if (sr && sr.enabled) { throw new OSAException("The ScrollRect is not needed anymore starting with v4.0. Remove or disable it!"); } if (!Content) { throw new OSAException("Content not set!"); } if (!Viewport) { Viewport = ScrollViewRT; if (Content.parent != ScrollViewRT) { throw new OSAException("Content's parent should be the ScrollView itself if there's no viewport specified!"); } } if (!_Snapper) { _Snapper = ScrollViewRT.GetComponent <Snapper8>(); } if (ForwardDragSameDirectionAtBoundary && !ForwardDragToParents) { Debug.Log("OSA: ForwardDragSameDirectionAtBoundary is true, but ForwardDragToParents is false. This will have no effect"); } if ((ContentPadding.left == -1) != (ContentPadding.right == -1)) { Debug.Log("OSA: ContentPadding.right and .left should either be both zero or positive or both -1. Setting both to 0..."); ContentPadding.left = ContentPadding.right = 0; } if ((ContentPadding.top == -1) != (ContentPadding.bottom == -1)) { Debug.Log("OSA: ContentPadding.top and .bottom should either be both zero or positive or both -1. Setting both to 0..."); ContentPadding.top = ContentPadding.bottom = 0; } effects.InitIfNeeded(); // There's no concept of content padding when looping. spacing should be used instead if (effects.LoopItems) { bool showLog = false; int ctSp = (int)ContentSpacing; if (IsHorizontal) { if (ContentPadding.left != ctSp) { showLog = true; ContentPadding.left = ctSp; } if (ContentPadding.right != ctSp) { showLog = true; ContentPadding.right = ctSp; } } else { if (ContentPadding.top != ctSp) { showLog = true; ContentPadding.top = ctSp; } if (ContentPadding.bottom != ctSp) { showLog = true; ContentPadding.bottom = ctSp; } } if (showLog) { Debug.Log("OSA: setting conteng padding to be the same as content spacing (" + ContentSpacing.ToString("#############.##") + "), because looping is enabled"); } } }
/// <summary> /// Called internally in <see cref="OSA{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(IOSA iAdapter) { _ScrollViewRT = iAdapter.AsMonoBehaviour.transform as RectTransform; var sr = ScrollViewRT.GetComponent <ScrollRect>(); if (sr && sr.enabled) { throw new UnityException("OSA: The ScrollRect is not needed anymore starting with v4.0. Remove or disable it!"); } if (!Content) { throw new UnityException("OSA: Content not set!"); } if (!Viewport) { Viewport = ScrollViewRT; if (Content.parent != ScrollViewRT) { throw new UnityException("OSA: Content's parent should be the ScrollView itself if there's no viewport specified!"); } } if (!_Snapper) { _Snapper = ScrollViewRT.GetComponent <Snapper8>(); } effects.InitIfNeeded(); // There's no concept of content padding when looping. spacinf should be used instead if (effects.loopItems) { bool showLog = false; int ctSp = (int)ContentSpacing; if (IsHorizontal) { if (ContentPadding.left != ctSp) { showLog = true; ContentPadding.left = ctSp; } if (ContentPadding.right != ctSp) { showLog = true; ContentPadding.right = ctSp; } } else { if (ContentPadding.top != ctSp) { showLog = true; ContentPadding.top = ctSp; } if (ContentPadding.bottom != ctSp) { showLog = true; ContentPadding.bottom = ctSp; } } if (showLog) { Debug.Log("OSA: setting conteng padding to be the same as content spacing (" + ContentSpacing.ToString("#############.##") + "), because looping is enabled"); } } }
/// <inheritdoc/> public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); if (!Grid.CellPrefab) { throw new OSAException(typeof(GridParams).Name + ": the prefab was not set. Please set it through inspector or in code"); } _CellPrefabLayoutElement = Grid.CellPrefab.GetComponent <LayoutElement>(); if (!_CellPrefabLayoutElement) { throw new OSAException(typeof(GridParams).Name + ": no LayoutElement found on the cellPrefab: you should add one to configure how the cell's parent LayoutGroup should position/size it"); } AssertValidWidthHeight(Grid.CellPrefab); if (Grid.SpacingInGroup == -1f) { Grid.SpacingInGroup = ContentSpacing; } if (Grid.MaxCellsPerGroup == 0) { Grid.MaxCellsPerGroup = -1; } _CellTransversalSizeIfConstant = -1f; if (Grid.PreserveCellAspectRatio) { if (Grid.UseDefaultItemSizeForCellGroupSize) { throw new OSAException(typeof(GridParams).Name + ".PreserveCellAspectRatio only works if UseDefaultItemSizeForCellGroupSize is false"); } if (Grid.MaxCellsPerGroup <= 0) { throw new OSAException(typeof(GridParams).Name + ".PreserveCellAspectRatio only works if MaxCellsPerGroup is set to a strictly positive value (otherwise the aspect ratio is already constant)"); } if (AnyWidthPropertiesEnabledFor(_CellPrefabLayoutElement) || AnyHeightPropertiesEnabledFor(_CellPrefabLayoutElement)) { Debug.Log( "OSA: " + typeof(GridParams).Name + ".cellPrefab.LayoutElement: found non-default values. They'll be ignored/overridden because Grid.PreserveCellAspectRatio is true. To remove this warning, disable all values in the prefab's LayoutElement" ); } if (Grid.CellHeightForceExpandInGroup || Grid.CellWidthForceExpandInGroup) { Debug.Log( "OSA: " + typeof(GridParams).Name + ": CellHeightForceExpandInGroup and CellWidthForceExpandInGroup aren't needed when PreserveCellAspectRatio is true. To remove this warning, set them to false" ); } // Calculating number of cells per group before setting the default item size (because the latter dependd on the former). // This should actually return exactly MaxCellsPerGroup, but we call CalculateCurrentNumCellsPerGroup just for consistency _CurrentUsedNumCellsPerGroup = CalculateCurrentNumCellsPerGroup(); var prefabSize = Grid.CellPrefab.rect.size; float aspectRatio = prefabSize.x / prefabSize.y; //int hor0_vert1 = IsHorizontal ? 0 : 1; //float horAspectRatio_vertInverseAspectRatio = prefabSize[hor0_vert1] / prefabSize[1 - hor0_vert1]; int numSpaces = _CurrentUsedNumCellsPerGroup - 1; float spacingInGroupComulative = Grid.SpacingInGroup * numSpaces; float transvSizeCumulative; float transvSizeDivider; float additionalPadding; if (IsHorizontal) { transvSizeCumulative = Viewport.rect.height - ContentPadding.vertical - spacingInGroupComulative - Grid.GroupPadding.vertical; transvSizeDivider = 1f / aspectRatio; additionalPadding = Grid.GroupPadding.horizontal; } else { transvSizeCumulative = Viewport.rect.width - ContentPadding.horizontal - spacingInGroupComulative - Grid.GroupPadding.horizontal; transvSizeDivider = aspectRatio; additionalPadding = Grid.GroupPadding.vertical; } _CellTransversalSizeIfConstant = transvSizeCumulative / _CurrentUsedNumCellsPerGroup; float cellSize = _CellTransversalSizeIfConstant / transvSizeDivider; DefaultItemSize = cellSize + additionalPadding; } else { if (!Grid.UseDefaultItemSizeForCellGroupSize) { // DefaultItemSize refers to the group's size here, so we're also adding the groupPadding to it if (IsHorizontal) { DefaultItemSize = _CellPrefabLayoutElement.preferredWidth; if (DefaultItemSize < 0) { DefaultItemSize = _CellPrefabLayoutElement.minWidth; if (DefaultItemSize < 0) { if (_CellPrefabLayoutElement.flexibleWidth == -1) { throw new OSAException( typeof(GridParams).Name + ".cellPrefab.LayoutElement: Could not determine the cell group's width(UseDefaulfItemSizeForCellGroupSize=false). " + "Please specify at least preferredWidth, minWidth or flexibleWidth(case in which the current width of the cell will be used as the group's width)" ); } DefaultItemSize = Grid.CellPrefab.rect.width; } } DefaultItemSize += Grid.GroupPadding.horizontal; } else { DefaultItemSize = _CellPrefabLayoutElement.preferredHeight; if (DefaultItemSize < 0) { DefaultItemSize = _CellPrefabLayoutElement.minHeight; if (DefaultItemSize < 0) { if (_CellPrefabLayoutElement.flexibleHeight == -1) { throw new OSAException( typeof(GridParams).Name + ".cellPrefab.LayoutElement: Could not determine the cell group's height(UseDefaulfItemSizeForCellGroupSize=false). " + "Please specify at least preferredHeight, minHeight or flexibleHeight(case in which the current height of the cell will be used as the group's height)" ); } DefaultItemSize = Grid.CellPrefab.rect.height; } } DefaultItemSize += Grid.GroupPadding.vertical; } } _CurrentUsedNumCellsPerGroup = CalculateCurrentNumCellsPerGroup(); } // 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(IOSA) is called at Init time (in MonoBehaviour.Start()) CreateOrReinitCellGroupPrefab(); // Make sure we cover the default case where a cell has a 'Views' child of root where UI elements are added, // so we'll correctly detect a ViewsHolder from a child Button of root.Views if (Navigation.MaxSearchDepthForViewsHolder < 2) { Navigation.MaxSearchDepthForViewsHolder = 2; } }
void Start() { _OSA = GetComponent(typeof(IOSA)) as IOSA; _OSA.ItemsRefreshed += OnItemsRefreshed; }
/// <inheritdoc/> public override void InitIfNeeded(IOSA iAdapter) { base.InitIfNeeded(iAdapter); InitItemPrefab(); }
public static ScrollbarFixer8 ConfigureDinamicallyCreatedScrollbar(UnityEngine.UI.Scrollbar scrollbar, IOSA iAdapter, RectTransform viewport, bool addFixerIfDoesntExist = true) { var instanceScollbarFixer = scrollbar.GetComponent <ScrollbarFixer8>(); if (!instanceScollbarFixer) { if (!addFixerIfDoesntExist) { return(null); } instanceScollbarFixer = scrollbar.gameObject.AddComponent <ScrollbarFixer8>(); } //instanceScollbarFixer.scrollRect = _WindowParams.scrollRect; instanceScollbarFixer.externalScrollRectProxy = iAdapter; instanceScollbarFixer.viewport = viewport; return(instanceScollbarFixer); }