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
4c7eff3e
Commit
4c7eff3e
authored
Jun 27, 2023
by
shujianhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
dad803f7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
248 additions
and
0 deletions
+248
-0
mainGameScaleMove.cs
Assets/scripts/common/mainGameScaleMove.cs
+237
-0
mainGameScaleMove.cs.meta
Assets/scripts/common/mainGameScaleMove.cs.meta
+11
-0
No files found.
Assets/scripts/common/mainGameScaleMove.cs
0 → 100644
View file @
4c7eff3e
using
System.Collections
;
using
System.Collections.Generic
;
using
Unity.VisualScripting
;
using
UnityEngine
;
delegate
void
CheckInput
();
public
class
mainGameScaleMove
:
MonoBehaviour
{
private
CheckInput
checkInput
=
null
;
private
Vector2
tempVector
=
new
Vector2
(
0
,
0
);
private
Vector2
defvalueVector
=
new
Vector2
(-
90000
,
-
90000
);
private
Vector2
nowScale
=
new
Vector2
();
private
Vector2
nowPos
=
new
Vector2
();
private
Vector2
nowSize
=
new
Vector2
();
private
bool
skipDoubleScale
=
false
;
public
float
OldTouchCurrDis
=
-
1000
;
public
float
minScale
=
0.25f
;
public
float
maxScale
=
8f
;
public
Vector2
NowPos
{
get
{
return
nowPos
;
}
}
public
Vector2
NowScale
{
get
{
return
nowScale
;
}
}
// Start is called before the first frame update
void
Start
()
{
setCheckInput
();
Vector3
tempVector3
;
Quaternion
quaternion
;
for
(
int
i
=
0
;
i
<
transform
.
childCount
;
i
++)
{
var
itemChild
=
transform
.
GetChild
(
i
);
itemChild
.
GetLocalPositionAndRotation
(
out
tempVector3
,
out
quaternion
);
itemChild
.
SetLocalPositionAndRotation
(
tempVector3
,
quaternion
);
if
(
i
==
0
)
{
nowPos
=
new
Vector2
(
tempVector3
.
x
,
tempVector3
.
y
);
nowScale
=
itemChild
.
localScale
;
Rect
rect
=
GetComponent
<
RectTransform
>().
rect
;
nowSize
=
new
Vector2
(
rect
.
width
,
rect
.
height
);
}
}
}
private
void
setCheckInput
()
{
if
(
checkInput
==
null
)
{
switch
(
Application
.
platform
)
{
case
RuntimePlatform
.
WindowsEditor
:
case
RuntimePlatform
.
WindowsPlayer
:
case
RuntimePlatform
.
WebGLPlayer
:
case
RuntimePlatform
.
OSXEditor
:
case
RuntimePlatform
.
OSXPlayer
:
checkInput
=
checkInputByComputer
;
break
;
case
RuntimePlatform
.
Android
:
case
RuntimePlatform
.
IPhonePlayer
:
checkInput
=
checkInputByPhone
;
break
;
default
:
checkInput
=
checkInputByPhone
;
break
;
}
}
}
void
checkInputByPhone
()
{
if
(
Input
.
touchCount
==
2
)
{
clearOneTouchBegin
();
Touch
touch1
=
Input
.
GetTouch
(
0
);
Touch
touch2
=
Input
.
GetTouch
(
1
);
if
(
touch1
.
phase
==
TouchPhase
.
Moved
||
touch2
.
phase
==
TouchPhase
.
Moved
)
{
if
(
skipDoubleScale
)
return
;
onDoubleTouchHandler
(
Vector2
.
Distance
(
touch1
.
position
,
touch2
.
position
));
}
else
{
OldTouchCurrDis
=
-
1000
;
}
skipDoubleScale
=
false
;
//else
//{
//}
}
else
if
(
Input
.
touchCount
==
1
)
{
var
oneTouch
=
Input
.
GetTouch
(
0
);
TouchPhase
touchPhase
=
oneTouch
.
phase
;
if
(
touchPhase
==
TouchPhase
.
Began
)
{
onOneTouchBegin
(
oneTouch
.
position
);
}
else
if
(
touchPhase
==
TouchPhase
.
Moved
)
{
onOneTouchMove
(
oneTouch
.
position
,
oneTouch
.
deltaPosition
);
}
else
if
(
touchPhase
==
TouchPhase
.
Ended
)
{
onOneTouchEnd
(
oneTouch
.
position
,
oneTouch
.
deltaPosition
);
}
else
if
(
touchPhase
==
TouchPhase
.
Canceled
)
{
clearOneTouchBegin
();
}
}
}
void
onDoubleTouchHandler
(
float
nowTouchDistance
)
{
if
(
OldTouchCurrDis
<
-
999
)
{
OldTouchCurrDis
=
nowTouchDistance
;
return
;
}
var
nowOffset
=
(
nowTouchDistance
-
OldTouchCurrDis
)
*
0.002f
;
if
(
nowOffset
<
0
)
{
if
(
nowScale
.
x
+
nowOffset
<
minScale
)
{
skipDoubleScale
=
true
;
nowOffset
=
0.8f
;
}
}
else
if
(
nowOffset
>
0
)
{
if
(
nowScale
.
x
+
nowOffset
>
maxScale
)
{
skipDoubleScale
=
true
;
return
;
}
}
nowScale
=
new
Vector2
(
nowScale
.
x
+
nowOffset
,
nowScale
.
y
+
nowOffset
)
;
OldTouchCurrDis
=
nowTouchDistance
;
for
(
int
i
=
0
;
i
<
transform
.
childCount
;
i
++)
{
var
itemChild
=
transform
.
GetChild
(
i
);
itemChild
.
localScale
=
nowScale
;
}
}
void
clearOneTouchBegin
()
{
utilsTools
.
delUserDataByKey
(
gameObject
,
"oneTouchBegin"
);
}
//左键点击 右键缩放
void
checkInputByComputer
()
{
////0 1 2 鼠标 左中右
//bool RDown = Input.GetMouseButtonDown(2);
//bool LDown = Input.GetMouseButtonDown(0);
//if (RDown == LDown && RDown == true)//当作双指滑动 制造缩放
//{
//}else if(RDown != LDown && LDown == true)
//{
// Vector3 mousePosition = Input.mousePosition;
// if (utilsTools.ContainsKey(gameObject, "oneTouchBegin") == false)
// onOneTouchBegin(new Vector2(mousePosition.x, mousePosition.y));
// else
// {
// }
//}else if(LDown == false){
// if (utilsTools.ContainsKey(gameObject, "oneTouchBegin") == false) return;
//}
}
private
void
onOneTouchBegin
(
Vector2
vector2
)
{
utilsTools
.
setUserData
(
gameObject
,
"oneTouchBegin"
,
vector2
);
}
private
void
onOneTouchMove
(
Vector2
nowPos
,
Vector2
delatPos
)
{
Vector3
tempVector3
=
new
Vector3
(
0
,
0
);
Quaternion
quaternion
=
new
Quaternion
();
for
(
int
i
=
0
;
i
<
transform
.
childCount
;
i
++)
{
var
itemChild
=
transform
.
GetChild
(
i
);
if
(
i
==
0
)
{
itemChild
.
GetLocalPositionAndRotation
(
out
tempVector3
,
out
quaternion
);
float
width
=
nowScale
.
x
*
nowSize
.
x
;
float
height
=
nowScale
.
y
*
nowSize
.
y
;
if
(
delatPos
.
x
<
0
&&
(
tempVector3
.
x
+
delatPos
.
x
)
<
(
width
/
-
2
))
{
delatPos
.
x
=
0
;
}
else
if
(
delatPos
.
x
>
0
&&
(
tempVector3
.
x
+
delatPos
.
x
)
>
(
width
/
2
))
{
delatPos
.
x
=
0
;
}
if
(
delatPos
.
y
<
0
&&
(
tempVector3
.
y
+
delatPos
.
y
)
<
(
height
/
-
2
))
{
delatPos
.
y
=
0
;
}
else
if
(
delatPos
.
y
>
0
&&
(
tempVector3
.
y
+
delatPos
.
y
)
>
(
height
/
2
))
{
delatPos
.
y
=
0
;
}
if
(
delatPos
.
x
==
delatPos
.
y
&&
delatPos
.
x
==
0
)
return
;
//都不用移动就不更新坐标
tempVector3
.
x
+=
delatPos
.
x
;
tempVector3
.
y
+=
delatPos
.
y
;
}
itemChild
.
SetLocalPositionAndRotation
(
tempVector3
,
quaternion
);
}
//更新坐标 应该记录当前显示的位置
}
private
void
onOneTouchEnd
(
Vector2
nowPos
,
Vector2
delatPos
)
{
utilsTools
.
getUserData
<
Vector2
>(
gameObject
,
"oneTouchBegin"
,
out
tempVector
,
defvalueVector
);
if
(
tempVector
.
Equals
(
defvalueVector
))
//说明之前已经移除了
{
return
;
}
float
sqrMagnitude
=
(
nowPos
-
defvalueVector
).
SqrMagnitude
();
clearOneTouchBegin
();
if
(
sqrMagnitude
>
20f
)
{
//按下和抬起距离太远就不算点击
return
;
}
onOneClick
(
nowPos
);
}
private
void
onOneClick
(
Vector2
nowPos
)
{
print
(
"点击>>>>"
+
nowPos
.
ToString
());
}
// Update is called once per frame
void
Update
()
{
setCheckInput
();
checkInput
();
}
}
Assets/scripts/common/mainGameScaleMove.cs.meta
0 → 100644
View file @
4c7eff3e
fileFormatVersion: 2
guid: c3deb1e6e6112304d918d673de43ccc6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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