Ejemplo n.º 1
0
        protected override void DrawGUI()
        {
            var generateInfos = GameTextLanguage.GameTextInfos;

            if (generateInfos == null)
            {
                return;
            }

            Reload();

            GUILayout.Space(3f);

            GameTextGenerateInfo info = null;

            if (selection.HasValue)
            {
                info = generateInfos.ElementAtOrDefault(selection.Value);
            }

            using (new DisableScope(info == null))
            {
                if (GUILayout.Button("Generate"))
                {
                    GameTextGenerater.Generate(connector, info);
                    Repaint();
                }
            }

            GUILayout.Space(3f);

            var labels = generateInfos.Select(x => x.Language).ToArray();

            EditorGUI.BeginChangeCheck();

            var index = EditorGUILayout.Popup(GameTextLanguage.Prefs.selection, labels);

            if (EditorGUI.EndChangeCheck())
            {
                selection = index;
                GameTextLanguage.Prefs.selection = index;

                GameTextLoader.Reload();
            }
        }
Ejemplo n.º 2
0
        public static void Generate(SpreadsheetConnector connector, GameTextGenerateInfo generateInfo)
        {
            if (generateInfo == null)
            {
                return;
            }

            var progressTitle   = "Generate Progress";
            var progressMessage = string.Empty;

            var gameTextConfig = GameTextConfig.Instance;

            progressMessage = "Connection Spreadsheet.";
            EditorUtility.DisplayProgressBar(progressTitle, progressMessage, 0f);

            var asset = LoadAsset(gameTextConfig.ScriptableObjectFolderPath, generateInfo.AssetPath);

            progressMessage = "Load GameText form Spreadsheet.";
            EditorUtility.DisplayProgressBar(progressTitle, progressMessage, 0f);

            // Spreadsheetに接続しデータを取得 (同期通信).
            var spreadsheets = connector.GetSpreadsheet(gameTextConfig.SpreadsheetId).ToArray();

            EditorUtility.DisplayProgressBar(progressTitle, progressMessage, 1f);

            if (spreadsheets.Any())
            {
                // 全更新するので最も最近編集されたシート情報から最終更新日を取得.
                var spreadsheetsUpdateDate = spreadsheets.Select(x => x.LastUpdateDate).Max().ToUnixTime();

                var lastUpdateDate = asset.updateTime.HasValue ? asset.updateTime.Value : DateTime.MinValue.ToUnixTime();

                // ローカルデータが最新なら更新処理は行わない.
                if (lastUpdateDate < spreadsheetsUpdateDate)
                {
                    AssetDatabase.StartAssetEditing();

                    progressMessage = "Generating GameTextScript.";
                    EditorUtility.DisplayProgressBar(progressTitle, progressMessage, 0f);

                    GameTextScriptGenerator.Generate(spreadsheets, gameTextConfig, generateInfo.TextColumn);

                    EditorUtility.DisplayProgressBar(progressTitle, progressMessage, 0.2f);

                    progressMessage = "Generating GameTextAsset.";
                    EditorUtility.DisplayProgressBar(progressTitle, progressMessage, 0.5f);

                    GameTextAssetGenerator.Build(asset, spreadsheets, gameTextConfig, generateInfo.TextColumn);

                    EditorUtility.DisplayProgressBar(progressTitle, progressMessage, 0.8f);

                    EditorUtility.DisplayProgressBar(progressTitle, progressMessage, 1f);

                    UnityConsole.Info("GameTextを出力しました");

                    SaveLastUpdateDate(asset, spreadsheetsUpdateDate);

                    AssetDatabase.SaveAssets();

                    AssetDatabase.StopAssetEditing();
                }
                else
                {
                    UnityConsole.Info("GameTextは最新の状態です");
                }
            }
            else
            {
                Debug.LogError("Spreadsheetにデータがありません.");
            }

            EditorUtility.ClearProgressBar();
        }