본문 바로가기
개발/C#

유니티 C# 구글 스프레드 시트 Google Sheet 간단 사용법

by SPNK 2022. 7. 13.
반응형
  • 코드 작성
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
public class Example : MonoBehaviour
{
    const string DownloadURL = "https://docs.google.com/spreadsheets/d/" + "주소 Id 값" + "/export?format=tsv&gid=0";

    void Awake()
    {
        StartCoroutine(DownloadFile());
    }

    IEnumerator DownloadFile()
    {
        Debug.Log("File Downloading...");

        UnityWebRequest www = UnityWebRequest.Get(DownloadURL);
        yield return www.SendWebRequest();
        File.WriteAllText(GetPath() + "FileName.txt", www.downloadHandler.text);

        Debug.Log("File Download Complete!");
    }

    public string GetPath()
    {
        string path = null;
        switch (Application.platform)
        {
            case RuntimePlatform.Android:
                path = Application.persistentDataPath;
                path = path.Substring(0, path.LastIndexOf('/'));
                return Path.Combine(Application.persistentDataPath, "Resources/");
            case RuntimePlatform.IPhonePlayer:
            case RuntimePlatform.OSXEditor:
            case RuntimePlatform.OSXPlayer:
                path = Application.persistentDataPath;
                path = path.Substring(0, path.LastIndexOf('/'));
                return Path.Combine(path, "Assets", "Resources/");
            case RuntimePlatform.WindowsEditor:
                path = Application.dataPath;
                path = path.Substring(0, path.LastIndexOf('/'));
                return Path.Combine(path, "Assets", "Resources/");
            default:
                path = Application.dataPath;
                path = path.Substring(0, path.LastIndexOf('/'));
                return Path.Combine(path, "Resources/");
        }
    }
}

 


참고할만한 글

 

 

유니티 C# 룰렛 만들기 간단 구현 Unity Roulette

코드 작성 using UnityEngine; using System.Collections; public class Roulette : MonoBehaviour { public int[] numbers; //당첨될 것들 private int winningNumber; //당첨 번호 private bool spinning = false; public float spinTime = 5.0f; void Start()

parksh3641.tistory.com

 

 

유니티 C# 플레이어를 추적하는 적 코드 간단 구현 Unity

코드 작성 using UnityEngine; public class Enemy : MonoBehaviour { public float speed = 5f; private Transform player; void Start() { // 태그로 플레이어 찾기 player = GameObject.FindGameObjectWithTag("Player").transform; } void Update() { Vector

parksh3641.tistory.com

 

반응형

댓글