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

카테고리

분류 전체보기 (2834)
Unity3D (883)
Programming (479)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (187)
협업 (64)
3DS Max (3)
Game (12)
Utility (140)
Etc (98)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (52)
Android (16)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (19)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday

'Unity3D'에 해당되는 글 883건

  1. 2013.01.15 Player Settings
  2. 2013.01.15 Layer
  3. 2013.01.15 C# 사용할때 주의할 점
  4. 2013.01.15 웹브라우저 유니티 툴바
  5. 2013.01.04 Expand/Collapse All(모두 펴기/접기)
  6. 2013.01.04 해상도에 맞게 UI 위치 조절
  7. 2013.01.04 해상도에 맞게 UI Scale
  8. 2012.12.23 UnityVS
  9. 2012.12.14 InGame Button
  10. 2012.12.09 TinyXmlReader

Player Settings

Unity3D / 2013. 1. 15. 14:30

유니티는 빌드 타겟(웹플레이어, 아이폰, 안드로이드 등등) 에 따른 각각의 플레이어 셋팅이 있다.

각각 디바이스 환경에 따라 최적화 및 여러 요소가 달라지기 때문이다.

우선 중요한 사항들 몇몇가지만 알아보도록 하자.

  Api Compatibility Level 

.NET 에서 지원해주는 Library 를 어느정도 사용할지에 대한 설정이다.
혹시 데스크탑에서는 잘 돌아가는 프로젝트가 아이폰이나 안드로이드에서 작동하지 않는다면
이 설정을   .Net 2.0 Subset 에서  .Net 2.0 으로  바꾸어 보길.

이 설정에 따른 장단점은
   .Net 2.0 의 경우 거의 모든 .Net 2.0 Library 가 다 들어가지만
1. 어플리케이션 전체의 용량이 증가한다.
2. 초기 실행 시간이 살짝 느려질 수 있다.





반응형

'Unity3D' 카테고리의 다른 글

Sorting Layer 사용하기  (0) 2015.07.20
Layer  (0) 2013.01.15
간단한 Nav Mesh 예제  (0) 2012.11.21
런타임 중 텍스쳐 교체  (0) 2012.11.20
상체 애니메이션 덧붙이기(AddMixingTransform)  (2) 2012.11.16
Posted by blueasa
, |

Layer

Unity3D / 2013. 1. 15. 14:27

유니티에서는 Layer 관리를 인스펙터 창에서 한다.
기본적으로 Default, Transparent FX, Player 등의 기본 레이어가 있으며
사용자가 추가적으로 생성할 수 있다.

이 레이어들은 Camera, Phisycs 등에서 Mask 형식으로 주로 사용 되어진다.

Camera 에서는 culling 설정을 하여 해당 레이어를 렌더링 해서 화면에 보여줄지 말지를 설정 할 수 있으며
Phisycs 에서는 충돌체크시에 해당 레이어의 Collider 들을 계산할지 말지를 설정 할 수 있다.

ex1)

int layerMask = (-1) - (1 << LayerMask.NameToLayer("Player"));  // Everything에서 Player 레이어만 제외하고 충돌 체크함
Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), hit, Mathf.Infinity, layerMask);

ex2)

int layerMask = (-1) - (1 << LayerMask.NameToLayer("Player"));

RaycastHit hit;

Ray ray = Camera.mainCamera.ScreenPointToRay( screenPos ); // screenPos는 화면상 클릭 좌표

bool result = Physics.Raycast( ray, out hit, 10000.0f, layerMask );


마지막 인자로 레이어 마스크 값이 쓰였으며 저기에 해당하는 레이어는 제외하고 충돌 검사를 한다. 

레퍼런스에는 충돌을 제외할 레이어 마스크 값이라고 적혀 있지만, 실제는 충돌 체크할 레이어 마스크를 넣어야 함.



P.s. Everything Layer = -1



반응형

'Unity3D' 카테고리의 다른 글

Sorting Layer 사용하기  (0) 2015.07.20
Player Settings  (0) 2013.01.15
간단한 Nav Mesh 예제  (0) 2012.11.21
런타임 중 텍스쳐 교체  (0) 2012.11.20
상체 애니메이션 덧붙이기(AddMixingTransform)  (2) 2012.11.16
Posted by blueasa
, |

