#region 控件字典
protected Dictionary<string, string> dicWidgetFullName = new Dictionary<string, string>();
//递归调用,将rootTransform下面所有子物体,按照物体名称——物体路径,缓存到dicWidgetFullName
//递归遍历控件,填充控件字典
protected void GetWidgetFullName(Transform rootTransform)
{
for (int i = 0;i < rootTransform.childCount;++i)
{
AddWigetFullName(rootTransform.GetChild(i).name, GetFullName(rootTransform.GetChild(i)));
GetWidgetFullName(rootTransform.GetChild(i));
}
}
//填充控件字典
private void AddWigetFullName(string widgetName, string fullName)
{
if (!dicWidgetFullName.ContainsKey(widgetName))
{
dicWidgetFullName.Add(widgetName, fullName);
}
}
//获取该控件的完整路径名
private string GetFullName(Transform currentTransform)
{
string fullName = "";
while (currentTransform != transform)
{
fullName = currentTransform.name + fullName;
if (currentTransform.parent != transform)
fullName = "/" + fullName;
currentTransform = currentTransform.parent;
}
return fullName;
}
protected Transform FindTransform(string transformName)
{
if (dicWidgetFullName.ContainsKey(transformName))
return transform.Find(dicWidgetFullName[transformName]);
return null;
}
#endregion
控件字典
最新推荐文章于 2022-07-23 16:25:38 发布