[M] deep link
This commit is contained in:
45
sdk-intergration/Assets/Scripts/OneLinkTest.cs
Normal file
45
sdk-intergration/Assets/Scripts/OneLinkTest.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user