1. MonoBehaviour, ScriptableObject 로 부터 ( 직접 혹은 간접으로 ) 상속 받아야 한다.

     ps. GameObject 에 Attach 하려면 MonoBehavior로 부터 상속받고,

           일반 로직등에 필요한 클래스는 ScriptableObject로 부터 상속 받는다. 

 

2. 클래스 이름과 파일 이름이 일치해야 한다.

 

3. namespace를 사용할 수 없다.

 

4. MonoBehaviour 일 경우, 멤버 변수만 Inspector 에 나타난다.

 

5. MonoBehaviour 일 경우, 생성자를 사용하지 말고,  Awake( 이게 생성자 ), Start 함수를 사용한다.

 

6. ScriptableObject일 경우, MonoBehaviour 상속받은 스크립트에서 인스턴스 생성시 new를 사용하지 말고,ScriptableObject.CreateInstance("클래스명") as 클래스형을 사용한다.

 

7. ScriptableObject일 경우,  인스턴스 생성후에 새로운 객체를 재할당 할 때는, GameObject.DestroyImmediate(인스턴스) 호출하여 메모리를 꼭 해지하고 재할당.

 

8. Corutine은 다른 문법으로 사용된다.

반환형은 IEnumerator를 사용해야 하며, yield ... 를 사용할 때, yield return ... 을 사용한다.

 

using System.Collections;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
    // C# coroutine
    IEnumerator SomeCoroutine () {
    // Wait for one frame
    yield return 0;
   
    // Wait for two seconds
    yield return new WaitForSeconds (2);
}

}



[출처] C# 사용할때 주의할 점|작성자 내영

반응형
Posted by blueasa
, |

Link : http://unity3developer.toolbar.fm/



유니티 개발자용 웹브라우저 툴바가 있어서 링크 해 봅니다.


외국에서 만들어서 영문쪽이긴 하지만 쓰는데 별 불편함은 없는 것 같네요.

관심 있으시거나 심심하신 분들은 한 번 깔아보세요.

주의 : 툴바가 기본 브라우저로 설정 된 브라우저에만 깔리는 것 같으니 툴바를 설치하고 싶으신 브라우저를 기본 브라우저로 셋팅 후, 설치해 주세요.

반응형

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

[링크][화면보호기] 플립형 시계 화면보호기(스크린 세이버, screen saver) 모음  (0) 2019.08.06
Unity3d Document for VS2012/VS2013  (2) 2014.11.10
3D Model Viewer  (0) 2013.01.18
Unity3D Tools  (0) 2013.01.18
UnityVS  (0) 2012.12.23
Posted by blueasa
, |

Hierarchy와 Project에서 트리 구조를 살펴보기 위해서 하나하나 열다가 왜 모두 펴고 접는 메뉴가 없는거지..


하고 이리저리 찾아보니 단축키가 있네요.



(이미지_1)


'이미지_1'에서 보이는 빨간 사각형의 화살표를 Left-Alt를 누른채로 마우스 L-Button을 누르면 아래 '이미지_2'와 같이 모두 펴기/접기 토글이 됩니다.


단축키 : L-Alt + L-Button Toggle


(이미지_2)


Project의 스샷만 있습니다만, Hierarchy도 잘 되는걸 확인했습니다.

반응형
Posted by blueasa
, |



참조 : http://www.tasharen.com/?page_id=197


동영상 링크 : http://www.youtube.com/watch?v=XAeRXckXMMw


반응형
Posted by blueasa
, |

1) NGUI의 Panel에 UIStretch 추가

    (조절이 필요한 곳에 모두 넣는다. 패널이 여러개면 여러 패널에 모두 순서대로 진행)


2) Ui Camera에 NGUI 카메라 추가(Drag & Drop)


3) Style : Both(카메라에 맞춰서 스케일이 조절돼버림. 스케일 수정 안됨)


4) 스케일이 직접 조절이 안되므로 Relative Size를 조절함


