Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- //just expirimenting.
- public abstract class EnumButton : MonoBehaviour
- {
- }
- public interface IFooButtonListener
- {
- void OnClick(Foo foo);
- }
- public enum Foo{bar, age};
- [RequireComponent(typeof(Button))]
- public class FooButton : EnumButton
- {
- [SerializeField] public Foo foo = Foo.bar;
- public void Init(IFooButtonListener listener)
- {
- gameObject.GetComponent<Button>().
- onClick.AddListener(
- ()=>listener.OnClick(foo)
- );
- }
- }
- public class Usage : MonoBehaviour, IFooButtonListener
- {
- [SerializeField] List<FooButton> buttons;
- public void Awake()
- {
- foreach(var b in buttons)
- {
- b.Init(this);
- }
- }
- public void OnClick(Foo foo)
- {
- Debug.Log("button click from "+foo);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment