private void Init() { if (this.fieldInfo != null) { var tp = this.fieldInfo.FieldType; if (tp.IsListType()) { tp = tp.GetElementTypeOfListType(); } _restrictionType = tp; } if (this.attribute != null && this.attribute is SelectableComponentAttribute) { //created as part as a PropertyHandler var attrib = (this.attribute as SelectableComponentAttribute); this.AllowSceneObject = attrib.AllowSceneObjects; this.ForceOnlySelf = attrib.ForceOnlySelf; this.SearchChildren = attrib.SearchChildren; if (attrib.InheritsFromType != null) { _restrictionType = attrib.InheritsFromType; } } if (this.ChoiceSelector == null) { this.ChoiceSelector = new DefaultComponentChoiceSelector(); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { this.Init(); if (property.propertyType != SerializedPropertyType.ObjectReference || !TypeUtil.IsType(_restrictionType, typeof(Component), typeof(IComponent))) { this.DrawAsMismatchedAttribute(position, property, label); return; } if (this.ChoiceSelector == null) { this.ChoiceSelector = new DefaultComponentChoiceSelector(); } this.ChoiceSelector.BeforeGUI(property, _restrictionType); if(property.objectReferenceValue == null) { //SPEditorGUI.DefaultPropertyField(position, property, label); this.DrawObjectRefField(position, property, label); } else { float w = (label == GUIContent.none) ? position.width : Mathf.Max(position.width - EditorGUIUtility.labelWidth, 0); var ra = new Rect(position.xMin, position.yMin, w * this.PopupWidthScale, position.height); var rb = new Rect(ra.xMax, position.yMin, w - ra.width, position.height); var components = this.ChoiceSelector.GetComponents(); var names = this.ChoiceSelector.GetPopupEntries(); int oi = this.ChoiceSelector.GetPopupIndexOfComponent(property.objectReferenceValue as Component); int ni = EditorGUI.Popup(ra, label, oi, names); if(oi != ni) property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni); this.DrawObjectRefField(rb, property, GUIContent.none); } this.ChoiceSelector.GUIComplete(property); }
private void Init() { if (this.fieldInfo != null) { var tp = this.fieldInfo.FieldType; if (tp.IsListType()) tp = tp.GetElementTypeOfListType(); _restrictionType = tp; } if (this.attribute != null && this.attribute is SelectableComponentAttribute) { //created as part as a PropertyHandler var attrib = (this.attribute as SelectableComponentAttribute); this.AllowSceneObject = attrib.AllowSceneObjects; this.ForceOnlySelf = attrib.ForceOnlySelf; this.SearchChildren = attrib.SearchChildren; if (attrib.InheritsFromType != null) _restrictionType = attrib.InheritsFromType; } if (this.ChoiceSelector == null) { this.ChoiceSelector = new DefaultComponentChoiceSelector(); } }