示例#1
0
        /// <summary>
        /// Calculates how tall the element is
        /// </summary>
        /// <param name="index">The index of the element being rendered</param>
        /// <returns>The height that the element should have</returns>
        private float GetElementHeight(int index)
        {
            if (IsFilteredOut(index))
            {
                return(0f);
            }

            SerializedSceneVariable serializedVariable =
                serializedVariables.GetSerializedVariableAt(index);

            if (IsBuiltInVariable(serializedVariable.ValueProp))
            {
                return(EditorGUIUtility.singleLineHeight + elementMargin);
            }
            else
            {
                IInlineEditor inlineEditor = GetCustomInlineEditor(serializedVariable);

                if (inlineEditor != null)
                {
                    return(inlineEditor.GetInlineEditorHeight() + EditorGUIUtility.singleLineHeight + elementMargin);
                }
                else
                {
                    // 2f because without a custom inline editor we render the name + the object reference
                    // 1.5f because we use half element margin between var name and value and around the whole element
                    return(EditorGUIUtility.singleLineHeight * 2f + (elementMargin * 1.5f));
                }
            }
        }
示例#2
0
        /// <summary>
        /// Renders a SceneVariable defined as a 'custom' type (one that isn't considered
        /// 'built-in')
        /// </summary>
        /// <param name="serializedVar">The serialized representation of the variable</param>
        /// <param name="rect">The rect to render in</param>
        /// <param name="index">The index of the item in the list</param>
        /// <param name="isActive">True if the element is active, false if not</param>
        /// <param name="isSelected">True if the element is selected, false if not</param>
        private void RenderCustomVariable(SerializedSceneVariable serializedVar,
                                          Rect rect, int index, bool isActive, bool isSelected)
        {
            float originalHeight = rect.height;

            rect.height = EditorGUIUtility.singleLineHeight;

            Rect nameRect = new Rect(rect);

            nameRect.width = EditorGUIUtility.labelWidth;

            RenderVariableName(nameRect, serializedVar.NameProp, index, isSelected);

            Rect refreshToggleRect = new Rect(rect);

            refreshToggleRect.xMin  = nameRect.xMax + 2f;
            refreshToggleRect.width = 20f;

            RenderRefreshToggle(refreshToggleRect, serializedVar);

            IInlineEditor inlineEditor = GetCustomInlineEditor(serializedVar);

            Rect valueRect = new Rect(rect);

            valueRect.yMin   = nameRect.yMax + (elementMargin * 0.5f);
            valueRect.height = originalHeight - rect.height - (elementMargin * 0.5f);

            if (inlineEditor == null)
            {
                EditorGUI.BeginDisabledGroup(true);

                serializedVar.ValueProp.isExpanded =
                    EditorGUI.PropertyField(valueRect, serializedVar.ValueProp, GUIContent.none);

                EditorGUI.EndDisabledGroup();
            }
            else
            {
                inlineEditor.OnInlineEditorGUI(valueRect);
            }
        }
示例#3
0
        /// <summary>
        /// Helper to get the inline editor for the provided property
        /// </summary>
        /// <param name="elementProperty">The variable property</param>
        /// <param name="valueProperty">The variable value property</param>
        /// <returns>The inline editor, or null if none exist</returns>
        private IInlineEditor GetCustomInlineEditor(SerializedSceneVariable serializedVariable)
        {
            IInlineEditor inlineEditor = null;

            string dictKey = serializedVariable.VariableElementProp.propertyPath;

            if (!inlineEditors.TryGetValue(dictKey, out inlineEditor))
            {
                Editor editor = CreateEditor(serializedVariable.ValueProp.objectReferenceValue);

                if (editor is IInlineEditor)
                {
                    inlineEditor = editor as IInlineEditor;
                    inlineEditors.Add(dictKey, inlineEditor);
                }
                else
                {
                    inlineEditors.Add(dictKey, null);
                    DestroyImmediate(editor);
                }
            }

            return(inlineEditor);
        }