48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
using System.Linq;
|
|
namespace BITKit
|
|
{
|
|
public static partial class Extensions
|
|
{
|
|
public static bool TryGetRoot(this Component self, out Root root)
|
|
{
|
|
root = null;
|
|
try
|
|
{
|
|
if (self is not null && self.TryGetComponent<Root>(out root))
|
|
{
|
|
root = root.root;
|
|
return true;
|
|
}
|
|
}
|
|
catch (System.Exception)
|
|
{
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
public class Root : MonoBehaviour
|
|
{
|
|
[Header(Constant.Header.Settings)]
|
|
public Root root;
|
|
public string id;
|
|
[Header(Constant.Header.Gameobjects)]
|
|
public Dictionary<string, Root> childs = new();
|
|
public Root Get(string id)
|
|
{
|
|
if (id.IsNullOrEmpty())
|
|
{
|
|
return this;
|
|
}
|
|
else
|
|
{
|
|
return childs[id];
|
|
}
|
|
}
|
|
|
|
}
|
|
} |