1 using System;
2 using
UnityEngine;
3
4 namespace
UnityStandardAssets.CrossPlatformInput.PlatformSpecific
5 {
6     
public class MobileInput : VirtualInput
7     {
8         
private void AddButton(string name)
9         {
10             
// we have not registered this button yet so add it, happens in the constructor
11             CrossPlatformInputManager.RegisterVirtualButton(
new CrossPlatformInputManager.VirtualButton(name));
12         }
13
14
15         
private void AddAxes(string name)
16         {
17             
// we have not registered this button yet so add it, happens in the constructor
18             CrossPlatformInputManager.RegisterVirtualAxis(
new CrossPlatformInputManager.VirtualAxis(name));
19         }
20
21
22         
public override float GetAxis(string name, bool raw)
23         {
24             
if (!m_VirtualAxes.ContainsKey(name))
25             {
26                 AddAxes(name);
27             }
28             
return m_VirtualAxes[name].GetValue;
29         }
30
31
32         
public override void SetButtonDown(string name)
33         {
34             
if (!m_VirtualButtons.ContainsKey(name))
35             {
36                 AddButton(name);
37             }
38             m_VirtualButtons[name].Pressed();
39         }
40
41
42         
public override void SetButtonUp(string name)
43         {
44             
if (!m_VirtualButtons.ContainsKey(name))
45             {
46                 AddButton(name);
47             }
48             m_VirtualButtons[name].Released();
49         }
50
51
52         
public override void SetAxisPositive(string name)
53         {
54             
if (!m_VirtualAxes.ContainsKey(name))
55             {
56                 AddAxes(name);
57             }
58             m_VirtualAxes[name].Update(
1f);
59         }
60
61
62         
public override void SetAxisNegative(string name)
63         {
64             
if (!m_VirtualAxes.ContainsKey(name))
65             {
66                 AddAxes(name);
67             }
68             m_VirtualAxes[name].Update(-
1f);
69         }
70
71
72         
public override void SetAxisZero(string name)
73         {
74             
if (!m_VirtualAxes.ContainsKey(name))
75             {
76                 AddAxes(name);
77             }
78             m_VirtualAxes[name].Update(
0f);
79         }
80
81
82         
public override void SetAxis(string name, float value)
83         {
84             
if (!m_VirtualAxes.ContainsKey(name))
85             {
86                 AddAxes(name);
87             }
88             m_VirtualAxes[name].Update(
value);
89         }
90
91
92         
public override bool GetButtonDown(string name)
93         {
94             
if (m_VirtualButtons.ContainsKey(name))
95             {
96                 
return m_VirtualButtons[name].GetButtonDown;
97             }
98
99             AddButton(name);
100             
return m_VirtualButtons[name].GetButtonDown;
101         }
102
103
104         
public override bool GetButtonUp(string name)
105         {
106             
if (m_VirtualButtons.ContainsKey(name))
107             {
108                 
return m_VirtualButtons[name].GetButtonUp;
109             }
110
111             AddButton(name);
112             
return m_VirtualButtons[name].GetButtonUp;
113         }
114
115
116         
public override bool GetButton(string name)
117         {
118             
if (m_VirtualButtons.ContainsKey(name))
119             {
120                 
return m_VirtualButtons[name].GetButton;
121             }
122
123             AddButton(name);
124             
return m_VirtualButtons[name].GetButton;
125         }
126
127
128         
public override Vector3 MousePosition()
129         {
130             
return virtualMousePosition;
131         }
132     }
133 }