Commit 88ea57af authored by JiangWanZhi's avatar JiangWanZhi

修改第一次缩放会乱跑的bug

parent a036130f
......@@ -412,10 +412,10 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 400
m_Right: 400
m_Top: 400
m_Bottom: 400
m_Left: 300
m_Right: 300
m_Top: 300
m_Bottom: 300
m_ChildAlignment: 4
m_Spacing: 0
m_ChildForceExpandWidth: 1
......@@ -5403,7 +5403,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 400, y: 0}
m_AnchoredPosition: {x: 300, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &4535739684591336511
......@@ -5950,13 +5950,14 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
target: {fileID: 2902754919140836122}
scaleSpeed: 1.2
scaleSpeed: 0.9
canvasCamera: {fileID: 0}
scrollRect: {fileID: 1238786231969924280}
MinScale: 0.375
MaxScale: 7
Min_Move: 0.23
Max_Move: 8
group: {fileID: 237648084539702437}
--- !u!1 &6884362798581633399
GameObject:
m_ObjectHideFlags: 0
......@@ -6013,6 +6014,9 @@ MonoBehaviour:
pos: {fileID: 4755947299850074345}
v1: {x: 0, y: 0, z: 30}
v2: {x: 0, y: 5, z: 0}
curCount: 0
count: 0
step: 0
--- !u!1 &8495604213876096662
GameObject:
m_ObjectHideFlags: 0
......
......@@ -860,7 +860,6 @@ GameObject:
- component: {fileID: 414882563}
- component: {fileID: 414882562}
- component: {fileID: 414882561}
- component: {fileID: 414882565}
m_Layer: 0
m_Name: Canvas
m_TagString: Untagged
......@@ -954,19 +953,6 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &414882565
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 414882560}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c60e12901bc362d42b8b38a9e419ec96, type: 3}
m_Name:
m_EditorClassIdentifier:
AllowDebugging: 1
--- !u!1 &491076100
GameObject:
m_ObjectHideFlags: 0
......@@ -5005,7 +4991,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 5448574956194434760}
m_Direction: 0
m_MinValue: 0
m_MaxValue: 100
m_MaxValue: 1
m_WholeNumbers: 0
m_Value: 0
m_OnValueChanged:
......@@ -8115,6 +8101,7 @@ MonoBehaviour:
MaxScale: 10
Min_Move: 0.2
Max_Move: 12
group: {fileID: 0}
--- !u!114 &8094727572906316438
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -8149,7 +8136,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
ReSetPos_Btn: {fileID: 3853497852481138177}
ShowBtnScale: 1
ShowBtnScale: 0.6
AutoFille_Btn: {fileID: 3745291635547366485}
--- !u!1 &8136062125027934181
GameObject:
m_ObjectHideFlags: 0
......@@ -8560,6 +8548,10 @@ MonoBehaviour:
AllProcress: {fileID: 1667660345673518993}
AllProcress_Text: {fileID: 4457589912443491345}
OffSet_CLickMove: 35
bigvalue: 1
bigtime: 0.1
smalltime: 0.2
movetime: 0.3
--- !u!114 &9174292048928438190
MonoBehaviour:
m_ObjectHideFlags: 0
......
......@@ -31,7 +31,7 @@ public static class EventName
public const string Event_GroupListCreate = "Event_GroupListCreate";//加载组的数量
public const string Event_GropuItemChange = "Event_GropuItemChange";//某个组的进度改变
public const string Event_GroupItemClick = "Event_GroupItemClick";//点击某一个组
public const string Event_GroupItemSelect = "Event_GroupItemSelect";//选中某一个组
public const string Event_ChoiseGroupByPic = "Event_ChoiseGroupByPic"; //图片区域长按选择某一个组
public const string Event_AllGroupOver = "Event_AllGroupOver";//游戏结束,全部组都涂完了
......@@ -42,6 +42,7 @@ public static class EventName
public const string Event_ImageScallChange = "Event_ImageScallChange"; //图片的缩放改变
public const string Event_ReSetPicPos_Scale = "Event_ReSetPicPos_Scale"; //重新设置图片的位置和缩放
}
public class DataName
......
......@@ -21,6 +21,7 @@ public class ScaleToImage : MonoBehaviour
public float Min_Move;
public float Max_Move;
public HorizontalLayoutGroup group;
private Vector3 ToFigerCenter; //指向手指中间的向量
private float ToFigerdistance; //距离
......@@ -43,10 +44,12 @@ public class ScaleToImage : MonoBehaviour
private Vector3 OnInitScale; //初始化时的缩放
private Vector3 OnInitPos;
private int groupInitSize;
private void Start()
{
canvasCamera = transform.parent.GetComponent<ScaleToImage>().canvasCamera;
groupInitSize = group.padding.left;
RegisterEvent(true);
StartCoroutine(Delay());
}
......@@ -74,12 +77,13 @@ public class ScaleToImage : MonoBehaviour
private void Update()
{
#if UNITY_EDITOR
Editor_Scale();
return;
MouseScale();
#endif
if (Input.touchCount == 2)
{
RefreshScrollview();
Scale();
flag = true;
scrollRect.inertia = false;
......@@ -133,54 +137,76 @@ public class ScaleToImage : MonoBehaviour
}
}
private void Editor_Scale()
private void RefreshScrollview()
{
var mouse = Input.GetAxis("Mouse ScrollWheel");
if (mouse != 0) //向前,该放大
target.gameObject.SetActive(false);
target.gameObject.SetActive(true);
scrollRect.inertia = true;
}
private void StopScaleToSetSize()
{
if (ScaleSize_List.Count > 0)
{
ChangeFontSize(ScaleSize_List[ScaleSize_List.Count - 1]);
ScaleSize_List.Clear();
}
}
private void ChangeFontSize(float scalesize)
{
GameMgr.Ins.tiMgr.SizeChange(scalesize);
EventDispatcher.Dispatch(EventName.Event.Event_ImageScallChange, scalesize);
float value = groupInitSize / scalesize;
group.padding.left = (int)value;
group.padding.right = (int)value;
group.padding.top = (int)value;
group.padding.bottom = (int)value;
}
private void Scale()
{
if (!isInit_Scale)
{
SetscrollRectEnable(false);
var mouseposition = Input.mousePosition;
pos = canvasCamera.ScreenToWorldPoint(mouseposition);
pos = new Vector3(pos.x, pos.y, 0);
//两指点位
touch1 = canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position);
touch2 = canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position);
touch1 = new Vector3(touch1.x, touch1.y, 0);
touch2 = new Vector3(touch2.x, touch2.y, 0);
//图片的初始点位
oriPos = new Vector3(target.position.x, target.position.y, 0);
float distance = Vector2.Distance(touch1, touch2) / 2f;
var normal = (touch1 - touch2).normalized;
pos = normal * distance + touch2; //两个手指中间的点
//指向中心的单位向量
//指向手指中心的单位向量
ToFigerCenter = (pos - oriPos).normalized;
//距离
ToFigerdistance = Vector3.Distance(pos, oriPos);
oriScale = target.localScale.x;//开始的缩放值
isInit_Scale = true;
MoveValue = 1 / oriScale;
scale = mouse;
bool isBig = scale > 0;
float scale_target = 0;
//控制缩放速度
scale = scale * scaleSpeed; //正的话就是放大图片
OnScale(scale_target, isBig);
delaytime = 0;
RefreshScrollview();
}
else
{
if (delaytime >= 0.5f && !scrollRect.enabled)
{
SetscrollRectEnable(true);
}
else
{
delaytime += Time.deltaTime;
}
SatrtScale = target.localScale.x;
StartPos = target.position;
return;
}
}
float delaytime = 0;
private void OnScale(float scale_target, bool isBig)
{
//两指缩放比例
float nowdis = Vector3.Distance(canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position), canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position));
scale = nowdis / Vector3.Distance(touch1, touch2); //大于1是放大,小于是缩小
bool isBig = scale > 1;
float scale_target = 0;
//控制缩放速度
scale = (scale - 1) * scaleSpeed; //正的话就是放大图片
if (scale < 0)
{
scale = scale * oriScale * scaleSpeed; //缩小速度
......@@ -199,6 +225,10 @@ public class ScaleToImage : MonoBehaviour
}
scale_target = (Vector3.one * (oriScale + scale)).x;
if (scale_target < 0)
{
scale_target = MinScale;
}
Vector3 targetscale;
if (scale_target < MinScale)
......@@ -245,44 +275,29 @@ public class ScaleToImage : MonoBehaviour
ScaleSize_List.Clear();
ChangeFontSize(NowScale);
}
}
private void RefreshScrollview()
{
target.gameObject.SetActive(false);
target.gameObject.SetActive(true);
scrollRect.inertia = true;
}
private void StopScaleToSetSize()
private void MouseScale()
{
if (ScaleSize_List.Count > 0)
var mousepos = Input.mousePosition;
if (mousepos.x > Screen.width || mousepos.y > Screen.height || mousepos.x < 0 || mousepos.y < 0)
{
ChangeFontSize(ScaleSize_List[ScaleSize_List.Count - 1]);
ScaleSize_List.Clear();
return;
}
}
private void ChangeFontSize(float scalesize)
{
GameMgr.Ins.tiMgr.SizeChange(scalesize);
}
private void Scale()
{
if (!isInit_Scale)
var mouse = Input.GetAxis("Mouse ScrollWheel");
if (mouse != 0)
{
SetscrollRectEnable(false);
//两指点位
touch1 = canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position);
touch2 = canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position);
mousepos = canvasCamera.ScreenToWorldPoint(mousepos);
touch1 = new Vector3(touch1.x, touch1.y, 0);
touch2 = new Vector3(touch2.x, touch2.y, 0);
mousepos = new Vector3(mousepos.x, mousepos.y, 0);
//图片的初始点位
oriPos = new Vector3(target.position.x, target.position.y, 0);
float distance = Vector2.Distance(touch1, touch2) / 2f;
var normal = (touch1 - touch2).normalized;
pos = normal * distance + touch2; //两个手指中间的点
pos = mousepos;
//指向手指中心的单位向量
ToFigerCenter = (pos - oriPos).normalized;
......@@ -293,20 +308,70 @@ public class ScaleToImage : MonoBehaviour
isInit_Scale = true;
MoveValue = 1 / oriScale;
SatrtScale = target.localScale.x;
StartPos = target.position;
return;
}
//两指缩放比例
scale = mouse;
bool isBig = mouse > 0;
float scale_target = 0;
//两指缩放比例
float nowdis = Vector3.Distance(canvasCamera.ScreenToWorldPoint(Input.GetTouch(0).position), canvasCamera.ScreenToWorldPoint(Input.GetTouch(1).position));
scale = nowdis / Vector3.Distance(touch1, touch2); //大于1是放大,小于是缩小
bool isBig = scale > 1;
float scale_target = 0;
//控制缩放速度
scale = (scale) * scaleSpeed; //正的话就是放大图片
if (scale < 0)
{
scale = scale * oriScale * scaleSpeed; //缩小速度
OnScale(scale_target, isBig);
}
scale_target = (Vector3.one * (oriScale + scale)).x;
if (target.localScale.x < MinScale)
{
PlayAniFlag_Scale = true;
if (target.localScale.x > Min_Move)
target.localScale = Vector3.one * scale_target;
return;
}
}
scale_target = (Vector3.one * (oriScale + scale)).x;
if (scale_target < 0)
{
scale_target = MinScale;
}
Vector3 targetscale;
if (scale_target < MinScale)
{
targetscale = Vector3.one * scale_target;
target.localScale = targetscale;
ChangeFontSize(target.localScale.x);
ScaleSize_List.Clear();
return;
}
else if (scale_target > MaxScale)
{
targetscale = Vector3.one * (oriScale + scale);
PlayAniFlag_Scale = true;
}
else
{
targetscale = Vector3.one * (oriScale + scale);
}
target.localScale = targetscale;
//改变目标位置,让位置保持不变
var newpos = ToFigerCenter * (target.localScale.x - oriScale) * ToFigerdistance * MoveValue;
target.position = oriPos - newpos;
target.localPosition = new Vector3(target.localPosition.x, target.localPosition.y, 0);
NowScale = targetscale.x;
ChangeFontSize(NowScale);
SetscrollRectEnable(true);
RefreshScrollview();
}
}
private void SetscrollRectEnable(bool enable)
{
scrollRect.enabled = enable;
......
......@@ -8,16 +8,27 @@ public class Gameing : MonoBehaviour
{
public Button ReSetPos_Btn;
public float ShowBtnScale;//显示重设位置按钮的缩放值
public GameObject AutoFille_Btn; //自动涂色的按钮
// Start is called before the first frame update
void Start()
{
ResiterEvent(true);
ReSetPos_Btn.onClick.AddListener(ReSetPos_Btn_Click);
ReSetPos_Btn.gameObject.SetActive(false);
AutoFille_Btn.SetActive(false);
}
private void ResiterEvent(bool flag)
{
EventDispatcher.RegisterEvent(EventName.Event.Event_ImageScallChange,ChangeScale_Pic, flag);
EventDispatcher.RegisterEvent(EventName.Event.Event_GroupItemSelect, ShowAutoFill_Btn, flag);
}
private void ShowAutoFill_Btn(object[] values)
{
if (!AutoFille_Btn.activeSelf)
{
AutoFille_Btn.SetActive(true);
}
}
private void ChangeScale_Pic(object[] values)
......
......@@ -24,6 +24,7 @@ public class GroupListManager : MonoBehaviour
public TextMeshProUGUI AllProcress_Text; //百分比進度
public float OffSet_CLickMove = 35f;
private float AllAreaCount;
private float ClickAreaCount;
private List<colorItem> AllItem = new List<colorItem>();
......@@ -42,6 +43,19 @@ public class GroupListManager : MonoBehaviour
AllProcress_Text.gameObject.SetActive(true);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
var item = AllItem[1];
if (item != null)
{
RemoveAGroup(item);
}
}
}
private void ResiterEvent(bool flag)
{
EventDispatcher.RegisterEvent(EventName.Event.Event_GroupListCreate, CreateGroup, flag);
......@@ -80,6 +94,8 @@ public class GroupListManager : MonoBehaviour
item.IsSelect = true;
item.switchPlayAnimation();
EventDispatcher.Dispatch(EventName.Event.Event_GroupItemSelect);
}
}
......@@ -116,6 +132,7 @@ public class GroupListManager : MonoBehaviour
}
}
SetTotalProcress();
EventDispatcher.Dispatch(EventName.Event.Event_GroupItemSelect);
}
private void SetTotalProcress()
......@@ -125,60 +142,73 @@ public class GroupListManager : MonoBehaviour
AllProcress_Text.text = value.ToString("P0");
}
public float bigvalue=1;
public float bigtime=0.1f;
public float smalltime=0.2f;
public float movetime=0.3f;
private void RemoveAGroup(colorItem removeitem)
{
AllItem.Remove(removeitem);
removeitem.transform.DOScale(Vector3.zero, 0.3f).onComplete = () =>
Content.enabled = false;
Content.GetComponent<ContentSizeFitter>().enabled = false;
removeitem.transform.DOScale(Vector3.one * bigvalue, bigtime).onComplete = () =>
{
removeitem.gameObject.SetActive(false);
};
int NextItemIndex = 0;
float childsize = removeitem.transform.GetComponent<RectTransform>().sizeDelta.x;
removeitem.transform.DOScale(Vector3.zero, smalltime).onComplete = () =>
{
StartCoroutine(DelayToSetContent());
if (removeitem.index < AllItem.Count)
{
NextItemIndex = removeitem.index + 1;
}
else
{
NextItemIndex = AllItem.Count - 1;
removeitem.gameObject.SetActive(false);
int NextItemIndex = 0;
float childsize = removeitem.transform.GetComponent<RectTransform>().sizeDelta.x;
for (int i = 0; i < AllItem.Count; i++)
{
var ite = AllItem[i];
ite.transform.DOLocalMoveX(ite.transform.localPosition.x + childsize, 0.3f);
if (ite.index == NextItemIndex)
if (removeitem.index < AllItem.Count)
{
ite.IsSelect = true;
ite.switchPlayAnimation();
GameMgr.Ins.ChooseGroup(ite.GID);
NextItemIndex = removeitem.index + 1;
}
}
else
{
NextItemIndex = AllItem.Count - 1;
for (int i = 0; i < AllItem.Count; i++)
{
var ite = AllItem[i];
ite.transform.DOLocalMoveX(ite.transform.localPosition.x + childsize, movetime);
if (ite.index == NextItemIndex)
{
ite.IsSelect = true;
ite.switchPlayAnimation();
GameMgr.Ins.ChooseGroup(ite.GID);
}
}
return;
}
return;
}
for (int i = 0; i < AllItem.Count; i++)
{
var ite = AllItem[i];
if (ite.index > removeitem.index)
{
ite.transform.DOLocalMoveX(ite.transform.localPosition.x - childsize, 0.3f);
if (ite.index == NextItemIndex)
for (int i = 0; i < AllItem.Count; i++)
{
ite.IsSelect = true;
ite.switchPlayAnimation();
GameMgr.Ins.ChooseGroup(ite.GID);
var ite = AllItem[i];
if (ite.index > removeitem.index)
{
ite.transform.DOLocalMoveX(ite.transform.localPosition.x - childsize, movetime);
if (ite.index == NextItemIndex)
{
ite.IsSelect = true;
ite.switchPlayAnimation();
GameMgr.Ins.ChooseGroup(ite.GID);
}
ite.index--;
}
}
ite.index--;
}
}
};
};
}
IEnumerator DelayToSetContent()
{
yield return new WaitForSeconds(movetime);
Content.enabled = true;
Content.GetComponent<ContentSizeFitter>().enabled = true;
}
private void CreateGroup(object[] values)
{
AllAreaCount = 0;
......@@ -335,6 +365,8 @@ public class GroupListManager : MonoBehaviour
}
StartCoroutine(DelayToRefreshGrid());
EventDispatcher.Dispatch(EventName.Event.Event_GroupItemSelect);
}
IEnumerator DelayToRefreshGrid()
{
......
......@@ -2,6 +2,7 @@ using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
......@@ -66,8 +67,17 @@ public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
isSelect = value;
Select_CirCle.SetActive(isSelect);
JIndu_Wave.gameObject.SetActive(isSelect);
Jindu_NotWave.gameObject.SetActive(!isSelect);
if (NowProgress > 0)
{
JIndu_Wave.gameObject.SetActive(isSelect);
Jindu_NotWave.gameObject.SetActive(!isSelect);
}
else
{
JIndu_Wave.gameObject.SetActive(false);
Jindu_NotWave.gameObject.SetActive(true);
}
if (NowProgress > 0)
{
JIndu_Wave.PlayFlag = isSelect;
......@@ -82,10 +92,10 @@ public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
public void Init(Color color,float Jindu,int groupid)
{
IsSelect = false;
targetProgress = Jindu;
NowProgress = Jindu;
nowvalue = Jindu;
IsSelect = false;
UseColor = color;
GID = groupid;
IdName = groupid.ToString();
......@@ -127,6 +137,9 @@ public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
if (isSelect && value>0)
{
JIndu_Wave.PlayFlag = true;
JIndu_Wave.gameObject.SetActive(true);
Jindu_NotWave.gameObject.SetActive(false);
}
}
get
......
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