43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
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;
|
||
}
|
||
}
|
||
} |