How edit Global volume profiles from script

How I can edit those from script.

if (volume.profile.TryGet<ShadowsMidtonesHighlights>(out shadowMidHigh))
        {
            shadowMidHigh.active = true;

            shadowMidHigh.highlights = new UnityEngine.Rendering.Vector4Parameter(new Vector4(Random.Range(-1, 1), Random.Range(-1, 1), Random.Range(-1, 1), Random.Range(-1, 1)));
            shadowMidHigh.highlights.overrideState = true;
            shadowMidHigh.shadows = new UnityEngine.Rendering.Vector4Parameter(new Vector4(Random.Range(-1, 1), Random.Range(-1, 1), Random.Range(-1, 1), Random.Range(-1, 1)));
            shadowMidHigh.shadows.overrideState = true;
            shadowMidHigh.midtones = new UnityEngine.Rendering.Vector4Parameter(new Vector4(Random.Range(-1, 1), Random.Range(-1, 1), Random.Range(-1, 1), Random.Range(-1, 1)));
            shadowMidHigh.midtones.overrideState = true;
        }

but when I run Script those effect does’not come to used.
Instanded of that clone button there is “save”. When i press it it activate those effects. but now i wonnder how I can press that button from code?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class SliderBrightness : MonoBehaviour
{
private GameObject cam;
private float lastValue;
private ShadowsMidtonesHighlights shadowMidHigh;
public VolumeProfile profile;

// Start is called before the first frame update
void Start()
{
cam = Camera.main.gameObject;
}

// Update is called once per frame
private void FixedUpdate() {
if(GetComponent().value!=lastValue){
lastValue = GetComponent().value;
if (profile.TryGet(out shadowMidHigh))
{
Vector4 shadowVal = shadowMidHigh.shadows.value;
shadowMidHigh.shadows.overrideState = true;
shadowMidHigh.shadows.SetValue(new UnityEngine.Rendering.Vector4Parameter(new Vector4(1, 1, 1, lastValue)));
}
}
}
}

4 Likes