docs.unity3d.com
    目次を表示する/隠す

    Class GoogleSheetsExtension

    Provides an editor interface to GoogleSheets.

    Inheritance
    Object
    CollectionExtension
    GoogleSheetsExtension
    Inherited Members
    CollectionExtension.TargetCollection
    CollectionExtension.Initialize()
    CollectionExtension.Destroy()
    Namespace: UnityEditor.Localization.Plugins.Google
    Syntax
    [Serializable]
    public class GoogleSheetsExtension : CollectionExtension
    Examples

    This example uses the data that was configured in the GoogleSheetsExtension to perform a Push.

    [MenuItem("Localization/Google Sheets/Push With Google Extension")]
    public static void PushWithExtension()
    {
        // You should provide your String Table Collection name here
        var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
        var googleExtension = tableCollection.Extensions.FirstOrDefault(e => e is GoogleSheetsExtension) as GoogleSheetsExtension;
        if (googleExtension == null)
        {
            Debug.LogError($"String Table Collection {tableCollection.TableCollectionName} Does not contain a Google Sheets Extension.");
            return;
        }
    
        PushExtension(googleExtension);
    }
    
    static void PushExtension(GoogleSheetsExtension googleExtension)
    {
        // Setup the connection to Google
        var googleSheets = new GoogleSheets(googleExtension.SheetsServiceProvider);
        googleSheets.SpreadSheetId = googleExtension.SpreadsheetId;
    
        // Now send the update. We can pass in an optional ProgressBarReporter so that we can updates in the Editor.
        googleSheets.PushStringTableCollection(googleExtension.SheetId, googleExtension.TargetCollection as StringTableCollection, googleExtension.Columns, new ProgressBarReporter());
    }

    This example shows how to use the data that was configured in a Google Sheets extension to perform a pull.

    [MenuItem("Localization/Google Sheets/Pull With Google Extension")]
    public static void PullWithExtension()
    {
        // You should provide your String Table Collection name here
        var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
        var googleExtension = tableCollection.Extensions.FirstOrDefault(e => e is GoogleSheetsExtension) as GoogleSheetsExtension;
        if (googleExtension == null)
        {
            Debug.LogError($"String Table Collection {tableCollection.TableCollectionName} Does not contain a Google Sheets Extension.");
            return;
        }
    
        PullExtension(googleExtension);
    }
    
    static void PullExtension(GoogleSheetsExtension googleExtension)
    {
        // Setup the connection to Google
        var googleSheets = new GoogleSheets(googleExtension.SheetsServiceProvider);
        googleSheets.SpreadSheetId = googleExtension.SpreadsheetId;
    
        // Now update the collection. We can pass in an optional ProgressBarReporter so that we can updates in the Editor.
        googleSheets.PullIntoStringTableCollection(googleExtension.SheetId, googleExtension.TargetCollection as StringTableCollection, googleExtension.Columns, reporter: new ProgressBarReporter());
    }

    This example shows how to push every StringTableCollection that contains a GoogleSheetsExtension.

    [MenuItem("Localization/Google Sheets/Push All Google Sheets Extensions")]
    public static void PushAllExtensions()
    {
        // Get every String Table Collection
        var stringTableCollections = LocalizationEditorSettings.GetStringTableCollections();
    
        foreach (var collection in stringTableCollections)
        {
            // Its possible a String Table Collection may have more than one GoogleSheetsExtension.
            // For example if each Locale we pushed/pulled from a different sheet.
            foreach (var extension in collection.Extensions)
            {
                if (extension is GoogleSheetsExtension googleExtension)
                {
                    PushExtension(googleExtension);
                }
            }
        }
    }

    This example shows how to pull every StringTableCollection that contains a GoogleSheetsExtension.

    [MenuItem("Localization/Google Sheets/Pull All Google Sheets Extensions")]
    public static void PullAllExtensions()
    {
        // Get every String Table Collection
        var stringTableCollections = LocalizationEditorSettings.GetStringTableCollections();
    
        foreach (var collection in stringTableCollections)
        {
            // Its possible a String Table Collection may have more than one GoogleSheetsExtension.
            // For example if each Locale we pushed/pulled from a different sheet.
            foreach (var extension in collection.Extensions)
            {
                if (extension is GoogleSheetsExtension googleExtension)
                {
                    PullExtension(googleExtension);
                }
            }
        }
    }

    Properties

    Columns

    The column mappings. Each SheetColumn represents a column in a Google sheet. The column mappings are responsible for converting to and from cell data.

    Declaration
    public List<SheetColumn> Columns { get; }
    Property Value
    Type Description
    List<SheetColumn>

    RemoveMissingPulledKeys

    If this value is set then after PullIntoStringTableCollection(Int32, StringTableCollection, IList<SheetColumn>, Boolean, ITaskReporter, Boolean) any keys that were not in the sheet will be removed. This is useful if you want to use a single sheet and will be adding and removing keys however if using multiple sheets then this value should be false to prevent accidental loss of data.

    Declaration
    public bool RemoveMissingPulledKeys { get; set; }
    Property Value
    Type Description
    Boolean

    SheetId

    The id of a sheet inside of a Google Spreadsheet. Each tab is a separate sheet. The sheet id can be found in the url after the gid section: https://docs.google.com/spreadsheets/d/>SpreadsheetId/edit#gid=SheetId

    Declaration
    public int SheetId { get; set; }
    Property Value
    Type Description
    Int32

    SheetsServiceProvider

    The SheetsServiceProvider provides the authorization and connection to the Google Sheets service.

    Declaration
    public SheetsServiceProvider SheetsServiceProvider { get; set; }
    Property Value
    Type Description
    SheetsServiceProvider

    SpreadsheetId

    The Id of the Google Sheet. This can be found by examining the url: https://docs.google.com/spreadsheets/d/>SpreadsheetId/edit#gid=SheetId Further information can be found here.

    Declaration
    public string SpreadsheetId { get; set; }
    Property Value
    Type Description
    String
    トップに戻る
    Copyright © 2023 Unity Technologies — 商標と利用規約
    • 法律関連
    • プライバシーポリシー
    • クッキー
    • 私の個人情報を販売または共有しない
    • Your Privacy Choices (Cookie Settings)