1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CustomEditorとCustomPropertyDrawerのどちらが先に動くのか

Last updated at Posted at 2018-12-25

CustomEditorとCustomPropertyDrawerのどちらが先に動くのか

Version : Unity 2017.4.17f1

CustomEditorに全項目の表示を書き連ねることで分割衝動にかられた為、CustomPropertyDrawerで項目別に書けないかと検証した。

実際のコード

namespaceの記述は手間の都合でそのままにしています。申し訳ない。

A.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Example004
{
	[Serializable]
	public class A : MonoBehaviour {
		private string name;
	}
}
B.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Example004
{
	public class B : MonoBehaviour {
		[SerializeField]
		private A a;
	}
}
APropertyDrawer.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace Example004
{
	[CustomPropertyDrawer(typeof(A))]
	public class APropertyDrawer : PropertyDrawer {
		public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
		{
			Debug.Log("APropertyDrawer");
		}
	}
}
BEditor.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace Example004
{
	[CustomEditor(typeof(B))]
	public class BEditor : Editor {
        public override void OnInspectorGUI()
        {
            Debug.Log("BEditor");
            this.DrawDefaultInspector();
        }
	}
}

そしてこうなる

image.png

CustomEditorが先でそのあとにCustomPropertyDrawerが動く。
やってからそりゃそうだなってなったよ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?