사용자 도구

사이트 도구


사이드바

카테고리

language:unity:6-inspector

basic template

  • 에디터용 네임스페이스 추가
  • CustomEditor 속성 추가
  • Editor에서 상속되는 클래스
  • OnInspectorGUI() 오버라이드 함수
//
// TestClass 에 대한 커스텀 인스펙터를 정의하는 예
//
 
// 포함해야할 using
using UnityEngine;
using UnityEditor;
 
// CustomEditor : 어떤 클래스에 대응 되는 인스펙터인가
[CustomEditor(typeof(TestClass))]
// TestClassEditor : [ClassName]Editor 형식상 원래 클래스 이름에 'Editor'를 붙이는 듯
public class TestClassEditor : Editor
{
  // 인스펙터에 요소들을 표시하는 방법을 코딩한다.
  public override void OnInspectorGUI()
  {
    // 이 인스펙터에 대응되는 타켓 스크립트
    TestClass test_class = target as TestClass;
  }
}

클래스 이름은 “<Target Class>Editor” or “<Target Class>Inspector” 아무거나 선택.

편하게, 도움을 주는

  • NGUI 플러그인을 사용하는 것이면 : NGUIEditorTools 클래스가 도움이 된다.

아직 모르는 개념들

  • SerializedProperty;

메소드 몇개

Button 과 같은 이벤트 리시버를 인스펙터에 추가

UnityEvent 로 public 변수를 선언하면 알맞게 표시된다.

using UnityEngine.Events;
public class SampleClass : MonoBehaviour {
  public UnityEvent onMoveFowardDone;
  public UnityEvent onMoveBackwardDone;
}

Prefab 생성하는 에디터

  // Create a new prefab for the atlas
	Object prefab = (go != null) ? go : PrefabUtility.CreateEmptyPrefab(prefabPath);
 
	// Create a new game object for the atlas
	string atlasName = prefabPath.Replace(".prefab", "");
	atlasName = atlasName.Substring(prefabPath.LastIndexOfAny(new char[] { '/', '\\' }) + 1);
	go = new GameObject(atlasName);
	go.AddComponent<UIAtlas>().spriteMaterial = mat;
 
	// Update the prefab
	PrefabUtility.ReplacePrefab(go, prefab);
	DestroyImmediate(go);
	AssetDatabase.SaveAssets();
	AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

형식

using UnityEngine;
using UnityEditor;

// 에디터 이름
public class UIAtlasMaker : EditorWindow
{
}
language/unity/6-inspector.txt · 마지막으로 수정됨: 2022/12/07 22:30 저자 kieuns