Public variable or Property? - Unity Forum
[SerialiseField]
- Used whenever a variable needs to be exposed to the inspector.
변수를 인스펙터 창에 보이게 하고 싶을때
public
- Used whenever another script needs to access a variable.
다른 스크립트가 변수에 접근해야 할때
Auto properties
- Used whenever you need different access modifies on the set or get properties.
자동: (?) get set 접근 수정이 필요할 때
(private get; set; 이런거 말하는 건가)
Explicit properties
- Used whenever you need to get clever. For example data validation, triggering on change events, complex setting or getting behaviour.
명시적: 데이터 검증, 이벤트 트리거 등 값을 넣을 때 처리가 필요하거나, 데이터 바인딩할 것이라면
Method
- Used whenever there are additional side effects above and beyond setting and getting a variable.
변수 get set 하면 부작용 있을 때
And there are a couple of bad practices you should stomp out mercilessly: 하면 병신짓
Using a public variable just to expose it to the inspector. 인스펙터에 그냥 보이려고 public 쓰기
Using auto properties on everything, regardless of need. 안 필요한데 무지성 자동 프로퍼티 쓰기
기타: 프로퍼티 직렬화 serialize
https://forum.unity.com/threads/serialize-c-properties-how-to-with-code.506027/
오토 프로퍼티와 퍼블릭의 차이는 아직도 잘 모르겠어
인터페이스 쓸때 필요한거 아닌가 - dc App
필드하고 프로퍼티를 비교하는게 좀 더 맞다 생각하는데 프로퍼티는 기본적으로 메소드에 가까움 오토 프로퍼티는 숨겨진 필드를 가지고 있고 Getter와 Setter 메소드가 자동으로 만들어지는 구문 설탕 같은거임
More Effective C# 추천드려