//ObjectCreator.cs By DAKDAE
using UnityEngine;
using System.Collections;
using System;
using System.IO;
public class ObjectCreator : MonoBehaviour
{
public GameObject obj_Box;
public GameObject obj_XBox;
string fileName = null;
string readText = null;
TextReader textReader = null;
void Awake()
{
textReader = new TextReader();
fileName = "/createBox.txt";
readText = textReader.TextRead(fileName);
if(readText.Length < 0)
{
Debug.Log("Read File Length is Zero");
return;
}
else
{
string tempStr = null;
for(int _x = 0; _x < (int)eLINE_SIZE.X_LINE; _x++)
{
tempStr = TextCommand(1, _x + 1, readText);
if(tempStr == null) return;
Debug.Log(tempStr);
int _y = 1;
int _z = 0;
foreach(char obj in tempStr)
{
int objType = Int32.Parse(obj.ToString());
Vector3 objPosition = new Vector3( (float)_x * (float)eOBJECT_SIZE.X_SIZE,
(float)_y * (float)eOBJECT_SIZE.Y_SIZE,
(float)_z * (float)eOBJECT_SIZE.Z_SIZE);
CreateObject((eOBJECT_TYPE)objType, objPosition);
_z++;
}
}
}
textReader.Close();
}
//텍스트에서 커멘드 잘라내기.
public string TextCommand(int floor, int row, string readText)
{
string beginLine = "[b" + (floor).ToString() + "," + (row).ToString() + "]";
string endLine = "[e" + (floor).ToString() + "," + (row).ToString() + "]";
string resultText = null;
if(readText.IndexOf(beginLine) > -1)
{
resultText = readText.Substring(readText.IndexOf(beginLine) + beginLine.Length);
if(readText.IndexOf(endLine) > -1)
{
resultText = resultText.Substring(0, resultText.IndexOf(endLine));
return resultText;
}
}
Debug.Log("Command Text Fail");
return null;
}
//오브젝트 만들기(복사.)
public bool CreateObject(eOBJECT_TYPE objType, Vector3 objPosition)
{
GameObject obj = null;
switch(objType)
{
case eOBJECT_TYPE.TYPE_BOX:
{
obj = obj_Box;
break;
}
case eOBJECT_TYPE.TYPE_XBOX:
{
obj = obj_XBox;
break;
}
}
if(obj != null)
{
Instantiate(obj, objPosition, Quaternion.identity);
return true;
}
return false;
}
}
최근 덧글