OpenByUrl.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. public class OpenByUrl : MonoBehaviour
  5. {
  6. [DllImport("__Internal")]
  7. private static extern string StringReturnValueFunction();
  8. public static string UrlMsg = string.Empty;
  9. public GameObject panel_1;
  10. public GameObject panel_2;
  11. public GameObject panel_3;
  12. public PageIndex defaultPage;
  13. private void Awake()
  14. {
  15. panel_1 = this.transform.GetChild(0).gameObject;
  16. panel_2 = this.transform.GetChild(1).gameObject;
  17. panel_3 = this.transform.GetChild(2).gameObject;
  18. panel_1.SetActive(false);
  19. panel_2.SetActive(false);
  20. panel_3.SetActive(false);
  21. SelectPage();
  22. }
  23. void SelectPage()
  24. {
  25. UrlMsg = "null";
  26. try
  27. {
  28. UrlMsg = StringReturnValueFunction();
  29. }
  30. catch (System.Exception e)
  31. {
  32. UrlMsg = "[catch]"+e.Message;
  33. Debug.Log("获取URL参数错误!!!");
  34. }
  35. switch (UrlMsg)
  36. {
  37. case "?panel=1":
  38. GlobalData.pageIndex = PageIndex.Page1;
  39. panel_1.SetActive(true);
  40. break;
  41. case "?panel=2":
  42. GlobalData.pageIndex = PageIndex.Page2;
  43. panel_2.SetActive(true);
  44. break;
  45. case "?panel=3":
  46. GlobalData.pageIndex = PageIndex.Page3;
  47. panel_3.SetActive(true);
  48. break;
  49. default:
  50. switch (defaultPage) {
  51. case PageIndex.Page1:
  52. GlobalData.pageIndex = PageIndex.Page1;
  53. panel_1.SetActive(true);
  54. break;
  55. case PageIndex.Page2:
  56. GlobalData.pageIndex = PageIndex.Page2;
  57. panel_2.SetActive(true);
  58. break;
  59. case PageIndex.Page3:
  60. GlobalData.pageIndex = PageIndex.Page3;
  61. panel_3.SetActive(true);
  62. break;
  63. }
  64. break;
  65. }
  66. }
  67. }