using System; using System.Runtime.InteropServices; using UnityEngine; public class OpenByUrl : MonoBehaviour { [DllImport("__Internal")] private static extern string StringReturnValueFunction(); public static string UrlMsg = string.Empty; public GameObject panel_1; public GameObject panel_2; public GameObject panel_3; public PageIndex defaultPage; private void Awake() { panel_1 = this.transform.GetChild(0).gameObject; panel_2 = this.transform.GetChild(1).gameObject; panel_3 = this.transform.GetChild(2).gameObject; panel_1.SetActive(false); panel_2.SetActive(false); panel_3.SetActive(false); SelectPage(); } void SelectPage() { UrlMsg = "null"; try { UrlMsg = StringReturnValueFunction(); } catch (System.Exception e) { UrlMsg = "[catch]"+e.Message; Debug.Log("获取URL参数错误!!!"); } switch (UrlMsg) { case "?panel=1": GlobalData.pageIndex = PageIndex.Page1; panel_1.SetActive(true); break; case "?panel=2": GlobalData.pageIndex = PageIndex.Page2; panel_2.SetActive(true); break; case "?panel=3": GlobalData.pageIndex = PageIndex.Page3; panel_3.SetActive(true); break; default: switch (defaultPage) { case PageIndex.Page1: GlobalData.pageIndex = PageIndex.Page1; panel_1.SetActive(true); break; case PageIndex.Page2: GlobalData.pageIndex = PageIndex.Page2; panel_2.SetActive(true); break; case PageIndex.Page3: GlobalData.pageIndex = PageIndex.Page3; panel_3.SetActive(true); break; } break; } } }