반응형

//ExecuteInEditMode : 스크립트가 에디터모드에서 동작하도록 설정합니다.

//RequireComponent 속성은 요구되는 의존 컴포넌트를 자동으로 추가해줍니다.

[ExecuteInEditMode, RequireComponent(typeof(CanvasGroup))]

public class UI___Bar : MonoBehaviour 

{

}



ExecuteInEditMode


Description

스크립트가 에디터모드에서 동작하도록 설정합니다.

기본 설정으로, 스크립트 컴포넌트는 플레이 모드에서만 동작하도록 설정되어 있습니다. 이 어트리뷰트(attribute)를 추가 하면, 각 스크립트 컴포넌트들 역시 플레이모드가 아닌 에디터 모드에서 해당 콜백 함수를 수행할 수 있습니다.

The functions are not called constantly like they are in play mode.
Update is only called when something in the scene changed.
OnGUI is called when the Game View recieves an Event.
- 씬뷰 또는 게임뷰에서 repaint호출이 있을 때 마다 OnRenderObject 와 또다른 렌더링 콜백 함수들이 호출됩니다.

using UnityEngine;
using System.Collections;

[ExecuteInEditMode] public class ExampleClass : MonoBehaviour { public Transform target; void Update() { if (target) transform.LookAt(target); } }


RequireComponent


Description

RequireComponent 속성은 요구되는 의존 컴포넌트를 자동으로 추가해줍니다.

RequireComponent를 사용하는 스크립트를 추가하면, 요구되는 컴포너트가 자동으로 해당 게임오브젝트에 추가됩니다. 설정 오류를 피하는 데 유용합니다. 예를 들어, 리지드 바디가 요구되는 스크립트가, 항상 같은 게임오브젝트에 첨부되는 경우. RequireComponent를 사용하면 이 작업이 자동으로 이루어 지기 때문에, 설정에 대한 실수를 할 염려가 없습니다. Note that RequireComponent only checks for missing dependencies during the moment the component is added to a GameObject. Existing instances of the component whose GameObject lacks the new dependencies will not have those dependencies automatically added.

using UnityEngine;

// PlayerScript requires the GameObject to have a Rigidbody component [RequireComponent (typeof (Rigidbody))] public class PlayerScript : MonoBehaviour { Rigidbody rb; void Start() { rb = GetComponent<Rigidbody>(); } void FixedUpdate() { rb.AddForce(Vector3.up); } }



ref : https://docs.unity3d.com/kr/530/ScriptReference/ExecuteInEditMode.html

ref : https://docs.unity3d.com/kr/530/ScriptReference/RequireComponent.html






반응형

+ Recent posts