forked from zxl/LaboratoryProtection
76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
using Cysharp.Threading.Tasks;
|
|
|
|
using PMaker.DependencyInjection;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
|
|
using UnityEngine;
|
|
|
|
namespace PMaker.Set
|
|
{
|
|
public class ObjectSet : SingletonMonobehaviour
|
|
{
|
|
public List<GameObject> objects;
|
|
|
|
[ReadOnly]
|
|
public HashSet<Dictionary<string, GameObject>> subObjectSetMapper;
|
|
|
|
[ReadOnly]
|
|
public Dictionary<string, string> nameMapper;
|
|
|
|
public GameObject this[string name]
|
|
{
|
|
get
|
|
{
|
|
if (nameMapper.TryGetValue(name, out var newName))
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
newName = name;
|
|
}
|
|
var go = objects.FirstOrDefault(o => o.name == newName);
|
|
if (go == default)
|
|
{
|
|
foreach (var item in subObjectSetMapper)
|
|
{
|
|
if (item.TryGetValue(newName, out go) == true)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return go;
|
|
}
|
|
}
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
subObjectSetMapper = new HashSet<Dictionary<string, GameObject>>();
|
|
nameMapper = new Dictionary<string, string>();
|
|
}
|
|
}
|
|
|
|
public static class BaseBehaviourExtension
|
|
{
|
|
public static async UniTask WaitHighlightClick(this BaseBehaviour baseBehaviour, string name, CancellationToken cancellationToken)
|
|
{
|
|
if (IoC.TryGetSingleton<ObjectSet>(out var set))
|
|
{
|
|
var go = set[name];
|
|
if (go == true)
|
|
{
|
|
await go.WaitClickHighlightAsync(cancellationToken);
|
|
return;
|
|
}
|
|
}
|
|
await UniTask.Yield(cancellationToken);
|
|
}
|
|
}
|
|
} |