VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_Controller_ModuleWizard.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEditor;
5 using System.Linq;
6 
7 namespace AVR.UEditor.Core {
8  public class AVR_Controller_ModuleWizard : AVR_HookableWizard<AVR_Controller_ModuleWizard> { }
9 
10  public class AVR_ControllerWizard_Hook_InputManager : AVR_WizardHook_SimpleToggle<AVR_Controller_ModuleWizard, AVR.Core.AVR_ControllerInputManager>
11  {
12  protected override string moduleName => "InputManager";
13  protected override string prefabPathSettingsToken => "/editor/defaultPrefabPaths/inputModule";
14  }
15 
16  public class AVR_ControllerWizard_Hook_ControllerVisual : AVR_WizardHook_SimpleToggle<AVR_Controller_ModuleWizard, AVR.Core.AVR_ControllerVisual>
17  {
18  protected override string moduleName => "InputManager";
19  protected override string prefabPathSettingsToken => _token;
20  private string _token = "/editor/defaultPrefabPaths/viveControllerVisual";
21 
22  public enum visualType { ViveController, Cube, Sphere };
23  protected visualType type;
24  protected visualType old_type;
25 
26  public override void on_create_wizard(GameObject targetObject)
27  {
28  base.on_create_wizard(targetObject);
29 
30  // We can't really know what type of visual is attatched atm, so we make an educated guess based on the objects name.
31  if (_module.Length > 0)
32  {
33  string name = _module[0].gameObject.name;
34  if (name.IndexOf("vive", System.StringComparison.OrdinalIgnoreCase) >= 0) type = visualType.ViveController;
35  else if (name.IndexOf("cube", System.StringComparison.OrdinalIgnoreCase) >= 0) type = visualType.Cube;
36  else if (name.IndexOf("sphere", System.StringComparison.OrdinalIgnoreCase) >= 0) type = visualType.Sphere;
37  }
38 
39  old_type = type;
40  }
41 
42  public override void embed_GUI() {
43  module = EditorGUILayout.BeginToggleGroup("ControllerVisual", module);
44  type = (visualType)EditorGUILayout.EnumPopup(type);
45  EditorGUILayout.EndToggleGroup();
46  }
47 
48  public override void on_submit(GameObject targetObject)
49  {
50  if (module && old_type != type)
51  {
52  foreach (AVR.Core.AVR_ControllerVisual c in _module) GameObject.DestroyImmediate(c.gameObject);
53  _module = new AVR.Core.AVR_ControllerVisual[0];
54  }
55 
56  switch (type)
57  {
58  case visualType.ViveController: { _token = "/editor/defaultPrefabPaths/viveControllerVisual"; break; }
59  case visualType.Cube: { _token = "/editor/defaultPrefabPaths/cubeControllerVisual"; break; }
60  case visualType.Sphere: { _token = "/editor/defaultPrefabPaths/sphereControllerVisual"; break; }
61  default: { AVR.Core.AVR_DevConsole.cwarn("It looks like the given visualType is not implemented: " + type.ToString(), "ControllerVisual Hook"); _token = "/editor/defaultPrefabPaths/viveControllerVisual"; break; }
62  }
63 
64  base.on_submit(targetObject);
65  }
66  }
67 }
Represents a visual of a controller, such as a 3d model or sprite.