//[NoToLua] //[ContextMenu("ClearLuaHandlerLink")] //public void ClearLuaHandlerLink() //{ // _LuaPanelObject = null; //} //Add Callbacks to UI Components in LinkHolder public void RegisterHandler() { if (!_HasRegistered) { GButton[] gBtns; Button[] buttons; Toggle[] toggles; Scrollbar[] scrollbars; InputField[] inputFields; Dropdown[] dropDowns; GNewListBase[] newLists; GNewTabList[] newTabLists; GNewLayoutTable[] newLayoutTables; //GUIAnim[] newUIAnims; GWebView[] newWebViews; GDragablePageView[] dragablePageViews; DG.Tweening.DOTweenAnimation[] newDOTAnims; GScrollWatcher[] scrollWatchers; GSlideButton[] slideBtns; InteractableUIHolder holder = gameObject.GetComponent <InteractableUIHolder>(); if (holder != null) { gBtns = holder.GBtns; buttons = holder.Buttons; toggles = holder.Toggles; scrollbars = holder.Scrollbars; inputFields = holder.InputFields; dropDowns = holder.Dropdowns; //GNewUI newLists = holder.NewLists; newTabLists = holder.NewTabLists; newLayoutTables = holder.NewLayoutTables; //newUIAnims = holder.newUIAnims; newWebViews = holder.newWebViews; dragablePageViews = holder.dragablePageViews; //DOT newDOTAnims = holder.newDOTAnims; scrollWatchers = holder.ScrollDrags; slideBtns = holder.SlideButtons; } else { gBtns = gameObject.GetComponentsInChildren <GButton>(true); buttons = gameObject.GetComponentsInChildren <Button>(true); toggles = gameObject.GetComponentsInChildren <Toggle>(true); scrollbars = gameObject.GetComponentsInChildren <Scrollbar>(true); inputFields = gameObject.GetComponentsInChildren <InputField>(true); dropDowns = gameObject.GetComponentsInChildren <Dropdown>(true); //GNewUI newLists = gameObject.GetComponentsInChildren <GNewListBase>(true); newTabLists = gameObject.GetComponentsInChildren <GNewTabList>(true); newLayoutTables = gameObject.GetComponentsInChildren <GNewLayoutTable>(true); //newUIAnims = gameObject.GetComponentsInChildren<GUIAnim>(true); newWebViews = gameObject.GetComponentsInChildren <GWebView>(true); dragablePageViews = gameObject.GetComponentsInChildren <GDragablePageView>(true); newDOTAnims = gameObject.GetComponentsInChildren <DG.Tweening.DOTweenAnimation>(true); scrollWatchers = gameObject.GetComponentsInChildren <GScrollWatcher>(true); slideBtns = gameObject.GetComponentsInChildren <GSlideButton>(true); } for (int i = 0; i < gBtns.Length; i++) { GButton gbtn = gBtns[i]; gbtn.OnClick = OnClick; if (gbtn.IsProfessionModel) { gbtn.PointerUpHandler = go => { //Debug.LogWarning("OnPointerUp"); CallPanelFunc("OnPointerUp", go.name); }; gbtn.PointerDownHandler = go => { //Debug.LogWarning("OnPointerDown"); CallPanelFunc("OnPointerDown", go.name); }; gbtn.OnPointerEnterHandler = go => { CallPanelFunc("OnPointerEnter", go.name); }; gbtn.OnPointerExitHandler = go => { CallPanelFunc("OnPointerExit", go.name); }; gbtn.OnPointerLongPressHandler = go => { CallPanelFunc("OnPointerLongPress", go.name); }; } } for (int i = 0; i < buttons.Length; i++) { Button btn = buttons[i]; btn.onClick.RemoveAllListeners(); btn.onClick.AddListener(delegate() { OnClick(btn.gameObject); }); } for (int i = 0; i < toggles.Length; i++) { Toggle toggle = toggles[i]; toggle.onValueChanged.RemoveAllListeners(); toggle.onValueChanged.AddListener(delegate(bool ischeck) { OnToggle(toggle.gameObject, ischeck); }); GNewBtnExpress btx = toggle.GetComponent <GNewBtnExpress>(); if (btx) { btx.RegisterToToggle(toggle); } } for (int i = 0; i < scrollbars.Length; i++) { Scrollbar scrollbar = scrollbars[i]; scrollbar.onValueChanged.RemoveAllListeners(); scrollbar.onValueChanged.AddListener(delegate(float value) { OnScroll(scrollbar.gameObject, value); }); } for (int i = 0; i < inputFields.Length; i++) { InputField inputField = inputFields[i]; inputField.onEndEdit.RemoveAllListeners(); inputField.onValueChanged.RemoveAllListeners(); inputField.onEndEdit.AddListener(delegate(string str) { OnEndEdit(inputField.gameObject, str); }); //try to cut out emoji if (inputField.contentType == InputField.ContentType.Standard) { inputField.onValidateInput = OnValidInputdelegate; } //inputField.onValueChanged.AddListener(delegate(string str) //{ // string str_new = Regex.Replace(str, @"\p{Cs}", ""); //屏蔽emoji // if (string.CompareOrdinal(str, str_new) != 0) // { // inputField.text = str_new; // } //}); inputField.onValueChanged.AddListener(delegate(string str) { OnValueChanged(inputField.gameObject, str); }); } for (int i = 0; i < dropDowns.Length; i++) { Dropdown dpd = dropDowns[i]; GNewDropDown gndpd = dpd as GNewDropDown; if (gndpd != null) { gndpd.OnInitItem = this.OnInitItem; } dpd.onValueChanged.RemoveAllListeners(); dpd.onValueChanged.AddListener(index => { OnDropDown(dpd.gameObject, index); }); } //NewUI for (int i = 0; i < newLists.Length; i++) { GNewListBase list = newLists[i]; list.ClickItemCallBack = this.OnSelectItem; //list.PressItemCallBack = this.OnPressItem; //list.ReleaseItemCallBack = this.OnReleaseItem; list.LongPressCallBack = this.OnLongPressItem; list.InitItemCallBack = this.OnInitItem; if (list.HasChildButton) { list.ClickItemButtonCallBack = this.OnSelectItemButton; } } for (int i = 0; i < newTabLists.Length; i++) { GNewTabList list = newTabLists[i]; list.ClickItemCallBack = this.OnTabListSelectItem; list.InitItemCallBack = this.OnTabListInitItem; if (list.HasChildButton) { list.ClickItemButtonCallBack = this.OnSelectItemButton; } list.ClickSubListItemButtonCallBack = this.OnTabSubListItemButton; } for (int i = 0; i < newLayoutTables.Length; i++) { GNewLayoutTable list = newLayoutTables[i]; list.ClickItemCallBack = this.OnSelectItem; list.InitItemCallBack = this.OnInitItem; if (list.HasChildButton) { list.ClickItemButtonCallBack = this.OnSelectItemButton; } } for (int i = 0; i < newWebViews.Length; i++) { GWebView gwv = newWebViews[i]; gwv.OnReceiveMessage = this.OnReceiveWebViewMessage; } for (int i = 0; i < dragablePageViews.Length; i++) { GDragablePageView gdv = dragablePageViews[i]; gdv._PageItemInitCallBack = this.OnInitItem; gdv._ClickPageItemCallBack = this.OnSelectItem; gdv._ClickPageItemButtonCallBack = this.OnSelectItemButton; gdv._PageItemIndexChangeCallBack = this.OnDragablePageIndexChange; } for (int i = 0; i < newDOTAnims.Length; i++) { if (newDOTAnims[i].IsCallLuaOnComplete) { newDOTAnims[i].OnComplete2Lua = this.OnDOTComplete; } } for (int i = 0; i < scrollWatchers.Length; i++) { scrollWatchers[i].SetHandler(OnScrollWithoutFocus); } for (int i = 0; i < slideBtns.Length; i++) { slideBtns[i].OnSlide = this.OnButtonSlide; } _PanelName = this.name; Schedule.SetTag(_PanelName); _HasRegistered = true; } }
//Remove Callbacks of UI Components in LinkHolder, seem to be of no use? void RemoveHandler() { if (_HasRegistered) { GButton[] gBtns; Button[] buttons; Toggle[] toggles; Scrollbar[] scrollbars; InputField[] inputFields; Dropdown[] dropDowns; GNewListBase[] newLists; GNewTabList[] newTabLists; GNewLayoutTable[] newLayoutTables; GWebView[] newWebViews; GDragablePageView[] dragablePageViews; DG.Tweening.DOTweenAnimation[] newDOTAnims; GScrollWatcher[] scrollWatchers; GSlideButton[] slideBtns; InteractableUIHolder holder = gameObject.GetComponent <InteractableUIHolder>(); if (holder != null) { gBtns = holder.GBtns; buttons = holder.Buttons; toggles = holder.Toggles; scrollbars = holder.Scrollbars; inputFields = holder.InputFields; dropDowns = holder.Dropdowns; //GNewUI newLists = holder.NewLists; newTabLists = holder.NewTabLists; newLayoutTables = holder.NewLayoutTables; newWebViews = holder.newWebViews; dragablePageViews = holder.dragablePageViews; newDOTAnims = holder.newDOTAnims; scrollWatchers = holder.ScrollDrags; slideBtns = holder.SlideButtons; } else { gBtns = gameObject.GetComponentsInChildren <GButton>(true); buttons = gameObject.GetComponentsInChildren <Button>(true); toggles = gameObject.GetComponentsInChildren <Toggle>(true); scrollbars = gameObject.GetComponentsInChildren <Scrollbar>(true); inputFields = gameObject.GetComponentsInChildren <InputField>(true); dropDowns = gameObject.GetComponentsInChildren <Dropdown>(true); //GNewUI newLists = gameObject.GetComponentsInChildren <GNewListBase>(true); newTabLists = gameObject.GetComponentsInChildren <GNewTabList>(true); newLayoutTables = gameObject.GetComponentsInChildren <GNewLayoutTable>(true); newWebViews = gameObject.GetComponentsInChildren <GWebView>(true); dragablePageViews = gameObject.GetComponentsInChildren <GDragablePageView>(true); newDOTAnims = gameObject.GetComponentsInChildren <DG.Tweening.DOTweenAnimation>(true); scrollWatchers = gameObject.GetComponentsInChildren <GScrollWatcher>(true); slideBtns = gameObject.GetComponentsInChildren <GSlideButton>(true); } for (int i = 0; i < gBtns.Length; i++) { GButton gbtn = gBtns[i]; gbtn.OnClick = null; if (gbtn.IsProfessionModel) { gbtn.PointerUpHandler = null; gbtn.PointerDownHandler = null; gbtn.OnPointerEnterHandler = null; gbtn.OnPointerExitHandler = null; gbtn.OnPointerLongPressHandler = null; } } for (int i = 0; i < buttons.Length; i++) { buttons[i].onClick.RemoveAllListeners(); } for (int i = 0; i < toggles.Length; i++) { toggles[i].onValueChanged.RemoveAllListeners(); } for (int i = 0; i < scrollbars.Length; i++) { scrollbars[i].onValueChanged.RemoveAllListeners(); } for (int i = 0; i < inputFields.Length; i++) { inputFields[i].onEndEdit.RemoveAllListeners(); inputFields[i].onValueChanged.RemoveAllListeners(); } for (int i = 0; i < dropDowns.Length; i++) { GNewDropDown gndpd = dropDowns[i] as GNewDropDown; if (gndpd != null) { gndpd.OnInitItem = null; } dropDowns[i].onValueChanged.RemoveAllListeners(); } //NewUI for (int i = 0; i < newLists.Length; i++) { newLists[i].ClickItemCallBack = null; newLists[i].LongPressCallBack = null; newLists[i].InitItemCallBack = null; newLists[i].ClickItemButtonCallBack = null; } for (int i = 0; i < newTabLists.Length; i++) { GNewTabList list = newTabLists[i]; list.ClickItemCallBack = null; list.InitItemCallBack = null; list.ClickItemButtonCallBack = null; list.ClickSubListItemButtonCallBack = null; } for (int i = 0; i < newLayoutTables.Length; i++) { GNewLayoutTable list = newLayoutTables[i]; list.ClickItemCallBack = null; list.InitItemCallBack = null; list.ClickItemButtonCallBack = null; } for (int i = 0; i < newWebViews.Length; i++) { GWebView gwv = newWebViews[i]; gwv.OnReceiveMessage = null; } for (int i = 0; i < dragablePageViews.Length; i++) { GDragablePageView gdv = dragablePageViews[i]; gdv._PageItemInitCallBack = null; gdv._ClickPageItemCallBack = null; gdv._ClickPageItemButtonCallBack = null; gdv._PageItemIndexChangeCallBack = null; } for (int i = 0; i < newDOTAnims.Length; i++) { if (newDOTAnims[i].IsCallLuaOnComplete) { newDOTAnims[i].OnComplete2Lua = null; } } for (int i = 0; i < scrollWatchers.Length; i++) { scrollWatchers[i].SetHandler(null); } for (int i = 0; i < slideBtns.Length; i++) { slideBtns[i].OnSlide = null; } _HasRegistered = false; } }