private void DriveHeadersParent() { if (headersParent != null && !swipyMenu.FreezeHeaders) { headersParentRectDriver.Clear(); headersParentRectDriver = new DrivenRectTransformTracker(); headersParentRectDriver.Clear(); headersParentRectDriver.Add(this, headersParent, DrivenTransformProperties.All); } }
protected override void OnDisable() { CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild(this); if (m_HorizontalScrollbar) { m_HorizontalScrollbar.onValueChanged.RemoveListener(SetHorizontalNormalizedPosition); } if (m_VerticalScrollbar) { m_VerticalScrollbar.onValueChanged.RemoveListener(SetVerticalNormalizedPosition); } m_HasRebuiltLayout = false; m_Tracker.Clear(); m_Velocity = Vector2.zero; LayoutRebuilder.MarkLayoutForRebuild(rectTransform); base.OnDisable(); }
// ILayoutElement Interface public virtual void CalculateLayoutInputHorizontal() { m_RectChildren.Clear(); for (int i = 0; i < rectTransform.childCount; i++) { RectTransform rect = rectTransform.GetChild(i) as RectTransform; if (rect == null) { continue; } ILayoutIgnorer ignorer = rect.GetComponent(typeof(ILayoutIgnorer)) as ILayoutIgnorer; if (rect.gameObject.activeInHierarchy && !(ignorer != null && ignorer.ignoreLayout)) { m_RectChildren.Add(rect); } } m_Tracker.Clear(); }
protected virtual void HandleSlaves() { tracker.Clear(); for (int i = 0; i < slaveList.Count; i++) { Slave slave = slaveList[i]; if (slave.rectTransform == null) { continue; } if (horizontal) { tracker.Add(this, slave.rectTransform, DrivenTransformProperties.SizeDeltaX); slave.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectTransform.sizeDelta.x + slave.sizeOffset.x); } if (vertical) { tracker.Add(this, slave.rectTransform, DrivenTransformProperties.SizeDeltaY); slave.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectTransform.sizeDelta.y + slave.sizeOffset.y); } } }
public void Execute() { rectTransform = GetComponent <RectTransform>(); Children.Clear(); for (int i = 0; i < rectTransform.childCount; i++) { RectTransform ct = transform.GetChild(i) as RectTransform; Children.Add(ct); } m_Tracker.Clear(); SetLayoutHorizontal(); SetLayoutVertical(); }
/// <summary> /// This function is called when the behaviour becomes disabled. /// </summary> protected override void OnDisable() { UIParticleUpdater.Unregister(this); if (!_shouldBeRemoved) particles.Exec(p => p.GetComponent<ParticleSystemRenderer>().enabled = true); _tracker.Clear(); // Destroy object. MeshPool.Return(_bakedMesh); _bakedMesh = null; base.OnDisable(); }
private void SetupDrivenTransforms() { tracker = new DrivenRectTransformTracker(); tracker.Clear(); //So that we can calculate everything correctly foreach (RectTransform child in contentTransform) { tracker.Add(this, child, DrivenTransformProperties.Anchors); child.anchorMax = new Vector2(0, 1); child.anchorMin = new Vector2(0, 1); } }
public void MatchChildDimensions() { m_Tracker.Clear(); if (rectTransform.childCount > 1) { Debug.LogWarning("SimpleContentSizeFitter:: This layout element will only function correctly if this element has a single child."); return; } if (rectTransform.childCount != 1) { return; } var child = rectTransform.GetChild(0) as RectTransform; var height = child.rect.height; var width = child.rect.width; m_Tracker.Add(this, rectTransform, DrivenTransformProperties.SizeDelta); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); }
// ILayoutElement Interface public virtual void CalculateLayoutInputHorizontal() { m_RectChildren.Clear(); var toIgnoreList = ListPool <Component> .Get(); for (int i = 0; i < rectTransform.childCount; i++) { var rect = rectTransform.GetChild(i) as RectTransform; if (rect == null || !rect.gameObject.activeInHierarchy) { continue; } rect.GetComponents(typeof(ILayoutIgnorer), toIgnoreList); if (toIgnoreList.Count == 0) { m_RectChildren.Add(rect); continue; } for (int j = 0; j < toIgnoreList.Count; j++) { var ignorer = (ILayoutIgnorer)toIgnoreList[j]; if (!ignorer.ignoreLayout) { m_RectChildren.Add(rect); break; } } } ListPool <Component> .Release(toIgnoreList); m_Tracker.Clear(); }
public void DrivePreviewImages(float gazeNormalizedValue) { tracker.Clear(); // Adjust the position of the fill image using anchors if (sliderFillPreview != null) { tracker.Add(slider, sliderFillPreview, DrivenTransformProperties.Anchors); Vector2 anchorMin = Vector2.zero; Vector2 anchorMax = Vector2.one; if (sliderFillImage != null && sliderFillImage.type == Image.Type.Filled) { sliderFillImage.fillAmount = gazeNormalizedValue; } else { if (ReverseValue) { anchorMin [Axis] = 1 - gazeNormalizedValue; } else { anchorMax [Axis] = gazeNormalizedValue; } } sliderFillPreview.anchorMin = anchorMin; sliderFillPreview.anchorMax = anchorMax; } // Adjust the position of the handle image using a moving anchored point. if (sliderHandlePreview != null) { tracker.Add(slider, sliderHandlePreview, DrivenTransformProperties.Anchors); Vector2 anchorMin = Vector2.zero; Vector2 anchorMax = Vector2.one; anchorMin [Axis] = anchorMax [Axis] = (ReverseValue ? (1 - gazeNormalizedValue) : gazeNormalizedValue); sliderHandlePreview.anchorMin = anchorMin; sliderHandlePreview.anchorMax = anchorMax; } }
void CalculateRadial() { m_Tracker.Clear(); if (transform.childCount == 0) { return; } int activeChildren = 0; for (int i = 0; i < transform.childCount; i++) { if (transform.GetChild(i).gameObject.activeSelf) { activeChildren++; } } float fOffsetAngle = ((MaxAngle - MinAngle)) / (activeChildren - 1); if (MaxAngle - MinAngle == 360) { fOffsetAngle = ((MaxAngle - MinAngle)) / (activeChildren); } float fAngle = StartAngle; for (int i = 0; i < activeChildren; i++) { RectTransform child = (RectTransform)transform.GetChild(i); if (child != null) { //Adding the elements to the tracker stops the user from modifiying their positions via the editor. m_Tracker.Add(this, child, DrivenTransformProperties.Anchors | DrivenTransformProperties.AnchoredPosition | DrivenTransformProperties.Pivot); Vector3 vPos = new Vector3(Mathf.Cos(fAngle * Mathf.Deg2Rad), Mathf.Sin(fAngle * Mathf.Deg2Rad), 0); child.localPosition = vPos * fDistance; //Force objects to be center aligned, this can be changed however I'd suggest you keep all of the objects with the same anchor points. child.anchorMin = child.anchorMax = child.pivot = new Vector2(0.5f, 0.5f); fAngle -= fOffsetAngle; } } }
public void UpdateUI() { // Get my rect trasform RectTransform rectTransform = transform as RectTransform; // Drive some properties on the rect transform rectTransformTracker.Clear(); rectTransformTracker.Add(this, rectTransform, DrivenTransformProperties.AnchoredPosition | DrivenTransformProperties.SizeDelta | DrivenTransformProperties.Anchors | DrivenTransformProperties.Pivot); // Setup the properties of the rect transform rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.pivot = Vector2.one * 0.5f; rectTransform.sizeDelta = offset; }
/// <summary>Updates the scale property of the RectTransform.</summary> protected virtual void UpdateRectScale() { m_tracker.Clear(); if (m_scaleMode == ScaleMode.Disabled) { rectTransform.localScale = new Vector3(1f, 1f, rectTransform.localScale.z); } if (!IsActive() || m_scaleMode == ScaleMode.Disabled) { return; } ScaleMode calcMode = GetCalculationMode(m_scaleMode); Vector3 scale = CalculateScaleValues(calcMode); ApplyCalculatedValues(scale, calcMode); }
/*protected override void Awake() * { * base.Awake(); * * this.useGUILayout = false; * } * * public override void CalculateLayoutInputHorizontal() * { * base.CalculateLayoutInputHorizontal(); * Debug.Log("TableRow::Update"); * UpdateLayout(); * }*/ public void UpdateLayout() { _tracker.Clear(); var cells = Cells; foreach (var cell in cells) { var rectTransform = ((RectTransform)cell.transform); _tracker.Add(this, rectTransform, DrivenTransformProperties.All); rectTransform.pivot = new Vector2(0, 1); rectTransform.sizeDelta = new Vector2(cell.actualWidth, cell.actualHeight); rectTransform.anchoredPosition3D = new Vector3(cell.actualX, cell.actualY, 0); rectTransform.localScale = new Vector3(1, 1, 1); rectTransform.anchorMin = new Vector2(0, 1); rectTransform.anchorMax = new Vector2(0, 1); cell.Initialise(m_tableLayout, this); } }
/// <summary> /// Drive RectTransform`s to prevent user from editing RectTransform`s that supposed to be handled only by SwipyMenuGenerator. /// </summary> private void DriveRectTransforms() { rectsDriver.Clear(); rectsDriver = new DrivenRectTransformTracker(); rectsDriver.Clear(); if (menusParent != null) { rectsDriver.Add(this, menusParent, DrivenTransformProperties.All); } if (menusContent != null) { rectsDriver.Add(this, menusContent, DrivenTransformProperties.All); } for (int i = 0; i < swipyMenu.menus.Length; i++) { rectsDriver.Add(this, headersParent.GetChild(i).GetComponent <RectTransform>(), DrivenTransformProperties.All); rectsDriver.Add(this, menusContent.GetChild(i).GetComponent <RectTransform>(), DrivenTransformProperties.All); } DriveHeadersParent(); }
protected void SetContentProperties() { m_Tracker.Clear(); if (content != null) { m_Tracker.Add( this, content, DrivenTransformProperties.Pivot | DrivenTransformProperties.Anchors | (layout == RectTransform.Axis.Horizontal ? DrivenTransformProperties.AnchoredPositionY : DrivenTransformProperties.AnchoredPositionX) | DrivenTransformProperties.Scale | DrivenTransformProperties.SizeDelta | DrivenTransformProperties.Rotation ); if (layout == RectTransform.Axis.Horizontal) { content.anchorMin = new Vector2(0.5f, 0f); content.anchorMax = new Vector2(0.5f, 1f); } else { content.anchorMin = new Vector2(0f, 0.5f); content.anchorMax = new Vector2(1f, 0.5f); } int axisIndex = (int)layout; Vector2 size = content.sizeDelta; size[axisIndex] = GetComponent <RectTransform>().sizeDelta[axisIndex]; content.sizeDelta = size; content.pivot = new Vector2(0.5f, 0.5f); content.localScale = Vector3.one; } }
private void CalculateLayout() { if (this.RectChildren.Count < 0) { return; } rectChildren.Clear(); for (int i = 0; i < RectTransform.childCount; i++) { RectTransform rect = RectTransform.GetChild(i) as RectTransform; if (rect == null) { continue; } ILayoutIgnorer ignorer = rect.GetComponent(typeof(ILayoutIgnorer)) as ILayoutIgnorer; if (rect.gameObject.activeInHierarchy && !(ignorer != null && ignorer.ignoreLayout)) { rectChildren.Add(rect); } } tracker.Clear(); }
/// <summary> /// Clear tracker. /// </summary> public void Clear() { PropertiesTracker.Clear(); }
protected override void OnDisable() { Font.textureRebuilt -= TextureRebuilted; base.OnDisable(); layoutTracker.Clear(); }
// ILayoutElement Interface public virtual void CalculateLayoutInputHorizontal() { m_LayoutChildren.Clear(); m_Tracker.Clear(); }
protected void OnDisable() { m_Tracker.Clear(); }
protected override void OnDisable() { m_Tracker.Clear(); base.OnDisable(); }
protected virtual void OnDisable() { tracker.Clear(); }
public void UpdateLayout() { //Debug.Log("TableLayout::UpdateLayout"); _tracker.Clear(); var tableRect = this.rectTransform.rect; var tableHeight = tableRect.height; var tableWidth = tableRect.width; var rows = this.Rows.ToList(); if (!rows.Any()) { return; } var rowHeights = new List <float>(); var availableHeight = Mathf.Max(0, tableHeight - rows.Sum(r => r.preferredHeight) - (this.padding.top + this.padding.bottom) - (this.CellSpacing * (rows.Count - 1))); var numberOfAutoSizeRows = rows.Count(r => r.preferredHeight == 0); float calculatedAutoSizeRowHeight = 0; if (numberOfAutoSizeRows > 0) { calculatedAutoSizeRowHeight = availableHeight / numberOfAutoSizeRows; } foreach (var row in rows) { rowHeights.Add(row.preferredHeight > 0 ? row.preferredHeight : calculatedAutoSizeRowHeight); } #if !UNITY_IOS var columnCount = rows.Max(r => r.Cells.Sum(c => c.columnSpan)); #else var columnCount = 0; foreach (var row in rows) { var rowColumnCount = 0; foreach (var cell in row.Cells) { rowColumnCount += cell.columnSpan; } columnCount = Math.Max(columnCount, rowColumnCount); } #endif if (AutomaticallyRemoveEmptyColumns && columnCount < ColumnWidths.Count) { ColumnWidths.RemoveRange(columnCount, ColumnWidths.Count - columnCount); } // 0 == auto-size var availableWidth = tableWidth - (this.padding.left + this.padding.right) - (this.CellSpacing * (columnCount - 1)); foreach (var columnWidth in ColumnWidths) { availableWidth -= columnWidth; if (availableWidth < 0) { availableWidth = 0; break; } } for (var c = 0; c < columnCount; c++) { // If we don't have enough column width entries, then // a) if we should automatically add column widths, then add a new zero value (which is translated into AutoSize) // c) if we don't want to automatically add column widths, then additional cells over the column count will likely have a width of zero (which is only a problem if that happens) if (AutomaticallyAddColumns && ColumnWidths.Count <= c) { ColumnWidths.Add(0); } } var numberOfAutoSizeColumns = ColumnWidths.Count(c => c == 0); float calculatedAutoSizeColumnWidth = 0f; if (numberOfAutoSizeColumns > 0) { calculatedAutoSizeColumnWidth = availableWidth / numberOfAutoSizeColumns; } var columnWidths = new List <float>(); for (var c = 0; c < columnCount; c++) { columnWidths.Add(ColumnWidths.Count > c && ColumnWidths[c] != 0 ? ColumnWidths[c] : calculatedAutoSizeColumnWidth); } float y = -this.padding.top; for (var r = 0; r < rows.Count; r++) { var row = rows[r]; row.Initialise(this); if (!row.dontUseTableRowBackground) { row.image.sprite = RowBackgroundImage; row.image.color = !UseAlternateRowBackgroundColors || r % 2 == 0 ? RowBackgroundColor : RowBackgroundColorAlternate; } var rowHeight = rowHeights[r]; row.actualHeight = rowHeight; var rowRectTransform = row.transform as RectTransform; _tracker.Add(this, rowRectTransform, DrivenTransformProperties.All); rowRectTransform.pivot = new Vector2(0, 1); rowRectTransform.anchorMin = new Vector2(0, 1); rowRectTransform.anchorMax = new Vector2(0, 1); rowRectTransform.localScale = new Vector3(1, 1, 1); rowRectTransform.localPosition = Vector3.zero; rowRectTransform.localRotation = new Quaternion(); rowRectTransform.sizeDelta = new Vector2(tableWidth - (this.padding.left + this.padding.right), rowHeight); rowRectTransform.anchoredPosition = new Vector2(this.padding.left, y); y -= rowHeight; y -= CellSpacing; float x = 0f; int c = 0; var cells = row.Cells.ToList(); foreach (var cell in cells) { float columnWidth = 0f; var endColumn = c + cell.columnSpan; for (var c2 = c; c2 < endColumn; c2++) { columnWidth += columnWidths[c2]; } columnWidth += (cell.columnSpan - 1) * CellSpacing; var difference = tableWidth - x; columnWidth = Mathf.Min(columnWidth, difference); cell.actualWidth = columnWidth; cell.actualHeight = rowHeight; cell.actualX = x; if (UseGlobalCellPadding && !cell.overrideGlobalPadding) { cell.padding = new RectOffset(CellPadding.left, CellPadding.right, CellPadding.top, CellPadding.bottom); } if (!cell.dontUseTableCellBackground) { cell.image.sprite = this.CellBackgroundImage; cell.image.color = !this.UseAlternateCellBackroundColors || c % 2 == 0 ? this.CellBackgroundColor : this.CellBackgroundColorAlternate; } x += columnWidth + CellSpacing; c = endColumn; } // Apply the changes to the cells row.UpdateLayout(); } if (AutoCalculateHeight) { rectTransform.pivot = new Vector2(rectTransform.pivot.x, 1); rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, -y); rectTransform.anchorMin = new Vector2(rectTransform.anchorMin.x, 1); rectTransform.anchorMax = new Vector2(rectTransform.anchorMax.x, 1); rectTransform.anchoredPosition = new Vector2(rectTransform.anchoredPosition.x, 0); if (_layoutElement != null) { _layoutElement.preferredHeight = rectTransform.rect.height; } } }
/// <summary> /// See MonoBehaviour.OnDisable. /// </summary> void OnDisable() { m_Tracker.Clear(); SetLayoutDirty(); }
public void UpdateSliderTooltip(PointerEventData eventData) { Vector2 localCursorPoint; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(sliderRect, eventData.position, eventData.enterEventCamera, out localCursorPoint)) { return; } // Adjust the tooltip location Vector2 _tmp = sliderTooltip.anchoredPosition; _tmp.x = localCursorPoint.x; sliderTooltip.anchoredPosition = _tmp; // Get the normalized position of where we are looking localCursorPoint -= sliderRect.rect.position; float val = Mathf.Clamp01(localCursorPoint[Axis] / sliderRect.rect.size[Axis]); float normalizedValue = (ReverseValue ? 1f - val : val); int predictedPage = GetPageForNormalizedValue(normalizedValue); Vector3 predictedPagePosition = Vector3.zero; scrollSnap.GetPositionforPage(predictedPage, ref predictedPagePosition); // Find values to normalize int childCount = scrollSnap._screensContainer.childCount; float maximumPosition = scrollSnap._screensContainer.GetChild(0).gameObject.transform.localPosition[Axis] - (scrollSnap._scroll_rect.viewport.rect.size[Axis] * 0.5f); Debug.Log("Maximum position " + maximumPosition); float minimumPosition = scrollSnap._screensContainer.GetChild(childCount - 1).transform.localPosition[Axis] - (scrollSnap._scroll_rect.viewport.rect.size[Axis] * 0.5f); Debug.Log("Minimum position " + minimumPosition); // Normalize the value float pageNormalizedValue = (predictedPagePosition[Axis] - minimumPosition) / (maximumPosition - minimumPosition); Debug.Log("Page: " + predictedPage + " Value: " + pageNormalizedValue + " Transform Position: " + predictedPagePosition); // Adjust the hit target preview based on the cursor point if (showPreview) { tracker.Clear(); // Adjust the position of the fill image using anchors if (sliderFillPreview != null) { tracker.Add(slider, sliderFillPreview, DrivenTransformProperties.Anchors); Vector2 anchorMin = Vector2.zero; Vector2 anchorMax = Vector2.one; if (sliderFillImage != null && sliderFillImage.type == Image.Type.Filled) { sliderFillImage.fillAmount = pageNormalizedValue; } else { if (ReverseValue) { anchorMin[Axis] = 1 - pageNormalizedValue; } else { anchorMax[Axis] = pageNormalizedValue; } } sliderFillPreview.anchorMin = anchorMin; sliderFillPreview.anchorMax = anchorMax; } // Adjust the position of the handle image using a moving anchored point if (sliderHandlePreview != null) { tracker.Add(slider, sliderHandlePreview, DrivenTransformProperties.Anchors); Vector2 anchorMin = Vector2.zero; Vector2 anchorMax = Vector2.one; anchorMin [Axis] = anchorMax [Axis] = (ReverseValue ? (1 - pageNormalizedValue) : pageNormalizedValue); sliderHandlePreview.anchorMin = anchorMin; sliderHandlePreview.anchorMax = anchorMax; } } }
void OnDisable() { Orientation.OnChanged -= OrientationChanged; _driven.Clear(); }
/// <summary> /// Process the disable event. /// </summary> protected override void OnDisable() { propertiesTracker.Clear(); base.OnDisable(); }
protected override void OnDisable() { m_Tracker.Clear(); LayoutRebuilder.MarkLayoutForRebuild(rectTransform); base.OnDisable(); }
// // // void OnDisable() { drivenRectTransformTracker.Clear(); LayoutRebuilder.MarkLayoutForRebuild(GetComponent <RectTransform>()); }