💻
UGS 개발문서
  • Unity Google Sheet
  • Getting Start
    • 다운로드
    • Apps Script Setup
    • GoogleDrive Setup
  • HOW TO USE
    • 시트 생성 및 데이터 만들기
    • 로컬에서 불러오기
    • 시트에서 불러오기(LiveLoad)
    • 시트에 데이터 쓰기(LiveWrite)
  • Advanced User Features
    • UGS APIs
    • Use CustomType
    • Use EnumType
    • SpreadSheet Detail
    • Use UGS on WPF, Console C# Project
  • Details
    • * API 제한사항 (할당량)
    • * 보안 주의사항
    • * 추가기능 개발
  • Examples and Tutorial
    • Awesome Sunny!
  • Trouble Shooting
    • Exception : Reference has errors 'HamsterGoogleSpreadSheet'.
    • Exception : InvalidOperationException: You are trying to read Input ...
    • Exception : index index was out of bounds of array
    • Exception : Newtonsoft.Json Confict
Powered by GitBook
On this page

Was this helpful?

  1. Advanced User Features

Use CustomType

커스텀 타입을 추가하는 방법에 대해서 설명합니다.

PreviousUGS APIsNextUse EnumType

Last updated 2 years ago

Was this helpful?

UGS에서는 간단하게 IType 인터페이스를 상속받아 사용자 정의 클래스나 구조체를 시트 내에서 사용할 수 있습니다.

만약 Vector3을 시트에 입력하고 싶다면 어떻게 해야할까요? 아주 단순합니다. 다음과 같이 정의해보세요! (Vector3은 이미 UGS에서 지원하므로 별도로 추가 할 필요가 없긴 합니다.)

using UnityEngine; 
namespace Hamster.ZG.Type
{ 
    [Type(typeof(Vector3), new string[] { "vector3", "Vector3", "vec3" })]
    public class Vector3Type : IType
    {
        public object DefaultValue => Vector3.zero;
        /// <summary>
        /// value는 스프레드 시트에 적혀있는 값
        /// </summary> 
        public object Read(string value)
        {
             // value : [1,2,3] 
             var values = ReadUtil.GetBracketValueToArray(value);
             float x = float.Parse(values[0]);
             float y = float.Parse(values[1]);
             float z = float.Parse(values[2]); 
             return new Vector3(x,y,z);
        }

        /// <summary>
        /// value write to google sheet
        /// </summary> 
        public string Write(object value)
        {
            Vector3 v = (Vector3)value;
            return $"[{v.x},{v.y},{v.z}]";
        }
    }
}

작성을하고 파일을 저장하면 UGS 자동으로 타입을 인식합니다. 이제 시트를 다음과 같이 수정해봅시다.

이후, 데이터를 불러와봅시다.


using UnityEngine;

public class test : MonoBehaviour
{ 
    void Start()
    {  
        Cube.Data.Load(); 
        foreach(var data in Cube.Data.DataList)
        {
            var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.transform.position = data.position;
        }
    } 
}