Пример #1
0
    public static void Load(Type type)
    {
        try
        {
            string json = LoadJson(type);
            var    obj  = JsonUtility.FromJson(json, type);

            type.InvokeMember(
                "Instance",
                BindingFlags.Public | BindingFlags.Static | BindingFlags.SetField | BindingFlags.FlattenHierarchy,
                null, null, new object[] { obj });

            var afterLoaded = type.GetMethod(
                "AfterLoaded",
                BindingFlags.NonPublic | BindingFlags.Instance);
            if (null != afterLoaded)
            {
                afterLoaded.Invoke(obj, null);
            }
        }
        catch (Exception e)
        {
            ConfigLog.LogError("Failed to load " + type.Name);
            ConfigLog.LogException(e);
        }
    }
Пример #2
0
 public static bool Exists(string key)
 {
     if (null == Instance || null == Instance.query)
     {
         ConfigLog.LogError("I18n has not been initialized!");
         return(false);
     }
     return(Instance.query.ContainsKey(key));
 }
Пример #3
0
    public static void Load(string name)
    {
        Type type = Array.Find(types, v => v.Name == name);

        if (null == type)
        {
            ConfigLog.LogError("ConfigLoader.Load: type is not found, " + name);
            return;
        }
        Load(type);
    }
Пример #4
0
    public static string Get(string key)
    {
        if (null == Instance || null == Instance.query)
        {
            ConfigLog.LogError("I18n has not been initialized!");
            return(ErrorValue);
        }

        string value;

        if (!Instance.query.TryGetValue(key, out value))
        {
            value = ErrorValue;
        }
        return(value);
    }