Ejemplo n.º 1
0
        /// <summary>
        /// Draws a scene variable element of the lsit
        /// </summary>
        /// <param name="rect">The rectangle to render the variable in</param>
        /// <param name="index">The index of the property</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 DrawElement(Rect rect, int index, bool isActive, bool isSelected)
        {
            if (IsFilteredOut(index))
            {
                return;
            }

            SerializedSceneVariable serializedVar = serializedVariables.GetSerializedVariableAt(index);

            rect.yMin   += (elementMargin * 0.5f);
            rect.height -= (elementMargin * 0.5f);

            EditorGUI.BeginChangeCheck();

            if (IsBuiltInVariable(serializedVar.ValueProp))
            {
                RenderBuiltInVariable(serializedVar, rect, index, isSelected);
            }
            else
            {
                RenderCustomVariable(serializedVar, rect, index, isActive, isSelected);
            }

            if (EditorGUI.EndChangeCheck())
            {
                serializedVariables.SerializedContainer.ApplyModifiedProperties();

                if (!EditorApplication.isPlaying)
                {
                    serializedVariables.SceneVariablesContainer.ResetVariables();
                }

                OnSomethingChanged.SafeInvoke(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 2
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));
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines if the variable at the specified index
        /// should be filtered out from being rendered
        /// </summary>
        /// <param name="index">The index of the list item</param>
        /// <returns>True to filter out, false to include</returns>
        private bool IsFilteredOut(int index)
        {
            if (!HasFilterString())
            {
                return(false);
            }

            SerializedSceneVariable serializedVar = serializedVariables.GetSerializedVariableAt(index);

            return(!serializedVar.NameProp.stringValue.
                   Contains(currentSearchString, StringComparison.OrdinalIgnoreCase));
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles rendering a variable that is considered a 'built-in' supported
        /// type
        /// </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 RenderBuiltInVariable(SerializedSceneVariable serializedVar,
                                           Rect rect, int index, bool isSelected)
        {
            SerializedObject serializedValue = serializedVar.GetSerializedValue();

            SerializedProperty activeValueProp = serializedValue.FindProperty("DefaultValue");

            if (EditorApplication.isPlaying)
            {
                activeValueProp = serializedValue.FindProperty("currentValue");
            }

            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);

            Rect valueRect = new Rect(rect);

            valueRect.xMin = refreshToggleRect.xMax + 2f;

            EditorGUI.BeginChangeCheck();

            EditorGUI.PropertyField(valueRect, activeValueProp, GUIContent.none);

            if (EditorGUI.EndChangeCheck())
            {
                serializedValue.ApplyModifiedProperties();
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Handles display of the refresh-on-transition button
 /// </summary>
 /// <param name="elementProp">The owner of the refresh property</param>
 private void RenderRefreshToggle(Rect rect, SerializedSceneVariable serializedVar)
 {
     serializedVar.ResetOnTransProp.boolValue = GUI.Toggle(rect,
                                                           serializedVar.ResetOnTransProp.boolValue,
                                                           refreshTransitionContent, SceneManagerResources.RefreshOnTransitionStyle);
 }