ConsoleDlg.cs 18 KB

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