Last active
August 18, 2017 09:06
-
-
Save iwashihead/54ac2a1988494bb4cf72b2121ee84d73 to your computer and use it in GitHub Desktop.
無理やりScriptableObjectのインスペクターにUnityEventを表示させる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CustomEditor(typeof(Validator))] | |
public class ValidatorInspector : Editor | |
{ | |
public override void OnInspectorGUI () | |
{ | |
var validator = target as Validator; | |
var width = EditorGUIUtility.currentViewWidth - 20; | |
var drawer = new UnityEventDrawer (); | |
if (GUILayout.Button ("Validate")) { | |
validator.DoValidate (); | |
} | |
var sp = serializedObject.FindProperty ("ue"); | |
drawer.OnGUI (new Rect (new Vector2 (10, 80), new Vector2 (width, EditorGUI.GetPropertyHeight (sp))), sp, new GUIContent ("ue")); | |
} | |
} | |
[Serializable] | |
[CreateAssetMenu] | |
public class Validator : ScriptableObject | |
{ | |
public UnityEvent ue; | |
} |
あとインスペクターの横幅の取得方法
var width = EditorGUIUtility.currentViewWidth - 20;
と、シリアライズプロパティの高さの取得方法
EditorGUI.GetPropertyHeight (sp)
がわかったのは地味に嬉しい
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
結論から言うと表示させることはできるけどかなりインスペクタ拡張しないとダメで実用性低い。
UnityEventDrawer(カスタムプロパティドロワー)のOnGUIメソッドがoverloadされてて片方しか表示の対応をしていない。
ScriptableObjectのOnInspectorGUIがなぜMonoBehaviourと違うのかはわからないが、SrciptableObjectだと
表示対応されていないOnGUIを呼び出していた模様。
ScriptableObjectをインスペクター拡張して対応してる方の OnGUIを呼び出せば一応は解決。