강의

멘토링

커뮤니티

Inflearn Community Q&A

pokor21074's profile image
pokor21074

asked

[MMORPG Game Development Series with C# and Unity] Part3: Unity Engine

UI Automation #2

_object.Add() 타이밍 질문있습니다~

Written on

·

308

0

Bind 메서드에서 아래의 Add가 먼저되고 난다음에 objects에 컴포넌트가 채워지는데 objects가 참조형 변수라서 먼저 Add를 해도 메서드를 빠져나가기 전에 objects가 변경되면 해당 objects로 Add가 되는게 맞나요? 

여기서 직관적으로 Add를 for 문 뒤로 빼면 안되나요?

_object.Add(typeof(T), objects);

        for (int i = 0; i < names.Length; i++)

       { 

            objects[i] = Util.FindChild<T>(gameObject, names[i], true);

        }

C#unity

Answer 2

0

pokor2님의 프로필 이미지
pokor2
Questioner

자세한 설명 감사합니다!

0

Rookiss님의 프로필 이미지
Rookiss
Instructor

objects는 배열이고 배열은 참조값이니
_object.Add 할 때 Dictionary에 (key, 배열의 참조)가 들어가는 것이고,

objects[i] = Util.FindChild... 를 할 때는 
objects 배열의 특정 인덱스에 접근해 데이터를 채워주고 있습니다.

둘은 아무런 연관성이 없기 때문에 순서는 편하실 대로 바꿔도 상관없습니다.
그림으로 보면 다음과 같습니다.

pokor21074's profile image
pokor21074

asked

Ask a question