블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2740)
Unity3D (817)
Programming (475)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (54)
Android (15)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
05-14 01:42

유니티3D에서 text 파일 읽고/쓰는 소스코드 몇가지를 올립니다. 
이거 잘 안되서 저는 엄청 혼났거든요. 
아래 소스들 중 골라서 사용해보세요. 

1. c#코드, FileInfo 클래스 사용하는게 특징이네요. 
파일 읽기는 부분만 있습니다. 

using System; 
using System.IO; 

public class LineReader : MonoBehaviour 

    protected FileInfo theSourceFile = null; 
    protected StreamReader reader = null; 
    protected string text = " "; // assigned to allow first line to be read below 

    void Start () { 
        theSourceFile = new FileInfo ("Test.txt"); 
        reader = theSourceFile.OpenText(); 
    } 
    
    void Update () { 
        if (text != null) { 
            text = reader.ReadLine(); 
            //Console.WriteLine(text); 
            print (text); 
        } 
    } 


******* 
2. javascript 코드, 
파일 읽고/쓰는 함수가 다 있습니다. 
읽을 때 File 클래스를 사용합니다. 

import System.IO; 
var filePath = "/Users/ResetOfDirectoryPath/testWrite.txt"; 

function Update() { 
if (Input.GetKeyDown("r")) { 
WriteFile(filePath); 

if (Input.GetKeyDown("f")) { 
ReadFile(filePath); 



function WriteFile(filepathIncludingFileName : String) 

var sw : StreamWriter = new StreamWriter(filepathIncludingFileName); 
sw.WriteLine("Line to write"); 
sw.WriteLine("Another Line"); 
sw.Flush(); 
sw.Close(); 


function ReadFile(filepathIncludingFileName : String) { 
sr = new File.OpenText(filepathIncludingFileName); 

input = ""; 
while (true) { 
input = sr.ReadLine(); 
if (input == null) { break; } 
Debug.Log("line="+input); 

sr.Close(); 


****** 
3. javascript 코드, 파일 읽기는 부분만인데 
읽을 때 StreamReader 클래스를 이용합니다. 

import System.IO; 
var fileName = "foo.txt"; 
function Start () 

    var sr = new StreamReader(Application.dataPath + "/" + fileName); 
    var fileContents = sr.ReadToEnd(); 
    sr.Close(); 
    var lines = fileContents.Split("\n"[0]); 
    for (line in lines) { 
        print (line); 
    } 


***** 
4. 기타 
이 부분은 저도 테스트를 못했습니다. 
var pathToFile = "path/to/example.txt"; 
var url = "file://" + pathToFile; 
yiel download = new WWW(url); 
text = download.data; 

**** 
여기 나온 코드들은 unity3d 포럼에 나와있는 코드들인데 개발 시에 사용하려고 복사해뒀던 것들입니다.



출처 : http://www.applclub.com/bbs/board.php?bo_table=F&wr_id=1170&sca=%B0%AD%C1%C2%2F%C6%C1

반응형

'Unity3D' 카테고리의 다른 글

Inspector에 다차원 배열 값 셋팅하기(for C#)  (1) 2012.10.24
Unity3D Scripting Overview  (0) 2012.10.24
에셋 서버 Scene Merge 관련..  (0) 2012.10.19
유니티 관련  (0) 2012.10.17
Transform Custom Editor  (0) 2012.10.15
Posted by blueasa
, |

1) 유니티 실행 아이콘 우클릭-속성-대상


2) 커맨드라인으로 '-projectPath' 추가.

    (예:"C:\Program Files (x86)\Unity\Editor\Unity.exe" -projectPath)


3) '확인' 버튼


4) 실행

반응형
Posted by blueasa
, |

새벽코딩반 (2012/02/22) 삭제 채택

3.5 부터는 씬머지를 하실 수 있습니다. Edit->Project Settings-> Editor에 가셔서 Asset Serialization 부분을 Force Text로 설정해주시면 됩니다.


라고 써있네요.


수정해봐야 겠습니다.


참조 : http://sizx.blog.me/100155808518


출처 : http://korea.unity3d.com/board/?db=qnalist&no=264&mari_mode=view@view

반응형

'Unity3D' 카테고리의 다른 글

Unity3D Scripting Overview  (0) 2012.10.24
text 파일 Read/Write 하는 소스 몇가지  (0) 2012.10.22
유니티 관련  (0) 2012.10.17
Transform Custom Editor  (0) 2012.10.15
Gizmos로 카메라 프러스텀 보이게 하기  (0) 2012.10.15
Posted by blueasa
, |

유니티 관련

Unity3D / 2012. 10. 17. 12:48



링크 : http://smilejsu.tistory.com/

반응형
Posted by blueasa
, |

Button Cooldown effect

Unity3D/NGUI / 2012. 10. 16. 22:20

It's really simple. Create one UISprite. Give it a grey tint. Now create a UIFilledSpriteusing the same sprite texture, right on top of the original. Set it to radial 360. That's it, really. Drag the filled sprite's slider to see it change.



참조 : http://www.tasharen.com/forum/index.php?topic=539.msg2724#msg2724


출처 : http://www.tasharen.com/forum/index.php?topic=1205.msg6124#msg6124

반응형

'Unity3D > NGUI' 카테고리의 다른 글

NGUI - Sticky Floating Text  (0) 2012.10.28
NGUI: HUD Text  (0) 2012.10.26
NGUI와 NGUI: HUD Text 패키지 임포트 시 에러 문제..  (0) 2012.10.25
NGUI health bar, vital bar  (0) 2012.10.25
NGUI 링크 모음  (0) 2012.10.16
Posted by blueasa
, |

NGUI 링크 모음

Unity3D/NGUI / 2012. 10. 16. 19:52

개발사

http://www.tasharen.com/?page_id=140


레퍼런스

http://www.tasharen.com/ngui/docs/index.html


http://www.looah.com/myevannet


http://forum.unity3d.com/threads/114833-NGUI-(Next-Gen-UI)-demo-amp-final-feedback-request




[출처] NGUI 링크 모음|작성자 crazylulu

반응형

'Unity3D > NGUI' 카테고리의 다른 글

NGUI - Sticky Floating Text  (0) 2012.10.28
NGUI: HUD Text  (0) 2012.10.26
NGUI와 NGUI: HUD Text 패키지 임포트 시 에러 문제..  (0) 2012.10.25
NGUI health bar, vital bar  (0) 2012.10.25
Button Cooldown effect  (0) 2012.10.16
Posted by blueasa
, |

Transform Custom Editor

Unity3D / 2012. 10. 15. 15:26

링크 : http://wiki.unity3d.com/index.php?title=TransformInspector


위 링크를 보면 Transform Custom Editor 기본 소스가 있다.


스크립트를 저장해서 Assets/Editor 안에 넣으면 준비 완료..


이제 고치면..되는데..


삽질이 필요한 시기군..

반응형

'Unity3D' 카테고리의 다른 글

에셋 서버 Scene Merge 관련..  (0) 2012.10.19
유니티 관련  (0) 2012.10.17
Gizmos로 카메라 프러스텀 보이게 하기  (0) 2012.10.15
유니티에 툴바 만들기..  (0) 2012.10.15
유니티에서 툴 만들기  (0) 2012.10.12
Posted by blueasa
, |

나(me)같은 초보를 위해 사용법(?) 추가..;


1. C# 스크립트 생성.

2. 생성한 스크립트에 아래 소스 추가/저장.

3. 생성한 스크립트를 Main Camera에 드래그&드랍..

4. Scene창의 Gizmos에 보면 추가한 스크립트가 추가된 게 보이고, 토글이 가능하다.

------------------------------------------------------------------------------------------

NGUI(무료버전) 레이아웃 작업 중....


현재 화면에서 GUI배치하기가 너무 어려워서 현재 화면 크기를 카메라를 선택하지 않아도 계속 유지하고 싶었다.


역시나 나 같은 생각을 가진 사람이 있었다. 아래 링크를 참고하자.

http://answers.unity3d.com/questions/291467/scene-view-stretches-camera-frustum-gizmo.html


링크를 가고 싶지 않은 사람은 아래 코드를 가져다가 쓰면 된다.


    public static Vector2 GetMainGameViewSize()

{ System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor"); System.Reflection.MethodInfo GetSizeOfMainGameView = T.GetMethod("GetSizeOfMainGameView",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); System.Object Res = GetSizeOfMainGameView.Invoke(null,null); return (Vector2)Res; } void OnDrawGizmos() { Camera cam = this.camera; // Top left Vector3 tlN = cam.ScreenToWorldPoint(new Vector3(Screen.width*0, Screen.height, cam.nearClipPlane)); Vector3 tlF = cam.ScreenToWorldPoint(new Vector3(Screen.width*0, Screen.height, cam.farClipPlane)); // Top right Vector3 trN = cam.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, cam.nearClipPlane)); Vector3 trF = cam.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, cam.farClipPlane)); // Bottom left Vector3 blN = cam.ScreenToWorldPoint(new Vector3(0.0f, 0.0f, cam.nearClipPlane)); Vector3 blF = cam.ScreenToWorldPoint(new Vector3(0.0f, 0.0f, cam.farClipPlane)); // Bottom right Vector3 brN = cam.ScreenToWorldPoint(new Vector3(Screen.width, 0.0f, cam.nearClipPlane)); Vector3 brF = cam.ScreenToWorldPoint(new Vector3(Screen.width, 0.0f, cam.farClipPlane)); // Scale for aspect ratio Vector2 gameViewsize = GetMainGameViewSize(); // float gameViewAspect = gameViewsize.x / gameViewsize.y;

 // 화면 비율에 맞추기 위해서 수정[blueasa]

float gameViewAspect = Screen.width / Screen.height; float s = gameViewAspect / cam.aspect; tlN.x *= s; tlF.x *= s; trN.x *= s; trF.x *= s; blN.x *= s; blF.x *= s; brN.x *= s; brF.x *= s; Gizmos.color = Color.white; // Near Gizmos.DrawLine(tlN, trN); Gizmos.DrawLine(trN, brN); Gizmos.DrawLine(brN, blN); Gizmos.DrawLine(blN, tlN); // Far Gizmos.DrawLine(tlF, trF); Gizmos.DrawLine(trF, brF); Gizmos.DrawLine(brF, blF); Gizmos.DrawLine(blF, tlF); // Sides Gizmos.DrawLine(tlN, tlF); Gizmos.DrawLine(trN, trF); Gizmos.DrawLine(brN, brF); Gizmos.DrawLine(blN, blF); }


[출처] 유니티. Gizmos로 카메라 프러스텀 보이게 하기.|작성자 괴발자

반응형

'Unity3D' 카테고리의 다른 글

유니티 관련  (0) 2012.10.17
Transform Custom Editor  (0) 2012.10.15
유니티에 툴바 만들기..  (0) 2012.10.15
유니티에서 툴 만들기  (0) 2012.10.12
[링크] 유니티 관련 사이트  (0) 2012.10.12
Posted by blueasa
, |
using UnityEngine;
using UnityEditor;

public class MyToolbar : EditorWindow  
{
    // Add menu named "My Window" to the Window menu
    [MenuItem ("Window/Toolbar")]
    static void Init () {
        // Get existing open window or if none, make a new one:
        MyToolbar window = EditorWindow.GetWindow (typeof (MyToolbar)) as MyToolbar;
		//window.minSize = new Vector2(34f, 34f);
		//window.maxSize = new Vector2(1024f, 70f);
		window.position = new Rect(0,0,200,34);
    }
	
    void OnGUI()
	{
		// GUILayout, EditorGUILayout 둘 다 되는데 무슨 차이일까..
        //EditorGUILayout.BeginHorizontal ("Toolbar");
		GUILayout.BeginHorizontal ("Toolbar");

		// 텍스트이름 버튼
		if(GUILayout.Button ("AS", GUILayout.Width( 32f ), GUILayout.Height( 32f )))
		{
			// 유니티 메뉴에서 실행할 메뉴선택
			EditorApplication.ExecuteMenuItem( "Window/Asset Store" );	
		}
		
		GUILayout.Button ("Pop up", GUILayout.Width( 32f ), GUILayout.Height( 32f ));
		GUILayout.Space (10f);        // 표준 에디터 간격을 넣는다.
		GUILayout.Button ("Drop me down", GUILayout.Width( 32f ), GUILayout.Height( 32f ));
		
		// 이미지 버튼 넣기(이미지 없으면 텍스트로)
		string TPath = string.Format( "Assets/Room/Bluesky Up.jpg" ); 
        Texture tex = Resources.LoadAssetAtPath( TPath, typeof(Texture) ) as Texture; 
        if( tex != null ) 
        { 
            if( GUILayout.Button( tex, GUILayout.Width( 32f ), GUILayout.Height( 32f ) ) )
			{
                EditorApplication.ExecuteMenuItem( "Window/Asset Server" ); 
			}
        }
		else
		{
			if( GUILayout.Button( "Asset Server", GUILayout.Width( 32f ), GUILayout.Height( 32f ) ) )
			{
                EditorApplication.ExecuteMenuItem( "Window/Asset Server" ); 
			}
		}

		//EditorGUILayout.EndHorizontal ();
		GUILayout.EndHorizontal ();
    }
}



소스에 주석이 달려 있으므로 별로 설명은 필요 없을 것 같지만..


기본적으로 해야는 것 같은(?)건..


1. 툴바도 우선 메뉴는 필요한 듯..메뉴 포함 윈도우를 만듬.(크기 조절은 좀 필요할 듯 하다.)

2. 필요한 버튼을 만든다.(이미지로 처리된다면 Assets/아래 리소스를 첨부해야 될 듯)

3. 툴바 버튼 눌렀을 때 실행할 메뉴를 링크해 준다.(외부 프로그램도 실행방법이 있겠지? 나중에 확인해야지..)



P.s. 괴발자님의 블로그 글을 보고 이리저리 삽질하면서 만들었다.

       유니티는 아직 초보라 잘 설명해준 글도 삽질은 별 수 없나보다..

       정보 공유해주신 괴발자님 감사합니다. :)


참조 : http://blog.naver.com/clater11/80167664654

반응형

'Unity3D' 카테고리의 다른 글

Transform Custom Editor  (0) 2012.10.15
Gizmos로 카메라 프러스텀 보이게 하기  (0) 2012.10.15
유니티에서 툴 만들기  (0) 2012.10.12
[링크] 유니티 관련 사이트  (0) 2012.10.12
Visual Studio C# Integration  (0) 2012.10.05
Posted by blueasa
, |

유니티에서 툴 만들기

Unity3D / 2012. 10. 12. 17:04

유니티에서 툴을 만들려면 어째야 되는지 이리저리 알아보니 맥스 비슷하게 툴자체에 추가하는 형식 같다.


EditorWindow 라는 클래스를 사용해서 제작 되는 것 같다.


확인한 커스텀 에디터 제작 순서는 아래와 같다.


1. EditorWindow 를 상속한 클래스를 하나 만든다.(아래 출처의 소스 참조)

   (※ 난 C#이므로 using UnityEditor; 추가)


2. 만들어진 스크립트 파일을 넣고 싶은 프로젝트의 'Assets/Editor' 폴더에 넣는다.(Editor 폴더 없으면 생성)


3. 해당 프로젝트를 켜보면 'Project' 패널에 Editor가 추가 돼 있는게 보인다.


4. 위 메뉴에서 'Window' 메뉴에 보면 추가했던 윈도우(소스대로 했으면 My Window)가 보인다.


5. 클릭해보면 창이 뜬다. 원하는 곳에 붙이고 레이아웃을 저장하면 끝..



출처 : http://www.devkorea.co.kr/reference/Documentation/ScriptReference/EditorWindow.html



반응형

'Unity3D' 카테고리의 다른 글

Gizmos로 카메라 프러스텀 보이게 하기  (0) 2012.10.15
유니티에 툴바 만들기..  (0) 2012.10.15
[링크] 유니티 관련 사이트  (0) 2012.10.12
Visual Studio C# Integration  (0) 2012.10.05
유니티 강좌  (0) 2012.10.03
Posted by blueasa
, |