Commit 831d7cc1 authored by JiangWanZhi's avatar JiangWanZhi

缩放表现修改

parent e23830ed
...@@ -411,10 +411,10 @@ MonoBehaviour: ...@@ -411,10 +411,10 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Padding: m_Padding:
m_Left: 0 m_Left: 400
m_Right: 0 m_Right: 400
m_Top: 0 m_Top: 400
m_Bottom: 0 m_Bottom: 400
m_ChildAlignment: 4 m_ChildAlignment: 4
m_Spacing: 0 m_Spacing: 0
m_ChildForceExpandWidth: 1 m_ChildForceExpandWidth: 1
...@@ -5402,7 +5402,7 @@ RectTransform: ...@@ -5402,7 +5402,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 400, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &4535739684591336511 --- !u!114 &4535739684591336511
...@@ -5421,7 +5421,6 @@ MonoBehaviour: ...@@ -5421,7 +5421,6 @@ MonoBehaviour:
png: {fileID: 0} png: {fileID: 0}
jpg: {fileID: 0} jpg: {fileID: 0}
json: json:
allPos:
roomDatas: [] roomDatas: []
roomGroupsData: [] roomGroupsData: []
colorDiff: 0 colorDiff: 0
...@@ -5752,7 +5751,8 @@ MonoBehaviour: ...@@ -5752,7 +5751,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c99b850a1f8be4640b391afdbd751ee8, type: 3} m_Script: {fileID: 11500000, guid: c99b850a1f8be4640b391afdbd751ee8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
id: -1 roomId: -1
groupId: -1
IsUse: -1 IsUse: -1
SP: {fileID: 7114594662145661671} SP: {fileID: 7114594662145661671}
Rect: {fileID: 3859749812772851665} Rect: {fileID: 3859749812772851665}
......
...@@ -5563,6 +5563,7 @@ GameObject: ...@@ -5563,6 +5563,7 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 1147557151012020857} - component: {fileID: 1147557151012020857}
- component: {fileID: 8094727572906316438} - component: {fileID: 8094727572906316438}
- component: {fileID: 8094727572906316439}
m_Layer: 5 m_Layer: 5
m_Name: Gameing m_Name: Gameing
m_TagString: Untagged m_TagString: Untagged
...@@ -6239,7 +6240,7 @@ MonoBehaviour: ...@@ -6239,7 +6240,7 @@ MonoBehaviour:
m_SelectOnDown: {fileID: 0} m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0} m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0} m_SelectOnRight: {fileID: 0}
m_Transition: 0 m_Transition: 1
m_Colors: m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1} m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
...@@ -8201,6 +8202,20 @@ MonoBehaviour: ...@@ -8201,6 +8202,20 @@ MonoBehaviour:
cam: {fileID: 0} cam: {fileID: 0}
ListMoveOffSet: 35 ListMoveOffSet: 35
PlayImagePaent: {fileID: 1943337312} PlayImagePaent: {fileID: 1943337312}
--- !u!114 &8094727572906316439
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2077560325776199990}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0abda17aa99f2ed40ae8f906b43a260f, type: 3}
m_Name:
m_EditorClassIdentifier:
ReSetPos_Btn: {fileID: 3853497852481138177}
ShowBtnScale: 1
--- !u!1 &8136062125027934181 --- !u!1 &8136062125027934181
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -39,6 +39,9 @@ public static class EventName ...@@ -39,6 +39,9 @@ public static class EventName
public const string Event_FindGroupArea = "Event_FindGroupArea"; //提示按钮按下 public const string Event_FindGroupArea = "Event_FindGroupArea"; //提示按钮按下
public const string Event_AutoFullArea = "Event_AutoFullArea"; //自动涂按钮按下 public const string Event_AutoFullArea = "Event_AutoFullArea"; //自动涂按钮按下
public const string Event_BackToHome = "Event_BackToHome"; //点返回按钮 public const string Event_BackToHome = "Event_BackToHome"; //点返回按钮
public const string Event_ImageScallChange = "Event_ImageScallChange"; //图片的缩放改变
public const string Event_ReSetPicPos_Scale = "Event_ReSetPicPos_Scale"; //重新设置图片的位置和缩放
} }
public class DataName public class DataName
......
using DG.Tweening; using DG.Tweening;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
...@@ -21,26 +22,55 @@ public class ScaleToImage : MonoBehaviour ...@@ -21,26 +22,55 @@ public class ScaleToImage : MonoBehaviour
public float Min_Move; public float Min_Move;
public float Max_Move; public float Max_Move;
private Vector3 ToFigerCenter_Scale; //指向手指中间的向量 private Vector3 ToFigerCenter; //指向手指中间的向量
private float ToFigerdistance_Scale; //距离 private float ToFigerdistance; //距离
private float MoveValue_Scale; //移动,缩放大了就小一些 private float MoveValue; //移动,缩放大了就小一些
private bool PlayAniFlag_Scale; private bool PlayAniFlag_Scale;
private Vector3 SavePos_Scale; //这个是保存放大到最大的倍数的时候回正的位置
private float NowScale; private float NowScale;
private List<float> ScaleSize_List = new List<float>(); private List<float> ScaleSize_List = new List<float>();
private int ListMaxNum = 10; private int ListMaxNum = 10;
bool flag;
private float SatrtScale;
private Vector3 StartPos;
private float EndScale;
private Vector3 EndPos;
private Vector3 OnInitScale; //初始化时的缩放
private Vector3 OnInitPos;
private void Start() private void Start()
{ {
canvasCamera=transform.parent.GetComponent<ScaleToImage>().canvasCamera; canvasCamera=transform.parent.GetComponent<ScaleToImage>().canvasCamera;
RegisterEvent(true);
StartCoroutine(Delay());
} }
bool flag; IEnumerator Delay()
{
yield return new WaitForSeconds(1f);
OnInitScale = target.localScale;
OnInitPos = target.position;
}
private void RegisterEvent(bool flag)
{
EventDispatcher.RegisterEvent(EventName.Event.Event_ReSetPicPos_Scale, ResetPos_Scale, flag);
}
private void ResetPos_Scale(object[] values)
{
target.localScale= OnInitScale;
target.position = OnInitPos;
target.gameObject.SetActive(false);
target.gameObject.SetActive(true);
}
private void Update() private void Update()
{ {
...@@ -58,16 +88,28 @@ public class ScaleToImage : MonoBehaviour ...@@ -58,16 +88,28 @@ public class ScaleToImage : MonoBehaviour
flag = false; flag = false;
if (target.localScale.x <= Min_Move) //缩放小的回大 if (target.localScale.x <= Min_Move) //缩放小的回大
{ {
target.DOScale(Vector3.one * MinScale, 0.3f).onComplete=()=> target.DOScale(Vector3.one * MinScale, 0.3f).onComplete = () =>
{ {
RefreshScrollview(); RefreshScrollview();
}; };
NowScale = MinScale; NowScale = MinScale;
SetscrollRectEnable(true);
} }
else if (target.localScale.x >= MaxScale) //大的回来小 else if (target.localScale.x >= MaxScale) //大的回来小
{ {
SetscrollRectEnable(true);
EndScale = target.localScale.x;
EndPos = target.position;
float dis = EndScale - SatrtScale; //缩放差
float tolimit = EndScale - MaxScale; //结束到最大限制的差
float value = tolimit / dis; //比值
var toStart = (StartPos - EndPos).normalized; //指向开始点的向量
var distance = Vector3.Distance(StartPos, EndPos);
Vector3 Pos = EndPos + toStart * distance * value; //回去的位置
target.DOScale(Vector3.one * MaxScale, 0.3f); target.DOScale(Vector3.one * MaxScale, 0.3f);
target.DOMove(SavePos_Scale, 0.3f).onComplete = () => target.DOMove(Pos, 0.3f).onComplete = () =>
{ {
RefreshScrollview(); RefreshScrollview();
}; };
...@@ -80,6 +122,7 @@ public class ScaleToImage : MonoBehaviour ...@@ -80,6 +122,7 @@ public class ScaleToImage : MonoBehaviour
} }
if (flag) if (flag)
{ {
SetscrollRectEnable(true);
RefreshScrollview(); RefreshScrollview();
flag = false; flag = false;
} }
...@@ -111,6 +154,7 @@ public class ScaleToImage : MonoBehaviour ...@@ -111,6 +154,7 @@ public class ScaleToImage : MonoBehaviour
{ {
if (!isInit_Scale) if (!isInit_Scale)
{ {
SetscrollRectEnable(false);
//两指点位 //两指点位
touch1 = canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position); touch1 = canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position);
touch2 = canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position); touch2 = canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position);
...@@ -120,27 +164,42 @@ public class ScaleToImage : MonoBehaviour ...@@ -120,27 +164,42 @@ public class ScaleToImage : MonoBehaviour
//图片的初始点位 //图片的初始点位
oriPos = new Vector3(target.position.x, target.position.y, 0); oriPos = new Vector3(target.position.x, target.position.y, 0);
if (target.localScale.x >= MaxScale * 0.99f)
{
SavePos_Scale = target.position;
}
float distance = Vector2.Distance(touch1, touch2) / 2f; float distance = Vector2.Distance(touch1, touch2) / 2f;
var normal = (touch1 - touch2).normalized; var normal = (touch1 - touch2).normalized;
pos = normal * distance + touch2; //两个手指中间的点 pos = normal * distance + touch2; //两个手指中间的点
//指向手指中心的单位向量 //指向手指中心的单位向量
ToFigerCenter_Scale = (pos - oriPos).normalized; ToFigerCenter = (pos - oriPos).normalized;
//距离 //距离
ToFigerdistance_Scale = Vector3.Distance(pos, oriPos); ToFigerdistance = Vector3.Distance(pos, oriPos);
oriScale = target.localScale.x;//开始的缩放值 oriScale = target.localScale.x;//开始的缩放值
isInit_Scale = true; isInit_Scale = true;
MoveValue_Scale = 1 / oriScale; MoveValue = 1 / oriScale;
SatrtScale = target.localScale.x;
StartPos=target.position;
return; return;
} }
if (target.localScale.x < Min_Move)
{
PlayAniFlag_Scale = true;
if (ScaleSize_List.Count < ListMaxNum)
{
ScaleSize_List.Add(NowScale);
}
else
{
ScaleSize_List.Clear();
ChangeFontSize(Min_Move);
}
return;
}
//两指缩放比例 //两指缩放比例
float nowdis = Vector3.Distance(canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position), canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position)); float nowdis = Vector3.Distance(canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position), canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position));
scale = nowdis / Vector3.Distance(touch1, touch2); //大于1是放大,小于是缩小 scale = nowdis / Vector3.Distance(touch1, touch2); //大于1是放大,小于是缩小
...@@ -153,18 +212,14 @@ public class ScaleToImage : MonoBehaviour ...@@ -153,18 +212,14 @@ public class ScaleToImage : MonoBehaviour
scale = scale * oriScale * scaleSpeed; //缩小速度 scale = scale * oriScale * scaleSpeed; //缩小速度
} }
if (target.localScale.x < Min_Move)
{
PlayAniFlag_Scale = true;
return;
}
float scale_target = 0; float scale_target = 0;
scale_target = (Vector3.one * (oriScale + scale)).x; scale_target = (Vector3.one * (oriScale + scale)).x;
Vector3 targetscale; Vector3 targetscale;
if (scale_target < Min_Move) if (scale_target < Min_Move)
{ {
targetscale = Vector3.one * Min_Move * 0.99f; targetscale = Vector3.one * Min_Move * 0.99f;
target.localScale = targetscale;
return;
} }
else if (scale_target > MaxScale) else if (scale_target > MaxScale)
{ {
...@@ -174,14 +229,14 @@ public class ScaleToImage : MonoBehaviour ...@@ -174,14 +229,14 @@ public class ScaleToImage : MonoBehaviour
else else
{ {
targetscale = Vector3.one * (oriScale + scale); targetscale = Vector3.one * (oriScale + scale);
SavePos_Scale = target.position;
} }
target.localScale = targetscale; target.localScale = targetscale;
//改变目标位置,让位置保持不变 //改变目标位置,让位置保持不变
target.position = oriPos - ToFigerCenter_Scale * (target.localScale.x - oriScale) * ToFigerdistance_Scale * MoveValue_Scale; var newpos = ToFigerCenter * (target.localScale.x - oriScale) * ToFigerdistance * MoveValue;
target.position = oriPos - newpos;
target.localPosition = new Vector3(target.localPosition.x, target.localPosition.y, 0); target.localPosition = new Vector3(target.localPosition.x, target.localPosition.y, 0);
NowScale = targetscale.x; NowScale = targetscale.x;
...@@ -205,5 +260,9 @@ public class ScaleToImage : MonoBehaviour ...@@ -205,5 +260,9 @@ public class ScaleToImage : MonoBehaviour
} }
private void SetscrollRectEnable(bool enable)
{
scrollRect.enabled = enable;
}
} }
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Gameing : MonoBehaviour
{
public Button ReSetPos_Btn;
public float ShowBtnScale;//显示重设位置按钮的缩放值
// Start is called before the first frame update
void Start()
{
ResiterEvent(true);
ReSetPos_Btn.onClick.AddListener(ReSetPos_Btn_Click);
ReSetPos_Btn.gameObject.SetActive(false);
}
private void ResiterEvent(bool flag)
{
EventDispatcher.RegisterEvent(EventName.Event.Event_ImageScallChange,ChangeScale_Pic, flag);
}
private void ChangeScale_Pic(object[] values)
{
float scale = (float)values[0];
ReSetPos_Btn.gameObject.SetActive(ShowBtnScale <= scale);
}
private void ReSetPos_Btn_Click()
{
EventDispatcher.Dispatch(EventName.Event.Event_ReSetPicPos_Scale);
}
}
fileFormatVersion: 2
guid: 0abda17aa99f2ed40ae8f906b43a260f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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