Today I Learned :
Linq
int[] slicedArray = array.Skip(start).Take(end - start).ToArray();
- Skip : 컬렉션에서 지정된 개수의 요소를 건너뛰는 데 사용
- Take : 컬렉션에서 지정된 개수의 요소를 선택하는 데 사용
오브젝트 이동 제한
// 인풋으로 들어온 좌표
Vector2 targetPos = _camera.ScreenToWorldPoint(value.Get<Vector2>());
// 사이드로 가능경우 화면 밖으로 나가지 않도록 보정
// 1. 해당 오브젝트의 스케일의 반지름을 구해서 연산 범위안에 적용, 최대 이동거리 안쪽에 위치하게 한다.
// 이 경우 오브젝트의 스케일이 달라도 모두 적절하게 보정된다.
targetPos.x = Mathf.Clamp(targetPos.x, -4.5f + transform.localScale.x / 2f, 4.5f - transform.localScale.x / 2f);
// 2. 절대값으로 범위 고정. 오브젝트의 중심점을 기준으로 한다.
targetPos.x = Mathf.Clamp(targetPos.x, -2.6f, 2.6f);
HashSet
- 중복요소를 포함하지 않는 데이터 자료구조
- 해시 테이블을 기반으로 하기 때문에 검색, 삽입, 삭제 연산이 O(1)의 평균 시간 복잡도를 갖는다
- 매우 효율적인 성능을 제공
- 순서를 보장하지 않는다
// 중복제거
List<int> numbers = new List<int> { 1, 2, 2, 3, 4, 4, 5 };
HashSet<int> uniqueNumbers = new HashSet<int>(numbers);
HashSet<int> set1 = new HashSet<int> { 1, 2, 3, 4 };
HashSet<int> set2 = new HashSet<int> { 3, 4, 5, 6 };
// 교집합
HashSet<int> intersection = new HashSet<int>(set1);
intersection.IntersectWith(set2);
// 합집합
HashSet<int> union = new HashSet<int>(set1);
union.UnionWith(set2);
// 차집합
HashSet<int> difference = new HashSet<int>(set1);
difference.ExceptWith(set2);
Input System - AutoSwitch
컨트롤러 자동전환
하나의 액션을 여러 컨트롤러를 통하여 사용이 가능하다.
'TIL' 카테고리의 다른 글
20240131 TIL (0) | 2024.01.31 |
---|---|
20240130 TIL (0) | 2024.01.30 |
20240126 TIL (1) | 2024.01.26 |
20240125 TIL (0) | 2024.01.25 |
20240124 TIL (1) | 2024.01.24 |