Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. #if UNITY_EDITOR
  4. using UnityEditor;
  5. #endif
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System;
  9. using UnityEngine.EventSystems;
  10. using UnityEngine.Events;
  11. using VRDebug;
  12.  
  13. namespace VRDebug
  14. {
  15. [ExecuteInEditMode]
  16. public class VRDebugLogReceiver : MonoBehaviour
  17. {
  18. private GameObject vrLogWindow;
  19. private VRDebugScrollView scrollView;
  20. public int maxLog = 50;
  21. private EventSystem eventSystemObject;
  22. private BaseInputModule inputModule;
  23. private VRDebugInputModule debugInputModule;
  24.  
  25. void OnEnable()
  26. {
  27. CheckResource();
  28. Application.logMessageReceived += LogCallBackHandler;
  29. #if UNITY_EDITOR
  30. if (AssetDatabase.FindAssets("t:script SteamVR").Length > 0)
  31. {
  32. var nowSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  33. var addSymbol = "EXSISTENCE_STEAM_VR";
  34. if(nowSymbols.IndexOf(addSymbol) < 0)
  35. {
  36. addSymbol = ";" + addSymbol + ";";
  37. var newSymbols = nowSymbols + addSymbol;
  38. PlayerSettings.SetScriptingDefineSymbolsForGroup(
  39. EditorUserBuildSettings.selectedBuildTargetGroup,
  40. newSymbols
  41. );
  42. Debug.Log("Find asset \"SteamVR\".\nAdd DefineSymbols(Player Settings -> Other Settings -> Scripting Define Symbols).");
  43. }
  44. }
  45. //StandaloneInputModule:ON / VRDebugInputModule:OFF
  46. else
  47. {
  48. var nowSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  49. var newSymbols = nowSymbols.Replace("EXSISTENCE_STEAM_VR", "");
  50. PlayerSettings.SetScriptingDefineSymbolsForGroup(
  51. EditorUserBuildSettings.selectedBuildTargetGroup,
  52. newSymbols
  53. );
  54.  
  55. inputModule = CheckInputModule(inputModule, typeof(StandaloneInputModule));
  56. inputModule.enabled = true;
  57. debugInputModule = (VRDebugInputModule)CheckInputModule(debugInputModule, typeof(VRDebugInputModule));
  58. debugInputModule.Stop();
  59. debugInputModule.enabled = false;
  60. Debug.Log("Asset \"SteamVR\" not found, but VRDebugConsole does work without it.");
  61. }
  62. #endif
  63. }
  64.  
  65. void OnDisable()
  66. {
  67. Application.logMessageReceived -= LogCallBackHandler;
  68. }
  69.  
  70. void LogCallBackHandler(string _log, string _stackTrace, LogType _type)
  71. {
  72. #if UNITY_EDITOR
  73. if (EditorApplication.isPlaying)
  74. {
  75. scrollView.maxLog = maxLog;
  76. scrollView.AddItem(_log, _stackTrace, _type);
  77. }
  78. #endif
  79. }
  80.  
  81. private void CheckResource()
  82. {
  83. eventSystemObject = FindObjectOfType<EventSystem>();
  84. if (eventSystemObject == null)
  85. {
  86. var es = new GameObject("EventSystem", typeof(EventSystem));
  87. es.AddComponent<VRDebugInputModule>();
  88. }
  89. else
  90. {
  91. var getComp = eventSystemObject.gameObject.GetComponent<VRDebugInputModule>();
  92. if (getComp == null)
  93. {
  94. eventSystemObject.gameObject.AddComponent<VRDebugInputModule>();
  95. }
  96. }
  97. if (vrLogWindow == null)
  98. {
  99. var obj = GameObject.Find("VRLogWindow");
  100. if (obj == null)
  101. {
  102. obj = GameObject.Find("VRLogWindow(Clone)");
  103. }
  104. if (obj == null)
  105. {
  106. vrLogWindow = Resources.Load("VRLogWindow") as GameObject;
  107. vrLogWindow = (GameObject)Instantiate(vrLogWindow);
  108. vrLogWindow.name = "VRLogWindow";
  109. }
  110. else
  111. {
  112. vrLogWindow = obj;
  113. }
  114. }
  115. if(scrollView == null)
  116. {
  117. scrollView = vrLogWindow.transform.FindChild("MainWindow/ScrollView").GetComponent<VRDebugScrollView>();
  118. }
  119. }
  120.  
  121. /// <summary>
  122. /// Check component by name
  123. /// </summary>
  124. /// <param name="_componentName"></param>
  125. private BaseInputModule CheckInputModule(BaseInputModule _module, Type _componentName)
  126. {
  127. if (_module == null)
  128. {
  129. var comp = (BaseInputModule)GameObject.Find("EventSystem").gameObject.GetComponent(_componentName);
  130. _module = comp != null ? comp : (BaseInputModule)this.gameObject.AddComponent(_componentName);
  131. }
  132. return _module;
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement