응용프로그램/유니티(Unity)

Unity - 자습서 - 필수개념 - 인스펙터 사용자정의 빌딩

zelkova 2016. 12. 16. 10:52

<목차로 돌아가기>



immunity we can create a custom inspector to control which data from our scripts is visible and how it is represented editor


면책 특권 스크립트를 사용하여 표시 할 데이터와 표시되는 데이터를 제어하는 ​​사용자 정의 관리자를 만들 수 있습니다.


the ability to extend the editor in this way gives us a lot of power and flexibility scripts and the resulting workflow


이런 식으로 편집기를 확장 할 수 있는 능력은 우리에게 아주 강력하고 유연한 스크립트와 결과 워크 플로우를 제공합니다.



let's say we had a leveling system where every time a character earned 750 experience point they gained a new level


캐릭터가 750의 경험치 포인트를 얻을 때마다. 레벨업을 한다고 가정해 보겠습니다.


this is easy enough to calculate in the beginning but it could be a bit cumbersome as characters get to higher 

이것은 처음에는 계산하기가 쉽지만 캐릭터가 더 높은 레벨에 도달하면 약간 성가 시게됩니다.


levels luckily we can create a custom inspector to make this much simpler

운좋게도 커스텀 인스펙터를 만들어 훨씬 간단하게 만들 수 있습니다


here we have a script called level script this script represents the experience based leveling system mentioned before in the script we first have a variable named experience


 which will contain the total amount experience a character has accumulated next we have a property name level we can see that this property takes the current experience value and return the level equivalent for more information on properties see the lesson on properties link below


immunity we have an empty game object with the level script attached

notice how we can see the experience property in inspector it is easy to calculate the level in our experience is 0 


여기에 레벨 스크립트라는 스크립트가 있습니다.이 스크립트는 이전에 언급 한 경험 기반 변수 시스템

 캐릭터가 누적 한 총 경험치를 포함합니다 속성 이름 수준이 속성은 현재 경험 값을 사용하고 속성 값에 대한 자세한 정보는 해당 수준을 반환 함을 볼 수 있습니다 아래의 속성 링크에 대한 강의 참조

면책 특권 레벨 스크립트가 붙은 빈 게임 개체가 있습니다.
우리가 경험에서 레벨을 계산하기 쉽도록 inspector에서 경험 속성을 볼 수있는 방법을 알아 봅니다. 0


but what if it was forty nine thousand eight hundraed and sisty-five 

let's customize the inspector to show the level for us in order to customize the inspector

we need to make a folder to place our editor scripts in unity requires that forlder is named editor inside the editor folder we ceate a new script this script will contain custom inspector 


he can have any name but for thew sake of thisd example we will call is level script editor


in the level script editor we can begin writing our custom inspector before we begin running any editor specific code we must first declare that we are using the unity editor namespace for more information or namespaces see the lesson on namespaces linked below 


next we need to inhewrit from editor instead of monobehaviour this in effects is how we extend the editor for more information on inheritance see the lesson on inheritance link below from here we need to give our custom inspector and attribute to tell it which scirpt we are customizing the syntax for doing this starts with an open square bracket followed by the keyword cusdtom editor and parenthesses


그러나 그것이 hundraed하고 sisty-five의 사십 만 명 이었다면 어떨까요?
인스펙터를 사용자 정의하기 위해 인스펙터를 사용자 정의하여 레벨을 표시해 봅시다.
우리는 편집기 스크립트를 배치 할 폴더를 만들 필요가 있습니다. forlder는 편집기 폴더 안에 이름이 지정된 편집기가 필요합니다. 우리는이 스크립트에 사용자 정의 관리자를 포함 할 새 스크립트를 지정합니다.

그는 모든 이름을 가질 수 있지만,이 예제의 경우 우리는 호출 할 레벨 스크립트 편집기

레벨 스크립트 편집기에서 우리는 커스텀 인스펙터를 작성하기 시작할 수 있습니다. 에디터 특정 코드를 실행하기 전에, 먼저 유니티 에디터 네임 스페이스를 사용하여 더 많은 정보 나 네임 스페이스를 사용하고 있음을 선언해야합니다. 아래 링크 된 네임 스페이스에 대한 레슨을 참조하십시오.

다음으로 우리는 monobehaviour 대신 편집기에서 inhewrit해야합니다.이 효과는 상속에 대한 자세한 정보를 위해 편집기를 확장하는 방법입니다. 아래에서 상속 링크에 대한 강의를 봅니다. 여기에서 우리는 커스텀 인스펙터와 속성을 제공하여 커스터마이즈하는 부분을 알려줄 필요가 있습니다. 이 작업을 수행하는 구문은 열린 대괄호와 키워드 cusdtom 편집기 및 괄호로 시작합니다


inside the parentheses we use the keyword type of to specify thew type and then put the name for script in another set of parentheses we can see that in this example the script 


we are customizing  is the level script we end the line with a close square bracket inside

our  level script editor class we create the  method public override void on inspector GUI 


this is thew method that is called every time the inspector is drawn inside unity


for more information on what the override key word is doing

see the lesson on overriding linked below at the this inspector for the level script has been modified 


