/// <summary>
        /// See Unity documentation.
        /// </summary>
        /// <param name="position">See Unity documentation.</param>
        /// <param name="property">See Unity documentation.</param>
        /// <param name="label">See Unity documentation.</param>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var attr = (LocalComponentPopupAttribute)attribute;

            if (m_GuiElement == null)
            {
                m_GuiElement = new LocalComponentPopup(attr.ComponentType, attr.Required);
            }

            m_GuiElement.OnGUI(position, property, label,
                               EditorGUIUtil.GetReferenceObject(property, attr.SearchPropertyPath, false));
        }
        /// <summary>
        /// Draws the GUI element.
        /// </summary>
        /// <param name="position">The draw area of the element.</param>
        /// <param name="property">
        /// The property of type <c>SerializedPropertyType.ObjectReference</c>
        /// </param>
        /// <param name="label">The property label.</param>
        /// <param name="gameObject">The game object to search for local components, or null
        /// if the property's target object should be used.</param>
        public void OnGUI(Rect position, SerializedProperty property, GUIContent label,
                          GameObject gameObject = null)
        {
            if (label != null)
            {
                label = EditorGUI.BeginProperty(position, label, property);
            }

            if (!gameObject)
            {
                gameObject = EditorGUIUtil.GetReferenceObject(property);
            }

            if (m_ListInfo == null || m_ListInfo.GameObject != gameObject)
            {
                m_ListInfo = m_ListInfo == null ? new Info() : m_ListInfo;
                m_ListInfo.Refresh(gameObject, m_ComponentType, Required);
            }

            int      iOrig = 0;
            GUIStyle style = EditorStyles.popup;

            if (property.objectReferenceValue)
            {
                iOrig = m_ListInfo.Items.IndexOf(property.objectReferenceValue as Component);
                iOrig = iOrig == -1 ? 0 : iOrig;
            }
            else if (Required)
            {
                style = EditorGUIUtil.RedPopup;
            }

            int iSel = (label == null)
                ? EditorGUI.Popup(position, iOrig, m_ListInfo.ItemLabels, style)
                : EditorGUI.Popup(position, label, iOrig, m_ListInfo.ItemLabels, style);

            if (iSel != iOrig)
            {
                property.objectReferenceValue = m_ListInfo.Items[iSel];
            }

            if (label != null)
            {
                EditorGUI.EndProperty();
            }
        }
Beispiel #3
0
        public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (m_RequireLocal)
            {
                var go = EditorGUIUtil.GetReferenceObject(property, m_SearchPropertyPath, false);

                if (m_SearchInfo == null)
                {
                    m_SearchInfo = new SearchInfo();
                }

                m_SearchInfo.Update(go);
            }
            else
            {
                m_SearchInfo = null;
            }

            bool hasLabel = label != GUIContent.none;  // Must be before 'begin property'.

            label = EditorGUI.BeginProperty(position, label, property);

            Rect rect = EditorGUIUtil.SingleLinePosition(position);

            if (hasLabel)
            {
                EditorGUI.LabelField(rect, label);
            }

            var origLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 80;

            if (m_SearchInfo != null)
            {
                DrawLocal(rect, property, hasLabel);
            }
            else
            {
                DrawBasic(rect, property, hasLabel);
            }

            EditorGUIUtility.labelWidth = origLabelWidth;

            EditorGUI.EndProperty();
        }
        /// <summary>
        /// Draws the GUI element.
        /// </summary>
        /// <param name="position">The draw area.</param>
        /// <param name="property">
        /// The property representing an array <see cref="MaterialOverride"/> references.
        /// (For the same field as the property used in the constructor.)
        /// </param>
        /// <param name="label">The property label.</param>
        public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (m_LocalOnly)
            {
                var gameObject = EditorGUIUtil.GetReferenceObject(property, m_SearchPropertyPath, false);

                if (m_LocalInfo == null || m_LocalInfo.GameObject != gameObject)
                {
                    m_LocalInfo = new LocalInfo();
                    m_LocalInfo.Load(gameObject);
                }
            }

            label = EditorGUI.BeginProperty(position, label, property);

            m_List.serializedProperty = property;
            m_List.DoList(position);

            EditorGUI.EndProperty();
        }