Exemple #1
0
        /// <summary>
        /// Shows the filter window using the given provider.
        /// </summary>
        /// <param name="position">The position to show the filter window at.</param>
        /// <param name="provider">The provider of items for the filter window.</param>
        /// <returns>Returns true if the window is shown, false otherwise.</returns>
        public static bool Show(Vector2 position, IProvider provider)
        {
            // If the window is already open, close it instead.
            var wins = Resources.FindObjectsOfTypeAll(typeof(FilterWindow));

            if (wins.Length > 0)
            {
                try
                {
                    ((EditorWindow)wins[0]).Close();
                    return(false);
                }
                catch (Exception)
                {
                    s_FilterWindow = null;
                }
            }

            // We could not use realtimeSinceStartUp since it is set to 0 when entering/exitting
            // playmode, we assume an increasing time when comparing time.
            long nowMilliSeconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            bool justClosed      = nowMilliSeconds < s_LastClosedTime + 50;

            if (!justClosed)
            {
                Event.current.Use();

                if (s_FilterWindow == null)
                {
                    s_FilterWindow           = CreateInstance <FilterWindow>();
                    s_FilterWindow.hideFlags = HideFlags.HideAndDontSave;
                }

                s_FilterWindow.Init(position, provider);
                return(true);
            }
            return(false);
        }
        public void OnGUI()
        {
            if (asset == null)
            {
                return;
            }

            if (asset.isDirty)
            {
                RefreshEditors();
                asset.isDirty = false;
            }

            bool isEditable = !VersionControl.Provider.isActive ||
                              AssetDatabase.IsOpenForEdit(asset, StatusQueryOptions.UseCachedIfPossible);

            using (new EditorGUI.DisabledScope(!isEditable))
            {
                // Component list
                for (int i = 0; i < m_Editors.Count; i++)
                {
                    var    editor = m_Editors[i];
                    string title  = editor.GetDisplayTitle();
                    int    id     = i; // Needed for closure capture below

                    CoreEditorUtils.DrawSplitter();
                    bool displayContent = CoreEditorUtils.DrawHeaderToggle(
                        title,
                        editor.baseProperty,
                        editor.activeProperty,
                        pos => OnContextClick(pos, editor.target, id)
                        );

                    if (displayContent)
                    {
                        using (new EditorGUI.DisabledScope(!editor.activeProperty.boolValue))
                            editor.OnInternalInspectorGUI();
                    }
                }

                if (m_Editors.Count > 0)
                {
                    CoreEditorUtils.DrawSplitter();
                }
                else
                {
                    EditorGUILayout.HelpBox("This Volume Profile contains no overrides.", MessageType.Info);
                }

                EditorGUILayout.Space();

                using (var hscope = new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button(EditorGUIUtility.TrTextContent("Add Override"), EditorStyles.miniButton))
                    {
                        var r   = hscope.rect;
                        var pos = new Vector2(r.x + r.width / 2f, r.yMax + 18f);
                        FilterWindow.Show(pos, new VolumeComponentProvider(asset, this));
                    }
                }
            }
        }
Exemple #3
0
 void OnDisable()
 {
     s_LastClosedTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
     s_FilterWindow   = null;
 }
Exemple #4
0
 void OnEnable()
 {
     s_FilterWindow = this;
     m_Search       = "";
 }
Exemple #5
0
 /// <summary>
 /// A custom drawing method for this group.
 /// </summary>
 /// <param name="sFilterWindow">A reference to the parent <see cref="FilterWindow"/>.</param>
 /// <returns><c>true</c> if the builtin drawing function should execute for this group,
 /// <c>false</c> otherwise.</returns>
 public virtual bool OnGUI(FilterWindow sFilterWindow)
 {
     return(false);
 }
Exemple #6
0
 /// <summary>
 /// Handles custom keyboard events on this group.
 /// </summary>
 /// <param name="evt">The event.</param>
 /// <param name="window">A reference to the parent <see cref="FilterWindow"/>.</param>
 /// <param name="goToParent">The action to execute if a "back" action is triggered in the UI.</param>
 /// <returns><c>true</c> if the builtin events should execute for this group, <c>false</c> otherwise.</returns>
 public virtual bool HandleKeyboard(Event evt, FilterWindow window, Action goToParent)
 {
     return(false);
 }
        /// <summary>
        /// Draws the editor.
        /// </summary>
        public void OnGUI()
        {
            if (asset == null)
            {
                return;
            }

            // Even if the asset is not dirty, the list of component may have been changed by another inspector.
            // In this case, only the hash will tell us that we need to refresh.
            if (asset.isDirty || asset.GetComponentListHashCode() != m_CurrentHashCode)
            {
                RefreshEditors();
                m_CurrentHashCode = asset.GetComponentListHashCode();
                asset.isDirty     = false;
            }

            bool isEditable = !VersionControl.Provider.isActive ||
                              AssetDatabase.IsOpenForEdit(asset, StatusQueryOptions.UseCachedIfPossible);

            using (new EditorGUI.DisabledScope(!isEditable))
            {
                // Component list
                for (int i = 0; i < m_Editors.Count; i++)
                {
                    var editor = m_Editors[i];
                    var title  = editor.GetDisplayTitle();
                    int id     = i; // Needed for closure capture below

                    m_EditorDocumentationURLs.TryGetValue(editor.target.GetType(), out var documentationURL);

                    CoreEditorUtils.DrawSplitter();
                    bool displayContent = CoreEditorUtils.DrawHeaderToggle(
                        title,
                        editor.baseProperty,
                        editor.activeProperty,
                        pos => OnContextClick(pos, editor, id),
                        editor.hasAdditionalProperties ? () => editor.showAdditionalProperties : (Func <bool>)null,
                        () => editor.showAdditionalProperties ^= true,
                        documentationURL
                        );

                    if (displayContent)
                    {
                        using (new EditorGUI.DisabledScope(!editor.activeProperty.boolValue))
                            editor.OnInternalInspectorGUI();
                    }
                }

                if (m_Editors.Count > 0)
                {
                    CoreEditorUtils.DrawSplitter();
                }
                else
                {
                    EditorGUILayout.HelpBox("This Volume Profile contains no overrides.", MessageType.Info);
                }

                EditorGUILayout.Space();

                using (var hscope = new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button(EditorGUIUtility.TrTextContent("Add Override"), EditorStyles.miniButton))
                    {
                        var r   = hscope.rect;
                        var pos = new Vector2(r.x + r.width / 2f, r.yMax + 18f);
                        FilterWindow.Show(pos, new VolumeComponentProvider(asset, this));
                    }
                }
            }
        }