更改文件架构
This commit is contained in:
65
Packages/Common~/Scripts/Root/Root.cs
Normal file
65
Packages/Common~/Scripts/Root/Root.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
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 : SerializedMonoBehaviour
|
||||
{
|
||||
[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];
|
||||
}
|
||||
}
|
||||
[Button]
|
||||
void AutoSetUp()
|
||||
{
|
||||
if (id.IsNullOrEmpty())
|
||||
{
|
||||
id = name;
|
||||
}
|
||||
childs.Clear();
|
||||
if (root == this)
|
||||
{
|
||||
GetComponentsInChildren<Root>(true)
|
||||
.Where(x => x.root == root)
|
||||
.ForEach(x =>
|
||||
{
|
||||
childs.TryAdd(x.id, x);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/Root/Root.cs.meta
Normal file
11
Packages/Common~/Scripts/Root/Root.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b097545a8074b844a36f6c46d1021d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user