Create(string)
Creates and returns a GlobalKeyword that represents a new or existing global shader keyword.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Rendering
- Assembly: UnityEngine.CoreModule
public static GlobalKeyword Create(string name)
Parameters
The name of the global shader keyword.
Returns
Type | Description |
|---|---|
| GlobalKeyword | Returns a new instance of the GlobalKeyword class. |
Remarks
Unity creates and returns a struct to represent the global shader keyword with the given name. If a global shader keyword with the given name does not yet exist in Unity's internal list of global shader keywords, Unity adds a global shader keyword with the given name to the list.
GlobalKeywordThe following example creates a struct with the name , and caches it. It provides functions to enable and disable it.
GlobalKeywordEXAMPLE_FEATURE_ONusing UnityEngine;using UnityEngine.Rendering;public class GlobalKeywordExample : MonoBehaviour{ private GlobalKeyword exampleFeatureKeyword; private void Start() { exampleFeatureKeyword = GlobalKeyword.Create("EXAMPLE_FEATURE_ON"); } public void EnableExampleFeature() { Shader.EnableKeyword(exampleFeatureKeyword); } public void DisableExampleFeature() { Shader.DisableKeyword(exampleFeatureKeyword); }}
Additional Resources: Shader variants and keywords, LocalKeyword, GlobalKeyword, EnableKeyword, DisableKeyword, SetKeyword, IsKeywordEnabled, enabledGlobalKeywords, globalKeywords.