2016의 게시물 표시

GetSpectrumData 사운드에 맞춰 게임오브젝트의 형태 변환

이미지
using  UnityEngine; using  System.Collections; public   class   soundMag  :  MonoBehaviour  {      AudioSource  audio;      float [] spectrum =  new   float [64];      public   GameObject  cube;           void  Start () {         audio = GetComponent< AudioSource >(); } void  Update () {         MusicVisualization();     }           void  MusicVisualization()     {         audio.GetSpectrumData(spectrum, 0,  FFTWindow .BlackmanHarris);         cube.transform.localScale =  new   Vector3 (1, spectrum[1], 1);     } } https://www.youtube.com/watch?v=swzY1CHWcgk // 스펙트럼 데이터 값을 쪼개어 넣기 using  UnityEngine; using  System.Collections; using  System.Collections.Generic; public   class   soundMag  :  MonoBehaviour  {      AudioSource  audio;      float [] spectrum =  new   float [2048];      public   GameObject  cube;      List < GameObject > boxs =  new   List < GameObject >();      void  Start () {         audio = GetComponent< AudioSource

유니티 에티터 곡선 연결 노드 만들기

http://gamedevst.tistory.com/category/Unity5

타겟방향을 따라 회전 하기

using  UnityEngine; using  System.Collections; public   class   test_rotation  :  MonoBehaviour  {      public   Transform  target;      Vector3  lookDir;      void  Start () { } void  Update () {                   // 방향은 노멀라이즈 사용         lookDir = (target.position - transform.position).normalized;          Quaternion  from = transform.rotation;          Quaternion  to =  Quaternion .LookRotation(lookDir);         transform.rotation =  Quaternion .Lerp(from, to,  Time .fixedDeltaTime); } }

프레임 레이트 화면에 표시 하기 fps display

http://wiki.unity3d.com/index.php?title=FramesPerSecond 프레임 레이트 화면에 표시 하기 using UnityEngine ; using System.Collections ;   public class FPSDisplay : MonoBehaviour { float deltaTime = 0 . 0f ;   void Update ( ) { deltaTime += ( Time . deltaTime - deltaTime ) * 0 . 1f ; }   void OnGUI ( ) { int w = Screen . width , h = Screen . height ;   GUIStyle style = new GUIStyle ( ) ;   Rect rect = new Rect ( 0 , 0 , w, h * 2 / 100 ) ; style . alignment = TextAnchor . UpperLeft ; style . fontSize = h * 2 / 100 ; style . normal . textColor = new Color ( 0 . 0f, 0 . 0f, 0 . 5f, 1 . 0f ) ; float msec = deltaTime * 1000 . 0f ; float fps = 1 . 0f / deltaTime ; string text = string . Format ( "{0:0.0} ms ({1:0.} fps)" , msec, fps ) ; GUI . Label ( rect, text, style ) ; } }

포커스 컨트롤 사용하기 텍스트 필드 포커스 이동 GUI.FocusControl("");

http://www.devkorea.co.kr/reference/Documentation/ScriptReference/GUI.FocusControl.html GUI .FocusControl( "" ); // 포커스 아웃 // "사용자 이름"Textfield 선택된 때, 버튼을 누르면. var username : String = "username" ; var pwd : String = "a pwd" ; function OnGUI () { //textfield 집합 내부 이름 GUI.SetNextControlName ( "MyTextField" ); // 실제 텍스트 필드를 확인합니다. username = GUI.TextField ( Rect (10,10,100,20), username); pwd = GUI.TextField ( Rect (10,40,100,20), pwd); // 사용자가이 버튼을 누를 경우 키보드 포커스가 이동합니다. if ( GUI.Button ( Rect (10,70,80,20), "Move Focus" )) GUI.FocusControl ( "MyTextField" ); }

문자 첫번째 문자 지우기 , 마지막 문자 지우기

if  (option ==  "first" )             {                 textLength = text.Length;                 text = text.Substring(1, textLength - 1);             }              else             {                 textLength = text.Length;                 text = text.Substring(0, textLength - 1);             }

현재 선택된 게임오브젝트의 콜라이더 타입 알아내기

Debug .Log( Selection .gameObjects[0].GetComponent< Collider >().GetType());

게임 오브젝트 하이어라키 패널에서 숨기기

             GameObject  obj = Instantiate(mapMag.tile)  as   GameObject ;             obj.hideFlags =  HideFlags .HideInHierarchy; 

런타임에서 스트리밍 폴더 만들어 파일 읽어 오기

이미지
http://cafe.naver.com/unityhub/33749 using  UnityEngine; using  System.Collections; using  System.IO; public   class   TEST  :  MonoBehaviour  {      Texture  image;      string  path; // Use this for initialization void  Start () {         StartCoroutine(ImageTex()); }      IEnumerator  ImageTex()     {         path =  Path .Combine( "file:///"  +  Application .streamingAssetsPath,  "logo.jpg" );          WWW  w =  new   WWW (path);          yield   return  w;         image = w.texture;          Debug .Log(image.name);         gameObject.GetComponent< MeshRenderer >().material.mainTexture = image;     } // Update is called once per frame void  Update () { } }

상업 용도로 사용 가능한 무료 이미지 사이트

상업 용도로 사용 가능한 무료 이미지 사이트 http://opengameart.org/ http://www.wikitree.co.kr/main/news_view.php?id=181872 http://graphicriver.net/category/game-assets/sprites http://www.supergameasset.com/ https://www.gamedevmarket.net/ http://www.graphic-buffet.com/ http://opengameart.org/ http://www.2dgraphicsprogramming.com/forums/discussion/1/where-can-i-find-2d-art-for-my-game/p1 http://morguefile.com/archive http://imagebase.net/ http://www.freepik.com/ http://hanulsoblog.com/50189245935 http://opencast.naver.com/HB224 http://kan-k http://kan-kikuchi.hatenablog.com/entry/FreeMaterial http://gongu.copyright.or.kr/search/search.do?sk=all&kwd=%EC%95%B1%EC%84%BC%ED%84%B0&x=3&y=13 https://www.iconfinder.com

sorting sort 하이어라키 순서대로 리스트에 담는법

SORTOBJECT =  Selection .gameObjects.Where(g => ! AssetDatabase .Contains(g)).OrderBy(g => g.transform.GetSiblingIndex()).ToList();

씬 정보 조회.

// 씬 정보 조회. Scene activeScene = SceneManager.GetActiveScene(); Scene scene1 = SceneManager.GetSceneAt(0); Scene scene2 = SceneManager.GetSceneByName("SceneName"); Scene scene3 = SceneManager.GetSceneByPath("Assets/SceneName.unity"); Scene[] loadedScenes = SceneManager.GetAllScenes(); 오홍이 이런게 있었군

제일 처음 선택한 오브젝트 반환 프로젝트 창에서 선택한 오브젝트 인지 확인 하기 프로젝트에 포함 되어 있는지 확인 하기

하이어라키 상태에서 처음 선택한 오브젝트 = Selection .activeObject.name 프로젝트 상태에서 처음 선택한 오브젝트 = if  ( Selection .objects.Length == 1 &&  AssetDatabase .Contains( Selection .activeObject))        {           Object firstSelectedObj =  Selection .activeObject;        }

GUILAYOUT GUI 마지막 렉트 가지고 오기 마지막 박스 가지고 오기

Debug.Log(GUILayoutUtility.GetLastRect().position.y); // 마지막 렉트 위치 가지고 오기 http://docs.unity3d.com/kr/current/ScriptReference/GUILayoutUtility.GetLastRect.html

유니티 내장 스킨 가지고 오고 get style

http://docs.unity3d.com/ScriptReference/GUISkin.GetStyle.html

FindAssets 에셋 폴더에서 파일 찾아오기

http://docs.unity3d.com/kr/current/ScriptReference/AssetDatabase.FindAssets.html

json -> csv

https://json-csv.com/

c# 가변배열

http://cjh7163.blog.me/220444348740

날짜 시간 시간차 시간 계산 하기

System. DateTime  StartDate = System. Convert .ToDateTime( "2012/05/07 08:00" );  // 시작시간 System. DateTime  EndDate = System. Convert .ToDateTime( "2012/05/10 10:20" );  // 현재시간( 완료 시간 ) System. TimeSpan  timeCal = EndDate - StartDate;  // 시간차 계산 int  timeCalDay = timeCal.Days; //날짜 차이 int  timeCalHour = timeCal.Hours;  //시간차이 int  timeCalMinute = timeCal.Minutes; // 분 차이 Debug .Log(timeCalDay); Debug .Log(timeCalHour); Debug .Log(timeCalMinute); System. DateTime  time = System. DateTime .Now; Debug .Log(time.ToString( "hh:mm tt" ));  // 시간 / 분 / 오전오후 Debug .Log(time.ToString( "MM/dd/yyyy" ));  // 월 시간 코드 샘플 http://www.csharp-examples.net/string-format-datetime/ //경과 시간 계산 string  currentTime;     string  calTime;     string  startTime;     void  TimeCal()    {        currentTime = System. DateTime .Now.ToString( "h:mm:ss.ff" );        System. DateTime  start = System. Convert .ToDateTime(startTime);      

스크립터블 오브젝트 설명

http://m.blog.naver.com/tobik/220252078732

shader

Shader "Diffuse_Shader01" { Properties // 변수들 { _Color ("Main My Color", Color) = (1,1,1,1) // => 변수명 ("이름", 속성) = (값) _MainTex ("Base (RGB)", 2D) = "white" {} _SubTex ("Sub (RGB)", 2D) = "white" {} _BumpTex ("Normal" , 2D) = "bump"{} _f("Value",float) = 1 _RimColor("RimColor", Color) = (1,1,1,1) _RimPower("RimColor", float) = 3.0 } SubShader { Tags { "RenderType"="Opaque" } // 렌더링 되는 순서 LOD 200 CGPROGRAM // 쉐이더 코드 시작 #pragma surface surf Lambert // => #pragma 쉐이더가 어떤 것인지 정의 ( surface 는 픽셀 세이더 Lambert 버텍스 단위로 라이팅 ) sampler2D _MainTex; //자료형 변수 선언 sampler2D _SubTex; // 텍스쳐 추가 sampler2D _BumpTex; // 범프 텍스쳐 추가 float4 _RimColor;         float _RimPower; fixed4 _Color;      //자료형 변수 선언 float4(32bit), half4(16bit), fixed4(8bit) = 모바일에서는 half4만 사용된다. 주로 half4 사용하면 됨

델리게이트 연습 소스

using UnityEngine; using System.Collections; delegate void EventHandler( Color color ); class OrcParams { public event EventHandler OnColorChange; int _hp = 100;   public int hp{ get { return _hp; } set{ _hp = value; if (_hp < 50) OnColorChange (Color.red); } } } public class test : MonoBehaviour { GameObject ttt; void ChangeColor(Color color) { gameObject.GetComponent<MeshRenderer>().material.color = color; } void ShowColorValue (Color color){ Debug.Log (color); } OrcParams MyParam; void Start () { MyParam = new OrcParams(); MyParam.OnColorChange += ShowColorValue; MyParam.OnColorChange += ChangeColor; } void OnMouseDown() { MyParam.hp -= 10; //Debug.Log (MyParam.hp); } void Update () { } }

부모 오브젝트인지 아닌지 확인하기

if  ( Selection .gameObjects[0].transform.childCount == 0)        {             Debug .Log( "부모오브젝가 아닙니다" );        }         else        {             Debug .Log( "부모오브젝트 입니다" );        }