[M] deep link

This commit is contained in:
2025-01-15 18:53:22 +08:00
parent 0332758335
commit 90e54158f1
13 changed files with 1348 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
public class OneLinkTest : MonoBehaviour
{
[SerializeField] private GameObject btnContainer;
[SerializeField] private GameObject btn;
[SerializeField] private Text message;
void Start()
{
var aFInit = new AFInit();
aFInit.text = message;
// Get funcs methods witch has Btn attribute
var methods = aFInit.GetType().GetMethods();
foreach (var method in methods)
{
var btnAttr = method.GetCustomAttribute<BtnAttribute>();
if (btnAttr == null)
{
continue;
}
var btnObj = Instantiate(btn, btnContainer.transform);
btnObj.GetComponentInChildren<Text>().text = btnAttr.btnName;
btnObj.GetComponent<Button>().onClick.AddListener(() => method.Invoke(aFInit, null));
btnObj.SetActive(true);
}
}
}
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
public class BtnAttribute : Attribute
{
public string btnName;
public BtnAttribute(string btnName)
{
this.btnName = btnName;
}
}