Esempio n. 1
0
    public static GSheetSettings GetSettings()
    {
        string[] settings = AssetDatabase.FindAssets("t:GSheetSettings");
        if (settings.Length == 0)
        {
            Debug.Log("can't find settings");
            return(null);
        }
        if (settings.Length > 1)
        {
            Debug.Log("settings num > 1 error");
            return(null);
        }
        GSheetSettings setting = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(settings [0]), typeof(GSheetSettings)) as GSheetSettings;

        return(setting);
    }
Esempio n. 2
0
    void Download()
    {
        GSheetSettings setting = GSheetUtility.GetSettings();

        if (setting == null)
        {
            return;
        }
        SpreadsheetsService service = setting.GetService();

        WorksheetEntry worksheet = setting.GetWorkSheet(service, sheet.SpreadSheetName, sheet.WorkSheetName);

        AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);

        // Fetch the list feed of the worksheet.
        ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
        ListFeed  listFeed  = service.Query(listQuery);

        sheet.data = new List <Entry> ();
        Type         t           = typeof(Entry);
        BindingFlags bindingFlag = BindingFlags.NonPublic | BindingFlags.Instance;

        foreach (ListEntry row in listFeed.Entries)
        {
            object entry = Activator.CreateInstance(t);
            foreach (ListEntry.Custom element in row.Elements)
            {
                string    fieldName = string.Format("_{0}", element.LocalName.ToLower());
                FieldInfo field     = t.GetField(fieldName, bindingFlag);
                if (field == null)
                {
                    Debug.LogError("null field : " + element.LocalName);
                    continue;
                }
                SetValue(field, entry, element.Value);
            }
            sheet.data.Add(entry as Entry);
        }
    }
Esempio n. 3
0
    void Download()
    {
        GSheetSettings setting = GSheetUtility.GetSettings();

        if (setting == null)
        {
            return;
        }
        SpreadsheetsService service = setting.GetService();

        WorksheetEntry worksheet = setting.GetWorkSheet(service, sheet.SpreadSheetName, sheet.WorkSheetName);

        AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);

        // Fetch the list feed of the worksheet.
        ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
        ListFeed  listFeed  = service.Query(listQuery);

        sheet.data = new List <Entry> ();
        Type         t           = typeof(Entry);
        BindingFlags bindingFlag = BindingFlags.NonPublic | BindingFlags.Instance;

        foreach (ListEntry row in listFeed.Entries)
        {
            object entry = Activator.CreateInstance(t);
            foreach (ListEntry.Custom element in row.Elements)
            {
                //필드 이름이 비어있는 경우 _clrrx, _cyevm... 같은 형태로 연결되더라
                var blankGoogleSpreadsheetRegex = new Regex(@"_\w\w\w\w\w");
                if (blankGoogleSpreadsheetRegex.IsMatch(element.LocalName))
                {
                    continue;
                }
                // 타입으로 추정 안되면 건너뛰기
                var allowedPrefix = new HashSet <string>()
                {
                    "s", "f", "n"
                };
                bool prefixFound = false;
                foreach (var prefix in allowedPrefix)
                {
                    if (element.LocalName.StartsWith(prefix))
                    {
                        prefixFound = true;
                        break;
                    }
                }
                if (prefixFound == false)
                {
                    continue;
                }


                string    fieldName = string.Format("_{0}", element.LocalName.ToLower());
                FieldInfo field     = t.GetField(fieldName, bindingFlag);
                if (field == null)
                {
                    Debug.LogError("null field : " + element.LocalName);
                    continue;
                }
                SetValue(field, entry, element.Value);
            }
            sheet.data.Add(entry as Entry);
        }
    }
Esempio n. 4
0
    public void CreateScript()
    {
        GSheetSettings setting = GSheetUtility.GetSettings();

        if (setting == null)
        {
            return;
        }
        SpreadsheetsService service = setting.GetService();

        WorksheetEntry worksheet = setting.GetWorkSheet(service, manager.SpreadSheetName, manager.WorkSheetName);


        CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
        CellFeed  cellFeed  = service.Query(cellQuery);

        string        fieldFormat = setting.FieldTemplate.text;
        StringBuilder sb          = new StringBuilder();

        // Iterate through each cell, printing its value.
        foreach (CellEntry cell in cellFeed.Entries)
        {
            if (cell.Row > 1)
            {
                break;
            }
            string fieldType = "string";
            if (cell.Value[0] == 'n')
            {
                fieldType = "int";
            }
            else if (cell.Value[0] == 'f')
            {
                fieldType = "float";
            }
            else if (cell.Value[0] == '_')
            {
                continue;
            }

            string fieldScript = fieldFormat.Replace("{FieldName}", cell.Value).Replace("{LowerCaseFieldName}", cell.Value.ToLower()).Replace("{FieldType}", fieldType);
            sb.Append(fieldScript);
        }

        string        dataFormat = setting.DataTemplate.text;
        string        dataScript = dataFormat.Replace("{WorkSheetName}", manager.WorkSheetName).Replace("{FieldList}", sb.ToString());
        StringBuilder dataPathSB = new StringBuilder(setting.ScriptPath);

        if (setting.ScriptPath[setting.ScriptPath.Length - 1] != '/')
        {
            dataPathSB.Append("/");
        }
        dataPathSB.Append(manager.WorkSheetName);
        dataPathSB.Append("Data.cs");

        System.IO.File.WriteAllText(dataPathSB.ToString(), dataScript);


        string        editorFormat = setting.DataEditorTemplate.text;
        string        editorScript = editorFormat.Replace("{WorkSheetName}", manager.WorkSheetName);
        StringBuilder editorPathSB = new StringBuilder(setting.EditorScriptPath);

        if (setting.EditorScriptPath [setting.EditorScriptPath.Length - 1] != '/')
        {
            editorPathSB.Append("/");
        }
        editorPathSB.Append(manager.WorkSheetName);
        editorPathSB.Append("DataEditor.cs");

        System.IO.File.WriteAllText(editorPathSB.ToString(), editorScript);

        AssetDatabase.Refresh();
    }
Esempio n. 5
0
 void OnEnable()
 {
     settings = target as GSheetSettings;
 }
Esempio n. 6
0
 void OnEnable()
 {
     settings = target as GSheetSettings;
 }