Use UGS on WPF, Console C# Project

이 기능은 원래 목적으로하는 정식적인 기능은 아닙니다. 문제가 있을 수 있습니다.

UGS는 WPF 혹은 C#으로 만들어진 Console Application 에서도 사용 가능합니다. 이 기능을 제공하는 이유는, C#으로 만든 게임의 서버에서 클라이언트측 데이터를 검사하는데에 사용하거나, 게임 자체가 서버에서 시뮬레이션 될 수 있기 때문입니다. 먼저, 사용하려면 UGS를 임포트한 후, HamsterGoogleSpreadSheet.dll을 찾아 자신만의 C# 솔루션에 DLL을 불러오시길 바랍니다.

Use Example Code

임포트를 했다면 아래 코드를 참고해보세요. 코드 불러오기, 생성, 읽기쓰기 등 모든 예제가 포함되어 있습니다.

using Hamster.ZG;
using Hamster.ZG.IO.FileReader;
using Hamster.ZG.IO.FileWriter;
using UGS.Protocol.v2.Req;
using System;
using System.IO;

namespace ConsoleApp1
{
    class Program
    { 
        static void Main(string[] args)
        { 
            // Login
            GoogleSheet.Initialize("https://script.google.com/macros/s/AKfycbxpqlYM5SfX0pL2RHzgiT_cFykKFLkcr_PgzU1KKnVx2Aa6YNN3/exec", "123123");



            // Code Generate And Copy To Folder 
            GoogleSheet.Generate("1BXya0YQq980kbNBN_-hQAvmBrNkHFIoqXJkQTXIsXHQ",
            () => {
                System.IO.DirectoryInfo di1 = new System.IO.DirectoryInfo("TableScript");
                System.IO.DirectoryInfo di2 = new System.IO.DirectoryInfo("CachedJson");

                DirectoryCopy(di1.FullName, "../../../TableScript", true);
                DirectoryCopy(di2.FullName, "../../../CachedJson", true);
            });


            GoogleSheet.LoadAllData();
            foreach (var value in UnitData.Balance.BalanceList) 
                Console.WriteLine($"{value.id} {value.jump} {value.name} {value.speed}"); 
            
        }



        
        private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
        {
            // Get the subdirectories for the specified directory.
            DirectoryInfo dir = new DirectoryInfo(sourceDirName);

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException(
                    "Source directory does not exist or could not be found: "
                    + sourceDirName);
            }

            DirectoryInfo[] dirs = dir.GetDirectories();

            // If the destination directory doesn't exist, create it.       
            Directory.CreateDirectory(destDirName);

            // Get the files in the directory and copy them to the new location.
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                string tempPath = Path.Combine(destDirName, file.Name);
                file.CopyTo(tempPath, true);
            }

            // If copying subdirectories, copy them and their contents to new location.
            if (copySubDirs)
            {
                foreach (DirectoryInfo subdir in dirs)
                {
                    string tempPath = Path.Combine(destDirName, subdir.Name);
                    DirectoryCopy(subdir.FullName, tempPath, copySubDirs);
                }
            }
        }

    }
}

Last updated