[Script, C#] TextFile Read ProjectA

//TextReader.cs by DAKDAE

using UnityEngine;
using System;
using System.Collections;
using System.IO;

public class TextReader : MonoBehaviour
{
public string TextRead(string fileName)
{
string path;
string resultText;
StreamReader sr;
path = Application.dataPath;
     if(!File.Exists(path + fileName))
     {
     Debug.Log("no Exist File");
     return null;
     }
    
     Debug.Log("File Exist");
    
sr = new StreamReader(path + fileName, System.Text.Encoding.Default);
  if(sr == null)
  {
  Debug.Log("File Load Fail");
  return null;
  }
 
  Debug.Log("File Load Success");
 
  resultText = sr.ReadToEnd();
 
  sr.Close();
 
  return resultText;
}
public void Close() {this.Close();}
}


[Script, C#] Text파일에서 Object 생성 ProjectA

//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;
    }
}

6.18 ProjectA

일단 졸작으로 만들었던 게임 유니티 공부할겸 시작.
이제 바빠 지는데ㅠㅠ

완성 할 수 있을려나~

일단 Tutorial 스테이지만ㄱㄱ!

[Unity3D] Object Animation(오브젝트 애니메이션) Unity3D


[Unity3D] Script Execution Order(스크립트 실행 순서) Unity3D


  • All Awake calls
  • All Start Calls
  • while (stepping towards variable delta time)
    • All FixedUpdate functions
    • Physics simulation
    • OnEnter/Exit/Stay trigger functions
    • OnEnter/Exit/Stay collision functions
  • Rigidbody interpolation applies transform.position and rotation
  • OnMouseDown/OnMouseUp etc. events
  • All Update functions
  • Animations are advanced, blended and applied to transform
  • All LateUpdate functions
  • Rendering

First Scene :
Awake : Start() 전에 호출. Prefabinstantiate()된 후 에도 호출.
Start: 객체가 활성화(사용 가능한) 중일 때 호출.

Update 전에 실행.

Update :
Update : Frame당 한번 호출.

FixedUpdate : Update 보다 더 많이 호출될 때도 있다.
FPS가 낮거나, FPS가 높아서 모든 프레임 사이에 호출못하는 경우, 한 Frame당 여러번 호출될 수 있다.
모든 물리 계산과 갱신은 이 함수 뒤에 즉시 발생한다.
FPS 독립적으로 호출되기 때문에, 이동 관련 업데이트를 이 함수에서 한다면, Time.deltaTime은 필요가 없다.

LateUpdate :
 Update 가 끝나고 난뒤에 호출됨.
(3인칭 카메라를 사용할 경우, 
 Update 에서 캐릭터의 이동, 회전을 끝내고, 카메라의 이동, 회전을 LateUpdate 에서 수행한다면, 
 캐릭터의 이동이 완료된 뒤에 카메라가 따라 간다.)

Rendering :
OnPreCull : 컬링 전 부르는 함수.
OnBecameVisible / OnBecameInvisible : 객체가 visible/invisible 될때 호출.
OnWillRenderObject : 객체가 visible이라면, 각 카메라에서 한번만 호출.
OnPreRender :Scene을 렌더링 전에 호출.
OnRenderObject : 카메라가 Scene이 렌더링되고 난 후에 호출. GL class, Graphcis.DrawMeshNow를 이 곳에서 사용.
OnPostRender : 카메라가 Scene 렌더링을 완료한 후에 호출.
OnRenderImage(Pro only) :  Scene 렌더링 완료 후, Scene Image후처리(Postprocessing)를 하는 함수.
OnGUI : GUI 이벤트들의 응답. 여러번 호출될 수 있다.
OnDrawGizmos :  Scene View안에서 시각화 목적으로 Gizmos을 그릴 수 있게 해주는 함수.

Coroutine :
Update가 반환된 후에 호출.

종료될 때 : 
Scene에 활성화 중인 모든 객체에 알려준다.

OnApplicationQuit : 프로그램 종료전에 모든 객체들에 알려준다. 
      (에디터안에서 유저가 playmode를 끌때 호출된다.)
      (웹플레이어에서는 웹창을 닫을 때 호출된다.)

OnDisable : 사용불가 하거나 비활성화 될 때 호출.

1