if we go back in the unity we can see that we no longer see any properties of the script in the inspector of you since this is not very useful let's continue writing our custom inspector 


괄호 안쪽에 type 키워드를 사용하여 thew 유형을 지정한 다음 스크립트의 이름을 다른 괄호 세트에 넣습니다.이 예제에서 스크립트를 볼 수 있습니다

우리는 내부의 닫는 대괄호로 끝나는 레벨 스크립트를 커스터마이징하고있다.
우리의 레벨 스크립트 편집기 클래스 메소드 public override public void inspector GUI

이것은 검사자가 단결 안에 그려 질 때마다 호출되는 방법입니다

무시 키워드가 수행하는 작업에 대한 자세한 정보는
이 인스펙터에서 아래의 링크에 대한 재정의 레슨을 참조하십시오. 스크립트가 수정되었습니다.

우리가 단결로 돌아 가면 우리가 더 이상 쓸모가 없기 때문에 더 이상 당신의 검사관에서 스크립트의 속성을 볼 수 없다는 것을 볼 수 있습니다. 우리의 custom inspector를 계속 작성합시다.


back in the level script editor we will want to create some fields for the inspector

we automatically have a reference to our level script object named  target inside the on inspector going method 


this isn't  usable until we cast it into an appropriately type variable however


to do this we will create a level script variable named my level script and set it equal  to the inherited variable target


finally we will cast the variable  target as a level script variable by writing level script in parentheses next to it

we want our inspectors show two pieces of information the amount of experience the cahracter has and the current level of the character 


레벨 스크립트 편집기에서 인스펙터에 대한 필드를 만들고 싶습니다.
on inspector going 메서드 내에서 target이라는 이름의 스크립트 객체에 대한 참조를 자동으로 갖습니다.

우리가 적절하게 타입 변수에 넣을 때까지는 쓸모가 없다.

이를 위해 우리는 내 레벨 스크립트라는 수준의 스크립트 변수를 생성하여 상속 된 변수 target과 동일하게 설정합니다

마지막으로 변수 target을 레벨 스크립트 변수로 캐스팅합니다. 레벨 스크립트는 옆에 괄호 안에 레벨 스크립트를 작성합니다.
우리는 우리 검사관이 cahracter가 가지고있는 경험의 양과 캐릭터의 현재 레벨의 두 가지 정보를 보여주기를 바란다.


we can create an integer field in the inspector using the editor  GUI layout class


the syntax for this start with the class name editor GUI layout followed by a period and then the method int fieldw followed by parentheses


inside the indices we specify name of the field and the value of the field in this case we want the field to be named experience and the value to be the value of the experience variable of our my level script 


우리는 편집기 GUI 레이아웃 클래스를 사용하여 인스펙터에서 정수 필드를 생성 할 수있다.

이 구문은 클래스 이름 편집기 GUI 레이아웃 다음에 마침표가오고 그 다음에 메서드 int fieldw 뒤에 괄호가옵니다

인덱스 안에 필드 이름과 필드 값을 지정합니다.이 경우 필드의 이름을 experience로, 값을 my 레벨 스크립트의 경험 변수 값으로 지정합니다


since we want this field to be able to write back to our experience variable we set the entire line equal to my level script that experience we follow a similar process for the level field this time 


however we will be using the label field method of the editor GUI layout class a label is a read-only control so we do not have to worry about the user attempting to manually 


adjust the level in the inspector inside the parentheses of the label field method we pass in the name level and the value my level script. 


level since a label control requires a string as a value we will call the two-string method of the level property to turn in into a string at this point our custom inspector is complete 


we can go back into unity to see the result in the inspector we can see that one experience is 49,000 865 our level is 66


furthermore we can see that as we adjust the experience value the inspector automatically

tells us the level by customizing the editor for our scripts we can simplify and automate many of our otherwise cumbersome tasks


이 필드를 경험 변수에 다시 쓸 수 있기를 원하기 때문에 전체 레벨을 내 레벨 스크립트와 동일하게 설정하면 이번에는 레벨 필드와 비슷한 프로세스를 경험하게됩니다

그러나 우리는 편집기 GUI 레이아웃 클래스의 레이블 필드 메서드를 사용할 것입니다. 레이블은 읽기 전용 컨트롤이므로 수동으로 시도하는 사용자에 대해 걱정할 필요가 없습니다

이름 필드와 값 내 레벨 스크립트에서 전달하는 label 필드 메소드의 괄호 안의 인스펙터에서 레벨을 조정하십시오.

label 컨트롤은 문자열을 값으로 요구하기 때문에 level 속성의 2 스트링 메소드를 호출하여이 시점에서 문자열로 변환합니다. 그러면 커스텀 인스펙터가 완성됩니다

우리는 하나의 경험이 49,000 인 것을 볼 수있는 검사관의 결과를보기 위해 화합으로 되돌아 갈 수있다. 865 우리의 수준은 66이다.

또한 우리는 경험치를 조정할 때 검사관이 자동으로
스크립트의 에디터를 커스터마이징함으로써 레벨을 알려주며, 우리는 다른 방법으로는 번거로운 작업을 간소화하고 자동화 할 수 있습니다


반응형