36 lines
1016 B
C#
36 lines
1016 B
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace ZC
|
|||
|
{
|
|||
|
public class SceneGameObjectBinding : 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}");
|
|||
|
}
|
|||
|
public T GetValue<T>(string nameStr)where T: Component
|
|||
|
{
|
|||
|
foreach (var data in Datas)
|
|||
|
{
|
|||
|
if (data.name == nameStr)
|
|||
|
{
|
|||
|
return data.go.GetComponent<T>();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
throw new NullReferenceException($"没有找到绑定这个名字的物体,name:{nameStr}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|