実現したいこと
UnityでEventSystemを用いて他オブジェクトの関数を実行する。
独自ボタンを作り、ボタンを押したときに実行されるようにしたい。
試したこと
実行されてないようだったので試しにDebug.Logを入れてみるも何も表示されず。
OnPointerClickにあるDebugはしっかり表示された。
エラーが出ないため、自身では原因がわからず、困り果てたため質問します。
該当のソースコード
呼び出す方(ボタン側)のコード
C#
using DG.Tweening; using UnityEngine; using UnityEngine.EventSystems; public class ButtonEndTurn : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler { public System.Action onClickCallback; public GameObject objButton; public GameObject objSelectedCity; public GameObject objTarget; MakeCity city; [SerializeField] private CanvasGroup _canvasGroup; public void OnPointerClick(PointerEventData eventData) { onClickCallback?.Invoke(); city = objSelectedCity.GetComponent<MakeCity>(); ExecuteEvents.Execute<IEventCallerEndTurn>( target: objTarget, eventData: null, functor: Method ); //Debug.Log(city.selectedList[0].pos[0]); } private void Method(IEventCallerEndTurn reciever, BaseEventData eventData){ //reciever.ScoreTest(city.selectedList); Debug.Log("@@@@@@@@@"); } public void OnPointerDown(PointerEventData eventData) { transform.DOScale(0.95f, 0.24f).SetEase(Ease.OutCubic); _canvasGroup.DOFade(0.8f, 0.24f).SetEase(Ease.OutCubic); } public void OnPointerUp(PointerEventData eventData) { transform.DOScale(1f, 0.24f).SetEase(Ease.OutCubic); _canvasGroup.DOFade(1f, 0.24f).SetEase(Ease.OutCubic); } }
呼び出される方のコード
C#
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using TMPro; public interface IEventCallerEndTurn : IEventSystemHandler { void ScoreTest(List<MapInfo> city); } public class ScoreCheckerTest : MonoBehaviour, IEventCallerEndTurn { public TextMeshProUGUI score; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public void ScoreTest(List<MapInfo> loaded){ int countTest = 0; foreach (MapInfo m in loaded){ countTest++; } score.text = $"{countTest}"; Debug.Log("*********"); } }
補足情報
EDITER VERSION 2021.3.6f1
まだ回答がついていません
会員登録して回答してみよう