본문 바로가기

프로그래밍280

무결성 랜덤 (Random) A C# Mersenne Twister class - CodeProject A C# Mersenne Twister class A pseudorandom number generator. www.codeproject.com C++ 에 Boost::Random 이 있다면 C# 은 MersenneTwister 가 있다...? namespace MersenneTwister; void Test() { int rnd = (new MT19937()).RandomRange(0, 10); } 2021. 3. 9.
Spine Animation - AnimationState 가 null 일 때 SkeletonAnimation m_Spine; private void Awake() { m_Spine = GetComponent(); // 이 때 하면 AnimationState 가 null 일 때도 있다 m_Spine.AnimationState.SetEmptyAnimation(0, 0.0f); } private void Start() { // 이 때 하면 awake 에서는 null 이던게 아니게 된다 m_Spine.AnimationState.SetEmptyAnimation(0, 0.0f); } 늘 그런건 아니지만 Awake 에서 AnimationState 가 null 일 때도 있으니 한템포 쉬고 Start 쪽에서 참조하면 값이 있다.. 코루틴 같은 상황에서는 WaitFor 시리즈로 한틱 정도만 쉬어준.. 2021. 2. 26.
Unity Spine Animation y 축 180 돌렸을 때 덜덜 떨리는 현상 transform.rotation = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f); //gameObject.transform.SetPositionAndRotation(gameObject.transform.position, Quaternion.Euler(0, 0, 0)); transform.rotation = new Quaternion(0.0f, 180.0f, 0.0f, 0.0f); //SetPositionAndRotation(gameObject.transform.position, Quaternion.Euler(0, 180, 0)); 아래 주석으로 했을 때 180 돌린 후 이동하면 덜덜 떨었는데 new 로 한 다음엔 괜찮음 SetPositionAndRotation 말고도 Engle.. 2021. 2. 23.
30프레임에 한번씩 미리 가비지 컬렉션 if (Time.frameCount % 30 == 0) { System.GC.Collect(); } 2021. 2. 8.
C# foreach 중 삭제(Remove) feat Linq using System.Linq; Dictionary m_Dic = new Dictionary(); private void Start() { m_Dic.Add("test1", 1.0f); m_Dic.Add("test2", 2.0f); m_Dic.Add("test3", 3.0f); // error foreach (var tmp in m_Dic) if (tmp.Value < 2.0f) m_Dic.Remove(tmp.Key); // success foreach (var key in m_Dic.Keys.ToList()) if (m_Dic[key] < 2.0f) m_Dic.Remove(key); } 2021. 2. 2.
Unity 네비메쉬 2D GitHub - h8man/NavMeshPlus: Unity NavMesh 2D Pathfinding h8man/NavMeshPlus Unity NavMesh 2D Pathfinding. Contribute to h8man/NavMeshPlus development by creating an account on GitHub. github.com 네비메쉬플러스를 사용 :) 2021. 1. 26.
KinematicObject 계열의 캐릭터 주의점 유니티에서 샘플로 받을 수 있는 2D 플랫포머의 캐릭터 컨트롤러를 참고 하다보면 KinematicObject 라는 클래스를 참고해서 2D 게임을 만드는 경 우가 많을 것 같은데 본인 역시 이걸 가져다가 없는 기능 2개 정도를 추가해서 사용 중 다수의 총알을 쏘고 맞는 게임을 제작 중 이상 동작을 하는 것을 확인.. 대략 이틀 정도 고민 끝에 원인을 발견.. 원인은 여기서 ContactFilter2D 를 설정해서 RaycastHit2D[] 버퍼에 받는 과정이 문제... 일단 캐릭간 충돌, 총알과 캐릭간 충돌, 바닥 타일간 충돌 이 설정된 Enemy 라는 Layer를 사용했더니 다수의 탄을 맞을 때 RaycastHit2D의 디폴트 버퍼 15를 탄알이 가득 채워버리는 바람에 정작 해야할 그라운드의 체크를 못해.. 2021. 1. 25.
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.
에서 필요한 정식 매개 변수 에 해당하는 제공된 인수가 없습니다 클래스 상속시 'class' 에서 필요한 정식 매개 변수 ~~ 에 해당하는 제공된 인수가 없습니다 경고문 떴을 때 class StageData { public StageData(int id) { } } class StageData_Normal : StageData { public StageData_Normal(int id) : base(id) { } } : base 를 추가해주면 됩니다 2020. 11. 20.
C# 내일까지 남은 초 구하기 public static float NowToTomorrowSec() { return (float)((DateTime.Now - DateTime.Parse("0:00:00 AM").AddDays(1)).TotalSeconds); // 혹은 return (float)DateTime.Today.AddDays(1).Subtract(DateTime.Now).TotalSeconds; } 백문이 불여일견 2020. 11. 13.
List 루프 돌며 삭제 for (int i = 0; i < List.Count;) { if (List[i] == 조건) { List.RemoveAt(i); continue; } else i++; } 2020. 11. 11.
UGUI Sprite 늘리기 1. 보더를 설정할 이미지를 선택 2. Mesh Type 을 Full Rect 로 설정 3. 아래 Sprte Editor 버튼 누름 4. 보더를 잘 설정 후 어플라이 2020. 10. 19.
Shuffle Array + Array([]) to List(List<>) public T[] ShuffleArray(T[] array, int seed) { System.Random prng = new System.Random(seed); for (int i = 0; i < array.Length - 1; i++) { int randomIndex = prng.Next(i, array.Length); T tempItem = array[randomIndex]; array[randomIndex] = array[i]; array[i] = tempItem; } return array; } void Test() { List val = new List(); val.Add(1); val.Add(2); val.Add(3); List tmp = new List(ShuffleArray(val.T.. 2020. 10. 7.
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.