public void Do(ScrollData targetScrollData, bool animated) { scrollSystem.ScrollRect.StopMovement(); state = animated ? State.Animated : State.Directly; this.targetScrollData = targetScrollData; this.targetNormalizedPos = 0; }
public void Do(float targetNormalizedPos, bool animated) { scrollSystem.ScrollRect.StopMovement(); state = animated ? State.Animated : State.Directly; this.targetScrollData = null; targetNormalizedPos = Mathf.Clamp01(targetNormalizedPos); if (scrollSystem.scrollDirection == ScrollDirection.Vertical) { switch (scrollSystem.startCorner) { case 0: //Left Up case 1: //Right Up this.targetNormalizedPos = 1 - targetNormalizedPos; break; case 2: //Left Down case 3: //Right Down this.targetNormalizedPos = targetNormalizedPos; break; } } else { switch (scrollSystem.startCorner) { case 0: //Left Up case 2: //Left Down this.targetNormalizedPos = targetNormalizedPos; break; case 1: //Right Up case 3: //Right Down this.targetNormalizedPos = 1 - targetNormalizedPos; break; } } }
private void SetSingleContentDataWhenHorizontal(ScrollData data) { data.CalculateSize(); //指定使用新行 if (data.newLine == ScrollLayout.NewLine.None) { //发生过偏移,并且这次物体的右边界超过宽度 if (cursorPos.y > border.y && cursorPos.y + data.height > Height - border.y) { //那么执行换行操作 cursorPos.y = border.y; cursorPos.x += maxHeight; maxHeight = 0; } //设置位置 data.SetAnchoredPosition(cursorPos + data.Size / 2); //更新光标 cursorPos.y += data.height; //更新最大宽度 if (maxWidth < cursorPos.y) { maxWidth = cursorPos.y; } //增加间隔 if (data.height > 0) { cursorPos.y += spacing.y; } //更新最大高度 var curMaxHeight = data.width > 0 ? (data.width + spacing.x) : 0; if (maxHeight < curMaxHeight) { maxHeight = curMaxHeight; } } else { //发生过偏移 if (cursorPos.y > border.y) { //换行 cursorPos.x += maxHeight; maxHeight = 0; } //指定使用新行 switch (data.newLine) { case ScrollLayout.NewLine.Center: cursorPos.y = Width / 2; break; case ScrollLayout.NewLine.LeftOrUp: cursorPos.y = data.height / 2 + border.y; break; case ScrollLayout.NewLine.RightOrDown: cursorPos.y = Width - data.width / 2 - border.y; break; } //设置位置 data.SetAnchoredPosition(cursorPos + data.width / 2 * Vector2.right); //换新行 cursorPos.y = border.y; cursorPos.x += data.width + spacing.x; } }
private void AlignScrollDataWhenVertical(ScrollData data) { data.CalculateSize(); if (data.newLine == ScrollLayout.NewLine.None) { //发生过偏移,并且这次物体的右边界超过宽度 if (cursorPos.x > border.x && cursorPos.x + data.width > Width - border.x) { //那么执行换行操作 cursorPos.x = border.x; cursorPos.y += maxHeight; maxHeight = 0; } //设置位置 data.SetAnchoredPosition(cursorPos + data.Size / 2); //更新光标 cursorPos.x += data.width; //更新最大宽度 if (maxWidth < cursorPos.x) { maxWidth = cursorPos.x; } //增加间隔 if (data.width > 0) { cursorPos.x += spacing.x; } //更新最大高度 float curMaxHeight = data.height > 0 ? (data.height + spacing.y) : 0; if (maxHeight < curMaxHeight) { maxHeight = curMaxHeight; } } else { //发生过偏移 if (cursorPos.x > border.x) { //换行 cursorPos.y += maxHeight; maxHeight = 0; } //指定使用新行 switch (data.newLine) { case ScrollLayout.NewLine.Center: cursorPos.x = Width / 2; break; case ScrollLayout.NewLine.LeftOrUp: cursorPos.x = data.width / 2 + border.x; break; case ScrollLayout.NewLine.RightOrDown: cursorPos.x = Width - data.width / 2 - border.x; break; } //设置位置 data.SetAnchoredPosition(cursorPos + data.height / 2 * Vector2.up); //换新行 cursorPos.x = border.x; cursorPos.y += data.height + spacing.y; } }
public bool Update() { //if (!scrollSystem.moveEnable) { return; } if (state != State.None) { if (scrollSystem.scrollDirection == ScrollDirection.Vertical) { float offset = scrollSystem.contentSize - scrollSystem.Height; if (offset <= 0) { this.targetNormalizedPos = 0; } else { if (this.targetScrollData != null) { switch (scrollSystem.startCorner) { case 0: //Left Up case 1: //Right Up this.targetNormalizedPos = 1 - (this.targetScrollData.originPosition.y - this.targetScrollData.height / 2) / offset; break; case 2: //Left Down case 3: //Right Down this.targetNormalizedPos = (this.targetScrollData.originPosition.y - this.targetScrollData.height / 2) / offset; break; } } } } else { float offset = scrollSystem.contentSize - scrollSystem.Width; if (offset <= 0) { this.targetNormalizedPos = 0; } else { if (this.targetScrollData != null) { switch (scrollSystem.startCorner) { case 0: //Left Up case 2: //Left Down this.targetNormalizedPos = (this.targetScrollData.originPosition.x - this.targetScrollData.width / 2) / offset; break; case 1: //Right Up case 3: //Right Down this.targetNormalizedPos = 1 - (this.targetScrollData.originPosition.x - this.targetScrollData.width / 2) / offset; break; } } } } this.targetScrollData = null; this.targetNormalizedPos = Mathf.Clamp01(this.targetNormalizedPos); //根据state来判断如何跳转 switch (state) { case State.Directly: this.setNormalizedPos(targetNormalizedPos); state = State.None; break; case State.Animated: float lerpNormalizedPos = Mathf.Lerp(this.getNormalizedPos(), targetNormalizedPos, Time.deltaTime * scrollSystem.jumpToSpeed); var pixelDistance = Mathf.Abs(lerpNormalizedPos - targetNormalizedPos) * scrollSystem.contentSize; if (pixelDistance < 1) { this.setNormalizedPos(this.targetNormalizedPos); state = State.None; } else { this.setNormalizedPos(lerpNormalizedPos); } break; } return(true); } else { return(false); } }