void CheckReferenceValues(bool forceUpdate)
        {
            if (m_staticSwitchVarMode == StaticSwitchVariableMode.Reference)
            {
                if (m_reference == null && m_referenceNodeId > 0)
                {
                    m_reference        = ContainerGraph.GetNode(m_referenceNodeId) as StaticSwitch;
                    m_referenceArrayId = ContainerGraph.StaticSwitchNodes.GetNodeRegisterIdx(m_referenceNodeId);
                }

                if (m_reference != null)
                {
                    if (forceUpdate || m_reference.IsStaticSwitchDirty)
                    {
                        int count = m_inputPorts.Count;
                        for (int i = 0; i < count; i++)
                        {
                            m_inputPorts[i].Name    = m_reference.InputPorts[i].Name;
                            m_inputPorts[i].Visible = m_reference.InputPorts[i].Visible;
                        }
                        m_sizeIsDirty = true;
                    }
                }
            }
            else
            {
                m_isStaticSwitchDirty = false;
            }
        }
        public override void SetPreviewInputs()
        {
            base.SetPreviewInputs();

            if (m_conditionId == -1)
            {
                m_conditionId = Shader.PropertyToID("_Condition");
            }

            StaticSwitch node = (m_staticSwitchVarMode == StaticSwitchVariableMode.Reference && m_reference != null) ? m_reference : this;

            if (m_createToggle)
            {
                PreviewMaterial.SetInt(m_conditionId, node.MaterialValue);
            }
            else
            {
                PreviewMaterial.SetInt(m_conditionId, node.DefaultValue);
            }
        }
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory))
            {
                return(m_outputPorts[0].LocalValue(dataCollector.PortCategory));
            }

            base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar);

            StaticSwitch node = (m_staticSwitchVarMode == StaticSwitchVariableMode.Reference && m_reference != null) ? m_reference : this;

            this.OrderIndex       = node.RawOrderIndex;
            this.OrderIndexOffset = node.OrderIndexOffset;
            //if( m_keywordModeType == KeywordModeType.KeywordEnum )

            //node.RegisterPragmas( ref dataCollector );

            string outType = UIUtils.PrecisionWirePortToCgType(CurrentPrecisionType, m_outputPorts[0].DataType);

            if (node.KeywordModeTypeValue == KeywordModeType.KeywordEnum)
            {
                string defaultKey = "\t" + outType + " staticSwitch" + OutputId + " = " + m_inputPorts[node.DefaultValue].GeneratePortInstructions(ref dataCollector) + ";";

                string[] allOutputs = new string[node.KeywordEnumAmount];
                for (int i = 0; i < node.KeywordEnumAmount; i++)
                {
                    allOutputs[i] = m_inputPorts[i].GeneratePortInstructions(ref dataCollector);
                }

                for (int i = 0; i < node.KeywordEnumAmount; i++)
                {
                    string keyword = node.KeywordEnum(i);
                    if (i == 0)
                    {
                        dataCollector.AddLocalVariable(UniqueId, "#if defined(" + keyword + ")", true);
                    }
                    else
                    {
                        dataCollector.AddLocalVariable(UniqueId, "#elif defined(" + keyword + ")", true);
                    }

                    if (node.DefaultValue == i)
                    {
                        dataCollector.AddLocalVariable(UniqueId, defaultKey, true);
                    }
                    else
                    {
                        dataCollector.AddLocalVariable(UniqueId, "\t" + outType + " staticSwitch" + OutputId + " = " + allOutputs[i] + ";", true);
                    }
                }
                dataCollector.AddLocalVariable(UniqueId, "#else", true);
                dataCollector.AddLocalVariable(UniqueId, defaultKey, true);
                dataCollector.AddLocalVariable(UniqueId, "#endif", true);
            }
            else
            {
                string falseCode = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);
                string trueCode  = m_inputPorts[1].GeneratePortInstructions(ref dataCollector);

                //if( node.CurrentVarMode == StaticSwitchVariableMode.Fetch )
                dataCollector.AddLocalVariable(UniqueId, "#ifdef " + node.CurrentKeyword, true);
                //else
                //	dataCollector.AddLocalVariable( UniqueId, "#ifdef " + node.PropertyName + OnOffStr, true );
                dataCollector.AddLocalVariable(UniqueId, "\t" + outType + " staticSwitch" + OutputId + " = " + trueCode + ";", true);
                dataCollector.AddLocalVariable(UniqueId, "#else", true);
                dataCollector.AddLocalVariable(UniqueId, "\t" + outType + " staticSwitch" + OutputId + " = " + falseCode + ";", true);
                dataCollector.AddLocalVariable(UniqueId, "#endif", true);
            }

            m_outputPorts[0].SetLocalValue("staticSwitch" + OutputId, dataCollector.PortCategory);
            return(m_outputPorts[0].LocalValue(dataCollector.PortCategory));
        }
        void PropertyGroup()
        {
            EditorGUI.BeginChangeCheck();
            CurrentVarMode = (StaticSwitchVariableMode)EditorGUILayoutEnumPopup(ModeStr, CurrentVarMode);
            if (EditorGUI.EndChangeCheck())
            {
                if (CurrentVarMode == StaticSwitchVariableMode.Fetch)
                {
                    m_keywordModeType = KeywordModeType.Toggle;
                    UpdateLabels();
                }

                if (CurrentVarMode == StaticSwitchVariableMode.Reference)
                {
                    UIUtils.UnregisterPropertyNode(this);
                }
                else
                {
                    if (m_createToggle)
                    {
                        UIUtils.RegisterPropertyNode(this);
                    }
                    else
                    {
                        UIUtils.UnregisterPropertyNode(this);
                    }
                }
            }

            if (CurrentVarMode == StaticSwitchVariableMode.Create)
            {
                EditorGUI.BeginChangeCheck();
                m_multiCompile = EditorGUILayoutIntPopup(KeywordTypeStr, m_multiCompile, KeywordTypeList, KeywordTypeInt);
                if (EditorGUI.EndChangeCheck())
                {
                    BeginPropertyFromInspectorCheck();
                }
            }
            else if (CurrentVarMode == StaticSwitchVariableMode.Reference)
            {
                string[] arr = ContainerGraph.StaticSwitchNodes.NodesArr;
                bool     guiEnabledBuffer = GUI.enabled;
                if (arr != null && arr.Length > 0)
                {
                    GUI.enabled = true;
                }
                else
                {
                    m_referenceArrayId = -1;
                    GUI.enabled        = false;
                }

                EditorGUI.BeginChangeCheck();
                m_referenceArrayId = EditorGUILayoutPopup(Constants.AvailableReferenceStr, m_referenceArrayId, arr);
                if (EditorGUI.EndChangeCheck())
                {
                    m_reference = ContainerGraph.StaticSwitchNodes.GetNode(m_referenceArrayId);
                    if (m_reference != null)
                    {
                        m_referenceNodeId = m_reference.UniqueId;
                        CheckReferenceValues(true);
                    }
                    else
                    {
                        m_referenceArrayId = -1;
                        m_referenceNodeId  = -1;
                    }
                }
                GUI.enabled = guiEnabledBuffer;

                return;
            }

            if (CurrentVarMode == StaticSwitchVariableMode.Create || m_createToggle)
            {
                EditorGUI.BeginChangeCheck();
                m_keywordModeType = (KeywordModeType)EditorGUILayoutEnumPopup(TypeStr, m_keywordModeType);
                if (EditorGUI.EndChangeCheck())
                {
                    UpdateLabels();
                }
            }

            if (m_keywordModeType != KeywordModeType.KeywordEnum)
            {
                if (CurrentVarMode == StaticSwitchVariableMode.Create || m_createToggle)
                {
                    ShowPropertyInspectorNameGUI();
                    ShowPropertyNameGUI(true);
                    if (CurrentVarMode == StaticSwitchVariableMode.Create)
                    {
                        EditorGUILayout.BeginHorizontal();
                        bool guiEnabledBuffer = GUI.enabled;
                        GUI.enabled = !m_lockKeyword;
                        if (m_lockKeyword)
                        {
                            EditorGUILayout.TextField(KeywordNameStr, GetPropertyValStr());
                        }
                        else
                        {
                            m_currentKeyword = EditorGUILayoutTextField(KeywordNameStr, m_currentKeyword);
                        }
                        GUI.enabled   = guiEnabledBuffer;
                        m_lockKeyword = GUILayout.Toggle(m_lockKeyword, (m_lockKeyword ? UIUtils.LockIconOpen : UIUtils.LockIconClosed), "minibutton", GUILayout.Width(22));
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
            else
            {
                if (CurrentVarMode == StaticSwitchVariableMode.Create || m_createToggle)
                {
                    ShowPropertyInspectorNameGUI();
                    ShowPropertyNameGUI(true);
                    DrawEnumList();
                }
            }

            if (CurrentVarMode == StaticSwitchVariableMode.Fetch)
            {
                //ShowPropertyInspectorNameGUI();
                EditorGUI.BeginChangeCheck();
                m_currentKeywordId = EditorGUILayoutPopup(KeywordStr, m_currentKeywordId, UIUtils.AvailableKeywords);
                if (EditorGUI.EndChangeCheck())
                {
                    if (m_currentKeywordId != 0)
                    {
                        m_currentKeyword = UIUtils.AvailableKeywords[m_currentKeywordId];
                    }
                }

                if (m_currentKeywordId == 0)
                {
                    EditorGUI.BeginChangeCheck();
                    m_currentKeyword = EditorGUILayoutTextField(CustomStr, m_currentKeyword);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_currentKeyword = UIUtils.RemoveInvalidCharacters(m_currentKeyword);
                    }
                }
            }

#if UNITY_2019_1_OR_NEWER
            m_isLocal = EditorGUILayoutToggle(IsLocalStr, m_isLocal);
#endif

            //if( CurrentVarMode == StaticSwitchVariableMode.Create )
            {
                ShowAutoRegister();
            }

            EditorGUI.BeginChangeCheck();
            m_createToggle = EditorGUILayoutToggle(MaterialToggleStr, m_createToggle);
            if (EditorGUI.EndChangeCheck())
            {
                if (m_createToggle)
                {
                    UIUtils.RegisterPropertyNode(this);
                }
                else
                {
                    UIUtils.UnregisterPropertyNode(this);
                }
            }


            if (m_createToggle)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20);
                m_propertyTab = GUILayout.Toolbar(m_propertyTab, LabelToolbarTitle);
                EditorGUILayout.EndHorizontal();
                switch (m_propertyTab)
                {
                default:
                case 0:
                {
                    EditorGUI.BeginChangeCheck();
                    if (m_keywordModeType != KeywordModeType.KeywordEnum)
                    {
                        m_materialValue = EditorGUILayoutToggle(ToggleMaterialValueStr, m_materialValue == 1) ? 1 : 0;
                    }
                    else
                    {
                        m_materialValue = EditorGUILayoutPopup(ToggleMaterialValueStr, m_materialValue, m_keywordEnumList);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_requireMaterialUpdate = true;
                    }
                }
                break;

                case 1:
                {
                    if (m_keywordModeType != KeywordModeType.KeywordEnum)
                    {
                        m_defaultValue = EditorGUILayoutToggle(ToggleDefaultValueStr, m_defaultValue == 1) ? 1 : 0;
                    }
                    else
                    {
                        m_defaultValue = EditorGUILayoutPopup(ToggleDefaultValueStr, m_defaultValue, m_keywordEnumList);
                    }
                }
                break;
                }
            }

            //EditorGUILayout.HelpBox( "Keyword Type:\n" +
            //	"The difference is that unused variants of \"Shader Feature\" shaders will not be included into game build while \"Multi Compile\" variants are included regardless of their usage.\n\n" +
            //	"So \"Shader Feature\" makes most sense for keywords that will be set on the materials, while \"Multi Compile\" for keywords that will be set from code globally.\n\n" +
            //	"You can set keywords using the material property using the \"Property Name\" or you can set the keyword directly using the \"Keyword Name\".", MessageType.None );
        }