/// <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); }
/// <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]); }
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); }
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; }