본문 바로가기

프로그래밍/Unity95

2D Lookat / Lookat2D public void Set(Vector3 pos, Vector3 dir) { transform.position = pos; transform.rotation = Quaternion.AngleAxis(Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg, Vector3.forward); } // dir = (target.pos - pos).normalize protected void LookAt2D(Vector3 dir) { transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90); } 2021. 1. 21.
LayerMask.NameToLayer / Equals 성능/포퍼먼스 LayerMask.NameToLayer("Ground") 이렇게 쓰다보면 string 들어가니 성능 안나오고 그런게 아닐까.. 미리 다른 곳에 받아놓고 그걸 쓰는 사람들도 있고.. 과연 얼마나 차이가 있을까 실험을 해봅시다 using System.Diagnostics; private void Awake() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < 100000; i++) if (gameObject.layer == LayerMask.NameToLayer("Ground")) break; stopwatch.Stop(); Debug.Log($"Test 1 Sec {stopwatch.ElapsedMillisecon.. 2021. 1. 14.
Spine Render Separator spine-unity Runtime Documentation (esotericsoftware.com) spine-unity Runtime Documentation Licensing Integrating an official Spine Runtime into your applications requires a valid Spine license, though you are welcome to use the Spine Runtimes for evaluation purposes. To use the spine-unity runtime in your Unity project: Download and install Unit ko.esotericsoftware.com 에서 Transparency and Draw O.. 2021. 1. 8.
JobQueue wiki.unity3d.com/index.php/JobQueue JobQueue - Unify Community Wiki Description This is a simple threaded job queue for any kind jobs you want to execute on a thread. The JobQueue class is a management class, the actual job scheduler. When you create an instance of that class you have to specify the "job class" it will man wiki.unity3d.com ㄴ 원문 JobQueue.cs /**************************************.. 2020. 12. 27.
UGUI Sprite 늘리기 1. 보더를 설정할 이미지를 선택 2. Mesh Type 을 Full Rect 로 설정 3. 아래 Sprte Editor 버튼 누름 4. 보더를 잘 설정 후 어플라이 2020. 10. 19.
Coroutine Manager pro 1.0 매뉴얼 Coroutine Manager Pro 1.0 https://assetstore.unity.com/packages/templates/systems/coroutine-manager-pro-53120 Coroutine Manager Pro | 시스템 | Unity Asset Store Use Coroutine Manager Pro from that games guy to elevate your next project. Find this & more 시스템 and templates on the Unity Asset Store. assetstore.unity.com ## 씬 이동을 하면 CM_ 시리즈가 사용이 안되는데 어딘가 최초 로딩하는 부분에서 CM_Dispatcher.DontDestroyOnLoad(CM_.. 2020. 9. 29.
유니티에서 Dictionary 가 Clear 되는 현상 싱글턴으로 만든 A 클래스가 있고 A 안에서 new 로 할당해서 맴버로 가지고 있는 B 라는 클래스에서 Dictionary 를 가지고 있고 값을 넣었는데 씬 이동 후 B 의 Dictionary 의 Count 가 0 이 되는 현상이 있을 시 B 를 A 안에서 new 로 만들지 말고 싱글턴으로 독립시키면 위의 현상은 사라진다. 원래 구조대로 하고 싶다면 싱글턴으로 만든 B 를 A 에서 링크만 가지고 있는 식으로 구현하면 됨 이 현상이 일어나고 있나 확인하고 싶다면 A 를 디버그로 보면 B 가 null 로 비쥬얼스튜디오 상에서 구분이 된다 싱글턴으로 B 를 만들고 A 에 링크하는 순간 보면 null 이 아님 2020. 9. 29.
로컬 데이터 저장 자신의 플랫폼 (PC / Android / iOS 등) 에 현재 프로젝트의 로컬 데이터 저장용으로 유용한 기능을 유니티에서 지원하고 있는데 PlayerPrefs 클래스를 사용해보자 /// /// 기기에 저장한 값을 얻어온다. 없으면 생성 /// /// /// /// int GetLocalData(string Key, int DefaultValue) { if (PlayerPrefs.HasKey(Key) == false) // 저장된 값을 찾지 못했다 PlayerPrefs.SetInt(Key, DefaultValue); // 디폴트 값으로 생성 return PlayerPrefs.GetInt(Key); // 저장된 값을 반환 } 이거 하나면 끝 string float 는 알아서 응용을 하던가 해보자- 2020. 9. 28.
NGUI 스크롤뷰 만들기 1. NGUI>Create>Scroll View 2. 생성된 스크롤뷰에 NGUI>Create>Grid 3. Scroll View 컴포넌트 세팅 Static 체크 Movement 설정 Cancel Drag If Fits 체크 리지드바디 부착 > 그라비티 비활성, 키네마틱 활성 4. Grid 컴포넌트 세팅 Cell 세팅 Column Limit 세팅 Constrain to Panel 체크 5. 버튼 세팅 NGUI>DragScrollView 컴포넌트 부착 6. 소스상에서 버튼 생성 후 Grid 를 parent 로 세팅 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Lobby : MonoBehav.. 2020. 9. 23.
rotate 값 360 -> 0~1 구하기 한가지 착각하기 쉬운 것은 그냥 씬에 올려져있는 오브젝트를 가지고 회전시켜보면 x 나 y 나 z 값이 1. 0~360 으로 표시되는 경우 2. 0~180 , -0~-180 으로 표시되는 경우 가 있다.. 물론 이건 에디터 Inspector 화면에서만이고 실제 저 z 값을 gameObject.rotate.gameObject.transform.rotation.eulerAngles.z 이렇게 소스상에서 확인하면 0~360 으로 들어오는 것을 알 수 있다 Inspector 에서는 막 -150 이렇게 나와도 소스상에서는 정상으로 된다 막 -일때는 어떻게 하고 + 일때는 어떻게하고 할 필요가 없다;;; 그냥 gameObject.rotate.gameObject.transform.rotation.eulerAngles... 2020. 9. 22.
원형 그래프 (Kerisdiagramm) using System.Collections; using System.Collections.Generic; using UnityEngine; public class UI_Kerisdiagramm : MonoBehaviour { public UISprite m_SpriteCircle; float m_CurRatio = 0.0f; // Start is called before the first frame update void Start() { StartCoroutine(Add_(0.2f, Color.red)); StartCoroutine(Add_(0.3f, Color.blue)); StartCoroutine(Add_(0.1f, Color.green)); StartCoroutine(Add_(0.2f, Colo.. 2020. 9. 18.
csv 파일 쓰기 자신의 리스팅된 데이터를 유니티 Assets 폴더에 csv 파일로 생성하는 예제 입니다 using System.IO; void MakeCsv() { FileStream fs = new FileStream("Assets/result.csv", FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Unicode); var list = 당신의 데이터; for (int i = 0; i < list.Count; i++) { var tmp = list[i]; //Debug.Log(string.Format("{0},{1}", tmp.nIndex, tmp.sName)); sw.WriteLine(stri.. 2020. 9. 8.
Load Resources Csv & delegate & parser using System; using System.IO; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Tool_TableParser : MonoBehaviour { public delegate void Parser(string[] s); public void Read_Resources_Bytes(string Name, Parser parser) { TextAsset asset = Resources.Load(Name) as TextAsset; if (asset == null) { Debug.Log("asset == null"); return; } StringReader reader = ne.. 2020. 9. 3.
목록에 없는 API 레벨로 빌드하기 1. [Build System] 을 [Gradle] 로 2. [PlayerSetting/Publishing Setting] 의 [Custom Gradle Template] 체크 3. 2의 과정 후 [Asset/Plugins/Android] 폴더에 [mainTemplate] 파일이 생성되고 이걸 열어보면 2020. 8. 26.
Texture 다운로드 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; public class Main : MonoBehaviour { public string m_URL; public RawImage m_RawImage; // Start is called before the first frame update void Start() { StartCoroutine(Download_Image(m_URL)); } // Update is called once per frame void Update() { } IEnumerator Download_Ima.. 2020. 8. 25.
Unity 각종 앱 에뮬레이터와의 호환성 요즘은 PC로 앱 에뮬레이터로 게임을 하는 사람들이 많은 관계로 각종 에뮬레이터에 맞춰서 옵션을 조절해줘야 하는데 (아예 인기 있는 게임이 되서 그 에뮬레이터들이 알아서 맞춰주면 좋겠지만) 방법은 이것저것 돌려보면서 최대한 튀지 않는 선에서 유니티 옵 션을 만져줘야 한다 미뮤는 아예 옵션에서 OpenGL 모드와 DirectX 모드를 지원하기 때문에 최악의 경우 둘 중 하나만 잘 나오게 해도 되긴 하지만- 다른 플레이어는 어떨까요? 요즘 가장 가볍다고 소문난 LDPlayer 로 테스트를 해봅시다 시도해볼만한건 Player 나 Graphics 에서 옵션을 하나씩 건드려보면서 바꿔야 되는데 일단 대게 효과 있는건 GPU Skinning 같은거 꺼주는거랑 Job 처리 등 좀 고급지다 싶은건 안쓰는게 좋습니다 이.. 2020. 1. 25.
Unity 2019 기존 프로젝트에 LWRP 적용 이런 프로젝트에 LWRP 를 적용하면 어떻게 될지 해봅시다. 2019.3 버전 이후 URP 로 변경되긴 할꺼지만 완벽 호환을 장담했으니 뭐 미리 알아둬도 나쁘지 않겠죠? ㅎㅎ 1. 유니티에서 프로젝트를 열고 Window/Package Manager 를 오픈 2. 아래의 4가지 패키지를 설치 (서로 Dependency 로 연결되어 필수) Core RP Library Lightweight RP Post Processing Shader Graph 3. LRP 을 만들어야 되는데 Assets 폴더 하위에 적당한 공간을 만들고 거기서 우클릭 Create/Rendering/Lightweight Render Pipeline/Pipeline Asset 을 선택해서 제작 후 파라메터 값을 세팅 4. Edit/Projec.. 2020. 1. 25.
Unity 에뮬레이터 OpenGL 모드에서 모델링이 안보이는 현상 Project Settings/Player/Other Settings 에서 GPU Skinning 을 끄면 해결 2020. 1. 16.
애니메이션 애러 The animation state Idle could not be played because it couldn't be found! Please attach an animation clip with the name 'Idle' or call this function only for existing animations. 이런식으로 뜬다? 어디를 봐야할까 정답! 애니메이션 fbx 를 클릭해보면 Rig 부분에 애니메이션 타입이 나오는데 Legacy 로 바꾸고 나서 하면 애러가 나지 않는다 2019. 9. 24.
프린세스 커넥트의 AVI UI 뭔가 애니메이션 위에 UI 가 뜬게 여지껏 게임 중에 본적이 없어서 신기해 하던 중- 만들 수 있을까? 고민해서 뭐하랴 만들어 보았습니다- AVI 위에 UI 를 띄워놓으면 되는거긴 한데 -_-... 금방 만들 수 있었군요 :) 결국 이것을 구현하는데 최대 난관은... 유려한 애니메이션이 없다는거 -_-;; 본 게임 만큼 고품질의 애니메이션이 있어야 이런 것도 미려한 룩이 되는거지 ㅠㅠ 양키센스 애니메이션 위에 해봐야 개똥... 2019. 4. 11.