HAARFTE/Assets/DemoGame/GameScript/Hotfix/UI/UIBinding.cs

43 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
namespace ZC
{
public class GameObjectBinding : MonoBehaviour
{
[SerializeField] private List<GameObjectBindingData> Datas = new List<GameObjectBindingData>();
public GameObject GetValue(string nameStr)
{
foreach (var data in Datas)
{
if (data.name == nameStr)
{
return data.go;
}
}
throw new NullReferenceException($"没有找到绑定这个名字的物体name{nameStr}");
}
}
[System.Serializable]
public class GameObjectBindingData
{
[HorizontalGroup("aaa")] [LabelText("k"), LabelWidth(10)]
public string name;
[HorizontalGroup("aaa")] [LabelText("v"), LabelWidth(10)] [OnValueChanged(nameof(OnValueChanged))]
public GameObject go;
private void OnValueChanged()
{
if (go != null)
name = go.name;
else
name = string.Empty;
}
}
}