ConsoleDlg.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. using BeinLab.Util;
  2. using DG.Tweening;
  3. using SC.XR.Unity.Module_InputSystem;
  4. using SC.XR.Unity.Module_InputSystem.InputDeviceHead;
  5. using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
  6. using ShadowStudio.Tool;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using UnityEngine;
  11. using UnityEngine.UI;
  12. using XRTool.Util;
  13. using XRTool.WorldUI;
  14. using ShadowStudio.Model;
  15. using SC.XR.Unity.Module_InputSystem.InputDeviceGC.BT3Dof;
  16. using SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS;
  17. using Studio.Scripts;
  18. namespace ShadowStudio.UI
  19. {
  20. enum FilePanelType
  21. {
  22. ZiYuanKuDlg=0,
  23. PersonalDlg=1
  24. }
  25. [RequireComponent(typeof(WorldDlg))]
  26. /// <summary>
  27. /// 控制台窗口
  28. /// </summary>
  29. public class ConsoleDlg : UnitySingleton<ConsoleDlg>
  30. {
  31. private Transform AllMenuToggles;
  32. public List<GameObject> IconDlgList;
  33. public static int PaintBrushDlg = 0;
  34. public static int PiZhuDlg = 1;
  35. public static int ZiYuanKuDlg = 2;
  36. public static int PersonalFiledlg = 3;
  37. public static int FileListDlg = 4;
  38. private Transform IconDlgToggleGroupTran;
  39. private ToggleGroup IconDlgToggleGroup;
  40. public Toggle PiZhuToggle;
  41. private Button shortcutkey;
  42. public Transform AnmationPos;
  43. private Button userInfoBt;
  44. //private Button WenJianBt;
  45. private WorldDlg fileListDlg;
  46. public Camera vufora_camera;
  47. public Transform NotePadPar;
  48. public Transform WorldCanvas;
  49. public GameObject TipPop;
  50. public Text TipPopText;
  51. public static bool IsOne = false;
  52. public Vector3 GetCenterPos()
  53. {
  54. if (shortcutkey)
  55. {
  56. return shortcutkey.transform.position;
  57. }
  58. return Vector3.zero;
  59. }
  60. private void Start()
  61. {
  62. ArtInfoMgr.Instance.InitPackage(HomeProxy.Instance.ArtList);
  63. WorldDlg dlg = GetComponent<WorldDlg>();
  64. AnmationPos = dlg.GetBreadthChild<Transform>("AnmationPos");
  65. fileListDlg = dlg.GetBreadthChild<WorldDlg>("FileListDlg");
  66. fileListDlg.gameObject.SetActive(false);
  67. AllMenuToggles = dlg.GetBreadthChild<Transform>("AllMenuToggles");
  68. IconDlgToggleGroup = dlg.GetBreadthChild<ToggleGroup>("IconDlgToggleGroup");
  69. IconDlgToggleGroupTran = dlg.GetBreadthChild<Transform>("IconDlgToggleGroup");
  70. userInfoBt = dlg.GetBreadthChild<Button>("userInfoBt");
  71. shortcutkey = dlg.GetBreadthChild<Button>("Shortcutkey");
  72. // scanPictureBtn = dlg.GetBreadthChild<Button>("ScanPictureBtn");
  73. shortcutkey.onClick.AddListener(ClickOnShortcutkey);
  74. //scanPictureBtn.onClick.AddListener(ClickOnScan);
  75. for (int i = 0; i < IconDlgToggleGroupTran.childCount; i++)
  76. {
  77. Toggle toggle = IconDlgToggleGroupTran.GetChild(i).GetComponent<Toggle>();
  78. toggle.onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); });
  79. if (i == 1)
  80. {
  81. PiZhuToggle = toggle;
  82. }
  83. }
  84. if (GameSession.Instance)
  85. {
  86. GameSession.Instance.CameraEffect(true);
  87. }
  88. shortcutkey.gameObject.SetActive(false);
  89. InitScan();
  90. //Debug.Log(CommonMethod.roomConfig.Type + "***" + CommonMethod.roomConfig.Room_type + "+++" + CommonMethod.roomConfig.Is_created);
  91. if (CommonMethod.roomConfig.Type == "2")
  92. {
  93. if (CommonMethod.roomConfig.Room_type == "2")
  94. {
  95. Invoke("shortcutkeyShow", 1f);
  96. }
  97. else
  98. {
  99. if (CommonMethod.roomConfig.Is_created == "1")
  100. {
  101. Invoke("shortcutkeyShow", 1f);
  102. }
  103. }
  104. }
  105. else
  106. {
  107. Invoke("shortcutkeyShow", 1f);
  108. }
  109. //TimerMgr.Instance.CreateTimer(() =>
  110. //{
  111. // if (TransferCell.curActiveCell && !TransferCell.curActiveCell.IsLock)
  112. // {
  113. // TransferCell.curActiveCell.DisActiveCell();
  114. // }
  115. //}, 1.2f);
  116. }
  117. private void InitScan()
  118. {
  119. vufora_camera.enabled = false;
  120. Vuforia.VuforiaBehaviour.Instance.enabled = false;
  121. }
  122. public void ClickOnScan()
  123. {
  124. if (vufora_camera.enabled == true)
  125. {
  126. CommonMethod.ShowScanEffect(false);
  127. vufora_camera.enabled = false;
  128. Vuforia.VuforiaBehaviour.Instance.enabled = false;
  129. //if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
  130. //{
  131. // // StudioRtc.Instance.startCamera();
  132. //}
  133. if (ScanPictureBtn.Instance.Bg)
  134. {
  135. ScanPictureBtn.Instance.Bg.gameObject.SetActive(false);
  136. }
  137. //AgoraVideoAudioManager.Instance.OnClickEnableLocalVideo(true);
  138. //if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
  139. //{
  140. // StudioRtc.Instance.stopCamera();
  141. //}
  142. AgoraRTCManager.Instance.JoinChannel();
  143. }
  144. else
  145. {
  146. if(AgoraRTCManager.Instance.isSwitchCamera)
  147. {
  148. AgoraRTCManager.Instance.RtcEngine.SwitchCamera();
  149. AgoraRTCManager.Instance.isSwitchCamera = !AgoraRTCManager.Instance.isSwitchCamera;
  150. }
  151. AgoraRTCManager.Instance.LeaveChannel();
  152. // AgoraVideoAudioManager.Instance.OnClickEnableLocalVideo(false);
  153. //if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
  154. //{
  155. // StudioRtc.Instance.stopCamera();
  156. //}
  157. CommonMethod.ShowScanEffect(true);
  158. vufora_camera.enabled = true;
  159. Vuforia.VuforiaBehaviour.Instance.enabled = true;
  160. if (ScanPictureBtn.Instance.Bg)
  161. {
  162. ScanPictureBtn.Instance.Bg.gameObject.SetActive(true);
  163. }
  164. }
  165. }
  166. public void CloseScan()
  167. {
  168. //if (vufora_camera.enabled == true)
  169. //{
  170. // CommonMethod.ShowScanEffect(false);
  171. // vufora_camera.enabled = false;
  172. // Vuforia.VuforiaBehaviour.Instance.enabled = false;
  173. // //if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
  174. // //{
  175. // // StudioRtc.Instance.startCamera();
  176. // //}
  177. //}
  178. }
  179. private void shortcutkeyShow()
  180. {
  181. shortcutkey.gameObject.SetActive(true);
  182. }
  183. private void ClickOnShortcutkey()
  184. {
  185. if (isHide)
  186. {
  187. shortcutkey.GetComponent<ButtonEffect>().enabled = false;
  188. isHide = false;
  189. GameEffect.setAlpha(shortcutkey.gameObject, 0, 0.25f, (GameObject obj) =>
  190. {
  191. shortcutkey.gameObject.SetActive(false);
  192. });
  193. GameEffect.setAlpha(AllMenuToggles.gameObject, 1, 0.01f, (GameObject obj) =>
  194. {
  195. });
  196. AllMenuToggles.gameObject.SetActive(true);
  197. ListButtonEffect[] list = AllMenuToggles.GetComponentsInChildren<ListButtonEffect>();
  198. for (int i = 0; i < list.Length; i++)
  199. {
  200. list[i].showMove();
  201. }
  202. if (GameSession.Instance)
  203. {
  204. GameSession.Instance.CameraEffect(false);
  205. }
  206. }
  207. }
  208. private void OnToggle(bool isOn, Toggle toggle)
  209. {
  210. if (isOn)
  211. {
  212. switch (toggle.name)
  213. {
  214. case "PaintBrush":
  215. ShowIconDlgs(PaintBrushDlg);
  216. DrawPener.Instance.ActiveDrawPen();
  217. DesAllNotepad();
  218. break;
  219. case "NotePad":
  220. ShowIconDlgs(PiZhuDlg);
  221. DrawPener.Instance.DisActiveDrawPen();
  222. ArtContainer container = NotePadComponent.CreateLocalNotePad();
  223. TimerMgr.Instance.CreateTimer(() => { InitNotePad(container); }, 0f);
  224. break;
  225. case "ZiYuanKu":
  226. ShowIconDlgs(ZiYuanKuDlg);
  227. DrawPener.Instance.DisActiveDrawPen();
  228. DesAllNotepad();
  229. break;
  230. case "PersonalFile":
  231. ShowIconDlgs(PersonalFiledlg);
  232. DrawPener.Instance.DisActiveDrawPen();
  233. DesAllNotepad();
  234. break;
  235. case "SenceMgr":
  236. ShowIconDlgs(FileListDlg);
  237. DrawPener.Instance.DisActiveDrawPen();
  238. DesAllNotepad();
  239. break;
  240. }
  241. }
  242. else
  243. {
  244. if (!IconDlgToggleGroup.AnyTogglesOn())
  245. {
  246. CloseAllDlgs();
  247. DesAllNotepad();
  248. DrawPener.Instance.DisActiveDrawPen();
  249. }
  250. }
  251. }
  252. public void SetClose()
  253. {
  254. IconDlgToggleGroup.SetAllTogglesOff();
  255. }
  256. private void DesAllNotepad()
  257. {
  258. if (NotePadPar && NotePadPar.childCount > 0)
  259. {
  260. for (int i = 0; i < NotePadPar.childCount; i++)
  261. {
  262. Destroy(NotePadPar.GetChild(i).gameObject);
  263. }
  264. }
  265. }
  266. private void InitNotePad(ArtContainer container)
  267. {
  268. Transform NotePadTran = container.GetInstace().transform;
  269. NotePadTran.SetParent(NotePadPar, true);
  270. NotePadTran.localPosition = new Vector3(0f, 0f, 0f);
  271. NotePadTran.localEulerAngles = new Vector3(0f, 0f, 0f);
  272. NotePadTran.localScale = new Vector3(1250f, 1250f, 1250f);
  273. //NotePadTran.position = NotePadPar.position;
  274. //NotePadTran.rotation = NotePadPar.rotation;
  275. NotePadComponent notePadComponent = NotePadTran.GetComponentInChildren<NotePadComponent>();
  276. notePadComponent.Init();
  277. }
  278. private void Update()
  279. {
  280. checkMenu();
  281. }
  282. private bool isHide = true;
  283. private float TimeData;
  284. private List<GameObject> raycastList;
  285. public void checkMenu()
  286. {
  287. if (!IconDlgToggleGroup.AnyTogglesOn() && !isHide)
  288. {
  289. List<GameObject> list = checkFoucs();
  290. bool isLock = false;
  291. for (int i = 0; i < list.Count; i++)
  292. {
  293. if (list[i] != null)
  294. {
  295. isLock = true;
  296. break;
  297. }
  298. }
  299. if (!isLock)
  300. {
  301. TimeData = TimeData + Time.deltaTime;
  302. if (TimeData >= 2f)
  303. {
  304. TimeData = 0;
  305. HeidMenu();
  306. }
  307. }
  308. else
  309. {
  310. TimeData = 0;
  311. }
  312. }
  313. else
  314. {
  315. TimeData = 0;
  316. }
  317. }
  318. private void OnEnable()
  319. {
  320. DispatcherBase.KeyDownDelegateRegister(OnKeyDownAction);
  321. }
  322. private void OnKeyDownAction(InputKeyCode keyCode, InputDevicePartBase part)
  323. {
  324. var obj = part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject;//SDK里判断点击返回的物体
  325. if (!obj && !IconDlgToggleGroup.AnyTogglesOn() && !isHide)
  326. {
  327. HeidMenu();
  328. }
  329. if (!obj)
  330. {
  331. TransferCell.CancelCell();
  332. }
  333. }
  334. private void OnDisable()
  335. {
  336. TransferCell.CancelCell();
  337. DispatcherBase.KeyDownDelegateUnRegister(OnKeyDownAction);
  338. }
  339. public List<GameObject> checkFoucs()
  340. {
  341. if (raycastList == null)
  342. {
  343. raycastList = new List<GameObject>();
  344. }
  345. raycastList.Clear();
  346. InputDeviceBase inputdevice;
  347. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceHead>(InputDeviceType.Head);
  348. checkFoucs(raycastList, inputdevice);
  349. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceHand>(InputDeviceType.GGT26Dof);
  350. checkFoucs(raycastList, inputdevice);
  351. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceHand>(InputDeviceType.GGT26Dof);
  352. checkFoucs(raycastList, inputdevice);
  353. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceBT3Dof>(InputDeviceType.BT3Dof);
  354. checkFoucs(raycastList, inputdevice);
  355. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceKS>(InputDeviceType.KS);
  356. checkFoucs(raycastList, inputdevice);
  357. return raycastList;
  358. }
  359. private void checkFoucs(List<GameObject> raycastList, InputDeviceBase inputdevice)
  360. {
  361. if (inputdevice && inputdevice.inputDevicePartList != null)
  362. {
  363. foreach (var part in inputdevice.inputDevicePartList)
  364. {
  365. if (part && part.inputDataBase != null && part.inputDataBase.isVaild)
  366. {
  367. raycastList.Add(part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject);
  368. }
  369. }
  370. }
  371. }
  372. public void HeidMenu()
  373. {
  374. shortcutkey.GetComponent<ButtonEffect>().enabled = true;
  375. isHide = true;
  376. GameEffect.setAlpha(AllMenuToggles.gameObject, 0, 0.25F, (GameObject obj) => { obj.SetActive(false); });
  377. GameEffect.setAlpha(shortcutkey.gameObject, 1, 0.25F, (GameObject obj) => { obj.SetActive(true); });
  378. ListEffect[] listeffects = AllMenuToggles.GetComponentsInChildren<ListEffect>();
  379. for (int i = 0; i < listeffects.Length; i++)
  380. {
  381. listeffects[i].hideEffect();
  382. }
  383. ListButtonEffect[] list = AllMenuToggles.GetComponentsInChildren<ListButtonEffect>();
  384. for (int i = 0; i < list.Length; i++)
  385. {
  386. list[i].hideMove();
  387. }
  388. //aboutMeDlg.hideDlg();
  389. //fileListDlg.hideDlg();
  390. if (GameSession.Instance)
  391. {
  392. GameSession.Instance.CameraEffect(true);
  393. }
  394. }
  395. public void CloseAllDlgs()
  396. {
  397. for (int i = 0; i < IconDlgList.Count; i++)
  398. {
  399. if (IconDlgList[i].activeSelf)
  400. {
  401. IconDlgList[i].SetActive(false);
  402. //GameEffect.setAlpha(IconDlgList[i].gameObject, 0, 0.25f, (GameObject obj) =>
  403. //{
  404. // obj.SetActive(false);
  405. //});
  406. }
  407. }
  408. }
  409. public void xiao()
  410. {
  411. // OpenXRCamera.Instance.leftCamera.transform.localPosition = new Vector3(OpenXRCamera.Instance.head.GetComponent<Camera>().transform.localPosition.x - 0.001f, OpenXRCamera.Instance.head.GetComponent<Camera>().transform.localPosition.y, OpenXRCamera.Instance.leftCamera.transform.localPosition.z);
  412. // OpenXRCamera.Instance.rightCamera.transform.localPosition = new Vector3(OpenXRCamera.Instance.head.GetComponent<Camera>().transform.localPosition.x + 0.001f, OpenXRCamera.Instance.head.GetComponent<Camera>().transform.localPosition.y, OpenXRCamera.Instance.rightCamera.transform.localPosition.z);
  413. }
  414. public void da()
  415. {
  416. // OpenXRCamera.Instance.leftCamera.transform.localPosition = new Vector3(OpenXRCamera.Instance.head.GetComponent<Camera>().transform.localPosition.x + 0.001f, OpenXRCamera.Instance.head.GetComponent<Camera>().transform.localPosition.y, OpenXRCamera.Instance.leftCamera.transform.localPosition.z);
  417. // OpenXRCamera.Instance.rightCamera.transform.localPosition = new Vector3(OpenXRCamera.Instance.head.GetComponent<Camera>().transform.localPosition.x - 0.001f, OpenXRCamera.Instance.head.GetComponent<Camera>().transform.localPosition.y, OpenXRCamera.Instance.rightCamera.transform.localPosition.z);
  418. }
  419. public void ShowIconDlgs(int index)
  420. {
  421. for (int i = 0; i < IconDlgList.Count; i++)
  422. {
  423. if (index == i)
  424. {
  425. IconDlgList[i].SetActive(true);
  426. }
  427. else
  428. {
  429. if (IconDlgList[i].activeSelf)
  430. {
  431. IconDlgList[i].gameObject.SetActive(false);
  432. }
  433. }
  434. }
  435. }
  436. public void ShowTipPop(string msg)
  437. {
  438. TipPop.SetActive(true);
  439. TipPopText.text = msg;
  440. Invoke("HideTipPop", 3f);
  441. }
  442. private void HideTipPop()
  443. {
  444. TipPop.SetActive(false);
  445. }
  446. }
  447. }