Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
TouchView.cs
浏览该文件的文档.
1using CoreGraphics;
2using Engine;
3using Foundation;
4using UIKit;
5
6namespace SurvivalCraft.IOS {
7 class TouchView : UIView {
8 private UIView parent;
9 private float pixelScale;
10 Dictionary<UITouch, int> idMap = [];
11 private int globalId;
12 public TouchView(UIView parentView) {
13 parent = parentView;
14 Bounds = new CGRect(0, 0, Engine.Window.Size.X, Engine.Window.Size.Y);
15 pixelScale = (float)Bounds.Width / (float)parent.Bounds.Width;
16 MultipleTouchEnabled = true;
17 UserInteractionEnabled = true;
18 //禁止多个视图同时接收触摸
19 ExclusiveTouch = false;
20 globalId = 0;
21 }
22 public override void TouchesBegan(NSSet touches, UIEvent? evt) {
23 foreach (UITouch cc in touches.Cast<UITouch>()) {
24 var point = cc.LocationInView(parent);
25 int x = (int)(point.X * pixelScale);
26 int y = (int)(point.Y * pixelScale);
27 Vector2 vector = new Vector2(x, y);
28 idMap.Add(cc,++globalId);
30 //Console.WriteLine("[" + touches.GetHashCode() + "]touch start id:: " + globalId);
31 }
32 }
33 public override void TouchesMoved(NSSet touches, UIEvent? evt) {
34 foreach (UITouch cc in touches.Cast<UITouch>()) {
35 var point = cc.LocationInView(parent);
36 int x = (int)(point.X * pixelScale);
37 int y = (int)(point.Y * pixelScale);
38 Vector2 vector = new Vector2(x, y);
39 if (idMap.TryGetValue(cc, out int id)) {
41 //Console.WriteLine("[" + touches.GetHashCode() + "]touch move id:: " + id);
42 }
43 //else
44 // Console.WriteLine("Unknown touch move id::"+cc.GetHashCode());
45 }
46 }
47 public override void TouchesEnded(NSSet touches, UIEvent? evt) {
48 foreach (UITouch cc in touches.Cast<UITouch>()) {
49 var point = cc.LocationInView(parent);
50 int x = (int)(point.X * pixelScale);
51 int y = (int)(point.Y * pixelScale);
52 int processId = cc.GetHashCode();
53 Vector2 vector = new Vector2(x, y);
54 if(idMap.TryGetValue(cc,out int id)) {
56 //Console.WriteLine("[" + touches.GetHashCode() + "]touch end id:: " + id);
57 idMap.Remove(cc);
58 }
59 //else
60 // Console.WriteLine("Unknown touch move id::" + cc.GetHashCode());
61 }
62 }
63
64 public override void TouchesCancelled(NSSet touches, UIEvent? evt) {
66 }
67 }
68}
static void Clear()
static void ProcessTouchMoved(int id, Vector2 position)
static void ProcessTouchReleased(int id, Vector2 position)
static void ProcessTouchPressed(int id, Vector2 position)
static Point2 Size
override void TouchesMoved(NSSet touches, UIEvent? evt)
override void TouchesCancelled(NSSet touches, UIEvent? evt)
override void TouchesBegan(NSSet touches, UIEvent? evt)
override void TouchesEnded(NSSet touches, UIEvent? evt)
TouchView(UIView parentView)
Dictionary< UITouch, int > idMap