AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ProjectSettingsWindow.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using System.Collections.Generic;
6 using System.IO;
7 using System.Text.RegularExpressions;
8 using UnityEditor;
9 using UnityEngine;
10 using UnityEngine.Networking;
11 
12 namespace HoloToolkit.Unity
13 {
17  public class ProjectSettingsWindow : AutoConfigureWindow<ProjectSettingsWindow.ProjectSetting>
18  {
19  private const int SpatialMappingLayerId = 31;
20  private const string SpatialMappingLayerName = "Spatial Mapping";
21 
22  private const string SharingServiceURL = "https://raw.githubusercontent.com/Microsoft/MixedRealityToolkit-Unity/master/External/HoloToolkit/Sharing/Server/SharingService.exe";
23 
27  private List<string> axisNames = new List<string>();
28 
32  private SerializedObject inputManagerAsset;
33 
37  private readonly InputManagerAxis[] newInputAxes =
38  {
39  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_LEFT_STICK_HORIZONTAL, Dead = 0.19f, Sensitivity = 1, Invert = false, Type = AxisType.JoystickAxis, Axis = 1 },
40  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_LEFT_STICK_VERTICAL, Dead = 0.19f, Sensitivity = 1, Invert = true, Type = AxisType.JoystickAxis, Axis = 2 },
41  new InputManagerAxis() { Name = InputMappingAxisUtility.XBOX_SHARED_TRIGGER, Dead = 0.19f, Sensitivity = 1, Invert = false, Type = AxisType.JoystickAxis, Axis = 3 },
42  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_RIGHT_STICK_HORIZONTAL, Dead = 0.19f, Sensitivity = 1, Invert = false, Type = AxisType.JoystickAxis, Axis = 4 },
43  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_RIGHT_STICK_VERTICAL, Dead = 0.19f, Sensitivity = 1, Invert = true, Type = AxisType.JoystickAxis, Axis = 5 },
44  new InputManagerAxis() { Name = InputMappingAxisUtility.XBOX_DPAD_HORIZONTAL, Dead = 0.19f, Sensitivity = 1, Invert = false, Type = AxisType.JoystickAxis, Axis = 6 },
45  new InputManagerAxis() { Name = InputMappingAxisUtility.XBOX_DPAD_VERTICAL, Dead = 0.19f, Sensitivity = 1, Invert = false, Type = AxisType.JoystickAxis, Axis = 7 },
46  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_LEFT_TRIGGER, Dead = 0.19f, Sensitivity = 1, Invert = false, Type = AxisType.JoystickAxis, Axis = 9 },
47  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_RIGHT_TRIGGER, Dead = 0.19f, Sensitivity = 1, Invert = false, Type = AxisType.JoystickAxis, Axis = 10 },
48 
49  new InputManagerAxis() { Name = InputMappingAxisUtility.XBOX_A, PositiveButton = "joystick button 0", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
50  new InputManagerAxis() { Name = InputMappingAxisUtility.XBOX_B, PositiveButton = "joystick button 1", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
51  new InputManagerAxis() { Name = InputMappingAxisUtility.XBOX_X, PositiveButton = "joystick button 2", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
52  new InputManagerAxis() { Name = InputMappingAxisUtility.XBOX_Y, PositiveButton = "joystick button 3", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
53  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_LEFT_BUMPER_OR_GRIP, PositiveButton = "joystick button 4", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
54  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_RIGHT_BUMPER_OR_GRIP, PositiveButton = "joystick button 5", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
55  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_LEFT_MENU, PositiveButton = "joystick button 6", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
56  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_RIGHT_MENU, PositiveButton = "joystick button 7", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
57  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_LEFT_STICK_CLICK, PositiveButton = "joystick button 8", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
58  new InputManagerAxis() { Name = InputMappingAxisUtility.CONTROLLER_RIGHT_STICK_CLICK, PositiveButton = "joystick button 9", Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = AxisType.KeyOrMouseButton, Axis = 1 },
59  };
60 
64  private readonly InputManagerAxis[] obsoleteInputAxes = { };
65 
66  private bool updateToolkitAxes;
67 
68  #region Nested Types
69 
70  public enum ProjectSetting
71  {
72  BuildWsaUwp = 0,
73  WsaEnableXR,
74  WsaUwpBuildToD3D,
75  TargetOccludedDevices,
76  SharingServices,
77  UseInputManagerAxes,
78  DotNetScriptingBackend,
79  SetDefaultSpatialMappingLayer
80  }
81 
85  private enum AxisType
86  {
87  KeyOrMouseButton = 0,
88  MouseMovement,
89  JoystickAxis
90  };
91 
95  private class InputManagerAxis
96  {
97  public string Name = "";
98  public string DescriptiveName = "";
99  public string DescriptiveNegativeName = "";
100  public string NegativeButton = "";
101  public string PositiveButton = "";
102  public string AltNegativeButton = "";
103  public string AltPositiveButton = "";
104  public float Gravity = 0.0f;
105  public float Dead = 0.0f;
106  public float Sensitivity = 0.0f;
107  public bool Snap = false;
108  public bool Invert = false;
109  public AxisType Type = default(AxisType);
110  public int Axis = 0;
111  public int JoyNum = 0;
112  }
113 
114  #endregion // Nested Types
115 
116  #region Overrides / Event Handlers
117 
118  protected override void ApplySettings()
119  {
120  SaveMenuSettings();
121 
122  // Apply individual settings
123  if (Values[ProjectSetting.BuildWsaUwp])
124  {
125  if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.WSAPlayer)
126  {
127 #if UNITY_2017_1_OR_NEWER
128  EditorUserBuildSettings.SwitchActiveBuildTargetAsync(BuildTargetGroup.WSA, BuildTarget.WSAPlayer);
129 #else
130  EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WSA, BuildTarget.WSAPlayer);
131 #endif
132  }
133  else
134  {
135  UpdateSettings(EditorUserBuildSettings.activeBuildTarget);
136  }
137  }
138  else
139  {
140  EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64);
141  }
142  }
143 
144  protected override void LoadSettings()
145  {
146  for (int i = (int)ProjectSetting.BuildWsaUwp; i <= (int)ProjectSetting.SetDefaultSpatialMappingLayer; i++)
147  {
148  switch ((ProjectSetting)i)
149  {
150  case ProjectSetting.BuildWsaUwp:
151  case ProjectSetting.WsaEnableXR:
152  case ProjectSetting.WsaUwpBuildToD3D:
153  case ProjectSetting.DotNetScriptingBackend:
154  case ProjectSetting.SetDefaultSpatialMappingLayer:
155  Values[(ProjectSetting)i] = EditorPrefsUtility.GetEditorPref(Names[(ProjectSetting)i], true);
156  break;
157  case ProjectSetting.TargetOccludedDevices:
158  Values[(ProjectSetting)i] = EditorPrefsUtility.GetEditorPref(Names[(ProjectSetting)i], false);
159  break;
160  case ProjectSetting.SharingServices:
161  Values[(ProjectSetting)i] = EditorPrefsUtility.GetEditorPref(Names[(ProjectSetting)i], false);
162  break;
163  case ProjectSetting.UseInputManagerAxes:
164  Values[(ProjectSetting)i] = EditorPrefsUtility.GetEditorPref(Names[(ProjectSetting)i], false);
165  break;
166  default:
167  throw new ArgumentOutOfRangeException();
168  }
169  }
170  }
171 
172  private void UpdateSettings(BuildTarget currentBuildTarget)
173  {
174  if (Values[ProjectSetting.SharingServices])
175  {
176  string sharingServiceDirectory = Directory.GetParent(Path.GetFullPath(Application.dataPath)).FullName + "\\External\\HoloToolkit\\Sharing\\Server";
177  string sharingServicePath = sharingServiceDirectory + "\\SharingService.exe";
178  if (!File.Exists(sharingServicePath) &&
179  EditorUtility.DisplayDialog("Attention!",
180  "You're missing the Sharing Service Executable in your project.\n\n" +
181  "Would you like to download the missing files from GitHub?\n\n" +
182  "Alternatively, you can download it yourself or specify a target IP to connect to at runtime on the Sharing Stage.",
183  "Yes", "Cancel"))
184  {
185  using (var webRequest = UnityWebRequest.Get(SharingServiceURL))
186  {
187 #if UNITY_2017_2_OR_NEWER
188  webRequest.SendWebRequest();
189 #else
190  webRequest.Send();
191 #endif
192  while (!webRequest.isDone)
193  {
194  if (webRequest.downloadProgress > -1)
195  {
196  EditorUtility.DisplayProgressBar(
197  "Downloading the SharingService executable from GitHub",
198  "Progress...", webRequest.downloadProgress);
199  }
200  }
201 
202  EditorUtility.ClearProgressBar();
203 
204 #if UNITY_2017_1_OR_NEWER
205  if (webRequest.isNetworkError || webRequest.isHttpError)
206 #else
207  if (webRequest.isError)
208 #endif
209  {
210  Debug.LogError("Network Error: " + webRequest.error);
211  }
212  else
213  {
214  byte[] sharingServiceData = webRequest.downloadHandler.data;
215  Directory.CreateDirectory(sharingServiceDirectory);
216  File.WriteAllBytes(sharingServicePath, sharingServiceData);
217  }
218  }
219  }
220  else
221  {
222  Debug.LogFormat("Alternatively, you can download from this link: {0}", SharingServiceURL);
223  }
224 
225  PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.InternetClientServer, true);
226  PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.PrivateNetworkClientServer, true);
227  }
228  else
229  {
230  PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.InternetClient, false);
231  PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.InternetClientServer, false);
232  PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.PrivateNetworkClientServer, false);
233  }
234 
235  if (updateToolkitAxes)
236  {
237  bool useToolkitAxes = Values[ProjectSetting.UseInputManagerAxes];
238 
239  // Grabs the actual asset file into a SerializedObject, so we can iterate through it and edit it.
240  inputManagerAsset = new SerializedObject(AssetDatabase.LoadAssetAtPath("ProjectSettings/InputManager.asset", typeof(UnityEngine.Object)));
241 
242  if (useToolkitAxes)
243  {
244  foreach (InputManagerAxis axis in newInputAxes)
245  {
246  if (!DoesAxisNameExist(axis.Name))
247  {
248  AddAxis(axis);
249  }
250  }
251 
252  }
253  else
254  {
255  foreach (InputManagerAxis axis in newInputAxes)
256  {
257  if (DoesAxisNameExist(axis.Name))
258  {
259  RemoveAxis(axis.Name);
260  }
261  }
262 
263  foreach (InputManagerAxis axis in obsoleteInputAxes)
264  {
265  if (DoesAxisNameExist(axis.Name))
266  {
267  RemoveAxis(axis.Name);
268  }
269  }
270  }
271 
272  inputManagerAsset.ApplyModifiedProperties();
273  }
274 
275  if (currentBuildTarget != BuildTarget.WSAPlayer)
276  {
277  AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
278  Close();
279  return;
280  }
281 
282  EditorUserBuildSettings.wsaUWPBuildType = Values[ProjectSetting.WsaUwpBuildToD3D]
283  ? WSAUWPBuildType.D3D
284  : WSAUWPBuildType.XAML;
285 
286  UnityEditorInternal.VR.VREditor.SetVREnabledOnTargetGroup(BuildTargetGroup.WSA, Values[ProjectSetting.WsaEnableXR]);
287 
288  if (!Values[ProjectSetting.WsaEnableXR])
289  {
290  EditorUserBuildSettings.wsaSubtarget = WSASubtarget.AnyDevice;
291  UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(BuildTargetGroup.WSA, new[] { "None" });
292  PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.HumanInterfaceDevice, false);
293  BuildDeployPrefs.BuildPlatform = "Any CPU";
294  }
295  else
296  {
297 #if !UNITY_2017_2_OR_NEWER
298  Values[ProjectSetting.TargetOccludedDevices] = false;
299 #endif
300  if (!Values[ProjectSetting.TargetOccludedDevices])
301  {
302  EditorUserBuildSettings.wsaSubtarget = WSASubtarget.HoloLens;
303 #if UNITY_2017_2_OR_NEWER
304  UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(BuildTargetGroup.WSA, new[] { "WindowsMR" });
305 #else
306  UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(BuildTargetGroup.WSA, new[] { "HoloLens" });
307 #endif
308  PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.HumanInterfaceDevice, Values[ProjectSetting.UseInputManagerAxes]);
310 
311  for (var i = 0; i < QualitySettings.names.Length; i++)
312  {
313  QualitySettings.DecreaseLevel(true);
314  }
315  }
316  else
317  {
318  EditorUserBuildSettings.wsaSubtarget = WSASubtarget.PC;
319  UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(BuildTargetGroup.WSA, new[] { "WindowsMR" });
320  PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.HumanInterfaceDevice, false);
322 
323  for (var i = 0; i < QualitySettings.names.Length; i++)
324  {
325  QualitySettings.IncreaseLevel(true);
326  }
327  }
328 
329  int currentQualityLevel = QualitySettings.GetQualityLevel();
330 
331  // HACK: Edits QualitySettings.asset Directly
332  // TODO: replace with friendlier version that uses built in APIs when Unity fixes or makes available.
333  // See: http://answers.unity3d.com/questions/886160/how-do-i-change-qualitysetting-for-my-platform-fro.html
334  try
335  {
336  // Find the WSA element under the platform quality list and replace it's value with the current level.
337  string settingsPath = "ProjectSettings/QualitySettings.asset";
338  string matchPattern = @"(m_PerPlatformDefaultQuality.*Windows Store Apps:) (\d+)";
339  string replacePattern = @"$1 " + currentQualityLevel;
340 
341  string settings = File.ReadAllText(settingsPath);
342  settings = Regex.Replace(settings, matchPattern, replacePattern, RegexOptions.Singleline);
343 
344  File.WriteAllText(settingsPath, settings);
345  }
346  catch (Exception e)
347  {
348  Debug.LogException(e);
349  }
350  }
351 
352  PlayerSettings.SetScriptingBackend(BuildTargetGroup.WSA,
353  Values[ProjectSetting.DotNetScriptingBackend]
354  ? ScriptingImplementation.WinRTDotNET
355  : ScriptingImplementation.IL2CPP);
356 
357  if (Values[ProjectSetting.SetDefaultSpatialMappingLayer])
358  {
359  if (SetSpatialMappingLayer())
360  {
361  // Setting the Spatial Mapping layer implies the need for the Spatial Perception capability.
362  PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.SpatialPerception, true);
363  }
364  else
365  {
366  EditorUtility.DisplayDialog("Attention!",
367  "Unable to set the Spatial Mapping layer.\n\n" +
368  "This likely means that layer " + SpatialMappingLayerId.ToString() + " is already in use.\n\n" +
369  "Please check your project's Tags && Layers settings in the Inspector.",
370  "Ok");
371  }
372  }
373 
374  AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
375  Close();
376  }
377 
378  protected override void OnGuiChanged()
379  {
380  }
381 
382  protected override void LoadStrings()
383  {
384  Names[ProjectSetting.BuildWsaUwp] = "Target Windows Universal UWP";
385  Descriptions[ProjectSetting.BuildWsaUwp] =
386  "<b>Required</b>\n\n" +
387  "Switches the currently active target to produce a Store app targeting the Universal Windows Platform.\n\n" +
388  "<color=#ffff00ff><b>Note:</b></color> Cross platform development can be done with this toolkit, but many features and " +
389  "tools will not work if the build target is not Windows Universal.";
390 
391  Names[ProjectSetting.WsaEnableXR] = "Enable XR";
392  Descriptions[ProjectSetting.WsaEnableXR] =
393  "<b>Required</b>\n\n" +
394  "Enables 'Windows Holographic' for Windows Store apps.\n\n" +
395  "If disabled, your application will run as a normal UWP app on PC, and will launch as a 2D app on HoloLens.\n\n" +
396  "<color=#ff0000ff><b>Warning!</b></color> HoloLens and tools like 'Holographic Remoting' will not function without this enabled.";
397 
398  Names[ProjectSetting.WsaUwpBuildToD3D] = "Build for Direct3D";
399  Descriptions[ProjectSetting.WsaUwpBuildToD3D] =
400  "Recommended\n\n" +
401  "Produces an app that targets Direct3D instead of XAML.\n\n" +
402  "Pure Direct3D apps run faster than applications that include XAML. This option should remain checked unless you plan to " +
403  "overlay Unity content with XAML content or you plan to switch between Unity views and XAML views at runtime.";
404 
405  Names[ProjectSetting.TargetOccludedDevices] = "Target Occluded Devices";
406  Descriptions[ProjectSetting.TargetOccludedDevices] =
407  "Changes the target Device and updates the default quality settings, if needed. Occluded devices are generally VR hardware (like the Acer HMD) " +
408  "that do not have a 'see through' display, while transparent devices (like the HoloLens) are generally AR hardware where users can see " +
409  "and interact with digital elements in the physical world around them.\n\n" +
410 #if !UNITY_2017_2_OR_NEWER
411  "<color=#ff0000ff><b>Warning!</b></color> Occluded Devices are only supported in Unity 2017.2 and newer and cannot be enabled.\n\n" +
412 #endif
413  "<color=#ffff00ff><b>Note:</b></color> If you're not targeting Occluded devices, It's generally recommended that Transparent devices use " +
414  "the lowest default quality setting, and is set automatically for you. This can be manually changed in your the Project's Quality Settings.";
415 
416  Names[ProjectSetting.SharingServices] = "Enable Sharing Services";
417  Descriptions[ProjectSetting.SharingServices] =
418  "Enables the use of the Sharing Services in your project for all apps on any platform.\n\n" +
419  "<color=#ffff00ff><b>Note:</b></color> Start the Sharing Server via 'Mixed Reality Toolkit/Sharing Service/Launch Sharing Service'.\n\n" +
420  "<color=#ffff00ff><b>Note:</b></color> The InternetClientServer and PrivateNetworkClientServer capabilities will be enabled in the " +
421  "appx manifest for you.";
422 
423  Names[ProjectSetting.UseInputManagerAxes] = "Use Toolkit-specific InputManager axes";
424  Descriptions[ProjectSetting.UseInputManagerAxes] =
425  "Enables the use of the Xbox Controller for all apps on any platform.\n\n" +
426  "To remove the added axes, simply disable this setting.\n\n" +
427  "<color=#ffff00ff><b>Note:</b></color> The HoloLens platform target requires the HID capability to be defined in the appx manifest. " +
428  "This capability is automatically enabled for you if you select this setting, \"Enable XR\", and don't select \"Target Occluded Devices\".";
429 
430  Names[ProjectSetting.DotNetScriptingBackend] = "Enable .NET scripting backend";
431  Descriptions[ProjectSetting.DotNetScriptingBackend] =
432  "Recommended\n\n" +
433  "If you have the .NET unity module installed this will update the backend scripting profile, otherwise the scripting backend will be IL2CPP.";
434 
435  Names[ProjectSetting.SetDefaultSpatialMappingLayer] = "Set Default Spatial Mapping Layer";
436  Descriptions[ProjectSetting.SetDefaultSpatialMappingLayer] =
437  "Recommended\n\n" +
438  "Sets the default Spatial Mapping physics layer.\n\n" +
439  "On HoloLens, this enables specifying the Spatial Mapping mesh for collision detection and raycasting.\n\n" +
440  "<color=#ffff00ff><b>Note:</b></color> Selecting \"Set Default Spatial Mapping Layer\" implies the project will be using Spatial Mapping. " +
441  "The Spatial Perception capability is automatically enabled for you.";
442  }
443 
444  protected override void OnEnable()
445  {
446  base.OnEnable();
447 
448 #if UNITY_2017_1_OR_NEWER
449  AutoConfigureMenu.ActiveBuildTargetChanged += UpdateSettings;
450 #endif
451 
452  minSize = new Vector2(350, 350);
453  maxSize = minSize;
454  }
455 
456  private void OnDisable()
457  {
458  if (inputManagerAsset != null)
459  {
460  inputManagerAsset.Dispose();
461  }
462  }
463 
464  #endregion // Overrides / Event Handlers
465 
466  private void AddAxis(InputManagerAxis axis)
467  {
468  SerializedProperty axesProperty = inputManagerAsset.FindProperty("m_Axes");
469 
470  // Creates a new axis by incrementing the size of the m_Axes array.
471  axesProperty.arraySize++;
472 
473  // Get the new axis be querying for the last array element.
474  SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1);
475 
476  // Iterate through all the properties of the new axis.
477  while (axisProperty.Next(true))
478  {
479  switch (axisProperty.name)
480  {
481  case "m_Name":
482  axisProperty.stringValue = axis.Name;
483  break;
484  case "descriptiveName":
485  axisProperty.stringValue = axis.DescriptiveName;
486  break;
487  case "descriptiveNegativeName":
488  axisProperty.stringValue = axis.DescriptiveNegativeName;
489  break;
490  case "negativeButton":
491  axisProperty.stringValue = axis.NegativeButton;
492  break;
493  case "positiveButton":
494  axisProperty.stringValue = axis.PositiveButton;
495  break;
496  case "altNegativeButton":
497  axisProperty.stringValue = axis.AltNegativeButton;
498  break;
499  case "altPositiveButton":
500  axisProperty.stringValue = axis.AltPositiveButton;
501  break;
502  case "gravity":
503  axisProperty.floatValue = axis.Gravity;
504  break;
505  case "dead":
506  axisProperty.floatValue = axis.Dead;
507  break;
508  case "sensitivity":
509  axisProperty.floatValue = axis.Sensitivity;
510  break;
511  case "snap":
512  axisProperty.boolValue = axis.Snap;
513  break;
514  case "invert":
515  axisProperty.boolValue = axis.Invert;
516  break;
517  case "type":
518  axisProperty.intValue = (int)axis.Type;
519  break;
520  case "axis":
521  axisProperty.intValue = axis.Axis - 1;
522  break;
523  case "joyNum":
524  axisProperty.intValue = axis.JoyNum;
525  break;
526  }
527  }
528  }
529 
530  private void RemoveAxis(string axis)
531  {
532  SerializedProperty axesProperty = inputManagerAsset.FindProperty("m_Axes");
533 
534  // This loop accounts for multiple axes with the same name.
535  while (axisNames.Contains(axis))
536  {
537  int index = axisNames.IndexOf(axis);
538  axesProperty.DeleteArrayElementAtIndex(index);
539  axisNames.RemoveAt(index);
540  }
541  }
542 
546  private bool DoesAxisNameExist(string axisName)
547  {
548  if (axisNames.Count == 0 || inputManagerAsset.UpdateIfRequiredOrScript())
549  {
550  RefreshLocalAxesList();
551  }
552 
553  return axisNames.Contains(axisName);
554  }
555 
559  private void RefreshLocalAxesList()
560  {
561  axisNames.Clear();
562 
563  SerializedProperty axesProperty = inputManagerAsset.FindProperty("m_Axes");
564 
565  for (int i = 0; i < axesProperty.arraySize; i++)
566  {
567  axisNames.Add(axesProperty.GetArrayElementAtIndex(i).displayName);
568  }
569  }
570 
577  private bool SetSpatialMappingLayer()
578  {
579  UnityEngine.Object[] tagAssets = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset");
580  if ((tagAssets == null) ||
581  (tagAssets.Length == 0))
582  {
583  return false;
584  }
585 
586  SerializedObject tagsManager = new SerializedObject(tagAssets);
587  if (tagsManager == null)
588  {
589  return false;
590  }
591 
592  SerializedProperty layers = tagsManager.FindProperty("layers");
593  if (layers == null)
594  {
595  return false;
596  }
597 
598  SerializedProperty spatialMappingLayer = layers.GetArrayElementAtIndex(SpatialMappingLayerId);
599  if (spatialMappingLayer.stringValue == SpatialMappingLayerName)
600  {
601  // Spatial Mapping layer already set
602  return true;
603  }
604  else if (spatialMappingLayer.stringValue != string.Empty)
605  {
606  // Target layer in use and may be being used for something other than Spatial Mapping
607  return false;
608  }
609 
610  // Set the layer name.
611  spatialMappingLayer.stringValue = SpatialMappingLayerName;
612  return tagsManager.ApplyModifiedProperties();
613  }
614 
618  private void SaveMenuSettings()
619  {
620  updateToolkitAxes = Values[ProjectSetting.UseInputManagerAxes] != EditorPrefsUtility.GetEditorPref(Names[ProjectSetting.UseInputManagerAxes], false);
621 
622  for (int i = (int)ProjectSetting.BuildWsaUwp; i <= (int)ProjectSetting.SetDefaultSpatialMappingLayer; i++)
623  {
625  }
626  }
627  }
628 }
override void OnGuiChanged()
Called when a toggle has been flipped and a change has been detected.
Renders the UI and handles update logic for HoloToolkit/Configure/Apply Mixed Reality Project Setting...
static void SetEditorPref(string key, string value)
override void ApplySettings()
Called when settings should be applied.
Configuration options derived from here: https://developer.microsoft.com/en-us/windows/mixed-reality/...
override void LoadStrings()
Called when string names and descriptions should be loaded.
static string GetEditorPref(string key, string defaultValue)
Utility class for Unity&#39;s Input Manager Mappings. Input from all types should be defined here for use...
Base class for auto configuration build windows.
override void LoadSettings()
Called when settings should be loaded.