using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(Block))]
public class BlockEditor : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        Block block = target as Block;
        if (GUILayout.Button("제거"))
        {
            Debug.Log($"[{block.row},{block.col}]을 제거 합니다.");
        }
    }
}

 

https://docs.unity3d.com/ScriptReference/Editor.OnInspectorGUI.html

 

Unity - Scripting API: Editor.OnInspectorGUI

Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close

docs.unity3d.com

 

 

  • OnInspectorGUI 메서드는 Unity의 Inspector에서 해당 컴포넌트(Block)의 GUI를 그리는 메서드
  • base.OnInspectorGUI()는 기본적으로 해당 컴포넌트의 Inspector를 그리는 기능을 수행

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(Board))]
public class BoardEditor : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        
        Board board = target as Board;

        if (GUILayout.Button("배열 요소 출력"))
        {
            board.PrintBoard();;
        }
    }
}

 

 

public void PrintBoard()
    {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < board.GetLength(0); i++)    //행
        {
            for (int j = 0; j < board.GetLength(1); j++)    //열 
            {
                Block block = board[i, j];
                string strElement = (block == null) ? "null" : block.blockType.ToString();
                sb.Append($"[{i},{j}] = {strElement}  ");
            }
            sb.AppendLine();
        }
        Debug.Log(sb);
    }

 

+ Recent posts