using System; using System.Collections.Generic; using System.Linq; using FairyGUI; using UnityEngine; namespace ScrewsMaster { public class WebviewManager : MonoBehaviour { // Vector2 startPos; // float lastTouchTime = 0f; // float touchInterval = 0.3f; // void Update() // { // #if UNITY_IOS && !UNITY_EDITOR // if(Input.touchCount > 0) // { // Touch touch_ = Input.GetTouch(0); // // if(touch_.phase == TouchPhase.Began) // { // startPos = touch_.position; // lastTouchTime = Time.time; // } // if(touch_.phase == TouchPhase.Ended) // { // if ((Time.time - lastTouchTime) < touchInterval){ // // if (WebViewMgr.Instance.WebUIType == WebUIType.H5 && EventSystem.current.currentSelectedGameObject == null){ // // BrigdeIOS.SetTouchWebview(true, true); // // }else{ // // BrigdeIOS.SetTouchWebview(true); // // } // BrigdeIOS.SetClickView(); // } // } // // if(touch_.phase == TouchPhase.Moved){ // // Vector2 delta = touch_.position - startPos; // // // Debug.Log("delta Y: " + delta.y); // // BrigdeIOS.ScrollWebview(delta.x, delta.y); // // startPos = touch_.position; // // } // } // #endif // } public static WebviewManager Instance; public WebviewManager() { Instance = this; } public void OpenWebView(string url) { //Debug.Log("[WebviewManager] OpenWebView"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.OpenWebview(url); #endif } public void showDarkWebview() { //Debug.Log("[WebviewManager] OpenWebView"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.showDarkWebview(); #endif } public void CloseWebview() { //Debug.Log("[WebviewManager] CloseWebview"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.CloseWebview(); #endif } public void SetOffset(int offset_y, int offset_y1) { // Debug.Log($"barry [WebviewManager] SetOffset:{offset_y}, {offset_y1}"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.SetOffset(offset_y, offset_y1); #endif } public void SetPadding(float left, float top, float right, float bottom) { // Debug.Log("[WebviewManager] SetPadding"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.SetPadding(left, top, right, bottom); #endif } public void openWebview() { #if UNITY_IOS && !UNITY_EDITOR BrigdeIOS.openWebview(); #endif } public void SetDarkThough(bool though) { if(!GameHelper.IsGiftSwitch()) return; // Debug.Log("[WebviewManager] SetPadding"); #if UNITY_IOS && !UNITY_EDITOR BrigdeIOS.SetDarkThough(though); #endif } public void SetBtn(int left, int top, int right, int bottom) { // Debug.Log("[WebviewManager] SetBtn"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.SetBtn(left, top, right, bottom); #endif } public void SetCTEnable(bool flag) { // Debug.Log("[WebviewManager] SetCTEnable"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.SetCTEnable(flag); #endif } public void SetFullScreen() { // Debug.Log("[WebviewManager] SetFullScreen"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.SetFullScreen(); #endif } public void addH5Field(int field1, int field2, int field3, int field4, int field5, string field6, string field7, string dark_url, string light_url, bool is_gift, string web_through_str, string click_add_time) { #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.addH5Field(field1,field2,field3,field4,field5,field6,field7,dark_url,light_url,is_gift,web_through_str,click_add_time); #endif } public void ShowH5View(bool flag) { // Debug.Log("[WebviewManager] SetCTEnable"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.ShowH5View(flag); #endif } public void SetIconProgress(float val) { // Debug.Log("[WebviewManager] SetCTEnable"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.SetIconProgress(val); #endif } public void setInH5View(bool flag) { // Debug.Log("[WebviewManager] SetCTEnable"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.setInH5View(flag); #endif } public void upDataH5times(string weblink, int times, bool is_dark) { #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.upDataH5times( weblink, times,is_dark); #endif } public void ShowFlyBtn(bool flag) { // Debug.Log("[WebviewManager] SetCTEnable"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.ShowFlyBtn(flag); #endif } public void setFlyBtnTag(bool flag) { Debug.Log($"[WebviewManager] setFlyBtnTag ---{flag}"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.setFlyBtnTag(flag); #endif } public void setRewardBtnTag(bool flag) { Debug.Log($"[WebviewManager] setRewardBtnTag--- {flag}"); #if UNITY_IOS && !UNITY_EDITOR // BrigdeIOS.setRewardBtnTag(flag); #endif } public void ObjC_TouchClick(string name) { // Debug.Log("Touch click: " + name); GameDispatcher.Instance.Dispatch(GameMsg.H5ViewClickBtn, name); } public void H5AutoRefresh(string times) { if (times == "") return; DateTime newDate = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); newDate = newDate.AddSeconds(GameHelper.GetNowTime()); var newDays = newDate.Day; if (times == "Dailyrefreshtimes") { var last_time = PlayerPrefs.GetInt("Dayreftimes", 0); if (last_time == newDays) { var numbers = PlayerPrefs.GetInt("Dailyrefreshnum", 0); numbers++; PlayerPrefs.SetInt("Dailyrefreshnum", numbers); } else { PlayerPrefs.SetInt("Dailyrefreshnum", 1); PlayerPrefs.SetInt("Dayreftimes", newDays); string darkWVRefreshtime_str = ""; string darkWVDailyrefreshtimes_str = ""; for (int i = 0; i < ConfigSystem.GetConfig().darkWVRefreshtime.Length; i++) { if (i != 0) darkWVRefreshtime_str += "|"; darkWVRefreshtime_str += ConfigSystem.GetConfig().darkWVRefreshtime[i].ToString(); } for (int i = 0; i < ConfigSystem.GetConfig().darkWVRefreshtime2.Length; i++) { darkWVRefreshtime_str += "|"; darkWVRefreshtime_str += ConfigSystem.GetConfig().darkWVRefreshtime2[i].ToString(); } for (int i = 0; i < ConfigSystem.GetConfig().darkWVDailyrefreshtimes.Length; i++) { if (i != 0) darkWVDailyrefreshtimes_str += "|"; darkWVDailyrefreshtimes_str += ConfigSystem.GetConfig().darkWVDailyrefreshtimes[i].ToString(); } WebviewManager.Instance.addH5Field(ConfigSystem.GetConfig().flyCtRate, ConfigSystem.GetConfig().otherH5switch, ConfigSystem.GetConfig().H5Refreshtime, ConfigSystem.GetConfig().Dailyrefreshtimes, ConfigSystem.GetConfig().darkThoughProbability, darkWVRefreshtime_str, darkWVDailyrefreshtimes_str, "", "", GameHelper.IsGiftSwitch(), "", ""); } } else if (times.Contains("dark_Dailyrefreshtimes")) { var last_time = PlayerPrefs.GetInt("dark_refreshDay", 0); if (last_time == newDays) { // var numbers = PlayerPrefs.GetInt("dark_Dayref", 0); // numbers++; // PlayerPrefs.SetInt("dark_Dayref", numbers); string[] temp_arr = times.Split("|"); if (temp_arr.Length >= 2) { SaveData.GetSaveobject().dark_Dayref[Int32.Parse(temp_arr[1])]++; SaveData.saveDataFunc(); } } else { // PlayerPrefs.SetInt("dark_Dayref", 1); string[] temp_arr = times.Split("|"); if (temp_arr.Length >= 2) { SaveData.GetSaveobject().dark_Dayref[Int32.Parse(temp_arr[1])] = 1; SaveData.saveDataFunc(); } PlayerPrefs.SetInt("dark_refreshDay", newDays); string darkWVRefreshtime_str = ""; string darkWVDailyrefreshtimes_str = ""; for (int i = 0; i < ConfigSystem.GetConfig().darkWVRefreshtime.Length; i++) { if (i != 0) darkWVRefreshtime_str += "|"; darkWVRefreshtime_str += ConfigSystem.GetConfig().darkWVRefreshtime[i].ToString(); } for (int i = 0; i < ConfigSystem.GetConfig().darkWVRefreshtime2.Length; i++) { darkWVRefreshtime_str += "|"; darkWVRefreshtime_str += ConfigSystem.GetConfig().darkWVRefreshtime2[i].ToString(); } for (int i = 0; i < ConfigSystem.GetConfig().darkWVDailyrefreshtimes.Length; i++) { if (i != 0) darkWVDailyrefreshtimes_str += "|"; darkWVDailyrefreshtimes_str += ConfigSystem.GetConfig().darkWVDailyrefreshtimes[i].ToString(); } WebviewManager.Instance.addH5Field(ConfigSystem.GetConfig().flyCtRate, ConfigSystem.GetConfig().otherH5switch, ConfigSystem.GetConfig().H5Refreshtime, ConfigSystem.GetConfig().Dailyrefreshtimes, ConfigSystem.GetConfig().darkThoughProbability, darkWVRefreshtime_str, darkWVDailyrefreshtimes_str, "", "", GameHelper.IsGiftSwitch(), "", ""); } } else { string[] temp_array = times.Split("|"); if (temp_array.Length >= 2 && temp_array[0] != null && temp_array[0] != "") { if (temp_array[1] == "h5") { H5sendClass info = new H5sendClass() { link = temp_array[0], type = "h5" }; NetworkKit.PostWithHeader("event/h5Impressions", info, (isSuccess, obj) => { if (isSuccess) { int numbers = 0; for (int i = 0; i < ConfigSystem.light_weblist.Count; i++) { if (ConfigSystem.light_weblist[i].webLink == temp_array[0]) { Debug.Log("uuuuuuuuuuuuuuuuu明穿透" + temp_array[0] + "已经刷新了" + obj.times + "次" + "上限是" + ConfigSystem.light_weblist[i].refreshMax + "次"); numbers = ConfigSystem.light_weblist[i].refreshMax - obj.times; break; } } if (numbers < 0) numbers = 0; upDataH5times(temp_array[0], numbers, false); } }); } else { H5sendClass info = new H5sendClass() { link = temp_array[0], type = "h6" }; NetworkKit.PostWithHeader("event/h5Impressions", info, (isSuccess, obj) => { if (isSuccess) { int numbers = 0; for (int i = 0; i < ConfigSystem.dark_weblist.Count; i++) { if (ConfigSystem.dark_weblist[i].webLink == temp_array[0]) { Debug.Log("uuuuuuuuuuuuuuuuu暗穿透" + temp_array[0] + "已经刷新了" + obj.times + "次" + "上限是" + ConfigSystem.dark_weblist[i].refreshMax + "次"); numbers = ConfigSystem.dark_weblist[i].refreshMax - obj.times; break; } } if (numbers < 0) numbers = 0; upDataH5times(temp_array[0], numbers, true); } }); } } } } private GList select_glist; private float select_glist_y; // public void TouchClickPoint(string name) // { // Debug.Log("TouchClickPoint" + name); // if (string.IsNullOrEmpty(name)) return; // if (name == "flyBtn") // { // NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.fly_ct_number, 1); // //NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior,BuriedPointEvent.fly_ct_people,1); // // } // // if (name == "rewardBtn") // { // NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_ct_number, 1); // //NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior,BuriedPointEvent.annular_ct_people,1); // } // // if (name == "finish") // { // NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_finish_number, 1); // } // else // { // // string[] a = name.Split("|"); // if (a.Length < 2) return; // Vector2 fguiScreenPos; // // Debug.Log("mmmmmmmmmmmmmmmmmm" + a[0]); // // Debug.Log("mmmmmmmmmmmmmmmmmm" + a[1]); // // if (AppConst.DeviceLangue == "pt") // // { // // fguiScreenPos = new Vector2((float.Parse(a[0]) * GRoot.inst.width) / 1000000.0f, // // float.Parse(a[1]) * GRoot.inst.height / 1000000.0f); // // } // // else // // { // fguiScreenPos = new Vector2(float.Parse(a[0]) * GRoot.inst.width, // float.Parse(a[1]) * GRoot.inst.height); // //} // // GButton objUnderPoint = null; // // var child_array = GRoot.inst.GetChildren().Reverse(); // bool click_card = true; // foreach (GComponent child in child_array) //normal // { // if (child.GetChildren().Length > 0) // { // var com_array = child.GetChildren().Reverse(); // foreach (GComponent com_child in com_array) //com_层面 // { // if (child.name == "Popup" || child.name == "Highest") // { // click_card = false;/* */ // } // var btn_array = com_child.GetChildren(); // for (int i = btn_array.Length - 1; i >= 0; i--) //btn_层面 // { // // if (btn_array[i] .name=="btn_collect") // // { // // Debug.Log(btn_array[i].x); // // Debug.Log(btn_array[i].y); // // Debug.Log(fguiScreenPos.x); // // Debug.Log(fguiScreenPos.y); // // Debug.Log(btn_array[i].position.x <= fguiScreenPos.x && // // fguiScreenPos.x <= btn_array[i].position.x + btn_array[i].width); // // Debug.Log( btn_array[i].position.y <= fguiScreenPos.y && // // fguiScreenPos.y <= btn_array[i].position.y + btn_array[i].height); // // } // // if (btn_array[i] is GButton) // { // GButton temp = btn_array[i] as GButton; // // if (temp.onStage && temp.visible && temp.position.x <= fguiScreenPos.x && // fguiScreenPos.x <= temp.position.x + temp.width && // temp.position.y <= fguiScreenPos.y && // fguiScreenPos.y <= temp.position.y + temp.height) // { // objUnderPoint = btn_array[i] as GButton; // if (objUnderPoint.enabled) // { // objUnderPoint.FireClick(true, true); // } // else objUnderPoint.FireClick(true, false); // goto EndLoop; // } // } // // else if (btn_array[i] is GTextInput) // { // // GTextInput temp = btn_array[i] as GTextInput; // if (temp.onStage && temp.visible && temp.position.x <= fguiScreenPos.x && // fguiScreenPos.x <= temp.position.x + temp.width && // temp.position.y <= fguiScreenPos.y && // fguiScreenPos.y <= temp.position.y + temp.height) // { // // temp.RequestFocus(); // goto EndLoop; // } // // } // else if (btn_array[i] is GList) // { // // GList temp = btn_array[i] as GList; // if (temp.onStage && temp.visible && temp.position.x <= fguiScreenPos.x && // fguiScreenPos.x <= temp.position.x + temp.width && // temp.position.y <= fguiScreenPos.y && // fguiScreenPos.y <= temp.position.y + temp.height) // { // if (select_glist == null) // { // select_glist_y = fguiScreenPos.y; // select_glist = btn_array[i] as GList; // } // else // { // select_glist.scrollPane.posY -= (fguiScreenPos.y - select_glist_y); // select_glist_y = fguiScreenPos.y; // } // // goto EndLoop; // } // // } // else if (btn_array[i] is GComponent) // { // var child_btn_array = btn_array[i].asCom.GetChildren(); //嵌套的com // // for (int j = child_btn_array.Length - 1; j >= 0; j--) // { // if (child_btn_array[j] is GButton) // { // Vector2 local_pos = new Vector2(btn_array[i].x + child_btn_array[j].x, // btn_array[i].y + child_btn_array[j].y); // if (child_btn_array[j].visible && child_btn_array[j].onStage && child_btn_array[j].visible && local_pos.x <= fguiScreenPos.x && // fguiScreenPos.x <= local_pos.x + child_btn_array[j].width && // local_pos.y <= fguiScreenPos.y && fguiScreenPos.y <= // local_pos.y + child_btn_array[j].height) // { // objUnderPoint = child_btn_array[j] as GButton; // if (objUnderPoint.enabled) objUnderPoint.FireClick(true, true); // else objUnderPoint.FireClick(true, false); // goto EndLoop; // // } // } // } // // } // // } // } // if (child.name == "Popup" || child.name == "Highest") // { // goto EndLoop; // } // } // } // // EndLoop: Debug.Log(""); // if (click_card) // { // if (orthoCamera == null) orthoCamera = GameObject.Find("GameCamera").GetComponent(); // Ray ray = orthoCamera.ScreenPointToRay(new Vector2(float.Parse(a[0]) * Screen.width, (1 - float.Parse(a[1])) * Screen.height)); // RaycastHit hit; // int layerMask = 1 << 6; // // if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) // { // GameDispatcher.Instance.Dispatch(GameMsg.card_click, hit.collider.gameObject.name); // } // } // } // } public void TouchClickPoint(string message) { Debug.Log("TouchClickPoint " + message); if (string.IsNullOrEmpty(message)) return; // 埋点处理 HandleBuriedPoints(message); // 解析坐标信息 var a = message.Split('|'); if (a.Length < 2) return; var fairyGuiScreenPos = new Vector2(float.Parse(a[0]) * GRoot.inst.width, float.Parse(a[1]) * GRoot.inst.height); var clickType = HandleUIElements(fairyGuiScreenPos); if (clickType == ClickType.FairyGUI) return; HandleOtherClick(a); HandleCardClick(a); } private void HandleBuriedPoints(string message) { switch (message) { case "flyBtn": NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.fly_ct_number, 1); break; case "rewardBtn": NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_ct_number, 1); break; case "finish": NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_finish_number, 1); break; } } public ClickType HandleUIElements(Vector2 fguiScreenPos) { var childArray = GRoot.inst.GetChildren()?.Reverse(); if (childArray == null) { return ClickType.UGUI; } foreach (GComponent child in childArray) { if (child.GetChildren() != null && child.GetChildren().Length > 0) { var comArray = child.GetChildren().Reverse(); foreach (GComponent comChild in comArray) { var btnArray = comChild.GetChildren(); for (int i = btnArray.Length - 1; i >= 0; i--) { var item = btnArray[i]; if (IsInside(item, fguiScreenPos) && item.touchable && item.onStage && item.visible) { switch (item) { case GButton button: HandleButtonClick(button); break; case GTextInput textInput: HandleTextInputClick(textInput); break; case GList list: HandleListClick(list); break; case GComponent component: HandleNestedComponents(component); break; } return ClickType.FairyGUI; } } } } } return ClickType.UGUI; } private bool HandleButtonClick(GComponent component) { if (component is GButton button) { button.FireClick(button.enabled, true); return true; } return false; } private bool HandleTextInputClick(GTextInput textInput) { if (textInput != null) { textInput.RequestFocus(); return true; } return false; } private bool HandleListClick(GList list) { if (list != null) { // 处理列表点击逻辑 return true; } return false; } private bool HandleNestedComponents(GComponent component) { var children = component.GetChildren(); for (int j = children.Length - 1; j >= 0; j--) { if (children[j] is GButton button && HandleButtonClick(button)) return true; } return false; } private bool IsInside(GObject gObject, Vector2 fguiScreenPos) { // 获取GObject的位置和尺寸 float width = gObject.width; float height = gObject.height; // 计算左、右、上、下范围 float left, right, top, bottom; // 如果锚点已设置,按锚点计算位置,否则按pivot计算 if (gObject.pivotAsAnchor) { left = gObject.x - (gObject.pivot.x * width); right = left + width; bottom = gObject.y - (gObject.pivot.y * height); top = bottom + height; } else { left = gObject.position.x; right = left + width; bottom = gObject.position.y; top = bottom + height; // // 没有设置锚点的情况 // return gObject.position.x <= fguiScreenPos.x && // fguiScreenPos.x <= gObject.position.x + gObject.width && // gObject.position.y <= fguiScreenPos.y && // fguiScreenPos.y <= gObject.position.y + gObject.height; } return fguiScreenPos.x >= left && fguiScreenPos.x <= right && fguiScreenPos.y <= top && fguiScreenPos.y >= bottom; } private void HandleCardClick(string[] a) { if (orthoCamera == null) { orthoCamera = GameObject.Find("Stage Camera")?.GetComponent(); // orthoCamera = GameObject.Find("GameCamera").GetComponent(); } if (orthoCamera != null) { Ray ray = orthoCamera.ScreenPointToRay(new Vector2(float.Parse(a[0]) * Screen.width, (1 - float.Parse(a[1])) * Screen.height)); RaycastHit hit; int layerMask = 1 << 6; if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { GameDispatcher.Instance.Dispatch(GameMsg.card_click, hit.collider.gameObject.name); } } } private void HandleOtherClick(string[] a) { UIScreenTapTrigger.Instance.TriggerButtonAtScreenPosition(new Vector2(float.Parse(a[0]), float.Parse(a[1]))); } public Camera orthoCamera; public static Dictionary adCallbackInfo = new Dictionary(); public void SendH5Event(string numbers) { // adCallbackInfo.Clear(); // adCallbackInfo.Add("h5_revenue",ConfigSystem.GetConfig().h5_refreshRevenue.ToString()); // //Debug.Log("sssssssssssssssssss"+JsonConvert.SerializeObject(adCallbackInfo)); // AppsFlyer.sendEvent("Growing_Total_01_002",adCallbackInfo); } public void ClickAdEvent(string ad_msg) { string[] temp_array = ad_msg.Split("|"); if (temp_array.Length >= 2 && temp_array[0] != null && temp_array[0] != "") { H5sendClass info = new H5sendClass() { link = temp_array[0], type = temp_array[1] }; NetworkKit.PostWithHeader("/event/h5Clicks", info, (isSuccess, obj) => { // if (isSuccess) // { // Debug.Log("dadianchenggong" + temp_array[0]); // } }); } } public void haveSimCard(string have) { if (have == "TRUE") NetworkManager.haveSimCard = true; } } public class H5refreshTimes { public string link; public int times; } public class H5sendClass { public string link; public string type; } public enum ClickType { FairyGUI, Scene, UGUI } }