5) Relative Size 조절(결과적으로 패널의 스케일 값이 1이 나오게 Relative Size 값을 넣는다.)

   X = 패널의 1 / Scale.X

   Y = 패널의 1 / Scale.Y


[문제점]

- 해상도에 맞게 늘어나긴 하지만 UI 크기가 늘어나거나 줄어드는 문제가 있음.


[참조 글]

뀨니 2012.12.28 09:23:58 댓글달기
저도 같은문제로 게시판 뒤지다가 어떤분것 보고 도움을 받았는데요 NGUI쓰신다면 NGUI에 있는 스크립트를 사용하시면 됩니다.UIStretch스크립트를사용해서 해상도에따라 셋팅값에 따라 해상도에 맞춰 비율적으로 강제적으로 늘릴 수 있습니다. 예를 들자면UIStretch를 패널에 추가하시고, UI Camera에 NGUI카메라를 넣으시고, Style을 Both로 맞추시면 카메라에 맞춰 늘어나게 되는데요, 여기서 크기를 Relative Size로 셋팅해주시면 됩니다. 
저같은 경우는 엄청나게 커져버려서 X = 0.00085 Y = 0.00125 뭐이런식으로 맞췄 습니다.


참조글 링크 : http://devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=23789&page=0&sca=UNITY&sfl=wr_subject%7C%7Cwr_content&stx=UIStretch&spt=0&page=0&currentId=44#c_23991

반응형
Posted by blueasa
, |

UnityVS

Unity3D/Utility / 2012. 12. 23. 23:45

Visual Studio에서 Unity를 디버깅 가능하게 해주는 플러그인이다..


사야될 것 같은 유틸.. 링크해 두자..


http://unityvs.com/

반응형
Posted by blueasa
, |

InGame Button

Unity3D/Script / 2012. 12. 14. 22:27
추가 : 내가 잘못 쓰는지는 모르겠지만, 게임 내 어디에 있냐에 따라서 클릭이 되고 안되고 해서..좀 더 알아봐야 될 것 같다..

Button

Author: Jonathan Czeck (aarku)

