Skip to content

Commit 694e4bd

Browse files
committed
fix: Calculate canvas scale factor
1 parent 7f2c0c9 commit 694e4bd

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

Assets/JCSUnity/Scripts/Input/JCS_MobileMouseEvent.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class JCS_MobileMouseEvent : JCS_Instance<JCS_MobileMouseEvent>
4444

4545
/* Setter & Getter */
4646

47-
public float RaycastDistance { get { return this.mRaycastDistance; } set { this.mRaycastDistance = value; } }
47+
public float raycastDistance { get { return this.mRaycastDistance; } set { this.mRaycastDistance = value; } }
4848

4949
/* Functions */
5050

@@ -56,7 +56,7 @@ private void Awake()
5656
private void Start()
5757
{
5858
if (mCamera == null)
59-
this.mCamera = JCS_Camera.main.GetCamera();
59+
mCamera = JCS_Camera.main.GetCamera();
6060
}
6161

6262
private void Update()
@@ -163,7 +163,7 @@ private void Handle_UpOver()
163163

164164
if (im.Support_OnMouseUp)
165165
{
166-
if (mTouchedLastFrame && !ti.Touched)
166+
if (mTouchedLastFrame && !ti.touched)
167167
_SendMessage(obj, "OnMouseUp");
168168
}
169169

@@ -181,7 +181,7 @@ private void Handle_DownDrag()
181181
var im = JCS_InputManager.FirstInstance();
182182
var ti = JCS_TouchInput.FirstInstance();
183183

184-
if (!ti.Touched)
184+
if (!ti.touched)
185185
{
186186
this.mTouchedLastFrame = false;
187187
return;
@@ -200,7 +200,7 @@ private void Handle_DownDrag()
200200

201201
GameObject obj = hit.transform.gameObject;
202202

203-
if (ti.Touched)
203+
if (ti.touched)
204204
{
205205
if (im.Support_OnMouseDown)
206206
{
@@ -210,7 +210,7 @@ private void Handle_DownDrag()
210210

211211
if (im.Support_OnMouseDrag)
212212
{
213-
if (ti.DeltaPos != Vector2.zero)
213+
if (ti.deltaPos != Vector2.zero)
214214
_SendMessage(obj, "OnMouseDrag");
215215
}
216216
}

Assets/JCSUnity/Scripts/Input/JCS_TouchInput.cs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ public class JCS_TouchInput : JCS_Instance<JCS_TouchInput>
100100

101101
/* Setter & Getter */
102102

103-
public bool Touched { get { return this.mTouched; } }
104-
public Vector2 DeltaPos { get { return this.mDeltaPos; } }
105-
public Vector2 DragDistance { get { return this.mDragDistance; } }
106-
public Vector2 DragDisplacement { get { return this.mDragDisplacement; } }
107-
public bool Dragging { get { return this.mDragging; } }
108-
public float TouchTime { get { return this.mTouchTime; } }
103+
public bool touched { get { return this.mTouched; } }
104+
public Vector2 deltaPos { get { return this.mDeltaPos; } }
105+
public Vector2 dragDistance { get { return this.mDragDistance; } }
106+
public Vector2 dragDisplacement { get { return this.mDragDisplacement; } }
107+
public bool dragging { get { return this.mDragging; } }
108+
public float touchTime { get { return this.mTouchTime; } }
109109
#if (UNITY_ANDROID || UNITY_IPHIONE || UNITY_IOS)
110-
public bool MultiTouch { get { return this.mMultiTouch; } }
111-
public float TouchDistance { get { return this.mTouchDistance; } }
112-
public float TouchDistanceDelta { get { return this.mTouchDistanceDelta; } }
113-
public int DetectTouchCount { get { return this.mDetectTouchCount; } set { this.mDetectTouchCount = value; } }
110+
public bool multiTouch { get { return this.mMultiTouch; } }
111+
public float touchDistance { get { return this.mTouchDistance; } }
112+
public float touchDistanceDelta { get { return this.mTouchDistanceDelta; } }
113+
public int detectTouchCount { get { return this.mDetectTouchCount; } set { this.mDetectTouchCount = value; } }
114114
#else
115115
public JCS_MouseButton MouseType { get { return this.mMouseType; } set { this.mMouseType = value; } }
116116
#endif
@@ -176,21 +176,29 @@ private void WhenTouched()
176176

177177
if (mDeltaPos == Vector2.zero && mDragDistance == Vector2.zero)
178178
{
179-
this.mDragStartPosition = currPos;
179+
mDragStartPosition = currPos;
180180
}
181181
else
182182
{
183-
this.mDragging = true;
183+
mDragging = true;
184184
Vector2 dragEndPosition = currPos;
185185

186-
this.mDragDistance.x = JCS_Mathf.DistanceOfUnitVector(mDragStartPosition.x, dragEndPosition.x);
187-
this.mDragDistance.y = JCS_Mathf.DistanceOfUnitVector(mDragStartPosition.y, dragEndPosition.y);
186+
mDragDistance.x = JCS_Mathf.DistanceOfUnitVector(mDragStartPosition.x, dragEndPosition.x);
187+
mDragDistance.y = JCS_Mathf.DistanceOfUnitVector(mDragStartPosition.y, dragEndPosition.y);
188+
189+
// 標準視窗的變動係數.
190+
{
191+
float scaleFactor = JCS_Canvas.SCALE_FACTOR;
192+
193+
mDragDistance.x /= scaleFactor;
194+
mDragDistance.y /= scaleFactor;
195+
}
188196

189197
float xDiff = dragEndPosition.x - mDragStartPosition.x;
190198
float yDiff = dragEndPosition.y - mDragStartPosition.y;
191199

192-
this.mDragDisplacement.x = mDragDistance.x * JCS_Mathf.GetSign(xDiff);
193-
this.mDragDisplacement.y = mDragDistance.y * JCS_Mathf.GetSign(yDiff);
200+
mDragDisplacement.x = mDragDistance.x * JCS_Mathf.GetSign(xDiff);
201+
mDragDisplacement.y = mDragDistance.y * JCS_Mathf.GetSign(yDiff);
194202
}
195203

196204
#if (UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL)

0 commit comments

Comments
 (0)