ConsoleDlg.cs 19 KB

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