Transforms input from screen point to world point.
This commit is contained in:
12
Assets/Cryville/Common/Unity/Input/UnityCameraUtils.cs
Normal file
12
Assets/Cryville/Common/Unity/Input/UnityCameraUtils.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Unity.Input {
|
||||||
|
public static class UnityCameraUtils {
|
||||||
|
public static Vector2 ScreenToWorldPoint(Vector2 pos) {
|
||||||
|
Vector3 i = pos;
|
||||||
|
i.z = -Camera.main.transform.localPosition.z;
|
||||||
|
i = Camera.main.ScreenToWorldPoint(i);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Unity/Input/UnityCameraUtils.cs.meta
Normal file
11
Assets/Cryville/Common/Unity/Input/UnityCameraUtils.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 35a1c45601c39f94db20178505a68be2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -55,8 +55,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
void Update() {
|
void Update() {
|
||||||
double time = Time.timeAsDouble;
|
double time = Time.timeAsDouble;
|
||||||
Vector2 pos = unity::Input.mousePosition;
|
Vector3 pos = UnityCameraUtils.ScreenToWorldPoint(unity::Input.mousePosition);
|
||||||
pos.y = Screen.height - pos.y;
|
|
||||||
handler.Feed(0, 0, new InputVector(time, pos));
|
handler.Feed(0, 0, new InputVector(time, pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -57,8 +57,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
double time = Time.timeAsDouble;
|
double time = Time.timeAsDouble;
|
||||||
for (int i = 0; i < unity::Input.touchCount; i++) {
|
for (int i = 0; i < unity::Input.touchCount; i++) {
|
||||||
var t = unity::Input.GetTouch(i);
|
var t = unity::Input.GetTouch(i);
|
||||||
Vector2 pos = t.position;
|
Vector2 pos = UnityCameraUtils.ScreenToWorldPoint(t.position);
|
||||||
pos.y = Screen.height - pos.y;
|
|
||||||
var vec = new InputVector(time, pos);
|
var vec = new InputVector(time, pos);
|
||||||
if (t.phase == TouchPhase.Began || t.phase == TouchPhase.Stationary || t.phase == TouchPhase.Moved) {
|
if (t.phase == TouchPhase.Began || t.phase == TouchPhase.Stationary || t.phase == TouchPhase.Moved) {
|
||||||
handler.Feed(0, t.fingerId, vec);
|
handler.Feed(0, t.fingerId, vec);
|
||||||
|
@@ -214,7 +214,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
|
|
||||||
NativeMethods.POINT p = rawpinfo.ptPixelLocation;
|
NativeMethods.POINT p = rawpinfo.ptPixelLocation;
|
||||||
NativeMethods.ScreenToClient(hMainWindow, ref p);
|
NativeMethods.ScreenToClient(hMainWindow, ref p);
|
||||||
Vector2 _p = new Vector2(p.X, p.Y);
|
Vector2 _p = UnityCameraUtils.ScreenToWorldPoint(new Vector2(p.X, Screen.height - p.Y));
|
||||||
|
|
||||||
double time = (double)rawpinfo.PerformanceCount / freq;
|
double time = (double)rawpinfo.PerformanceCount / freq;
|
||||||
|
|
||||||
@@ -300,7 +300,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
Y = touch.y / 100
|
Y = touch.y / 100
|
||||||
};
|
};
|
||||||
NativeMethods.ScreenToClient(hMainWindow, ref p);
|
NativeMethods.ScreenToClient(hMainWindow, ref p);
|
||||||
Vector2 _p = new Vector2(p.X, p.Y);
|
Vector2 _p = UnityCameraUtils.ScreenToWorldPoint(new Vector2(p.X, Screen.height - p.Y));
|
||||||
|
|
||||||
/*Vector2? _cs = null;
|
/*Vector2? _cs = null;
|
||||||
if (touch.dwMask.HasFlag(NativeMethods.TOUCHINPUT_Mask.TOUCHINPUTMASKF_CONTACTAREA)) {
|
if (touch.dwMask.HasFlag(NativeMethods.TOUCHINPUT_Mask.TOUCHINPUTMASKF_CONTACTAREA)) {
|
||||||
|
Reference in New Issue
Block a user