Today I Learned :
readonly inspector field
인스펙터상에서 수정은 불가능한 읽기상태의 필드를 보여주고 싶어서 검색하고 추가했다.
using UnityEngine;
// 온전히 이해하고 쓴 코드는 아님
/// <summary>
/// Read Only attribute.
/// Attribute is use only to mark ReadOnly properties.
/// </summary>
public class ReadOnlyAttribute : PropertyAttribute { }
// ReadOnlyDrawer 정의
#if UNITY_EDITOR
namespace UnityEditor
{
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = false; // 편집 비활성화
EditorGUI.PropertyField(position, property, label);
GUI.enabled = true; // 편집 활성화
}
}
}
#endif
public class DataManager : SingletoneBase<DataManager>
{
[ReadOnly, SerializeField] private string _pidStr; // 해당값은 읽기전용으로 나온다.
...
}
List<object> 합치기
using System.Collections.Generic;
List<UnitController> list1 = new List<UnitController>();
List<UnitController> list2 = new List<UnitController>();
// list1과 list2를 합친 새로운 리스트를 만듭니다.
List<UnitController> combinedList = new List<UnitController>();
combinedList.AddRange(list1);
combinedList.AddRange(list2);
UUID 생성
// UUID 생성
Guid uuid = Guid.NewGuid();
8-4-4-4-12의 표준형식 UUID 생성
'TIL' 카테고리의 다른 글
20240227 TIL (0) | 2024.02.27 |
---|---|
20240223 TIL (0) | 2024.02.23 |
20240221 TIL (0) | 2024.02.21 |
20240220 TIL (1) | 2024.02.20 |
20240219 TIL (0) | 2024.02.19 |