Contents

 [hide

Description

This script uses a GUITexture and Unity mouse events to implement a regular push button that behaves properly like Mac OS X.

Warning: As of Unity 3.0.0, this script does not work on iOS devices, as OnMouseUp functions and the like do not work on iOS devices. Use the iPhone compatible version further below.

Usage

Attach this script to a GUITexture object. Add a ButtonPressed function to the object pointed to by the messageevariable to catch when the button has been pressed. (You can change the name of the function by changing themessage variable.)

JavaScript - Button.js

 var normalTexture : Texture;
 var hoverTexture : Texture;
 var pressedTexture : Texture;
 var messagee : GameObject;
 var message = "ButtonPressed";
 
 private var state = 0;
 private var myGUITexture : GUITexture;
 
 myGUITexture = GetComponent(GUITexture); 
 
 function OnMouseEnter()
 {
    state++;
    if (state == 1)
        myGUITexture.texture = hoverTexture;
 }
 
 function OnMouseDown()
 {
    state++;
    if (state == 2)
        myGUITexture.texture = pressedTexture;
 }
 
 function OnMouseUp()
 {
    if (state == 2)
    {
        state--;
        if (messagee)
            messagee.SendMessage(message, gameObject);
    }
    else
    {
        state --;
        if (state < 0)
            state = 0;
    }
    myGUITexture.texture = normalTexture;
 }
 
 function OnMouseExit()
 {
    if (state > 0)
        state--;
    if (state == 0)
        myGUITexture.texture = normalTexture;
 }

C# - Button.cs

The C# version is a bit different from the JS version. It shows off some new features in Unity 1.2 for automatically attaching the GUITexture component when attaching the Button (using the RequireComponent attribute) and placing the Button in a custom submenu in the Components menu (using the AddComponentMenu attribute.)

It also groups the textures together into a separate object and has a separate method for changing the texture to ease customisation. Note that some properties and methods are marked protected and/or virtual to make it possible to customise the Button class by creating a new subclass. See the ToggleButton snippet for an example on how to subclass the Button class.

using UnityEngine;
using System.Collections;
 
public enum ButtonState {
    normal,
    hover,
    armed
}
 
[System.Serializable] // Required so it shows up in the inspector 
public class ButtonTextures {
    public Texture normal=null;
    public Texture hover=null;
    public Texture armed=null;
    public ButtonTextures() {}
 
    public Texture this [ButtonState state] {
        get {
            switch(state) {
                case ButtonState.normal:
                    return normal;
                case ButtonState.hover:
                    return hover;
                case ButtonState.armed:
                    return armed;
                default:
                    return null;
            }
        }
    }
}
 
 
[RequireComponent(typeof(GUITexture))]
[AddComponentMenu ("GUI/Button")]    
public class Button : MonoBehaviour {
 
    public GameObject messagee;
    public string message = "ButtonPressed";
    public ButtonTextures textures;
 
    protected int state = 0;
    protected GUITexture myGUITexture;
 
    protected virtual void SetButtonTexture(ButtonState state) {
        myGUITexture.texture=textures[state];
    }
 
    public virtual void Reset() {
        messagee = gameObject;
        message = "ButtonPressed";
    }
 
    public virtual void Start() {
        myGUITexture = GetComponent(typeof(GUITexture)) as GUITexture; 
        SetButtonTexture(ButtonState.normal);
    }
 
    public virtual void OnMouseEnter()
    {
        state++;
        if (state == 1)
            SetButtonTexture(ButtonState.hover);
    }
 
    public virtual void OnMouseDown()
    {
        state++;
        if (state == 2)
            SetButtonTexture(ButtonState.armed);
    }
 
    public virtual void OnMouseUp()
    {
        if (state == 2)
        {
            state--;
            if (messagee != null)
                messagee.SendMessage(message, this);
        }
        else
        {
            state --;
            if (state < 0)
                state = 0;
        }
        SetButtonTexture(ButtonState.normal);
    }
 
    public virtual void OnMouseExit()
    {
        if (state > 0)
            state--;
        if (state == 0)
            SetButtonTexture(ButtonState.normal);
    }
}


C# - Button.cs (iPhone Compatible)

Same as the C# version above, but added support for recognizing touch input from iPhone or Android devices. Also adds callback function for when the button is double-clicked/double-tapped.

using UnityEngine;
using System.Collections;
 
public enum ButtonState
{
    normal,
    hover,
    armed
}
 
[System.Serializable] // Required so it shows up in the inspector 
public class ButtonTextures
{
    public Texture normal=null;
    public Texture hover=null;
    public Texture armed=null;
    public ButtonTextures() {}
 
    public Texture this [ButtonState state]
	{
        get
		{
            switch(state)
			{
                case ButtonState.normal:
                    return normal;
                case ButtonState.hover:
                    return hover;
                case ButtonState.armed:
                    return armed;
                default:
                    return null;
            }
        }
    }
}
 
 
[RequireComponent(typeof(GUITexture))]
[AddComponentMenu ("GUI/Button")]    
public class GuiButton : MonoBehaviour
{
    public GameObject messagee;
    public string message = "";
	public string messageDoubleClick = "";
    public ButtonTextures textures;
 
    protected int state = 0;
    protected GUITexture myGUITexture;
 
	private int clickCount = 1;
	private float lastClickTime = 0.0f;
	static private float doubleClickSensitivity = 0.5f;
 
    protected virtual void SetButtonTexture(ButtonState state)
	{
		if (textures[state] != null)
		{
        	myGUITexture.texture = textures[state];
		}
    }
 
    public virtual void Reset()
	{
        messagee = gameObject;
        message = "";
		messageDoubleClick = "";
    }
 
	public bool HitTest(Vector2 pos)
	{
		return myGUITexture.HitTest(new Vector3(pos.x, pos.y, 0));
	}
 
    public virtual void Start()
	{
        myGUITexture = GetComponent(typeof(GUITexture)) as GUITexture; 
        SetButtonTexture(ButtonState.normal);
    }
 
    public virtual void OnMouseEnter()
    {
        state++;
        if (state == 1)
            SetButtonTexture(ButtonState.hover);
    }
 
    public virtual void OnMouseDown()
    {
        state++;
        if (state == 2)
            SetButtonTexture(ButtonState.armed);
    }
 
    public virtual void OnMouseUp()
    {
		if (Time.time - lastClickTime <= doubleClickSensitivity)
		{
			++clickCount;
		}
		else
		{
			clickCount = 1;
		}
 
        if (state == 2)
        {
            state--;
			if (clickCount == 1)
			{
				if (messagee != null && message != "")
				{
					messagee.SendMessage(message, this);
				}
			}
			else
			{
				if (messagee != null && messageDoubleClick != "")
				{
					messagee.SendMessage(messageDoubleClick, this);
				}
			}
        }
        else
        {
            state --;
            if (state < 0)
                state = 0;
        }
        SetButtonTexture(ButtonState.normal);
		lastClickTime = Time.time;
    }
 
    public virtual void OnMouseExit()
    {
        if (state > 0)
            state--;
        if (state == 0)
            SetButtonTexture(ButtonState.normal);
    }
 
#if (UNITY_IPHONE || UNITY_ANDROID)
	void Update()
	{
		int count = Input.touchCount;
		for (int i = 0; i < count; i++)
		{
			Touch touch = Input.GetTouch(i);
			if (HitTest(touch.position))
			{
				if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
				{
					SetButtonTexture(ButtonState.normal);
				}
				else
				{
					SetButtonTexture(ButtonState.armed);
				}
				if (touch.phase == TouchPhase.Began)
				{
					if (touch.tapCount == 1)
					{
						if (messagee != null && message != "")
						{
							messagee.SendMessage(message, this);
						}
					}
					else if (touch.tapCount == 2)
					{
						if (messagee != null && messageDoubleClick != "")
						{
							messagee.SendMessage(messageDoubleClick, this);
						}
					}
				}
				break;
			}
		}
	}
#endif
}



출처 : http://wiki.unity3d.com/index.php/Button

반응형
Posted by blueasa
, |

TinyXmlReader

Unity3D/Xml / 2012. 12. 9. 20:29

TinyXmlReader

You can use Mono's System.Xml for handling XML files but this requires including the System.Xml dll into your Unity program which increases its file size by about 1 MB. Not to mention the lack of documentation for using System.Xml on UnityScript.

I found rolling my own XML parser was easier. Note however that this is a really simple XML parser, it doesn't recognize attributes (I did not implement it simply because I don't use XML attributes).

