using System; using UnityEngine.Events; using UnityEngine.EventSystems; namespace UnityEngine.UI { [SelectionBase] [ExecuteInEditMode] [DisallowMultipleComponent] [RequireComponent(typeof(RectTransform))] public class uGUIScrollRect : UIBehaviour, IInitializePotentialDragHandler, IBeginDragHandler, IEndDragHandler, IDragHandler, IScrollHandler, ICanvasElement, ILayoutElement, ILayoutGroup, IEventSystemHandler, ILayoutController { protected uGUIScrollRect() { } public RectTransform content { get { return this.m_Content; } set { this.m_Content = value; } } public bool horizontal { get { return this.m_Horizontal; } set { this.m_Horizontal = value; } } public bool vertical { get { return this.m_Vertical; } set { this.m_Vertical = value; } } public uGUIScrollRect.MovementType movementType { get { return this.m_MovementType; } set { this.m_MovementType = value; } } public float elasticity { get { return this.m_Elasticity; } set { this.m_Elasticity = value; } } public bool inertia { get { return this.m_Inertia; } set { this.m_Inertia = value; } } public float decelerationRate { get { return this.m_DecelerationRate; } set { this.m_DecelerationRate = value; } } public float scrollSensitivity { get { return this.m_ScrollSensitivity; } set { this.m_ScrollSensitivity = value; } } public RectTransform viewport { get { return this.m_Viewport; } set { this.m_Viewport = value; this.SetDirtyCaching(); } } public Slider horizontalSlider { get { return this.m_HorizontalSlider; } set { if (this.m_HorizontalSlider) { this.m_HorizontalSlider.onValueChanged.RemoveListener(new UnityAction(this.SetHorizontalNormalizedPosition)); } this.m_HorizontalSlider = value; if (this.m_HorizontalSlider) { this.m_HorizontalSlider.onValueChanged.AddListener(new UnityAction(this.SetHorizontalNormalizedPosition)); } this.SetDirtyCaching(); } } public Slider verticalSlider { get { return this.m_VerticalSlider; } set { if (this.m_VerticalSlider) { this.m_VerticalSlider.onValueChanged.RemoveListener(new UnityAction(this.SetVerticalNormalizedPosition)); } this.m_VerticalSlider = value; if (this.m_VerticalSlider) { this.m_VerticalSlider.onValueChanged.AddListener(new UnityAction(this.SetVerticalNormalizedPosition)); } this.SetDirtyCaching(); } } public uGUIScrollRect.SliderVisibility horizontalSliderVisibility { get { return this.m_HorizontalSliderVisibility; } set { this.m_HorizontalSliderVisibility = value; this.SetDirtyCaching(); } } public uGUIScrollRect.SliderVisibility verticalSliderVisibility { get { return this.m_VerticalSliderVisibility; } set { this.m_VerticalSliderVisibility = value; this.SetDirtyCaching(); } } public float horizontalSliderSpacing { get { return this.m_HorizontalSliderSpacing; } set { this.m_HorizontalSliderSpacing = value; this.SetDirty(); } } public float verticalSliderSpacing { get { return this.m_VerticalSliderSpacing; } set { this.m_VerticalSliderSpacing = value; this.SetDirty(); } } public uGUIScrollRect.ScrollRectEvent onValueChanged { get { return this.m_OnValueChanged; } set { this.m_OnValueChanged = value; } } protected RectTransform viewRect { get { if (this.m_ViewRect == null) { this.m_ViewRect = this.m_Viewport; } if (this.m_ViewRect == null) { this.m_ViewRect = (RectTransform)base.transform; } return this.m_ViewRect; } } public Vector2 velocity { get { return this.m_Velocity; } set { this.m_Velocity = value; } } private RectTransform rectTransform { get { if (this.m_Rect == null) { this.m_Rect = base.GetComponent(); } return this.m_Rect; } } public virtual void Rebuild(CanvasUpdate executing) { if (executing == CanvasUpdate.Prelayout) { this.UpdateCachedData(); } if (executing == CanvasUpdate.PostLayout) { this.UpdateBounds(); this.UpdateSliders(Vector2.zero); this.UpdatePrevData(); this.m_HasRebuiltLayout = true; } } public virtual void LayoutComplete() { } public virtual void GraphicUpdateComplete() { } private void UpdateCachedData() { Transform transform = base.transform; this.m_HorizontalSliderRect = ((!(this.m_HorizontalSlider == null)) ? (this.m_HorizontalSlider.transform as RectTransform) : null); this.m_VerticalSliderRect = ((!(this.m_VerticalSlider == null)) ? (this.m_VerticalSlider.transform as RectTransform) : null); bool flag = this.viewRect.parent == transform; bool flag2 = !this.m_HorizontalSliderRect || this.m_HorizontalSliderRect.parent == transform; bool flag3 = !this.m_VerticalSliderRect || this.m_VerticalSliderRect.parent == transform; bool flag4 = flag && flag2 && flag3; this.m_HSliderExpand = (flag4 && this.m_HorizontalSliderRect && this.horizontalSliderVisibility == uGUIScrollRect.SliderVisibility.AutoHideAndExpandViewport); this.m_VSliderExpand = (flag4 && this.m_VerticalSliderRect && this.verticalSliderVisibility == uGUIScrollRect.SliderVisibility.AutoHideAndExpandViewport); this.m_HSliderHeight = ((!(this.m_HorizontalSliderRect == null)) ? this.m_HorizontalSliderRect.rect.height : 0f); this.m_VSliderWidth = ((!(this.m_VerticalSliderRect == null)) ? this.m_VerticalSliderRect.rect.width : 0f); } protected override void OnEnable() { base.OnEnable(); if (this.m_HorizontalSlider) { this.m_HorizontalSlider.onValueChanged.AddListener(new UnityAction(this.SetHorizontalNormalizedPosition)); } if (this.m_VerticalSlider) { this.m_VerticalSlider.onValueChanged.AddListener(new UnityAction(this.SetVerticalNormalizedPosition)); } CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this); } protected override void OnDisable() { CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild(this); if (this.m_HorizontalSlider) { this.m_HorizontalSlider.onValueChanged.RemoveListener(new UnityAction(this.SetHorizontalNormalizedPosition)); } if (this.m_VerticalSlider) { this.m_VerticalSlider.onValueChanged.RemoveListener(new UnityAction(this.SetVerticalNormalizedPosition)); } this.m_HasRebuiltLayout = false; this.m_Tracker.Clear(); this.m_Velocity = Vector2.zero; LayoutRebuilder.MarkLayoutForRebuild(this.rectTransform); base.OnDisable(); } public override bool IsActive() { return base.IsActive() && this.m_Content != null; } private void EnsureLayoutHasRebuilt() { if (!this.m_HasRebuiltLayout && !CanvasUpdateRegistry.IsRebuildingLayout()) { Canvas.ForceUpdateCanvases(); } } public virtual void StopMovement() { this.m_Velocity = Vector2.zero; } public virtual void OnScroll(PointerEventData data) { if (!this.IsActive()) { return; } this.EnsureLayoutHasRebuilt(); this.UpdateBounds(); Vector2 scrollDelta = data.scrollDelta; scrollDelta.y *= -1f; if (this.vertical && !this.horizontal) { if (Mathf.Abs(scrollDelta.x) > Mathf.Abs(scrollDelta.y)) { scrollDelta.y = scrollDelta.x; } scrollDelta.x = 0f; } if (this.horizontal && !this.vertical) { if (Mathf.Abs(scrollDelta.y) > Mathf.Abs(scrollDelta.x)) { scrollDelta.x = scrollDelta.y; } scrollDelta.y = 0f; } Vector2 vector = this.m_Content.anchoredPosition; this.m_Velocity += scrollDelta * this.m_ScrollSensitivity; if (this.m_MovementType == uGUIScrollRect.MovementType.Clamped) { vector += this.CalculateOffset(vector - this.m_Content.anchoredPosition); } this.SetContentAnchoredPosition(vector); this.UpdateBounds(); } public virtual void OnInitializePotentialDrag(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } this.m_Velocity = Vector2.zero; } public virtual void OnBeginDrag(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } if (!this.IsActive()) { return; } this.UpdateBounds(); this.m_PointerStartLocalCursor = Vector2.zero; RectTransformUtility.ScreenPointToLocalPointInRectangle(this.viewRect, eventData.position, eventData.pressEventCamera, out this.m_PointerStartLocalCursor); this.m_ContentStartPosition = this.m_Content.anchoredPosition; this.m_Dragging = true; } public virtual void OnEndDrag(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } this.m_Dragging = false; } public virtual void OnDrag(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } if (!this.IsActive()) { return; } Vector2 a; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(this.viewRect, eventData.position, eventData.pressEventCamera, out a)) { return; } this.UpdateBounds(); Vector2 b = a - this.m_PointerStartLocalCursor; Vector2 vector = this.m_ContentStartPosition + b; Vector2 b2 = this.CalculateOffset(vector - this.m_Content.anchoredPosition); vector += b2; if (this.m_MovementType == uGUIScrollRect.MovementType.Elastic) { if (b2.x != 0f) { vector.x -= uGUIScrollRect.RubberDelta(b2.x, this.m_ViewBounds.size.x); } if (b2.y != 0f) { vector.y -= uGUIScrollRect.RubberDelta(b2.y, this.m_ViewBounds.size.y); } } this.SetContentAnchoredPosition(vector); } protected virtual void SetContentAnchoredPosition(Vector2 position) { if (!this.m_Horizontal) { position.x = this.m_Content.anchoredPosition.x; } if (!this.m_Vertical) { position.y = this.m_Content.anchoredPosition.y; } if (position != this.m_Content.anchoredPosition) { this.m_Content.anchoredPosition = position; this.UpdateBounds(); } } protected virtual void LateUpdate() { if (!this.m_Content) { return; } this.EnsureLayoutHasRebuilt(); this.UpdateSliderVisibility(); this.UpdateBounds(); float unscaledDeltaTime = Time.unscaledDeltaTime; Vector2 vector = this.CalculateOffset(Vector2.zero); if (!this.m_Dragging && (vector != Vector2.zero || this.m_Velocity != Vector2.zero)) { Vector2 vector2 = this.m_Content.anchoredPosition; for (int i = 0; i < 2; i++) { if (this.m_MovementType == uGUIScrollRect.MovementType.Elastic && vector[i] != 0f) { float num = this.m_Velocity[i]; vector2[i] = Mathf.SmoothDamp(this.m_Content.anchoredPosition[i], this.m_Content.anchoredPosition[i] + vector[i], ref num, this.m_Elasticity, float.PositiveInfinity, unscaledDeltaTime); if (Mathf.Abs(num) < 1f) { num = 0f; } this.m_Velocity[i] = num; } else if (this.m_Inertia) { int index; this.m_Velocity[index = i] = this.m_Velocity[index] * Mathf.Pow(this.m_DecelerationRate, unscaledDeltaTime); if (Mathf.Abs(this.m_Velocity[i]) < 1f) { this.m_Velocity[i] = 0f; } int index2; vector2[index2 = i] = vector2[index2] + this.m_Velocity[i] * unscaledDeltaTime; } else { this.m_Velocity[i] = 0f; } } if (this.m_MovementType == uGUIScrollRect.MovementType.Clamped) { vector = this.CalculateOffset(vector2 - this.m_Content.anchoredPosition); vector2 += vector; } if (this.m_Velocity != Vector2.zero || vector.sqrMagnitude >= 0.02f) { this.SetContentAnchoredPosition(vector2); } } if (this.m_Dragging && this.m_Inertia) { Vector3 b = (this.m_Content.anchoredPosition - this.m_PrevPosition) / unscaledDeltaTime; this.m_Velocity = Vector3.Lerp(this.m_Velocity, b, unscaledDeltaTime * 10f); } if (this.m_ViewBounds != this.m_PrevViewBounds || this.m_ContentBounds != this.m_PrevContentBounds || this.m_Content.anchoredPosition != this.m_PrevPosition) { this.UpdateSliders(vector); this.m_OnValueChanged.Invoke(this.normalizedPosition); this.UpdatePrevData(); } } protected void UpdatePrevData() { if (this.m_Content == null) { this.m_PrevPosition = Vector2.zero; } else { this.m_PrevPosition = this.m_Content.anchoredPosition; } this.m_PrevViewBounds = this.m_ViewBounds; this.m_PrevContentBounds = this.m_ContentBounds; } private void UpdateSliders(Vector2 offset) { if (this.m_HorizontalSlider) { this.m_HorizontalSlider.normalizedValue = this.horizontalNormalizedPosition; } if (this.m_VerticalSlider) { this.m_VerticalSlider.normalizedValue = this.verticalNormalizedPosition; } } public Vector2 normalizedPosition { get { return new Vector2(this.horizontalNormalizedPosition, this.verticalNormalizedPosition); } set { this.SetNormalizedPosition(value.x, 0); this.SetNormalizedPosition(value.y, 1); } } public float horizontalNormalizedPosition { get { this.UpdateBounds(); if (this.m_ContentBounds.size.x <= this.m_ViewBounds.size.x) { return (float)((this.m_ViewBounds.min.x <= this.m_ContentBounds.min.x) ? 0 : 1); } return (this.m_ViewBounds.min.x - this.m_ContentBounds.min.x) / (this.m_ContentBounds.size.x - this.m_ViewBounds.size.x); } set { this.SetNormalizedPosition(value, 0); } } public float verticalNormalizedPosition { get { this.UpdateBounds(); if (this.m_ContentBounds.size.y <= this.m_ViewBounds.size.y) { return (float)((this.m_ViewBounds.min.y <= this.m_ContentBounds.min.y) ? 0 : 1); } return (this.m_ViewBounds.min.y - this.m_ContentBounds.min.y) / (this.m_ContentBounds.size.y - this.m_ViewBounds.size.y); } set { this.SetNormalizedPosition(value, 1); } } private void SetHorizontalNormalizedPosition(float value) { this.SetNormalizedPosition(value, 0); } private void SetVerticalNormalizedPosition(float value) { this.SetNormalizedPosition(value, 1); } protected virtual void SetNormalizedPosition(float value, int axis) { this.EnsureLayoutHasRebuilt(); this.UpdateBounds(); float num = this.m_ContentBounds.size[axis] - this.m_ViewBounds.size[axis]; float num2 = this.m_ViewBounds.min[axis] - value * num; float num3 = this.m_Content.localPosition[axis] + num2 - this.m_ContentBounds.min[axis]; Vector3 localPosition = this.m_Content.localPosition; if (Mathf.Abs(localPosition[axis] - num3) > 0.01f) { localPosition[axis] = num3; this.m_Content.localPosition = localPosition; this.m_Velocity[axis] = 0f; this.UpdateBounds(); } } private static float RubberDelta(float overStretching, float viewSize) { return (1f - 1f / (Mathf.Abs(overStretching) * 0.55f / viewSize + 1f)) * viewSize * Mathf.Sign(overStretching); } protected override void OnRectTransformDimensionsChange() { this.SetDirty(); } private bool hScrollingNeeded { get { return !Application.isPlaying || this.m_ContentBounds.size.x > this.m_ViewBounds.size.x + 1f; } } private bool vScrollingNeeded { get { return !Application.isPlaying || this.m_ContentBounds.size.y > this.m_ViewBounds.size.y + 1f; } } public virtual void CalculateLayoutInputHorizontal() { } public virtual void CalculateLayoutInputVertical() { } public virtual float minWidth { get { return -1f; } } public virtual float preferredWidth { get { return -1f; } } public virtual float flexibleWidth { get { return -1f; } } public virtual float minHeight { get { return -1f; } } public virtual float preferredHeight { get { return -1f; } } public virtual float flexibleHeight { get { return -1f; } } public virtual int layoutPriority { get { return -1; } } public virtual void SetLayoutHorizontal() { this.m_Tracker.Clear(); if (this.m_HSliderExpand || this.m_VSliderExpand) { this.m_Tracker.Add(this, this.viewRect, DrivenTransformProperties.AnchoredPositionX | DrivenTransformProperties.AnchoredPositionY | DrivenTransformProperties.AnchorMinX | DrivenTransformProperties.AnchorMinY | DrivenTransformProperties.AnchorMaxX | DrivenTransformProperties.AnchorMaxY | DrivenTransformProperties.SizeDeltaX | DrivenTransformProperties.SizeDeltaY); this.viewRect.anchorMin = Vector2.zero; this.viewRect.anchorMax = Vector2.one; this.viewRect.sizeDelta = Vector2.zero; this.viewRect.anchoredPosition = Vector2.zero; LayoutRebuilder.ForceRebuildLayoutImmediate(this.content); this.m_ViewBounds = new Bounds(this.viewRect.rect.center, this.viewRect.rect.size); this.m_ContentBounds = this.GetBounds(); } if (this.m_VSliderExpand && this.vScrollingNeeded) { this.viewRect.sizeDelta = new Vector2(-(this.m_VSliderWidth + this.m_VerticalSliderSpacing), this.viewRect.sizeDelta.y); LayoutRebuilder.ForceRebuildLayoutImmediate(this.content); this.m_ViewBounds = new Bounds(this.viewRect.rect.center, this.viewRect.rect.size); this.m_ContentBounds = this.GetBounds(); } if (this.m_HSliderExpand && this.hScrollingNeeded) { this.viewRect.sizeDelta = new Vector2(this.viewRect.sizeDelta.x, -(this.m_HSliderHeight + this.m_HorizontalSliderSpacing)); this.m_ViewBounds = new Bounds(this.viewRect.rect.center, this.viewRect.rect.size); this.m_ContentBounds = this.GetBounds(); } if (this.m_VSliderExpand && this.vScrollingNeeded && this.viewRect.sizeDelta.x == 0f && this.viewRect.sizeDelta.y < 0f) { this.viewRect.sizeDelta = new Vector2(-(this.m_VSliderWidth + this.m_VerticalSliderSpacing), this.viewRect.sizeDelta.y); } } public virtual void SetLayoutVertical() { this.UpdateSliderLayout(); this.m_ViewBounds = new Bounds(this.viewRect.rect.center, this.viewRect.rect.size); this.m_ContentBounds = this.GetBounds(); } private void UpdateSliderVisibility() { uGUIScrollRect.UpdateOneSliderVisibility(this.vScrollingNeeded, this.m_Vertical, this.m_VerticalSliderVisibility, this.m_VerticalSlider); uGUIScrollRect.UpdateOneSliderVisibility(this.hScrollingNeeded, this.m_Horizontal, this.m_HorizontalSliderVisibility, this.m_HorizontalSlider); } private static void UpdateOneSliderVisibility(bool xScrollingNeeded, bool xAxisEnabled, uGUIScrollRect.SliderVisibility sliderVisibility, Slider slider) { if (slider) { if (sliderVisibility == uGUIScrollRect.SliderVisibility.Permanent) { if (slider.gameObject.activeSelf != xAxisEnabled) { slider.gameObject.SetActive(xAxisEnabled); } } else if (slider.gameObject.activeSelf != xScrollingNeeded) { slider.gameObject.SetActive(xScrollingNeeded); } } } private void UpdateSliderLayout() { if (this.m_VSliderExpand && this.m_HorizontalSlider) { this.m_Tracker.Add(this, this.m_HorizontalSliderRect, DrivenTransformProperties.AnchoredPositionX | DrivenTransformProperties.AnchorMinX | DrivenTransformProperties.AnchorMaxX | DrivenTransformProperties.SizeDeltaX); this.m_HorizontalSliderRect.anchorMin = new Vector2(0f, this.m_HorizontalSliderRect.anchorMin.y); this.m_HorizontalSliderRect.anchorMax = new Vector2(1f, this.m_HorizontalSliderRect.anchorMax.y); this.m_HorizontalSliderRect.anchoredPosition = new Vector2(0f, this.m_HorizontalSliderRect.anchoredPosition.y); if (this.vScrollingNeeded) { this.m_HorizontalSliderRect.sizeDelta = new Vector2(-(this.m_VSliderWidth + this.m_VerticalSliderSpacing), this.m_HorizontalSliderRect.sizeDelta.y); } else { this.m_HorizontalSliderRect.sizeDelta = new Vector2(0f, this.m_HorizontalSliderRect.sizeDelta.y); } } if (this.m_HSliderExpand && this.m_VerticalSlider) { this.m_Tracker.Add(this, this.m_VerticalSliderRect, DrivenTransformProperties.AnchoredPositionY | DrivenTransformProperties.AnchorMinY | DrivenTransformProperties.AnchorMaxY | DrivenTransformProperties.SizeDeltaY); this.m_VerticalSliderRect.anchorMin = new Vector2(this.m_VerticalSliderRect.anchorMin.x, 0f); this.m_VerticalSliderRect.anchorMax = new Vector2(this.m_VerticalSliderRect.anchorMax.x, 1f); this.m_VerticalSliderRect.anchoredPosition = new Vector2(this.m_VerticalSliderRect.anchoredPosition.x, 0f); if (this.hScrollingNeeded) { this.m_VerticalSliderRect.sizeDelta = new Vector2(this.m_VerticalSliderRect.sizeDelta.x, -(this.m_HSliderHeight + this.m_HorizontalSliderSpacing)); } else { this.m_VerticalSliderRect.sizeDelta = new Vector2(this.m_VerticalSliderRect.sizeDelta.x, 0f); } } } protected void UpdateBounds() { this.m_ViewBounds = new Bounds(this.viewRect.rect.center, this.viewRect.rect.size); this.m_ContentBounds = this.GetBounds(); if (this.m_Content == null) { return; } Vector3 size = this.m_ContentBounds.size; Vector3 center = this.m_ContentBounds.center; Vector2 pivot = this.m_Content.pivot; uGUIScrollRect.AdjustBounds(ref this.m_ViewBounds, ref pivot, ref size, ref center); this.m_ContentBounds.size = size; this.m_ContentBounds.center = center; if (this.movementType == uGUIScrollRect.MovementType.Clamped) { Vector3 zero = Vector3.zero; if (this.m_ViewBounds.max.x > this.m_ContentBounds.max.x) { zero.x = Math.Min(this.m_ViewBounds.min.x - this.m_ContentBounds.min.x, this.m_ViewBounds.max.x - this.m_ContentBounds.max.x); } else if (this.m_ViewBounds.min.x < this.m_ContentBounds.min.x) { zero.x = Math.Max(this.m_ViewBounds.min.x - this.m_ContentBounds.min.x, this.m_ViewBounds.max.x - this.m_ContentBounds.max.x); } if (this.m_ViewBounds.min.y < this.m_ContentBounds.min.y) { zero.y = Math.Max(this.m_ViewBounds.min.y - this.m_ContentBounds.min.y, this.m_ViewBounds.max.y - this.m_ContentBounds.max.y); } else if (this.m_ViewBounds.max.y > this.m_ContentBounds.max.y) { zero.y = Math.Min(this.m_ViewBounds.min.y - this.m_ContentBounds.min.y, this.m_ViewBounds.max.y - this.m_ContentBounds.max.y); } if (zero.sqrMagnitude > 0.01f) { this.m_ContentBounds = this.GetBounds(); size = this.m_ContentBounds.size; center = this.m_ContentBounds.center; pivot = this.m_Content.pivot; uGUIScrollRect.AdjustBounds(ref this.m_ViewBounds, ref pivot, ref size, ref center); this.m_ContentBounds.size = size; this.m_ContentBounds.center = center; } } } internal static void AdjustBounds(ref Bounds viewBounds, ref Vector2 contentPivot, ref Vector3 contentSize, ref Vector3 contentPos) { Vector3 vector = viewBounds.size - contentSize; if (vector.x > 0f) { contentPos.x -= vector.x * (contentPivot.x - 0.5f); contentSize.x = viewBounds.size.x; } if (vector.y > 0f) { contentPos.y -= vector.y * (contentPivot.y - 0.5f); contentSize.y = viewBounds.size.y; } } private Bounds GetBounds() { if (this.m_Content == null) { return default(Bounds); } this.m_Content.GetWorldCorners(this.m_Corners); Matrix4x4 worldToLocalMatrix = this.viewRect.worldToLocalMatrix; return uGUIScrollRect.InternalGetBounds(this.m_Corners, ref worldToLocalMatrix); } internal static Bounds InternalGetBounds(Vector3[] corners, ref Matrix4x4 viewWorldToLocalMatrix) { Vector3 vector = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); Vector3 vector2 = new Vector3(float.MinValue, float.MinValue, float.MinValue); for (int i = 0; i < 4; i++) { Vector3 lhs = viewWorldToLocalMatrix.MultiplyPoint3x4(corners[i]); vector = Vector3.Min(lhs, vector); vector2 = Vector3.Max(lhs, vector2); } Bounds result = new Bounds(vector, Vector3.zero); result.Encapsulate(vector2); return result; } private Vector2 CalculateOffset(Vector2 delta) { return uGUIScrollRect.InternalCalculateOffset(ref this.m_ViewBounds, ref this.m_ContentBounds, this.m_Horizontal, this.m_Vertical, this.m_MovementType, ref delta); } internal static Vector2 InternalCalculateOffset(ref Bounds viewBounds, ref Bounds contentBounds, bool horizontal, bool vertical, uGUIScrollRect.MovementType movementType, ref Vector2 delta) { Vector2 zero = Vector2.zero; if (movementType == uGUIScrollRect.MovementType.Unrestricted) { return zero; } Vector2 vector = contentBounds.min; Vector2 vector2 = contentBounds.max; if (horizontal) { vector.x += delta.x; vector2.x += delta.x; if (vector.x > viewBounds.min.x) { zero.x = viewBounds.min.x - vector.x; } else if (vector2.x < viewBounds.max.x) { zero.x = viewBounds.max.x - vector2.x; } } if (vertical) { vector.y += delta.y; vector2.y += delta.y; if (vector2.y < viewBounds.max.y) { zero.y = viewBounds.max.y - vector2.y; } else if (vector.y > viewBounds.min.y) { zero.y = viewBounds.min.y - vector.y; } } return zero; } protected void SetDirty() { if (!this.IsActive()) { return; } LayoutRebuilder.MarkLayoutForRebuild(this.rectTransform); } protected void SetDirtyCaching() { if (!this.IsActive()) { return; } CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this); LayoutRebuilder.MarkLayoutForRebuild(this.rectTransform); } Transform ICanvasElement.get_transform() { return base.transform; } bool ICanvasElement.IsDestroyed() { return base.IsDestroyed(); } [SerializeField] private RectTransform m_Content; [SerializeField] private bool m_Horizontal = true; [SerializeField] private bool m_Vertical = true; [SerializeField] private uGUIScrollRect.MovementType m_MovementType = uGUIScrollRect.MovementType.Elastic; [SerializeField] private float m_Elasticity = 0.1f; [SerializeField] private bool m_Inertia = true; [SerializeField] private float m_DecelerationRate = 0.135f; [SerializeField] private float m_ScrollSensitivity = 1f; [SerializeField] private RectTransform m_Viewport; [SerializeField] private Slider m_HorizontalSlider; [SerializeField] private Slider m_VerticalSlider; [SerializeField] private uGUIScrollRect.SliderVisibility m_HorizontalSliderVisibility; [SerializeField] private uGUIScrollRect.SliderVisibility m_VerticalSliderVisibility; [SerializeField] private float m_HorizontalSliderSpacing; [SerializeField] private float m_VerticalSliderSpacing; [SerializeField] private uGUIScrollRect.ScrollRectEvent m_OnValueChanged = new uGUIScrollRect.ScrollRectEvent(); private Vector2 m_PointerStartLocalCursor = Vector2.zero; protected Vector2 m_ContentStartPosition = Vector2.zero; private RectTransform m_ViewRect; protected Bounds m_ContentBounds; private Bounds m_ViewBounds; private Vector2 m_Velocity; private bool m_Dragging; private Vector2 m_PrevPosition = Vector2.zero; private Bounds m_PrevContentBounds; private Bounds m_PrevViewBounds; [NonSerialized] private bool m_HasRebuiltLayout; private bool m_HSliderExpand; private bool m_VSliderExpand; private float m_HSliderHeight; private float m_VSliderWidth; [NonSerialized] private RectTransform m_Rect; private RectTransform m_HorizontalSliderRect; private RectTransform m_VerticalSliderRect; private DrivenRectTransformTracker m_Tracker; private readonly Vector3[] m_Corners = new Vector3[4]; public enum MovementType { Unrestricted, Elastic, Clamped } public enum SliderVisibility { Permanent, AutoHide, AutoHideAndExpandViewport } [Serializable] public class ScrollRectEvent : UnityEvent { } } }