1 using System;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5
6 namespace
UnityStandardAssets.CrossPlatformInput
7 {
8     
public abstract class VirtualInput
9     {
10         
public Vector3 virtualMousePosition { get; private set; }
11         
12         
13         
protected Dictionary<string, CrossPlatformInputManager.VirtualAxis> m_VirtualAxes =
14             
new Dictionary<string, CrossPlatformInputManager.VirtualAxis>();
15             
// Dictionary to store the name relating to the virtual axes
16         
protected Dictionary<string, CrossPlatformInputManager.VirtualButton> m_VirtualButtons =
17             
new Dictionary<string, CrossPlatformInputManager.VirtualButton>();
18         
protected List<string> m_AlwaysUseVirtual = new List<string>();
19             
// list of the axis and button names that have been flagged to always use a virtual axis or button
20         
21
22         
public bool AxisExists(string name)
23         {
24             
return m_VirtualAxes.ContainsKey(name);
25         }
26
27         
public bool ButtonExists(string name)
28         {
29             
return m_VirtualButtons.ContainsKey(name);
30         }
31
32
33         
public void RegisterVirtualAxis(CrossPlatformInputManager.VirtualAxis axis)
34         {
35             
// check if we already have an axis with that name and log and error if we do
36             
if (m_VirtualAxes.ContainsKey(axis.name))
37             {
38                 Debug.LogError(
"There is already a virtual axis named " + axis.name + " registered.");
39             }
40             
else
41             {
42                 
// add any new axes
43                 m_VirtualAxes.Add(axis.name, axis);
44
45                 
// if we dont want to match with the input manager setting then revert to always using virtual
46                 
if (!axis.matchWithInputManager)
47                 {
48                     m_AlwaysUseVirtual.Add(axis.name);
49                 }
50             }
51         }
52
53
54         
public void RegisterVirtualButton(CrossPlatformInputManager.VirtualButton button)
55         {
56             
// check if already have a buttin with that name and log an error if we do
57             
if (m_VirtualButtons.ContainsKey(button.name))
58             {
59                 Debug.LogError(
"There is already a virtual button named " + button.name + " registered.");
60             }
61             
else
62             {
63                 
// add any new buttons
64                 m_VirtualButtons.Add(button.name, button);
65
66                 
// if we dont want to match to the input manager then always use a virtual axis
67                 
if (!button.matchWithInputManager)
68                 {
69                     m_AlwaysUseVirtual.Add(button.name);
70                 }
71             }
72         }
73
74
75         
public void UnRegisterVirtualAxis(string name)
76         {
77             
// if we have an axis with that name then remove it from our dictionary of registered axes
78             
if (m_VirtualAxes.ContainsKey(name))
79             {
80                 m_VirtualAxes.Remove(name);
81             }
82         }
83
84
85         
public void UnRegisterVirtualButton(string name)
86         {
87             
// if we have a button with this name then remove it from our dictionary of registered buttons
88             
if (m_VirtualButtons.ContainsKey(name))
89             {
90                 m_VirtualButtons.Remove(name);
91             }
92         }
93
94
95         
// returns a reference to a named virtual axis if it exists otherwise null
96         
public CrossPlatformInputManager.VirtualAxis VirtualAxisReference(string name)
97         {
98             
return m_VirtualAxes.ContainsKey(name) ? m_VirtualAxes[name] : null;
99         }
100
101
102         
public void SetVirtualMousePositionX(float f)
103         {
104             virtualMousePosition =
new Vector3(f, virtualMousePosition.y, virtualMousePosition.z);
105         }
106
107
108         
public void SetVirtualMousePositionY(float f)
109         {
110             virtualMousePosition =
new Vector3(virtualMousePosition.x, f, virtualMousePosition.z);
111         }
112
113
114         
public void SetVirtualMousePositionZ(float f)
115         {
116             virtualMousePosition =
new Vector3(virtualMousePosition.x, virtualMousePosition.y, f);
117         }
118
119
120         
public abstract float GetAxis(string name, bool raw);
121         
122         
public abstract bool GetButton(string name);
123         
public abstract bool GetButtonDown(string name);
124         
public abstract bool GetButtonUp(string name);
125
126         
public abstract void SetButtonDown(string name);
127         
public abstract void SetButtonUp(string name);
128         
public abstract void SetAxisPositive(string name);
129         
public abstract void SetAxisNegative(string name);
130         
public abstract void SetAxisZero(string name);
131         
public abstract void SetAxis(string name, float value);
132         
public abstract Vector3 MousePosition();
133     }
134 }


Tìm kết quả nhanh