/// <summary> /// For when there is a list of known renderers. (ProtoInfo is available.) /// </summary> private void DrawLocal(Rect position, SerializedProperty property, bool hasLabel) { var props = new Props(property); var rect = hasLabel ? EditorGUIUtil.NextGuiElementPosition(position) : position; int iOrig = 0; if (props.renderer.objectReferenceValue) { iOrig = m_SearchInfo.renderers.IndexOf(props.renderer.objectReferenceValue as Renderer); iOrig = iOrig == -1 ? 0 : iOrig; } int iSel = EditorGUI.Popup(rect, RendererLabel, iOrig, m_SearchInfo.rendererLabels); if (iSel != iOrig) { props.renderer.objectReferenceValue = m_SearchInfo.renderers[iSel]; } int iRen = iSel; rect = EditorGUIUtil.NextGuiElementPosition(rect); // iRen == 0 means 'No renderer selected.' DrawMaterials(rect, props.index, iRen == 0 ? null : m_SearchInfo.materialLabels[iRen]); }
/// <summary> /// Draw the GUI elements for when there are no known renderers. (SearchInfo is not avaiable.) /// </summary> private void DrawBasic(Rect position, SerializedProperty property, bool hasLabel) { var props = new Props(property); var rect = EditorGUIUtil.NextGuiElementPosition(position, 0, false); EditorGUI.PropertyField(rect, props.renderer); GUIContent[] labels; if (props.renderer.objectReferenceValue) { if (m_RendererInfo == null) { m_RendererInfo = new RendererInfo(); } var renderer = props.renderer.objectReferenceValue as Renderer; if (m_RendererInfo.renderer != renderer) { m_RendererInfo.Update(renderer); } labels = m_RendererInfo.materialLabels; } else { labels = null; } rect = EditorGUIUtil.NextGuiElementPosition(rect); DrawMaterials(rect, props.index, labels); }
private ReorderableList CreateList(SerializedProperty listProperty, string headerTitle, bool singleClickRemove) { var list = new ReorderableList(listProperty.serializedObject , listProperty, true, true, true, true); list.headerHeight = HeaderHeight; list.footerHeight = FooterHeight; list.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, headerTitle); }; list.elementHeight = ElementHeight; list.drawElementCallback = (position, index, isActive, isFocused) => { position = EditorGUIUtil.SingleLinePosition( position, EditorGUIUtility.standardVerticalSpacing * 1.5f); var element = list.serializedProperty.GetArrayElementAtIndex(index); EditorGUI.PropertyField(position, element, GUIContent.none); }; list.onAddCallback = roList => { roList.index = AddElement(roList.serializedProperty); }; if (singleClickRemove) { list.onRemoveCallback = EditorGUIUtil.DoSingleClickRemove; } return(list); }
/// <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)); }
private void StandardGUI(Rect position, SerializedProperty property) { var props = new Props(property); var rect = new Rect(position.x, position.y + EditorGUIUtility.standardVerticalSpacing , position.width, EditorGUIUtility.singleLineHeight); EditorGUI.PropertyField(rect, props.renderer); rect = EditorGUIUtil.NextGuiElementPosition(rect); EditorGUI.PropertyField(rect, props.index); rect = EditorGUIUtil.NextGuiElementPosition(rect); EditorGUI.PropertyField(rect, props.material); }
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 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(); } }
/// <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(); }
/// <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 = attribute as EnumFlagsAttribute; label = EditorGUI.BeginProperty(position, label, property); label.text = label.text; if (attr.displayValue) { label.text += " (" + property.intValue + ")"; } EditorGUI.BeginChangeCheck(); int val = EditorGUIUtil.DrawEnumFlagsField(position, property.intValue, attr.enumType, label, attr.sort); if (EditorGUI.EndChangeCheck()) { property.intValue = val; } }
private void DrawElement(Rect position, SerializedProperty elementProperty, bool isActive, bool isFocused) { position = EditorGUIUtil.SingleLinePosition( position, EditorGUIUtility.standardVerticalSpacing); var orig = elementProperty.objectReferenceValue; EditorGUI.PropertyField(position, elementProperty, GUIContent.none); var comp = elementProperty.objectReferenceValue; if (comp) { if (!ValidateComponent(comp)) { elementProperty.objectReferenceValue = null; } // TODO: BUG: Fix the duplicate check. It isn't working. if (orig && orig != comp) { int count = 0; for (int i = 0; i < m_ListProperty.arraySize; i++) { count = m_ListProperty.GetArrayElementAtIndex(i).objectReferenceValue == comp ? 1 : 0; } if (count > 1) { Debug.LogError("Duplicate objects are not allowed in list."); elementProperty.objectReferenceValue = null; } } } }
private void LocalGUI(Rect position, SerializedProperty property) { var origLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 80; var props = new Props(property); var info = m_LocalInfo; // Renderer int iOrig = 0; GUIStyle style; if (props.renderer.objectReferenceValue) { iOrig = info.Items.IndexOf(props.renderer.objectReferenceValue as Renderer); iOrig = iOrig == -1 ? 0 : iOrig; style = EditorStyles.popup; } else { style = EditorGUIUtil.RedPopup; } var rect = new Rect(position.x, position.y + EditorGUIUtility.standardVerticalSpacing + 2 , position.width, EditorGUIUtility.singleLineHeight * 1.15f); int iSel = EditorGUI.Popup(rect, RendererLabel, iOrig, info.Labels, style); if (iSel != iOrig) { props.renderer.objectReferenceValue = info.Items[iSel]; } rect = EditorGUIUtil.NextGuiElementPosition(rect); if (iSel == 0) { EditorGUI.LabelField(rect, TargetLabel, new GUIContent("None")); } else { GUIContent[] labels = info.MaterialLabels[iSel]; iOrig = Mathf.Clamp(props.index.intValue, 0, labels.Length); iSel = EditorGUI.Popup(rect, TargetLabel, iOrig, labels); if (iSel != iOrig) { props.index.intValue = iSel; } } // Override material. rect = EditorGUIUtil.NextGuiElementPosition(rect, 0, false); EditorGUI.PropertyField(rect, props.material, MaterialLabel); EditorGUIUtility.labelWidth = origLabelWidth; }