Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
T
tuseGameColor
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shujianhe
tuseGameColor
Commits
914f895e
Commit
914f895e
authored
Aug 12, 2023
by
JiangWanZhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整一下图片的缩放
parent
5d593044
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
414 additions
and
64 deletions
+414
-64
gameViewLogic.prefab
Assets/Resources/perfabs/gameViewLogic.prefab
+107
-45
gameScene.unity
Assets/Scenes/gameScene.unity
+246
-8
ScaleToImage.cs
Assets/scripts/ScaleToImage.cs
+58
-11
TagManager.asset
ProjectSettings/TagManager.asset
+3
-0
No files found.
Assets/Resources/perfabs/gameViewLogic.prefab
View file @
914f895e
This diff is collapsed.
Click to expand it.
Assets/Scenes/gameScene.unity
View file @
914f895e
This diff is collapsed.
Click to expand it.
Assets/scripts/ScaleToImage.cs
View file @
914f895e
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
)
//单指拖动
...
...
ProjectSettings/TagManager.asset
View file @
914f895e
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment