diff --git a/Assets/Resources/ChillConnectAssets/FGUI/Arrow_game_atlas0.png b/Assets/Resources/ChillConnectAssets/FGUI/Arrow_game_atlas0.png index 1680222..b4b2412 100644 Binary files a/Assets/Resources/ChillConnectAssets/FGUI/Arrow_game_atlas0.png and b/Assets/Resources/ChillConnectAssets/FGUI/Arrow_game_atlas0.png differ diff --git a/Assets/Resources/ChillConnectAssets/FGUI/Arrow_game_fui.bytes b/Assets/Resources/ChillConnectAssets/FGUI/Arrow_game_fui.bytes index c0b1654..9fdcaec 100644 Binary files a/Assets/Resources/ChillConnectAssets/FGUI/Arrow_game_fui.bytes and b/Assets/Resources/ChillConnectAssets/FGUI/Arrow_game_fui.bytes differ diff --git a/Assets/Scripts/ModuleUI/ArrowGame/ArrowGameUI.cs b/Assets/Scripts/ModuleUI/ArrowGame/ArrowGameUI.cs index 4f77b3f..cc3aea2 100644 --- a/Assets/Scripts/ModuleUI/ArrowGame/ArrowGameUI.cs +++ b/Assets/Scripts/ModuleUI/ArrowGame/ArrowGameUI.cs @@ -36,12 +36,19 @@ namespace ChillConnect private readonly float outOffset = 200f; // 网格边界 + private Vector2 _gridWorldCenter; // 网格世界中心点 + private float gridLeft; private float gridRight; private readonly int gridRowNum = 10; private float gridTop; private float gridBottom; + // 网格行列、单个格子尺寸(你原有网格参数) + private int _gridRow; + private int _gridCol; + private float _cellSize; + // 网格占用标记:true=该点位被占用,false=空闲 private bool[,] _gridOccupied; // 记录每个箭头占用的所有网格点位(行,列) @@ -98,6 +105,7 @@ namespace ChillConnect uiInfo.isNeedOpenAnim = false; uiInfo.isNeedCloseAnim = false; uiInfo.isNeedUIMask = true; + uiInfo.isTickUpdate = true; } #region 生命周期 @@ -155,11 +163,46 @@ namespace ChillConnect public override void OnUpdate() { - if (_levelConfig == null) return; - foreach (var arrow in _levelConfig.arrows) + // if (_levelConfig == null) return; + // foreach (var arrow in _levelConfig.arrows) + // { + // UpdateArrowMove(arrow); + // } + // + // ========= 编辑器模拟触摸(仅编辑模式生效) ========= +#if UNITY_EDITOR + //1. 鼠标左键 = 单指拖拽 + // Debug.Log($"Input.GetMouseButtonDown======={Input.GetMouseButtonDown(0)}"); + if (Input.GetMouseButtonDown(0)) { - UpdateArrowMove(arrow); + _lastTouchPos = Input.mousePosition; + _isDraging = true; } + if (Input.GetMouseButton(0) && _isDraging) + { + Vector2 curMousePos = Input.mousePosition; + Vector2 offset = curMousePos - _lastTouchPos; + MoveContainer(offset); + _lastTouchPos = curMousePos; + } + if (Input.GetMouseButtonUp(0)) + { + _isDraging = false; + } + + // 2. 鼠标滚轮 = 双指缩放 + // float scrollDelta = Input.GetMouseWheelDelta(); + // if (Mathf.Abs(scrollDelta) > 0) + // { + // float curScale = _viewContainer.scaleX; + // curScale += scrollDelta * 0.1f; + // curScale = Mathf.Clamp(curScale, _minScale, _maxScale); + // + // _viewContainer.scaleX = curScale; + // _viewContainer.scaleY = curScale; + // _zoomSlider.value = GetSliderValueByScale(curScale); + // } +#endif // ========= 双指 = 缩放(优先级最高) ========= if (Input.touchCount == 2) @@ -267,6 +310,7 @@ namespace ChillConnect ui.btn_hint.SetClick(OnClickHint); _fingerTipObj = com_finger.CreateInstance(); _viewContainer.AddChild(_fingerTipObj); + _fingerTipObj.visible = false; _currentTipArrow = null; _zoomSlider = ui.zoomSlide; @@ -466,6 +510,43 @@ namespace ChillConnect _viewContainer.AddChild(dot); } } + + // ========= 新增:网格绘制完成后,设置居中缩放轴心 ========= + CalculateGridCenter(cfg); + SetViewPivotToGridCenter(); + } + + /// 计算网格整体世界中心(原有网格坐标不变) + /// 计算整个网格圆点区域的世界中心点 + private void CalculateGridCenter(LevelConfig cfg) + { + int rows = cfg.gridRows; + int cols = cfg.gridCols; + + // 取四个角点位,算出整体中心 + Vector2 topLeft = RowColToPos(0, 0); + Vector2 bottomRight = RowColToPos(rows - 1, cols - 1); + + // 几何中心 + _gridWorldCenter.x = (topLeft.x + bottomRight.x) * 0.5f; + _gridWorldCenter.y = (topLeft.y + bottomRight.y) * 0.5f; + } + + /// 设置_viewContainer缩放轴心 = 网格中心,实现居中缩放 + private void SetViewPivotToGridCenter() + { + if (_viewContainer == null) return; + + // FGUI pivot 取值范围 0~1,是容器内部相对比例 + float pivotX = _gridWorldCenter.x / _viewContainer.width; + float pivotY = _gridWorldCenter.y / _viewContainer.height; + + // 限制在合法区间 + pivotX = Mathf.Clamp01(pivotX); + pivotY = Mathf.Clamp01(pivotY); + + // 设置轴心,此后所有缩放都围绕网格中心 + _viewContainer.pivot = new Vector2(pivotX, pivotY); } #endregion @@ -708,14 +789,23 @@ namespace ChillConnect /// 根据缩放值,计算滑动条 value(0~1) private float GetSliderValueByScale(float scale) { - float t = (scale - _minScale) / (_maxScale - _minScale); - return Mathf.Clamp01(t); + float validScale = Mathf.Clamp(scale, _minScale, _maxScale); + float ratio = (validScale - _minScale) / (_maxScale - _minScale); + float sliderVal = ratio * 100f; + + return Mathf.Clamp(sliderVal, 0f, 100f); } /// 根据滑动条 value(0~1),计算实际缩放值 private float GetScaleBySliderValue(float sliderValue) { - float scale = _minScale + sliderValue * (_maxScale - _minScale); + // 先把滑块值钳位在 0~100 内 + float val = Mathf.Clamp(sliderValue, 0f, 100f); + + // 线性映射:0→0.6,100→1.5 + float ratio = val / 100f; + float scale = _minScale + ratio * (_maxScale - _minScale); + return Mathf.Clamp(scale, _minScale, _maxScale); } @@ -1326,11 +1416,13 @@ namespace ChillConnect return; } - // 1. 恢复默认缩放 1倍 - _viewContainer.scaleX = 1f; - _viewContainer.scaleY = 1f; - // 2. 滑动条回归对应位置 - _zoomSlider.value = GetSliderValueByScale(1f); + // 1. 恢复默认缩放 1.0 + float defaultScale = 1f; + _viewContainer.scaleX = defaultScale; + _viewContainer.scaleY = defaultScale; + + // 2. 设置滑块对应位置 + _zoomSlider.value = GetSliderValueByScale(defaultScale); // 3. 容器屏幕居中 float startX = (Screen.width - _viewContainer.width) * 0.5f; float startY = (Screen.height - _viewContainer.height) * 0.5f;