|
1 |
| -# Add custom graphics settings |
| 1 | +# Add a settings group |
2 | 2 |
|
3 |
| -You can add custom graphics settings to the **Edit** > **Project Settings** > **Graphics** window, then use the values of the settings to customize your build. |
| 3 | +To add a custom graphics settings group to a Scriptable Render Pipeline, implement the `IRenderPipelineGraphicsSettings` interface. |
4 | 4 |
|
5 |
| -You can change the values of settings while you're editing your project. Unity makes the values static when it builds your project, so you can't change them at runtime. |
| 5 | +Follow these steps: |
6 | 6 |
|
7 |
| -## Add a setting |
| 7 | +1. Create a class that implements the `IRenderPipelineGraphicsSettings` interface, then add a `[Serializable]` attribute. |
8 | 8 |
|
9 |
| -To add a setting, follow these steps: |
10 |
| - |
11 |
| -1. Create a class that implements the `IRenderPipelineGraphicsSettings` interface, and add a `[Serializable]` attribute. This becomes a new settings group in the **Graphics** settings window. |
12 | 9 | 2. To set which render pipeline the setting applies to, add a `[SupportedOnRenderPipeline]` attribute and pass in a `RenderPipelineAsset` type.
|
13 |
| -3. Add a property. This becomes a setting. |
14 |
| -4. Implement the `version` field and set it to `0`. Unity doesn't currently use the `version` field, but you must implement it. |
15 | 10 |
|
16 |
| -For example, the following script adds a setting called **My Value** in a settings group called **My Settings**, in the graphics settings for the Universal Render Pipeline (URP). |
| 11 | + **Note:** If you don't add a `[SupportedOnRenderPipeline]` attribute, the setting applies to any Scriptable Render Pipeline. However each Scriptable Render Pipeline stores its own value for the setting. |
| 12 | + |
| 13 | +3. Implement the `version` property. Unity doesn't currently use the `version` property, but you must implement it. |
| 14 | + |
| 15 | +Unity adds the new settings group to the **Edit** > **Project Settings** > **Graphics** window. |
| 16 | + |
| 17 | +For example, the following script adds a settings group called **My Settings** in the **Graphics** settings window of the Universal Render Pipeline (URP). |
17 | 18 |
|
18 | 19 | ```c#
|
| 20 | +using System; |
19 | 21 | using UnityEngine;
|
20 | 22 | using UnityEngine.Rendering;
|
21 |
| -using System; |
| 23 | +using UnityEngine.Rendering.Universal; |
22 | 24 |
|
23 | 25 | [Serializable]
|
24 | 26 | [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
|
25 | 27 |
|
26 | 28 | // Create a new settings group by implementing the IRenderPipelineGraphicsSettings interface
|
27 | 29 | public class MySettings : IRenderPipelineGraphicsSettings
|
28 | 30 | {
|
29 |
| - // Implement the version field |
30 |
| - public int version => 0; |
| 31 | + // Add a private field for the version property |
| 32 | + int internalVersion = 1; |
| 33 | + |
| 34 | + // Implement the public version property |
| 35 | + public int version => internalVersion; |
31 | 36 |
|
32 |
| - // Create a new setting and set its default value to 100. |
33 |
| - public int myValue = 100; |
34 | 37 | }
|
35 | 38 | ```
|
36 | 39 |
|
37 |
| -## Add a reference property |
38 |
| - |
39 |
| -[Reference properties](https://docs.unity3d.com/2023.3/Documentation/Manual/EditingValueProperties.html#references) take compatible project assets or GameObjects in the scene as inputs. |
| 40 | +<br/> |
| 41 | +The **Edit** > **Project Settings** > **Graphics** window with the new custom settings group from the example script. |
40 | 42 |
|
41 |
| -To add a reference property, follow these steps: |
| 43 | +## Change the display order of settings groups |
42 | 44 |
|
43 |
| -1. Create a class that implements the `IRenderPipelineResources` interface. This becomes a new settings group in the Graphics Settings window. |
44 |
| -2. Add a property. This becomes a reference property. |
45 |
| -3. Implement the `version` field and set it to `0`. Unity doesn't currently use the `version` field, but you must implement it. |
46 |
| - |
47 |
| -For example, the following script adds a reference property called **My Material** that references a material. |
| 45 | +To change where a settings group appears, use the `[UnityEngine.Categorization.CategoryInfo]` attribute. For example, the following code gives the settings group the name **My Settings** and moves the group to the top of the graphics settings window. |
48 | 46 |
|
49 | 47 | ```c#
|
50 |
| -using UnityEngine; |
51 |
| -using UnityEngine.Rendering; |
52 |
| -using System; |
53 |
| - |
54 |
| -[Serializable] |
55 |
| -[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))] |
56 |
| - |
57 |
| -// Create a new reference property group by implementing the IRenderPipelineResources interface |
58 |
| -public class MySettings: IRenderPipelineResources |
| 48 | +[UnityEngine.Categorization.CategoryInfo(Name = "My Settings", Order = 0)] |
| 49 | +public class MySettings : IRenderPipelineGraphicsSettings |
59 | 50 | {
|
60 |
| - // Implement the version field |
61 |
| - public int version => 0; |
62 |
| - |
63 |
| - // Create a new reference property that references a material |
64 |
| - [SerializeField] public Material myMaterial; |
| 51 | + ... |
65 | 52 | }
|
66 | 53 | ```
|
67 | 54 |
|
68 |
| -To set a default asset, use a [`[ResourcePath]`](https://docs.unity3d.com/2023.3/Documentation/ScriptReference/Rendering.ResourcePathAttribute.html) attribute above the reference property. For example, in the example, add the following line above `public Material myMaterial`. |
69 |
| - |
70 |
| -```c# |
71 |
| -[ResourcePath('path-to-default-file')] |
72 |
| -``` |
73 |
| - |
74 |
| -## Change the name and layout of a settings group |
75 |
| - |
76 |
| -To change the name of a settings group in the **Graphics** settings window, follow these steps: |
77 |
| - |
78 |
| -1. Add `using System.ComponentModel` to your script. |
79 |
| -2. Add a `[Category]` attribute to your script. For example, `[Category("My Category")]`. |
80 |
| - |
81 |
| -You can also use the [PropertyDrawer](https://docs.unity3d.com/ScriptReference/PropertyDrawer.html) API to further customize the layout of custom settings. |
82 |
| - |
83 |
| -## Set which render pipeline a setting applies to |
84 |
| - |
85 |
| -To set which render pipeline a setting applies to, use the `[SupportedOnRenderPipeline]` attribute and pass in a `RenderPipelineAsset` type. |
86 |
| - |
87 |
| -For example, if your project uses the Universal Rendering Pipeline (URP) and you want your setting to appear only in the **URP** tab of the **Graphics** settings window, use the following code: |
88 |
| - |
89 |
| -```c# |
90 |
| -[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))] |
91 |
| -``` |
| 55 | +## Additional resources |
92 | 56 |
|
| 57 | +- [Add a setting](add-custom-graphics-setting.md) |
0 commit comments