2025-01-23 04:22:47 +00:00
|
|
|
using System;
|
2024-12-15 01:39:39 +00:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class MyEnumToInt : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[RuntimeInitializeOnLoadMethod]
|
|
|
|
|
static void OnRuntimeMethodLoad()
|
|
|
|
|
{
|
|
|
|
|
new GameObject("MyEnumToInt").AddComponent<MyEnumToInt>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MyEnumToInt Ins;
|
|
|
|
|
|
2025-01-23 04:22:47 +00:00
|
|
|
private Dictionary<Type, Dictionary<Enum, int>> enumToIntMapping = new Dictionary<Type, Dictionary<Enum, int>>();
|
2024-12-15 01:39:39 +00:00
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
Ins = this;
|
|
|
|
|
DontDestroyOnLoad(gameObject);
|
|
|
|
|
|
2025-01-23 04:22:47 +00:00
|
|
|
// 열거형 초기화
|
|
|
|
|
InitializeEnumMapping<UIMenu>();
|
|
|
|
|
InitializeEnumMapping<eGameMode>();
|
|
|
|
|
InitializeEnumMapping<eDungeon>();
|
|
|
|
|
InitializeEnumMapping<eDifficult>();
|
|
|
|
|
InitializeEnumMapping<eAttackType>();
|
|
|
|
|
InitializeEnumMapping<eSound>();
|
|
|
|
|
InitializeEnumMapping<eBGM>();
|
|
|
|
|
InitializeEnumMapping<eCommon>();
|
|
|
|
|
InitializeEnumMapping<eStat>();
|
|
|
|
|
InitializeEnumMapping<eBuffs>();
|
|
|
|
|
InitializeEnumMapping<eBuff>();
|
|
|
|
|
InitializeEnumMapping<NGUIAnchorSide>();
|
|
|
|
|
InitializeEnumMapping<eAttendance>();
|
|
|
|
|
InitializeEnumMapping<ePurpose>();
|
|
|
|
|
InitializeEnumMapping<eTime>();
|
|
|
|
|
}
|
2024-12-15 01:39:39 +00:00
|
|
|
|
2025-01-23 04:22:47 +00:00
|
|
|
private void InitializeEnumMapping<T>() where T : Enum
|
|
|
|
|
{
|
|
|
|
|
var mapping = new Dictionary<Enum, int>();
|
|
|
|
|
int index = 0;
|
2024-12-15 01:39:39 +00:00
|
|
|
|
2025-01-23 04:22:47 +00:00
|
|
|
foreach (T value in Enum.GetValues(typeof(T)))
|
|
|
|
|
{
|
|
|
|
|
mapping.Add(value, index++);
|
|
|
|
|
}
|
2024-12-15 01:39:39 +00:00
|
|
|
|
2025-01-23 04:22:47 +00:00
|
|
|
enumToIntMapping[typeof(T)] = mapping;
|
2024-12-15 01:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-23 04:22:47 +00:00
|
|
|
public int Get_Int<T>(T enumValue) where T : Enum
|
|
|
|
|
{
|
|
|
|
|
if (enumToIntMapping.TryGetValue(typeof(T), out var mapping))
|
|
|
|
|
{
|
|
|
|
|
return mapping[enumValue];
|
|
|
|
|
}
|
2024-12-15 01:39:39 +00:00
|
|
|
|
2025-01-23 04:22:47 +00:00
|
|
|
throw new Exception($"Enum type {typeof(T).Name} is not initialized.");
|
|
|
|
|
}
|
2024-12-15 01:39:39 +00:00
|
|
|
}
|