ConsoleDlg.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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. StartCoroutine(initVuforia());
  63. ArtInfoMgr.Instance.InitPackage(HomeProxy.Instance.ArtList);
  64. WorldDlg dlg = GetComponent<WorldDlg>();
  65. AnmationPos = dlg.GetBreadthChild<Transform>("AnmationPos");
  66. fileListDlg = dlg.GetBreadthChild<WorldDlg>("FileListDlg");
  67. fileListDlg.gameObject.SetActive(false);
  68. AllMenuToggles = dlg.GetBreadthChild<Transform>("AllMenuToggles");
  69. IconDlgToggleGroup = dlg.GetBreadthChild<ToggleGroup>("IconDlgToggleGroup");
  70. IconDlgToggleGroupTran = dlg.GetBreadthChild<Transform>("IconDlgToggleGroup");
  71. userInfoBt = dlg.GetBreadthChild<Button>("userInfoBt");
  72. shortcutkey = dlg.GetBreadthChild<Button>("Shortcutkey");
  73. // scanPictureBtn = dlg.GetBreadthChild<Button>("ScanPictureBtn");
  74. shortcutkey.onClick.AddListener(ClickOnShortcutkey);
  75. //scanPictureBtn.onClick.AddListener(ClickOnScan);
  76. for (int i = 0; i < IconDlgToggleGroupTran.childCount; i++)
  77. {
  78. Toggle toggle = IconDlgToggleGroupTran.GetChild(i).GetComponent<Toggle>();
  79. toggle.onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); });
  80. if (i == 1)
  81. {
  82. PiZhuToggle = toggle;
  83. }
  84. }
  85. if (GameSession.Instance)
  86. {
  87. GameSession.Instance.CameraEffect(true);
  88. }
  89. shortcutkey.gameObject.SetActive(false);
  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. static GameObject vgo;
  118. IEnumerator initVuforia()
  119. {
  120. if (!vgo)
  121. {
  122. vgo = Resources.Load<GameObject>("VufroiaManager");
  123. vgo = GameObject.Instantiate(vgo);
  124. }
  125. yield return null;
  126. if (DeviceType.type == "LeiNiao" || DeviceType.type == "YuanNi" || DeviceType.type == "Rokid")
  127. {
  128. VuforiaManagerSpace.Instance.Vuforia.gameObject.SetActive(false);
  129. VuforiaManagerSpace.Instance.NoVuforia.gameObject.SetActive(true);
  130. }
  131. else
  132. {
  133. VuforiaManagerSpace.Instance.NoVuforia.gameObject.SetActive(false);
  134. VuforiaManagerSpace.Instance.Vuforia.gameObject.SetActive(true);
  135. vufora_camera = VuforiaManagerSpace.Instance.VuforiaCamera;
  136. InitScan();
  137. }
  138. }
  139. private void InitScan()
  140. {
  141. if (DeviceType.type == "Phone"|| DeviceType.type == "LeiNiao" || DeviceType.type == "YuanNi")
  142. {
  143. }
  144. else
  145. {
  146. vufora_camera.enabled = false;
  147. Vuforia.VuforiaBehaviour.Instance.enabled = false;
  148. }
  149. XRRGBCamera.Instance.playCamera(CustomInfo.mWidth, CustomInfo.mHight);
  150. }
  151. public void ClickOnScan()
  152. {
  153. if(DeviceType.type== "Phone" || DeviceType.type == "LeiNiao" || DeviceType.type == "YuanNi")
  154. {
  155. return;
  156. }
  157. if (vufora_camera.enabled == true)
  158. {
  159. CommonMethod.ShowScanEffect(false);
  160. vufora_camera.enabled = false;
  161. Vuforia.VuforiaBehaviour.Instance.enabled = false;
  162. //if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
  163. //{
  164. // // StudioRtc.Instance.startCamera();
  165. //}
  166. XRRGBCamera.Instance.playCamera(CustomInfo.mWidth, CustomInfo.mHight);
  167. Debug.Log("startCamera===>");
  168. if (ScanPictureBtn.Instance.Bg)
  169. {
  170. ScanPictureBtn.Instance.Bg.gameObject.SetActive(false);
  171. }
  172. //AgoraVideoAudioManager.Instance.OnClickEnableLocalVideo(true);
  173. //if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
  174. //{
  175. // StudioRtc.Instance.stopCamera();
  176. //}
  177. AgoraRTCManager.Instance.JoinChannel();
  178. }
  179. else
  180. {
  181. XRRGBCamera.Instance.stopCamera();
  182. if (AgoraRTCManager.Instance.isSwitchCamera)
  183. {
  184. AgoraRTCManager.Instance.RtcEngine.SwitchCamera();
  185. AgoraRTCManager.Instance.isSwitchCamera = !AgoraRTCManager.Instance.isSwitchCamera;
  186. }
  187. AgoraRTCManager.Instance.LeaveChannel();
  188. // AgoraVideoAudioManager.Instance.OnClickEnableLocalVideo(false);
  189. //if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
  190. //{
  191. // StudioRtc.Instance.stopCamera();
  192. //}
  193. CommonMethod.ShowScanEffect(true);
  194. vufora_camera.enabled = true;
  195. Vuforia.VuforiaBehaviour.Instance.enabled = true;
  196. if (ScanPictureBtn.Instance.Bg)
  197. {
  198. ScanPictureBtn.Instance.Bg.gameObject.SetActive(true);
  199. }
  200. }
  201. }
  202. public void CloseScan()
  203. {
  204. if (DeviceType.type == "Phone" || DeviceType.type == "LeiNiao" || DeviceType.type == "YuanNi" || DeviceType.type == "Rokid")
  205. {
  206. return;
  207. }
  208. if (vufora_camera.enabled == true)
  209. {
  210. CommonMethod.ShowScanEffect(false);
  211. vufora_camera.enabled = false;
  212. Vuforia.VuforiaBehaviour.Instance.enabled = false;
  213. //if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
  214. //{
  215. // StudioRtc.Instance.startCamera();
  216. //}
  217. XRRGBCamera.Instance.playCamera(CustomInfo.mWidth, CustomInfo.mHight);
  218. }
  219. }
  220. private void shortcutkeyShow()
  221. {
  222. shortcutkey.gameObject.SetActive(true);
  223. }
  224. private void ClickOnShortcutkey()
  225. {
  226. if (isHide)
  227. {
  228. shortcutkey.GetComponent<ButtonEffect>().enabled = false;
  229. isHide = false;
  230. GameEffect.setAlpha(shortcutkey.gameObject, 0, 0.25f, (GameObject obj) =>
  231. {
  232. shortcutkey.gameObject.SetActive(false);
  233. });
  234. GameEffect.setAlpha(AllMenuToggles.gameObject, 1, 0.01f, (GameObject obj) =>
  235. {
  236. });
  237. AllMenuToggles.gameObject.SetActive(true);
  238. ListButtonEffect[] list = AllMenuToggles.GetComponentsInChildren<ListButtonEffect>();
  239. for (int i = 0; i < list.Length; i++)
  240. {
  241. list[i].showMove();
  242. }
  243. if (GameSession.Instance)
  244. {
  245. GameSession.Instance.CameraEffect(false);
  246. }
  247. }
  248. }
  249. private void OnToggle(bool isOn, Toggle toggle)
  250. {
  251. if (isOn)
  252. {
  253. switch (toggle.name)
  254. {
  255. case "PaintBrush":
  256. ShowIconDlgs(PaintBrushDlg);
  257. DrawPener.Instance.ActiveDrawPen();
  258. DesAllNotepad();
  259. break;
  260. case "NotePad":
  261. ShowIconDlgs(PiZhuDlg);
  262. DrawPener.Instance.DisActiveDrawPen();
  263. ArtContainer container = NotePadComponent.CreateLocalNotePad();
  264. TimerMgr.Instance.CreateTimer(() => { InitNotePad(container); }, 0f);
  265. break;
  266. case "ZiYuanKu":
  267. ShowIconDlgs(ZiYuanKuDlg);
  268. DrawPener.Instance.DisActiveDrawPen();
  269. DesAllNotepad();
  270. break;
  271. case "PersonalFile":
  272. ShowIconDlgs(PersonalFiledlg);
  273. DrawPener.Instance.DisActiveDrawPen();
  274. DesAllNotepad();
  275. break;
  276. case "SenceMgr":
  277. ShowIconDlgs(FileListDlg);
  278. DrawPener.Instance.DisActiveDrawPen();
  279. DesAllNotepad();
  280. break;
  281. }
  282. }
  283. else
  284. {
  285. if (!IconDlgToggleGroup.AnyTogglesOn())
  286. {
  287. CloseAllDlgs();
  288. DesAllNotepad();
  289. DrawPener.Instance.DisActiveDrawPen();
  290. }
  291. }
  292. }
  293. public void SetClose()
  294. {
  295. IconDlgToggleGroup.SetAllTogglesOff();
  296. }
  297. private void DesAllNotepad()
  298. {
  299. if (NotePadPar && NotePadPar.childCount > 0)
  300. {
  301. for (int i = 0; i < NotePadPar.childCount; i++)
  302. {
  303. Destroy(NotePadPar.GetChild(i).gameObject);
  304. }
  305. }
  306. }
  307. private void InitNotePad(ArtContainer container)
  308. {
  309. Transform NotePadTran = container.GetInstace().transform;
  310. NotePadTran.SetParent(NotePadPar, true);
  311. NotePadTran.localPosition = new Vector3(0f, 0f, 0f);
  312. NotePadTran.localEulerAngles = new Vector3(0f, 0f, 0f);
  313. NotePadTran.localScale = new Vector3(1250f, 1250f, 1250f);
  314. //NotePadTran.position = NotePadPar.position;
  315. //NotePadTran.rotation = NotePadPar.rotation;
  316. NotePadComponent notePadComponent = NotePadTran.GetComponentInChildren<NotePadComponent>();
  317. notePadComponent.Init();
  318. }
  319. private void Update()
  320. {
  321. checkMenu();
  322. }
  323. private bool isHide = true;
  324. private float TimeData;
  325. private List<GameObject> raycastList;
  326. public void checkMenu()
  327. {
  328. if (!IconDlgToggleGroup.AnyTogglesOn() && !isHide)
  329. {
  330. List<GameObject> list = checkFoucs();
  331. bool isLock = false;
  332. for (int i = 0; i < list.Count; i++)
  333. {
  334. if (list[i] != null)
  335. {
  336. isLock = true;
  337. break;
  338. }
  339. }
  340. if (!isLock)
  341. {
  342. TimeData = TimeData + Time.deltaTime;
  343. if (TimeData >= 2f)
  344. {
  345. TimeData = 0;
  346. HeidMenu();
  347. }
  348. }
  349. else
  350. {
  351. TimeData = 0;
  352. }
  353. }
  354. else
  355. {
  356. TimeData = 0;
  357. }
  358. }
  359. private void OnEnable()
  360. {
  361. DispatcherBase.KeyDownDelegateRegister(OnKeyDownAction);
  362. }
  363. private void OnKeyDownAction(InputKeyCode keyCode, InputDevicePartBase part)
  364. {
  365. var obj = part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject;//SDK里判断点击返回的物体
  366. if (!obj && !IconDlgToggleGroup.AnyTogglesOn() && !isHide)
  367. {
  368. HeidMenu();
  369. }
  370. if (!obj)
  371. {
  372. TransferCell.CancelCell();
  373. }
  374. }
  375. private void OnDisable()
  376. {
  377. TransferCell.CancelCell();
  378. DispatcherBase.KeyDownDelegateUnRegister(OnKeyDownAction);
  379. }
  380. public List<GameObject> checkFoucs()
  381. {
  382. if (raycastList == null)
  383. {
  384. raycastList = new List<GameObject>();
  385. }
  386. raycastList.Clear();
  387. InputDeviceBase inputdevice;
  388. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceHead>(InputDeviceType.Head);
  389. checkFoucs(raycastList, inputdevice);
  390. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceHand>(InputDeviceType.GGT26Dof);
  391. checkFoucs(raycastList, inputdevice);
  392. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceHand>(InputDeviceType.GGT26Dof);
  393. checkFoucs(raycastList, inputdevice);
  394. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceBT3Dof>(InputDeviceType.BT3Dof);
  395. checkFoucs(raycastList, inputdevice);
  396. inputdevice = Module_InputSystem.instance.GetInputDevice<InputDeviceKS>(InputDeviceType.KS);
  397. checkFoucs(raycastList, inputdevice);
  398. return raycastList;
  399. }
  400. private void checkFoucs(List<GameObject> raycastList, InputDeviceBase inputdevice)
  401. {
  402. if (inputdevice && inputdevice.inputDevicePartList != null)
  403. {
  404. foreach (var part in inputdevice.inputDevicePartList)
  405. {
  406. if (part && part.inputDataBase != null && part.inputDataBase.isVaild)
  407. {
  408. raycastList.Add(part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject);
  409. }
  410. }
  411. }
  412. }
  413. public void HeidMenu()
  414. {
  415. shortcutkey.GetComponent<ButtonEffect>().enabled = true;
  416. isHide = true;
  417. GameEffect.setAlpha(AllMenuToggles.gameObject, 0, 0.25F, (GameObject obj) => { obj.SetActive(false); });
  418. GameEffect.setAlpha(shortcutkey.gameObject, 1, 0.25F, (GameObject obj) => { obj.SetActive(true); });
  419. ListEffect[] listeffects = AllMenuToggles.GetComponentsInChildren<ListEffect>();
  420. for (int i = 0; i < listeffects.Length; i++)
  421. {
  422. listeffects[i].hideEffect();
  423. }
  424. ListButtonEffect[] list = AllMenuToggles.GetComponentsInChildren<ListButtonEffect>();
  425. for (int i = 0; i < list.Length; i++)
  426. {
  427. list[i].hideMove();
  428. }
  429. //aboutMeDlg.hideDlg();
  430. //fileListDlg.hideDlg();
  431. if (GameSession.Instance)
  432. {
  433. GameSession.Instance.CameraEffect(true);
  434. }
  435. }
  436. public void CloseAllDlgs()
  437. {
  438. for (int i = 0; i < IconDlgList.Count; i++)
  439. {
  440. if (IconDlgList[i].activeSelf)
  441. {
  442. IconDlgList[i].SetActive(false);
  443. //GameEffect.setAlpha(IconDlgList[i].gameObject, 0, 0.25f, (GameObject obj) =>
  444. //{
  445. // obj.SetActive(false);
  446. //});
  447. }
  448. }
  449. }
  450. public void xiao()
  451. {
  452. // 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);
  453. // 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);
  454. }
  455. public void da()
  456. {
  457. // 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);
  458. // 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);
  459. }
  460. public void ShowIconDlgs(int index)
  461. {
  462. for (int i = 0; i < IconDlgList.Count; i++)
  463. {
  464. if (index == i)
  465. {
  466. IconDlgList[i].SetActive(true);
  467. }
  468. else
  469. {
  470. if (IconDlgList[i].activeSelf)
  471. {
  472. IconDlgList[i].gameObject.SetActive(false);
  473. }
  474. }
  475. }
  476. }
  477. public void ShowTipPop(string msg)
  478. {
  479. TipPop.SetActive(true);
  480. TipPopText.text = msg;
  481. Invoke("HideTipPop", 3f);
  482. }
  483. private void HideTipPop()
  484. {
  485. TipPop.SetActive(false);
  486. }
  487. }
  488. }