UnityUGUI间接触发UI事件

    xiaoxiao2022-06-26  210

    间接触发UI 事件

    比如如果一个Image上有PointEnter和Exit的EventSystem事件,我想在点击另一个按钮或者执行其他操作的时候同时触发他的效果,这个博客可以帮到你。

    UI事件示例

    public class MouseHighLightPants : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { private List<GameObject> currentPart = new List<GameObject>(); public void OnPointerEnter(PointerEventData eventData) { Debug.Log(this.name); //HighLightPantsByName(); } public void OnPointerExit(PointerEventData eventData) { foreach (GameObject item in currentPart) { FlashManager.ConstantOff(item); } } }

    触发事件方法示例

    private void InputToggleListener() { for (int i = 0; i < needInputToggleGroup.transform.childCount; i++) { Toggle tol = needInputToggleGroup.transform.GetChild(i).GetComponent<Toggle>(); int currentIndex = i; tol.onValueChanged.AddListener((bool isOn) => { if (isOn) { currentInputText = tol.transform.GetComponentInChildren<Text>(); currentChangeInputText =changeInputTextGroup.transform.GetChild(currentIndex).GetComponent<Text(); currentUIImage = showPantsPartGroup.transform.GetChild(currentIndex).GetComponent<Image>(); inputKeyBoardPanel.SetActive(true); CancelConstant(); //触发image显示事件 ExecuteEvents.Execute<IPointerEnterHandler>(currentUIImage.gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.pointerEnterHandler); } }); } }

    参照

    [1]:参考链接.


    最新回复(0)