TinyXmlReader.cs

using UnityEngine;
using System.Collections;
 
public class TinyXmlReader
{
    private string xmlString = "";
    private int idx = 0;
 
    public TinyXmlReader(string newXmlString)
    {
        xmlString = newXmlString;
    }
 
    public string tagName = "";
    public bool isOpeningTag = false;
    public string content = "";
 
 
	// properly looks for the next index of _c, without stopping at line endings, allowing tags to be break lines	
	int IndexOf(char _c, int _i)
	{
		int i = _i;
		while (i < xmlString.Length)
		{
			if (xmlString[i] == _c)
				return i;
 
			++i;
		}
 
		return -1;
	}
 
    public bool Read()
    {
		if (idx > -1)
        	idx = xmlString.IndexOf("<", idx);
 
        if (idx == -1)
        {
            return false;
        }
        ++idx;
 
		// skip attributes, don't include them in the name!
		int endOfTag = IndexOf('>', idx);
		int endOfName = IndexOf(' ', idx);
        if ((endOfName == -1) || (endOfTag < endOfName))
	    {
			endOfName = endOfTag;
		}
 
		if (endOfTag == -1)
        {
            return false;
        }
 
        tagName = xmlString.Substring(idx, endOfName - idx);
 
        idx = endOfTag;
 
        // check if a closing tag
        if (tagName.StartsWith("/"))
        {
            isOpeningTag = false;
            tagName = tagName.Remove(0, 1); // remove the slash
        }
        else
        {
            isOpeningTag = true;
        }
 
        // if an opening tag, get the content
        if (isOpeningTag)
        {
            int startOfCloseTag = xmlString.IndexOf("<", idx);
            if (startOfCloseTag == -1)
            {
                return false;
            }
 
            content = xmlString.Substring(idx+1, startOfCloseTag-idx-1);
            content = content.Trim();
        }
 
        return true;
    }
 
