|
@@ -18,7 +18,8 @@ namespace GFGGame
|
|
|
private const string MOVE = "MOVE";
|
|
|
private const string SCALE = "SCALE";
|
|
|
private const string ROTATION = "ROTATION";
|
|
|
- private const int MaxTouchCount = 2;
|
|
|
+ private const float MaxScale = 2;
|
|
|
+ private const float MinScale = 0.1f;
|
|
|
|
|
|
private GameObject bodyParent;
|
|
|
private GameObject bgParent;
|
|
@@ -34,9 +35,6 @@ namespace GFGGame
|
|
|
private GameObject hitParentGameObj;//当前选中的父物体(需要进行移动缩放旋转的物体)
|
|
|
private Vector3 distance = Vector3.zero;//点击位置和点击物体原点的距离,用于
|
|
|
|
|
|
- private Vector2 firstTouchLastPos = Vector2.zero;//第一根手指上一次的位置
|
|
|
- private Vector2 secondTouchLastPos = Vector2.zero;//第二根手指上一次的位置
|
|
|
-
|
|
|
private SwipeGesture swipeGesture;
|
|
|
private PinchGesture pinchGesture;
|
|
|
private RotationGesture rotationGesture;
|
|
@@ -191,40 +189,17 @@ namespace GFGGame
|
|
|
private void OnClickUIMove(EventContext context)
|
|
|
{
|
|
|
if (hitParentGameObj == null) return;//未选中任何物体
|
|
|
- if (Stage.inst.touchCount > MaxTouchCount) return;//只监听两根手指
|
|
|
+ if (Stage.inst.touchCount > 1) return;//只监听1根手指
|
|
|
|
|
|
ControllerObjectPos(hitParentGameObj);
|
|
|
ControllerSelectBoxPos(hitParentGameObj);
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- private void OnPinch(EventContext context)
|
|
|
- {
|
|
|
-
|
|
|
- GTween.Kill(hitParentGameObj);
|
|
|
-
|
|
|
- PinchGesture gesture = (PinchGesture)context.sender;
|
|
|
- float newValue = Mathf.Clamp(hitParentGameObj.transform.localScale.x + gesture.delta, 0.3f, 2);
|
|
|
- hitParentGameObj.transform.localScale = new Vector3(newValue, newValue, newValue);
|
|
|
- _ui.m_comSelectBox.target.SetScale(newValue, newValue);
|
|
|
- }
|
|
|
-
|
|
|
- private void OnRotate(EventContext context)
|
|
|
- {
|
|
|
- GTween.Kill(hitParentGameObj.transform);
|
|
|
-
|
|
|
- RotationGesture gesture = (RotationGesture)context.sender;
|
|
|
- hitParentGameObj.transform.Rotate(Vector3.forward, -gesture.delta, Space.World);
|
|
|
- _ui.m_comSelectBox.target.rotation = -gesture.delta;
|
|
|
- }
|
|
|
-
|
|
|
private void OnClickUIEnd(EventContext context)
|
|
|
{
|
|
|
if (context.inputEvent.touchId == 0) hitParentGameObj = null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//选中物体的位置
|
|
|
private void ControllerObjectPos(GameObject hitParentGameObj)
|
|
|
{
|
|
@@ -254,41 +229,38 @@ namespace GFGGame
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //选中框的大小位置旋转
|
|
|
+ //选中框的位置
|
|
|
private void ControllerSelectBoxPos(GameObject hitParentGameObj)
|
|
|
{
|
|
|
SceneController.SetGameObjectCenter(hitParentGameObj);
|
|
|
//位置:角色、道具、npc全用对应父物体的位置
|
|
|
Vector2 objScreenPos = Camera.main.WorldToScreenPoint(hitParentGameObj.transform.position);
|
|
|
- Vector2 localPos = new Vector2(objScreenPos.x, Screen.height - objScreenPos.y);
|
|
|
- _ui.m_comSelectBox.target.SetXY(localPos.x, localPos.y);
|
|
|
+ // Vector2 localPos = new Vector2(objScreenPos.x + _ui.m_comSelectBox.target.width * 0.5f, (Screen.height - objScreenPos.y) + _ui.m_comSelectBox.target.height * 0.5f);
|
|
|
+ Vector2 localPos = new Vector2(objScreenPos.x, (Screen.height - objScreenPos.y));
|
|
|
+ _ui.m_comSelectBox.target.position = localPos;//(localPos.x, localPos.y);
|
|
|
|
|
|
}
|
|
|
|
|
|
- private string GetTransformState()
|
|
|
+ private void OnPinch(EventContext context)
|
|
|
{
|
|
|
- if (Stage.inst.touchCount == 1) return MOVE;//一根手指只能移动
|
|
|
+ if (hitParentGameObj == null) return;
|
|
|
+ GTween.Kill(hitParentGameObj);
|
|
|
|
|
|
- Vector2 lastDistance = secondTouchLastPos - firstTouchLastPos;
|
|
|
- Vector2 curDistance = Stage.inst.GetTouchPosition(1) - Stage.inst.GetTouchPosition(0);
|
|
|
+ PinchGesture gesture = (PinchGesture)context.sender;
|
|
|
+ float newValue = Mathf.Clamp(hitParentGameObj.transform.localScale.x + gesture.delta, 0.3f, 2);
|
|
|
+ if (newValue > MaxScale || newValue < MinScale) return;
|
|
|
+ hitParentGameObj.transform.localScale = new Vector3(newValue, newValue, newValue);
|
|
|
+ _ui.m_comSelectBox.target.SetScale(newValue, newValue);
|
|
|
+ }
|
|
|
|
|
|
- if (lastDistance == curDistance)
|
|
|
- {
|
|
|
- return MOVE;//向量大小和方向都不变是位移
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (lastDistance.magnitude != curDistance.magnitude)
|
|
|
- {
|
|
|
- //两指距离有变化是缩放
|
|
|
- return SCALE;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //两指距离无变化是缩放
|
|
|
- return ROTATION;
|
|
|
- }
|
|
|
- }
|
|
|
+ private void OnRotate(EventContext context)
|
|
|
+ {
|
|
|
+ if (hitParentGameObj == null) return;
|
|
|
+ GTween.Kill(hitParentGameObj.transform);
|
|
|
+
|
|
|
+ RotationGesture gesture = (RotationGesture)context.sender;
|
|
|
+ hitParentGameObj.transform.Rotate(Vector3.forward, -gesture.delta, Space.World);
|
|
|
+ _ui.m_comSelectBox.target.rotation = -gesture.delta;
|
|
|
}
|
|
|
//背景
|
|
|
private void UpdateBgOrNpcOrBorder(EnumPhotographType type, int itemId)
|