Skip to content

Commit e93e6c0

Browse files
authored
Merge pull request #8122 from Unity-Technologies/internal/6000.0/staging
Internal/6000.0/staging
2 parents a66eeaf + c9e3a3a commit e93e6c0

248 files changed

Lines changed: 36927 additions & 2553 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
55.8 KB
Loading
60.2 KB
Loading

Packages/com.unity.render-pipelines.core/Documentation~/TableOfContents.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
* [RTHandle fundamentals](rthandle-system-fundamentals.md)
2121
* [Using the RTHandle system](rthandle-system-using.md)
2222
* [Custom Material Inspector](custom-material-inspector.md)
23-
* [Custom settings](settings.md)
23+
* [Custom graphics settings](settings.md)
2424
* [Adding properties in the menu](adding-properties.md)
25-
* [Add custom graphics settings](add-custom-graphics-settings.md)
25+
* [Add a settings group](add-custom-graphics-settings.md)
26+
* [Add a setting](add-custom-graphics-setting.md)
27+
* [Customize the UI of a setting](customize-ui-for-a-setting.md)
2628
* [Get custom graphics settings](get-custom-graphics-settings.md)
27-
* [Include or excude a setting in your build](choose-whether-unity-includes-a-graphics-setting-in-your-build.md)
29+
* [Include or exclude a setting in your build](choose-whether-unity-includes-a-graphics-setting-in-your-build.md)
2830
* [Shaders](shaders.md)
2931
* [Use shader methods from the SRP Core shader library](built-in-shader-methods.md)
3032
* [Synchronizing shader code and C#](generating-shader-includes.md)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Add a setting
2+
3+
Add a simple property or a reference property to a [custom graphics settings group](add-custom-graphics-settings.md). You can change the values of the setting in the Unity Editor while you're editing your project.
4+
5+
Unity serializes the graphics settings you add. For more information, refer to [Script serialization](xref:um-script-serialization).
6+
7+
**Note:** The value of a custom setting is static in a built project. You can't change the setting at runtime.
8+
9+
## Add a simple property
10+
11+
To add a simple property, add a field to your `IRenderPipelineGraphicsSettings` class using the `[SerializeField]` attribute. For example:
12+
13+
```c#
14+
using System;
15+
using UnityEngine;
16+
using UnityEngine.Rendering;
17+
using UnityEngine.Rendering.Universal;
18+
19+
[Serializable]
20+
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
21+
22+
// Create a new settings group by implementing the IRenderPipelineGraphicsSettings interface
23+
public class MySettings : IRenderPipelineGraphicsSettings
24+
{
25+
// Add a private field for the version property
26+
int internalVersion = 1;
27+
28+
// Implement the public version property
29+
public int version => internalVersion;
30+
31+
// Add a float setting
32+
[SerializeField]
33+
private float mySetting = 1.0f;
34+
35+
// Add a Material reference property
36+
[SerializeField]
37+
public Material myMaterial;
38+
}
39+
```
40+
![](Images/customsettings-addsetting.png)<br/>
41+
The **Edit** > **Project Settings** > **Graphics** window with the new custom setting from the example script.
42+
43+
## Set the default asset for a reference property
44+
45+
To set a default asset for a [reference property](xref:um-editing-value-properties#references), for example a material, add a [`[ResourcePath]`](https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Rendering.ResourcePathAttribute.html) attribute. For example:
46+
47+
```c#
48+
public class MySettings: IRenderPipelineGraphicsSettings
49+
{
50+
...
51+
[SerializeField]
52+
[ResourcePath('path-to-default-file')]
53+
public Material myMaterial;
54+
}
55+
```
56+
57+
## Additional resources
58+
59+
- [SerializeField](xref:UnityEngine.SerializeField)
60+
- [Reference properties](xref:EditingValueProperties#references)
Lines changed: 27 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,57 @@
1-
# Add custom graphics settings
1+
# Add a settings group
22

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.
44

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:
66

7-
## Add a setting
7+
1. Create a class that implements the `IRenderPipelineGraphicsSettings` interface, then add a `[Serializable]` attribute.
88

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.
129
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.
1510

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).
1718

1819
```c#
20+
using System;
1921
using UnityEngine;
2022
using UnityEngine.Rendering;
21-
using System;
23+
using UnityEngine.Rendering.Universal;
2224

2325
[Serializable]
2426
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
2527

2628
// Create a new settings group by implementing the IRenderPipelineGraphicsSettings interface
2729
public class MySettings : IRenderPipelineGraphicsSettings
2830
{
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;
3136

32-
// Create a new setting and set its default value to 100.
33-
public int myValue = 100;
3437
}
3538
```
3639

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+
![](Images/customsettings-settingsgroup.png)<br/>
41+
The **Edit** > **Project Settings** > **Graphics** window with the new custom settings group from the example script.
4042

41-
To add a reference property, follow these steps:
43+
## Change the display order of settings groups
4244

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.
4846

4947
```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
5950
{
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+
...
6552
}
6653
```
6754

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
9256

57+
- [Add a setting](add-custom-graphics-setting.md)

Packages/com.unity.render-pipelines.core/Documentation~/choose-whether-unity-includes-a-graphics-setting-in-your-build.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
# Include or exclude a setting in your build
22

3-
By default, Unity doesn't include a setting ("strips" the setting) in your built project. For example, if you create a custom reference property where you set a shader asset, Unity doesn't include that property in your build.
3+
By default, Unity doesn't include a setting ("strips" the setting) in your built project to optimize performance and reduce build size. For example, if you create a custom reference property that points to a shader asset, by default Unity doesn't include that property in your build.
44

5-
You can choose to include a setting in your build instead. You can then get the value of the setting at runtime. The value is read-only.
5+
You can choose to include a setting in your build instead. The value of the property is read-only at runtime.
66

77
## Include a setting in your build
88

9-
To include a setting in your build by default, set the `IsAvailableInPlayerBuild` property of your [settings class](add-custom-graphics-settings.md) to `true`.
9+
To include a setting in your build by default, set the `IsAvailableInPlayerBuild` property of your [settings group class](add-custom-graphics-settings.md) to `true`.
1010

11-
For example, add the following line:
11+
For example:
1212

1313
```c#
14-
public bool IsAvailableInPlayerBuild => true;
14+
public class MySettings: IRenderPipelineGraphicsSettingsStripper
15+
{
16+
...
17+
// Make settings in this class available in your build
18+
public bool IsAvailableInPlayerBuild => true;
19+
}
1520
```
1621

1722
## Create your own stripping code
1823

19-
You can override the `IsAvailableInPlayerBuild` property by implementing the `IRenderPipelineGraphicsSettingsStripper` interface, and writing code that conditionally strips or keeps the setting.
24+
To conditionally control whether Unity includes or excludes a setting in your build, override the `IsAvailableInPlayerBuild` property by implementing the `IRenderPipelineGraphicsSettingsStripper` interface.
2025

2126
Follow these steps:
2227

2328
1. Create a class that implements the `IRenderPipelineGraphicsSettingsStripper` interface, and pass in your [settings class](add-custom-graphics-settings.md).
2429
2. Implement the `active` property. If you set `active` to `false`, the code in the class doesn't run.
25-
3. Implement the `CanRemoveSettings` method with your own code that decides whether to include the setting.
26-
4. In your code, return either `true` or `false` to strip or keep the setting.
30+
3. Implement the `CanRemoveSettings` method with your own code that decides whether to include the setting. Return `true` to strip the setting, or `false` to include the setting.
2731

28-
For example, in the following code, the `CanRemoveSettings` method returns `true` and strips the setting if the value of the setting is larger than 100.
32+
For example:
2933

3034
```c#
3135
using UnityEngine;
@@ -41,8 +45,8 @@ class SettingsStripper : IRenderPipelineGraphicsSettingsStripper<MySettings>
4145
// Implement the CanRemoveSettings method with our own code
4246
public bool CanRemoveSettings(MySettings settings)
4347
{
44-
// Strip the setting (return true) if the value is larger than 100
45-
return settings.myValue > 100;
48+
// Strip the setting (return true) if useMyFeature is false
49+
return !settings.useMyFeature;
4650
}
4751
}
4852
```
@@ -55,8 +59,9 @@ You can check if a setting exists at runtime. A setting might not exist at runti
5559

5660
- Unity didn't include the setting in your build.
5761
- The current pipeline doesn't support the setting.
62+
- The setting is in an assembly that Unity doesn't include in your build. Refer to [Organizing scripts into assemblies](xref:um-script-compilation-assembly-definition-files) for more information.
5863

59-
Use `TryGetRenderPipelineSettings` to check if the setting exists. `TryGetRenderPipelineSettings` puts the setting in an `out` variable if it exists. Otherwise it returns `false`.
64+
To check if the setting exists, use the `TryGetRenderPipelineSettings` API. `TryGetRenderPipelineSettings` puts the setting in an `out` variable if the setting exists. Otherwise it returns `false`.
6065

6166
For example, the following code checks whether a settings group called `MySettings` exists at runtime:
6267

@@ -65,3 +70,7 @@ if (GraphicsSettings.TryGetRenderPipelineSettings<MySettings>(out var mySetting)
6570
Debug.Log("The setting is in the build and its value is {mySetting.myValue}");
6671
}
6772
```
73+
74+
## Additional resources
75+
76+
- [Organizing scripts into assemblies](xref:um-script-compilation-assembly-definition-files)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Customize the UI of custom settings
2+
3+
To change the look of custom settings in the **Graphics** settings window, use the `PropertyDrawer` API.
4+
5+
Follow these steps:
6+
7+
1. Create a class that inherits from the [`PropertyDrawer`](xref:UnityEditor.PropertyDrawer) class.
8+
2. Add the `[CustomPropertyDrawer]` attribute to the class, with a reference to your settings class.
9+
3. Override the `PropertyDrawer.CreatePropertyGUI` method, and return a `VisualElement` object that contains the UI elements you want to display.
10+
11+
The following example creates a custom UI for a `MySettings` class that contains a Boolean and a float field. The Graphics settings window displays the float only when the Boolean field is enabled.
12+
13+
For more information, refer to [PropertyDrawer](xref:UnityEditor.PropertyDrawer).
14+
15+
```c#
16+
using UnityEngine;
17+
using UnityEditor;
18+
using UnityEngine.UIElements;
19+
20+
// Create a custom UI for the properties in the MySettings class
21+
[CustomPropertyDrawer(typeof(MySettings))]
22+
public class MySettingsPropertyDrawer : PropertyDrawer
23+
{
24+
// Override the CreatePropertyGUI method to define the custom UI
25+
public override VisualElement CreatePropertyGUI(SerializedProperty property)
26+
{
27+
// Create a container to hold the UI elements
28+
var container = new VisualElement();
29+
30+
// Find the properties to display
31+
var useProperty = property.FindPropertyRelative("m_UseMyFeature");
32+
var intensityProperty = property.FindPropertyRelative("m_MyFeatureIntensity");
33+
34+
// Create property fields for each property
35+
var usePropertyField = new PropertyField(useProperty);
36+
var intensityPropertyField = new PropertyField(intensityProperty);
37+
38+
// Enable or disable the intensity field based on the value of m_UseMyFeature
39+
usePropertyField.RegisterValueChangeCallback(evt =>
40+
{
41+
intensityPropertyField.SetEnabled(useProperty.boolValue);
42+
});
43+
44+
// Add the property fields to the container
45+
container.Add(usePropertyField);
46+
container.Add(intensityPropertyField);
47+
48+
// Return the container to be displayed in the Graphics settings window
49+
return container;
50+
}
51+
}
52+
```
53+
54+
## Customize the More (⋮) menu of a settings group
55+
56+
To add items to the **More** (⋮) menu of a settings group, follow these steps:
57+
58+
1. Create a class that implements the [`IRenderPipelineGraphicsSettingsContextMenu`](https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Rendering.IRenderPipelineGraphicsSettingsContextMenu.html) interface.
59+
2. Implement the `PopulateContextMenu` method.
60+
3. To add an item, use the `AddItem` API.
61+
62+
For example:
63+
64+
```c#
65+
public class MySettingsContextMenu : IRenderPipelineGraphicsSettingsContextMenu<MySettings>
66+
{
67+
void IRenderPipelineGraphicsSettingsContextMenu<MySettings>.PopulateContextMenu(MySettings setting, PropertyDrawer _, ref GenericMenu menu)
68+
{
69+
menu.AddItem(new GUIContent("My custom menu item"), false, () => { Debug.Log("Menu item was selected."); });
70+
}
71+
}
72+
```
73+
74+
## Additional resources
75+
76+
- [PropertyDrawer](xref:UnityEditor.PropertyDrawer)
77+
- [IRenderPipelineGraphicsSettingsContextMenu](https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Rendering.IRenderPipelineGraphicsSettingsContextMenu.html)

Packages/com.unity.render-pipelines.core/Documentation~/get-custom-graphics-settings.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
To get a custom setting and read its value, use the `GetRenderPipelineSettings` method.
44

5-
If you want to get a setting at runtime, you must [include the setting in your build](choose-whether-unity-includes-a-graphics-setting-in-your-build.md).
6-
7-
For example, the following script gets the `MySettings` settings class from the example in the [Add custom graphics settings](add-custom-graphics-settings.md) page, then logs the value of the `MyValue` setting:
5+
For example, the following script gets the `MySettings` settings class from the example in the [Add a setting](add-custom-graphics-setting.md) page, then logs the value of the `mySetting` setting:
86

97
```c#
108
using UnityEngine;
@@ -19,16 +17,16 @@ public class LogMySettingsValue : MonoBehaviour
1917
var mySettings = GraphicsSettings.GetRenderPipelineSettings<MySettings>();
2018

2119
// Log the value of the MyValue setting
22-
Debug.Log(mySettings.myValue);
20+
Debug.Log(mySettings.mySetting);
2321
}
2422
}
2523
```
2624

27-
## Detect when a setting changes
25+
## Get a notification when a setting changes
2826

29-
You can configure a property so it notifies other scripts when its value changes. This only works while you're editing your project, not at runtime.
27+
To configure a property so it notifies other scripts when its value changes, use the `SetValueAndNotify` method. You can use this to debug, update UI elements, or trigger other actions when a setting changes.
3028

31-
You can use this to fetch the value only when it changes, instead of every frame in the `Update()` method.
29+
This only works while you're editing your project, not at runtime. If you use `SetValueAndModify` in a built application, Unity throws an exception.
3230

3331
Follow these steps:
3432

@@ -63,8 +61,6 @@ Follow these steps:
6361
}
6462
```
6563

66-
If you use `SetValueAndModify' in a standalone application, Unity throws an exception.
67-
6864
3. Use the `GraphicsSettings.Subscribe` method to subscribe to notifications from the setting, and call an `Action` when the setting changes.
6965

7066
For example:
@@ -101,4 +97,6 @@ To stop calling a method when a setting changes, use the `GraphicsSettings.Unsub
10197
GraphicsSettings.Unsubscribe<MySettings>(onSettingChanged);
10298
```
10399

100+
## Additional resources
104101

102+
- [`IRenderPipelineGraphicsSettings`](https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Rendering.IRenderPipelineGraphicsSettings.html)

0 commit comments

Comments
 (0)