    // returns false when the endingTag is encountered
    public bool Read(string endingTag)
    {
        bool retVal = Read();
        if (tagName == endingTag && !isOpeningTag)
        {
            retVal = false;
        }
        return retVal;
    }
}

TinyXmlReader.js

class TinyXmlReader
{
 
private var xmlString = "";
private var idx = 0;
 
function TinyXmlReader(aXmlString : String)
{
	xmlString = aXmlString;
}
 
var tagName = "";
var isOpeningTag = false;
var content = "";
 
function Read() : boolean
{
	idx = xmlString.IndexOf("<", idx);
	if (idx == -1)
	{
		return false;
	}
	++idx;
 
	var endOfTag = xmlString.IndexOf(">", idx);
	if (endOfTag == -1)
	{
		return false;
	}
 
	tagName = xmlString.Substring(idx, endOfTag-idx);
 
	idx = endOfTag;
 
	// check if a closing tag
	if (tagName.StartsWith("/"))
	{
		isOpeningTag = false;
		tagName = tagName.Remove(0, 1); // remove the slash
	}
	else
	{
		isOpeningTag = true;
	}
 
	// if an opening tag, get the content
	if (isOpeningTag)
	{
		var startOfCloseTag = xmlString.IndexOf("<", idx);
		content = xmlString.Substring(idx+1, startOfCloseTag-idx-1);
		content = content.Trim();
	}
 
	return true;
}
 
// returns false when the endingTag is encountered
function Read(endingTag : String) : boolean
{
	var retVal = Read();
	if (tagName == endingTag && !isOpeningTag)
	{
		retVal = false;
	}
	return retVal;
}
 
}

Usage

Here I provide example code on how to use the TinyXmlReader.

private var text : String;
var skin : GUISkin;
 
function OnGUI()
{
	GUILayout.Label(text, skin.label);
}
 
function Start()
{
	var xmlText = System.IO.File.ReadAllText(Application.dataPath + "/Rifleman.xml");
	var reader = TinyXmlReader(xmlText);
	while (reader.Read())
	{
		if (reader.isOpeningTag)
		{
			text += (reader.tagName + " \"" + reader.content + "\"\n");
		}
		if (reader.tagName == "Skills" && reader.isOpeningTag)
		{
			while(reader.Read("Skills")) // read as long as not encountering the closing tag for Skills
			{
 
				if (reader.isOpeningTag)
				{
					text += ("Skill: " + reader.tagName + " \"" + reader.content + "\"\n");
				}
			}
		}
	}
}

Plus, here's the XML file used for the example code: <xml> <?xml version="1.0" encoding="UTF-8"?> <Unit> <Type>Rifleman</Type> <Label>ライフル銃兵 é (для Windows тоже!)</Label> <MaxHP>100</MaxHP> <SightRange>10</SightRange> <Skills> <UnitMovement> <Label>Move</Label> <Animation>move</Animation> <Range>10</Range> <Speed>6</Speed> </UnitMovement> <SimpleAttack> <Label>Attack</Label> <Animation>shoot</Animation> <Range>10</Range> <Damage>20</Damage> <AttackTime>0.348</AttackTime> <AttackType>Ranged</AttackType> </SimpleAttack> <Grenade> <Label>Throw Grenade</Label> <Animation>shoot</Animation> <Range>10</Range> <Damage>20</Damage> <AttackTime>0.348</AttackTime> <ExplosionRadius>5</ExplosionRadius> <NoOfUses>3</NoOfUses> </Grenade> </Skills> <Pahabol>oompa loompa doompity doo, we wouldn't hit that and neither should you</Pahabol> </Unit> </xml>

It produces this output:

TinyXmlReader Sample Output


출처 : http://wiki.unity3d.com/index.php/TinyXmlReader

반응형
Posted by blueasa
, |