public override void OnInspectorGUI()
        {
            serializedObject.Update();

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

            using (var vscope = new EditorGUILayout.VerticalScope())
            {
                EditorGUILayout.PropertyField(m_IsGlobal);

                if (!m_IsGlobal.boolValue) // Blend radius is not needed for global volumes
                {
                    EditorGUILayout.PropertyField(m_BlendRadius);
                    m_BlendRadius.floatValue = Mathf.Max(m_BlendRadius.floatValue, 0f);
                }

                EditorGUILayout.PropertyField(m_Weight);
                EditorGUILayout.PropertyField(m_Priority);

                EditorGUILayout.Space();

                // 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("No override set on this volume. Drop a component here or use the Add button.", MessageType.Info);
                }

                EditorGUILayout.Space();

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

                EditorGUILayout.Space();

                // Handle components drag'n'drop
                var e = Event.current;
                if (e.type == EventType.DragUpdated)
                {
                    if (IsDragValid(vscope.rect, e.mousePosition))
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        e.Use();
                    }
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                    }
                }
                else if (e.type == EventType.DragPerform)
                {
                    if (IsDragValid(vscope.rect, e.mousePosition))
                    {
                        DragAndDrop.AcceptDrag();

                        var objs = DragAndDrop.objectReferences;
                        foreach (var o in objs)
                        {
                            var compType = ((MonoScript)o).GetClass();
                            AddComponent(compType);
                        }

                        e.Use();
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #2
0
        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("No override set on this volume. Drop a component here or use the Add button.", MessageType.Info);
                }

                EditorGUILayout.Space();

                using (var hscope = new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button(CoreEditorUtils.GetContent("Add component overrides..."), 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));
                    }
                }
            }
        }