string[] An array of constant defines.
Gets a copy of the constant defines.
This method gets the constant define data from a ShaderBuildSettings struct. To make sure data stays valid, you can't read or write the original data. To apply the modified data back to the original data, use ShaderBuildSettings.Defines. The valid format for the array element data is a pair of identifier and numeric value, separated by a whitespace.
Additional resources: ShaderBuildSettings.
using System; using System.Collections.Generic; using UnityEditor.Rendering; using UnityEditor.Shaders; using UnityEngine; public class ConstantDefinesExample { void AddShaderConstantDefines() { // Get current shader build settings either from the currently active build profile // or if none is active, the global graphics settings. ShaderBuildSettings buildSettings = EditorGraphicsSettings.GetShaderBuildSettings(); // Get the copy of the existing defines and append the new ones var allDefines = new List<string>(buildSettings.GetDefinesCopy()); allDefines.Add("MAX_NUM_LIGHTS 8"); allDefines.Add("EPSILON 0.1f"); var defineArray = allDefines.ToArray(); // Check if the define array is valid string validationErrors; if (!ShaderBuildSettings.ValidateDefines(defineArray, out validationErrors)) { Debug.LogWarning(validationErrors); return; } // Set the modified defines. Throw an exception if the data is invalid. try { buildSettings.Defines = defineArray; } catch (ArgumentException ex) { Debug.LogError(ex.Message); return; } // Apply the modified settings data back to the Graphics settings or Build Profile settings EditorGraphicsSettings.SetShaderBuildSettings(buildSettings); } }