Esempio n. 1
0
        static void ReloadDecoratorTypes()
        {
            s_AttributeDecorators.Clear();

            // Look for all the valid attribute decorators
            var types = RuntimeUtilities.GetAllTypesDerivedFrom <AttributeDecorator>()
                        .Where(
                t => t.IsDefined(typeof(DecoratorAttribute), false) &&
                !t.IsAbstract
                );

            // Store them
            foreach (var type in types)
            {
                var attr      = type.GetAttribute <DecoratorAttribute>();
                var decorator = (AttributeDecorator)Activator.CreateInstance(type);
                s_AttributeDecorators.Add(attr.attributeType, decorator);
            }
        }
        /// <summary>
        /// Initializes the editor. This method should be called before <see cref="OnGUI"/> is
        /// called.
        /// </summary>
        /// <param name="asset">A reference to the <see cref="PostProcessProfile"/> that will be
        /// displayed.</param>
        /// <param name="serializedObject">A <see cref="SerializedObject"/> of the given <paramref
        /// name="asset"/> instance.</param>
        public void Init(PostProcessProfile asset, SerializedObject serializedObject)
        {
            Assert.IsNotNull(asset);
            Assert.IsNotNull(serializedObject);

            this.asset         = asset;
            m_SerializedObject = serializedObject;
            m_SettingsProperty = serializedObject.FindProperty("settings");
            Assert.IsNotNull(m_SettingsProperty);

            m_EditorTypes = new Dictionary <Type, Type>();
            m_Editors     = new List <PostProcessEffectBaseEditor>();

            // Gets the list of all available postfx editors
            var editorTypes = RuntimeUtilities.GetAllTypesDerivedFrom <PostProcessEffectBaseEditor>()
                              .Where(
                t => t.IsDefined(typeof(PostProcessEditorAttribute), false) &&
                !t.IsAbstract
                );

            // Map them to their corresponding settings type
            foreach (var editorType in editorTypes)
            {
                var attribute = editorType.GetAttribute <PostProcessEditorAttribute>();
                m_EditorTypes.Add(attribute.settingsType, editorType);
            }

            // Create editors for existing settings
            for (int i = 0; i < this.asset.settings.Count; i++)
            {
                CreateEditor(this.asset.settings[i], m_SettingsProperty.GetArrayElementAtIndex(i));
            }

            // Keep track of undo/redo to redraw the inspector when that happens
            Undo.undoRedoPerformed += OnUndoRedoPerformed;
        }