57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BITKit.Mod;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace BITKit
|
|
{
|
|
public static class ModServiceDictionaryReferenceExtensions
|
|
{
|
|
public static UniTask<T> LoadAssets<T>(int id) where T :class
|
|
{
|
|
var path = DictionaryReferenceScriptableObject.Dictionary[id];
|
|
return ModService.LoadAsset<T>(path);
|
|
}
|
|
}
|
|
public sealed class DictionaryReferenceConfigAttribute : System.Attribute
|
|
{
|
|
public readonly int index;
|
|
public DictionaryReferenceConfigAttribute(int index)
|
|
{
|
|
this.index = index;
|
|
}
|
|
public DictionaryReferenceConfigAttribute(string keyword)
|
|
{
|
|
index=keyword.GetHashCode();
|
|
}
|
|
public DictionaryReferenceConfigAttribute()
|
|
{
|
|
index=0;
|
|
}
|
|
}
|
|
[Serializable]
|
|
public struct DictionaryReference : IReference
|
|
{
|
|
[SerializeField] private int index;
|
|
#if UNITY_EDITOR
|
|
[SerializeField,HideInInspector] private string keyword;
|
|
#endif
|
|
|
|
public string Get()
|
|
{
|
|
|
|
if (DictionaryReferenceScriptableObject.Dictionary.TryGetValue(index, out var value))
|
|
{
|
|
return value;
|
|
}
|
|
return "Not Found";
|
|
}
|
|
}
|
|
|
|
}
|
|
|