コード例 #1
0
    public static T LoadUsingKey <T>(string key) where T : new()
    {
        SpreadsheetListFeed listFeed = GDocService.GetSpreadsheetContents(key);

        if (listFeed == null)
        {
            Debug.LogWarning("GameConfig spreadsheet was not loaded. Loading gameconfig.txt instead.");
            return(LoadFromResources <T>());
        }

        Hashtable tableRows = listFeed.GetRows();
        T         config    = new T();

        PropertyInfo[] properties = config.GetType().GetProperties();
        for (int i = 0; i < properties.Length; ++i)
        {
            PropertyInfo property = properties[i];
            if (tableRows.ContainsKey(property.Name))
            {
                Hashtable tableColumns = tableRows[property.Name] as Hashtable;
                if (tableColumns.Contains("value"))
                {
                    Log("Value of " + property.Name + " : " + tableColumns["value"]);
                    Log("Before: " + property.GetValue(config, null));
                    property.SetValue(config, Convert.ChangeType(tableColumns["value"], property.PropertyType), null);
                    Log("After: " + property.GetValue(config, null));
                }
            }
        }
        return(config);
    }