메뉴, 세부 메뉴 활성화/비활성화 기능 개발 및 검색 레이아웃 구성
This commit is contained in:
35
Assets/Scripts/ComponentFinderExtensions.cs
Normal file
35
Assets/Scripts/ComponentFinderExtensions.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ComponentFinderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 트랜스폼 기준으로 자식들의 컴포넌트를 이름(key)으로 매핑
|
||||
/// </summary>
|
||||
public static Dictionary<string, T> FindComponentDictionary<T>(this Transform root, bool includeInactive = true) where T : Component
|
||||
{
|
||||
var dict = new Dictionary<string, T>();
|
||||
var components = root.GetComponentsInChildren<T>(includeInactive);
|
||||
|
||||
foreach (var comp in components)
|
||||
{
|
||||
if (string.IsNullOrEmpty(comp.name))
|
||||
continue;
|
||||
|
||||
if (!dict.ContainsKey(comp.name))
|
||||
dict[comp.name] = comp;
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary에서 key로 안전하게 가져오기
|
||||
/// </summary>
|
||||
public static T GetOrNull<T>(this Dictionary<string, T> dict, string name)
|
||||
where T : UnityEngine.Object
|
||||
{
|
||||
dict.TryGetValue(name, out var value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user