42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using UnityEngine;
|
|
|
|
public class ReflectionTest : MonoBehaviour
|
|
{
|
|
public PermanentTriggerBase ptb;
|
|
public MobileController mc;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
FieldInfo[] fieldInfo = ptb.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
|
foreach (FieldInfo field in fieldInfo)
|
|
{
|
|
if (field.GetCustomAttribute<ReconnetAtrribute>() != null)
|
|
{
|
|
ReconnetAtrribute attribute = field.GetCustomAttribute<ReconnetAtrribute>();
|
|
object value = field.GetValue(ptb);
|
|
Debug.Log($"Field: {field.Name}, Value: {value}, Description: {attribute.Description}");
|
|
if (attribute.Description == "downIndex")
|
|
{
|
|
field.SetValue(ptb, 1);
|
|
}
|
|
Debug.Log($"=>Field: {field.Name}, Value: {value}, Description: {attribute.Description}");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.V))
|
|
{
|
|
Debug.Log("X");
|
|
Debug.Log("===>" + mc.downIndex);
|
|
}
|
|
}
|
|
}
|