ConsoleDlg.cs 19 KB

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