SteamVR_Input_BindingFile.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Valve.Newtonsoft.Json;
  7. using System.IO;
  8. namespace Valve.VR
  9. {
  10. [System.Serializable]
  11. public class SteamVR_Input_BindingFile
  12. {
  13. public string app_key;
  14. public Dictionary<string, SteamVR_Input_BindingFile_ActionList> bindings = new Dictionary<string, SteamVR_Input_BindingFile_ActionList>();
  15. public string controller_type;
  16. public string description;
  17. public string name;
  18. }
  19. [System.Serializable]
  20. public class SteamVR_Input_BindingFile_ActionList
  21. {
  22. public List<SteamVR_Input_BindingFile_Chord> chords = new List<SteamVR_Input_BindingFile_Chord>();
  23. public List<SteamVR_Input_BindingFile_Pose> poses = new List<SteamVR_Input_BindingFile_Pose>();
  24. public List<SteamVR_Input_BindingFile_Haptic> haptics = new List<SteamVR_Input_BindingFile_Haptic>();
  25. public List<SteamVR_Input_BindingFile_Source> sources = new List<SteamVR_Input_BindingFile_Source>();
  26. public List<SteamVR_Input_BindingFile_Skeleton> skeleton = new List<SteamVR_Input_BindingFile_Skeleton>();
  27. }
  28. [System.Serializable]
  29. public class SteamVR_Input_BindingFile_Chord
  30. {
  31. public string output;
  32. public List<List<string>> inputs = new List<List<string>>();
  33. public override bool Equals(object obj)
  34. {
  35. if (obj is SteamVR_Input_BindingFile_Chord)
  36. {
  37. SteamVR_Input_BindingFile_Chord chord = (SteamVR_Input_BindingFile_Chord)obj;
  38. if (this.output == chord.output && this.inputs != null && chord.inputs != null)
  39. {
  40. if (this.inputs.Count == chord.inputs.Count)
  41. {
  42. for (int thisIndex = 0; thisIndex < this.inputs.Count; thisIndex++)
  43. {
  44. if (this.inputs[thisIndex] != null && chord.inputs[thisIndex] != null && this.inputs[thisIndex].Count == chord.inputs[thisIndex].Count)
  45. {
  46. for (int thisSubIndex = 0; thisSubIndex < this.inputs[thisIndex].Count; thisSubIndex++)
  47. {
  48. if (this.inputs[thisIndex][thisSubIndex] != chord.inputs[thisIndex][thisSubIndex])
  49. {
  50. return false;
  51. }
  52. }
  53. return true;
  54. }
  55. }
  56. }
  57. }
  58. return false;
  59. }
  60. return base.Equals(obj);
  61. }
  62. public override int GetHashCode()
  63. {
  64. return base.GetHashCode();
  65. }
  66. }
  67. [System.Serializable]
  68. public class SteamVR_Input_BindingFile_Pose
  69. {
  70. public string output;
  71. public string path;
  72. public override bool Equals(object obj)
  73. {
  74. if (obj is SteamVR_Input_BindingFile_Pose)
  75. {
  76. SteamVR_Input_BindingFile_Pose pose = (SteamVR_Input_BindingFile_Pose)obj;
  77. if (pose.output == this.output && pose.path == this.path)
  78. return true;
  79. return false;
  80. }
  81. return base.Equals(obj);
  82. }
  83. public override int GetHashCode()
  84. {
  85. return base.GetHashCode();
  86. }
  87. }
  88. [System.Serializable]
  89. public class SteamVR_Input_BindingFile_Haptic
  90. {
  91. public string output;
  92. public string path;
  93. public override bool Equals(object obj)
  94. {
  95. if (obj is SteamVR_Input_BindingFile_Haptic)
  96. {
  97. SteamVR_Input_BindingFile_Haptic pose = (SteamVR_Input_BindingFile_Haptic)obj;
  98. if (pose.output == this.output && pose.path == this.path)
  99. return true;
  100. return false;
  101. }
  102. return base.Equals(obj);
  103. }
  104. public override int GetHashCode()
  105. {
  106. return base.GetHashCode();
  107. }
  108. }
  109. [System.Serializable]
  110. public class SteamVR_Input_BindingFile_Skeleton
  111. {
  112. public string output;
  113. public string path;
  114. public override bool Equals(object obj)
  115. {
  116. if (obj is SteamVR_Input_BindingFile_Skeleton)
  117. {
  118. SteamVR_Input_BindingFile_Skeleton pose = (SteamVR_Input_BindingFile_Skeleton)obj;
  119. if (pose.output == this.output && pose.path == this.path)
  120. return true;
  121. return false;
  122. }
  123. return base.Equals(obj);
  124. }
  125. public override int GetHashCode()
  126. {
  127. return base.GetHashCode();
  128. }
  129. }
  130. [System.Serializable]
  131. public class SteamVR_Input_BindingFile_Source
  132. {
  133. public string path;
  134. public string mode;
  135. public SteamVR_Input_BindingFile_Source_Input_StringDictionary parameters = new SteamVR_Input_BindingFile_Source_Input_StringDictionary();
  136. public SteamVR_Input_BindingFile_Source_Input inputs = new SteamVR_Input_BindingFile_Source_Input();
  137. protected const string outputKeyName = "output";
  138. public string GetOutput()
  139. {
  140. foreach (var input in inputs)
  141. {
  142. foreach (var entry in input.Value)
  143. {
  144. if (entry.Key == outputKeyName)
  145. {
  146. return entry.Value;
  147. }
  148. }
  149. }
  150. return null;
  151. }
  152. public override bool Equals(object obj)
  153. {
  154. if (obj is SteamVR_Input_BindingFile_Source)
  155. {
  156. SteamVR_Input_BindingFile_Source pose = (SteamVR_Input_BindingFile_Source)obj;
  157. if (pose.mode == this.mode && pose.path == this.path)
  158. {
  159. bool parametersEqual = false;
  160. if (parameters != null && pose.parameters != null)
  161. {
  162. if (this.parameters.Equals(pose.parameters))
  163. parametersEqual = true;
  164. }
  165. else if (parameters == null && pose.parameters == null)
  166. parametersEqual = true;
  167. if (parametersEqual)
  168. {
  169. bool inputsEqual = false;
  170. if (inputs != null && pose.inputs != null)
  171. {
  172. if (this.inputs.Equals(pose.inputs))
  173. inputsEqual = true;
  174. }
  175. else if (inputs == null && pose.inputs == null)
  176. inputsEqual = true;
  177. return inputsEqual;
  178. }
  179. }
  180. return false;
  181. }
  182. return base.Equals(obj);
  183. }
  184. public override int GetHashCode()
  185. {
  186. return base.GetHashCode();
  187. }
  188. }
  189. [System.Serializable]
  190. public class SteamVR_Input_BindingFile_Source_Input : Dictionary<string, SteamVR_Input_BindingFile_Source_Input_StringDictionary>
  191. {
  192. public override bool Equals(object obj)
  193. {
  194. if (obj is SteamVR_Input_BindingFile_Source_Input)
  195. {
  196. SteamVR_Input_BindingFile_Source_Input sourceInput = (SteamVR_Input_BindingFile_Source_Input)obj;
  197. if (this == sourceInput)
  198. return true;
  199. else
  200. {
  201. if (this.Count == sourceInput.Count)
  202. {
  203. foreach (var element in this)
  204. {
  205. if (sourceInput.ContainsKey(element.Key) == false)
  206. return false;
  207. if (this[element.Key].Equals(sourceInput[element.Key]) == false)
  208. return false;
  209. }
  210. return true;
  211. }
  212. }
  213. }
  214. return base.Equals(obj);
  215. }
  216. public override int GetHashCode()
  217. {
  218. return base.GetHashCode();
  219. }
  220. }
  221. [System.Serializable]
  222. public class SteamVR_Input_BindingFile_Source_Input_StringDictionary : Dictionary<string, string>
  223. {
  224. public override bool Equals(object obj)
  225. {
  226. if (obj is SteamVR_Input_BindingFile_Source_Input_StringDictionary)
  227. {
  228. SteamVR_Input_BindingFile_Source_Input_StringDictionary stringDictionary = (SteamVR_Input_BindingFile_Source_Input_StringDictionary)obj;
  229. if (this == stringDictionary)
  230. return true;
  231. return (this.Count == stringDictionary.Count && !this.Except(stringDictionary).Any());
  232. }
  233. return base.Equals(obj);
  234. }
  235. public override int GetHashCode()
  236. {
  237. return base.GetHashCode();
  238. }
  239. }
  240. }