Commit 914f895e authored by JiangWanZhi's avatar JiangWanZhi

调整一下图片的缩放

parent 5d593044
This diff is collapsed.
using DG.Tweening;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
...@@ -13,11 +14,17 @@ public class ScaleToImage : MonoBehaviour ...@@ -13,11 +14,17 @@ public class ScaleToImage : MonoBehaviour
public float scaleSpeed = 1; public float scaleSpeed = 1;
public bool isLimitScale; public bool isLimitScale;
public float min, max;
public Camera canvasCamera; public Camera canvasCamera;
public Transform ScrollRect; //组的列表 public Transform ScrollRect; //组的父节点
public float MinScale;
public float MaxScale;
public float Min_Move;
public float Max_Move;
private bool isInit_one; private bool isInit_one;
private Vector3 offset; private Vector3 offset;
...@@ -26,12 +33,35 @@ public class ScaleToImage : MonoBehaviour ...@@ -26,12 +33,35 @@ public class ScaleToImage : MonoBehaviour
private float ToFigerdistance; //距离 private float ToFigerdistance; //距离
private float MoveValue; //移动,缩放大了就小一些 private float MoveValue; //移动,缩放大了就小一些
private bool PlayAniFlag;
private Vector3 OldPos;
private void Update() private void Update()
{ {
//不是双指就关闭 //不是双指就关闭
if (Input.touchCount != 2) if (Input.touchCount != 2)
{ {
isInit = false; isInit = false;
if (PlayAniFlag)
{
if (target.GetChild(0).localScale.x <= Min_Move) //缩放小的回大
{
for (int i = 0; i < target.childCount; i++)
{
target.GetChild(i).DOScale(Vector3.one * MinScale, 0.3f);
}
}
else if (target.GetChild(0).localScale.x >= Max_Move) //大的回来小
{
for (int i = 0; i < target.childCount; i++)
{
target.GetChild(i).DOScale(Vector3.one * MaxScale, 0.3f);
target.GetChild(i).DOMove(oriPos, 0.3f);
}
}
PlayAniFlag = false;
}
} }
//初始化 //初始化
if (Input.touchCount == 2 && !isInit) if (Input.touchCount == 2 && !isInit)
...@@ -65,6 +95,7 @@ public class ScaleToImage : MonoBehaviour ...@@ -65,6 +95,7 @@ public class ScaleToImage : MonoBehaviour
} }
if (Input.touchCount == 2) if (Input.touchCount == 2)
{ {
isInit_one = false;
if (!IsImageArea(Input.GetTouch(0).position) || !IsImageArea(Input.GetTouch(1).position)) if (!IsImageArea(Input.GetTouch(0).position) || !IsImageArea(Input.GetTouch(1).position))
{ {
isInit = false; isInit = false;
...@@ -72,28 +103,44 @@ public class ScaleToImage : MonoBehaviour ...@@ -72,28 +103,44 @@ public class ScaleToImage : MonoBehaviour
} }
//两指缩放比例 //两指缩放比例
scale = Vector3.Distance(canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position), canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position)) / Vector3.Distance(touch1, touch2); //大于1是放大,小于是缩小 float nowdis = Vector3.Distance(canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position), canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position));
scale = nowdis / Vector3.Distance(touch1, touch2); //大于1是放大,小于是缩小
//利用scaleSpeed控制缩放速度 //利用scaleSpeed控制缩放速度
scale = scale - 1; //正的话就是放大图片 scale = (scale - 1) * 0.8f; //正的话就是放大图片
if (scale < 0) if (scale < 0)
{ {
scale = scale * oriScale; scale = scale * oriScale * 0.8f;
} }
if (target.GetChild(0).localScale.x < Min_Move)
{
PlayAniFlag = true;
return;
}
float scale_target;
for (int i = 0; i < target.childCount; i++) for (int i = 0; i < target.childCount; i++)
{ {
var item = target.GetChild(i); var item = target.GetChild(i);
//缩放目标大小 scale_target = (Vector3.one * (oriScale + scale)).x;
item.localScale = Vector3.one * (oriScale + scale); if (scale_target < Min_Move)
{
item.localScale = Vector3.one * Min_Move * 0.99f;
}
else if (scale_target > Max_Move)
{
item.localScale = Vector3.one * (oriScale + scale);
PlayAniFlag = true;
}
else
item.localScale = Vector3.one * (oriScale + scale);
//改变目标位置,让位置保持不变
//改变目标位置,让位置保持不变
item.position = oriPos - ToFigerCenter * (item.localScale.x - oriScale) * ToFigerdistance * MoveValue; item.position = oriPos - ToFigerCenter * (item.localScale.x - oriScale) * ToFigerdistance * MoveValue;
} }
isInit_one = false;
} }
if (Input.touchCount == 1) //单指拖动 if (Input.touchCount == 1) //单指拖动
......
...@@ -41,3 +41,6 @@ TagManager: ...@@ -41,3 +41,6 @@ TagManager:
- name: Default - name: Default
uniqueID: 0 uniqueID: 0
locked: 0 locked: 0
- name: UI
uniqueID: 4064369897
locked: 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment