'2013/12/14'에 해당되는 글 3건

  1. 2013.12.14 PlayerPrefs 배열로 저장하기
  2. 2013.12.14 유니티 텍스트 파일 읽기
  3. 2013.12.14 유니티 텍스트 파일 읽기

PlayerPrefs 배열로 저장하기

|

데이터가 int[] _data 안에 들어 있다고 가정하겠습니다. 
string _tmpStr = ""; 

for (int i = 0; i < _data.Length;i ++) { 
  _tmpStr = _tmpStr + _data[i]; 
  if (i < _data.Length) { 
      _tmpStr = _tmpStr + ","; 
  } 


PlayerPrefs.SetString("Data", _tmpStr);로 보존 합니다. 
불러 올때는 string[] _dataArr = PlayerPrefs.GetString("Data").Split(','); 하신후 
int[] _dataIn = new int[_dataArr.Length]; 
for (int i = 0; i < _dataArr.Length; i++) { 
  _dataIn[i] = System.Convert.ToInt32(_dataArr[i]); 


'잡다한것들전부 > ' 카테고리의 다른 글

2d toolkit 공식 사이트  (0) 2013.12.18
유니티 안드로이드 디버깅 방법  (0) 2013.12.16
PlayerPrefs 배열로 저장하기  (0) 2013.12.14
유니티 텍스트 파일 읽기  (0) 2013.12.14
유니티 텍스트 파일 읽기  (0) 2013.12.14
ngui 강좌 링크  (0) 2013.12.12
Trackback 0 And Comment 0

유니티 텍스트 파일 읽기

|


이런식으로 파일을 확장자를 빼고 불러온다음에 뒤에 .text 이런식으로 확장자를 붙이면 됨

 TextAsset textFile = Resources.Load("text/opening") as TextAsset; 

string s = "" + textFile.text;


Text Assets는 불러온 텍스트 파일을 위한 하나의 포맷입니다. 사용자가 사용자의 프로젝트 폴더에 하나의 텍스트 파일을 떨어뜨릴 때, 그것은 텍스트 에셋으로 변경될 것입니다. 지원되는 텍스트 포맷은 다음과 같습니다:

  • .txt
  • .html
  • .htm
  • .xml
  • .bytes

이런 확장자들을 지원함


오직 읽기만 지원 됨

'잡다한것들전부 > ' 카테고리의 다른 글

유니티 안드로이드 디버깅 방법  (0) 2013.12.16
PlayerPrefs 배열로 저장하기  (0) 2013.12.14
유니티 텍스트 파일 읽기  (0) 2013.12.14
유니티 텍스트 파일 읽기  (0) 2013.12.14
ngui 강좌 링크  (0) 2013.12.12
유니티 rpg 강좌  (0) 2013.12.11
Trackback 0 And Comment 0

유니티 텍스트 파일 읽기

|

using UnityEngine;

using System.Collections;

using System;

using System.IO;

 

public class CsTextManager : MonoBehaviour {

    public GUISkin skin;

    private int currentTextNumber;//현재 텍스트 번호

 

 

    string s;

        // Use this for initialization

        void Start () {

        currentTextNumber = 0;

        s = LoadTextFile("text/opening.txt");

        print(s);

        }

       

        // Update is called once per frame

        void Update () {

        if (Input.GetMouseButtonDown(0))

        {

            currentTextNumber++;

        }

        }

    string LoadTextFile(string fileName)

    {

        string t = "";

        string line = "";

        StreamReader sr = new StreamReader(Application.dataPath + "/Resources/" + fileName);

        if (sr == null)

        {

            print("Error : " + Application.dataPath + "/Resources/" + fileName);

        }

        else

        {

            line = sr.ReadLine();

            while (line != null)

            {

                t += line;

                line = sr.ReadLine();

                if (line != null)

                {

                    t += "\n";

                }

            }

            sr.Close();

            // print("Loaded " + Application.dataPath + "/Resources/db/" + fileName);

        }

        return t;

    }

 

    //gui

    void OnGUI()

    {

        //텍스트 파일에서 읽기

        GUI.skin = skin;

 

        int halfW = Screen.width / 2;

        int halfH = Screen.height / 2;

 

        int x = 40;

        int y = halfH + 40;

 

        GUI.Label(new Rect(x, y, halfW * 1, halfH * 1.2f), s);

}

}

 

'잡다한것들전부 > ' 카테고리의 다른 글

PlayerPrefs 배열로 저장하기  (0) 2013.12.14
유니티 텍스트 파일 읽기  (0) 2013.12.14
유니티 텍스트 파일 읽기  (0) 2013.12.14
ngui 강좌 링크  (0) 2013.12.12
유니티 rpg 강좌  (0) 2013.12.11
메모리 문제  (0) 2013.12.11
Trackback 0 And Comment 0
prev | 1 | next