public override void OnMasterNodeReplaced( MasterNode newMasterNode ) { base.OnMasterNodeReplaced( newMasterNode ): if( newMasterNode.CurrentMasterNodeCategory == AvailableShaderTypes.Template ) { FetchLocalVarData( newMasterNode ): } else { m_localVarsData = null: m_currentDataIdx = -1: } }
public override void OnMasterNodeReplaced(MasterNode newMasterNode) { base.OnMasterNodeReplaced(newMasterNode); if (newMasterNode.CurrentMasterNodeCategory == AvailableShaderTypes.Template) { FetchInterpolator(newMasterNode); } else { m_interpolatorData = null; m_currentDataIdx = -1; } }
public override bool GetUniformData(out string dataType, out string dataName, ref bool fullValue) { MasterNode currMasterNode = (m_containerGraph.CurrentMasterNode != null) ? m_containerGraph.CurrentMasterNode : m_containerGraph.ParentWindow.OutsideGraph.CurrentMasterNode; if (currMasterNode != null && currMasterNode.CurrentDataCollector.IsTemplate && currMasterNode.CurrentDataCollector.IsSRP) { dataType = "TEXTURE2D_ARRAY( " + PropertyName + ""; dataName = ");\nuniform SAMPLER( sampler" + PropertyName + " )"; return(true); } dataType = "UNITY_DECLARE_TEX2DARRAY("; dataName = PropertyName + " )"; return(true); }
public void Destroy() { m_masterNode = null; m_propertyNodes.Clear(); m_propertyNodes = null; m_inputDict.Clear(); m_inputDict = null; m_customInputDict.Clear(); m_customInputDict = null; m_propertiesDict.Clear(); m_propertiesDict = null; m_instancedPropertiesDict.Clear(); m_instancedPropertiesDict = null; m_uniformsDict.Clear(); m_uniformsDict = null; m_includesDict.Clear(); m_includesDict = null; m_pragmasDict.Clear(); m_pragmasDict = null; m_virtualCoordinatesDict.Clear(); m_virtualCoordinatesDict = null; m_localVariablesDict.Clear(); m_localVariablesDict = null; m_specialLocalVariablesDict.Clear(); m_specialLocalVariablesDict = null; m_vertexLocalVariablesDict.Clear(); m_vertexLocalVariablesDict = null; m_localFunctions.Clear(); m_localFunctions = null; m_vertexDataDict.Clear(); m_vertexDataDict = null; m_customOutputDict.Clear(); m_customOutputDict = null; }
public override void OnMasterNodeReplaced( MasterNode newMasterNode ) { base.OnMasterNodeReplaced( newMasterNode ): if( newMasterNode.CurrentMasterNodeCategory == AvailableShaderTypes.Template ) { SetTemplate( newMasterNode ): if( m_fetchScopeFromProperty ) { m_fetchScopeFromProperty = false: FetchScope(): } FetchShaderProperties(): FetchPropertyId(): //m_containerGraph.DeleteConnection( false, UniqueId, 0, false, true ): } }
public MasterNodeDataCollector(MasterNode masterNode) { m_masterNode = masterNode; m_input = "\t\tstruct Input\n\t\t{\n"; m_customInput = "\t\tstruct SurfaceOutput{0}\n\t\t{\n"; m_properties = IOUtils.PropertiesBegin; //"\tProperties\n\t{\n"; m_uniforms = ""; m_instructions = ""; m_includes = ""; m_pragmas = ""; m_localVariables = ""; m_specialLocalVariables = ""; m_customOutput = ""; m_inputDict = new Dictionary <string, PropertyDataCollector>(); m_customInputDict = new Dictionary <string, PropertyDataCollector>(); m_propertiesDict = new Dictionary <string, PropertyDataCollector>(); m_instancedPropertiesDict = new Dictionary <string, PropertyDataCollector>(); m_uniformsDict = new Dictionary <string, PropertyDataCollector>(); m_includesDict = new Dictionary <string, PropertyDataCollector>(); m_pragmasDict = new Dictionary <string, PropertyDataCollector>(); m_virtualCoordinatesDict = new Dictionary <string, int>(); m_localVariablesDict = new Dictionary <string, PropertyDataCollector>(); m_virtualVariablesDict = new Dictionary <string, string>(); m_specialLocalVariablesDict = new Dictionary <string, PropertyDataCollector>(); m_vertexLocalVariablesDict = new Dictionary <string, PropertyDataCollector>(); m_localFunctions = new Dictionary <string, string>(); m_vertexDataDict = new Dictionary <string, PropertyDataCollector>(); m_customOutputDict = new Dictionary <string, PropertyDataCollector>(); m_dirtyInputs = false; m_dirtyCustomInputs = false; m_dirtyProperties = false; m_dirtyInstancedProperties = false; m_dirtyUniforms = false; m_dirtyInstructions = false; m_dirtyIncludes = false; m_dirtyPragmas = false; m_dirtyLocalVariables = false; m_dirtySpecialLocalVariables = false; m_grabPassIsDirty = false; m_portCategory = MasterNodePortCategory.Fragment; m_propertyNodes = new Dictionary <int, PropertyNode>(); m_showDebugMessages = (m_showDebugMessages && DebugConsoleWindow.DeveloperMode); }
public void SetRenderingPlatforms(ref string ShaderBody) { int checkedPlatforms = 0; int uncheckedPlatforms = 0; for (int i = 0; i < m_renderingPlatformValues.Length; i++) { if (m_renderingPlatformValues[i]) { checkedPlatforms += 1; } else { uncheckedPlatforms += 1; } } if (checkedPlatforms > 0 && checkedPlatforms < m_renderingPlatformValues.Length) { string result = string.Empty; if (checkedPlatforms < uncheckedPlatforms) { result = "only_renderers "; for (int i = 0; i < m_renderingPlatformValues.Length; i++) { if (m_renderingPlatformValues[i]) { result += (RenderPlatforms)i + " "; } } } else { result = "exclude_renderers "; for (int i = 0; i < m_renderingPlatformValues.Length; i++) { if (!m_renderingPlatformValues[i]) { result += (RenderPlatforms)i + " "; } } } MasterNode.AddShaderPragma(ref ShaderBody, result); } }
public void BuildColorMask(ref string ShaderBody, bool customBlendAvailable) { int count = 0; string colorMask = string.Empty; for (int i = 0; i < m_colorMask.Length; i++) { if (m_colorMask[i]) { count++; colorMask += m_colorMaskChar[i]; } } if ((count != m_colorMask.Length && customBlendAvailable) || m_inlineMask.Active) { MasterNode.AddRenderState(ref ShaderBody, "ColorMask", m_inlineMask.GetValueOrProperty(((count == 0) ? "0" : colorMask))); } }
public override bool GetUniformData(out string dataType, out string dataName, ref bool fullValue) { if (m_containerGraph.SamplingThroughMacros) { if (m_containerGraph.IsSRP) { if (Constants.TexDeclarationSRPMacros.ContainsKey(m_currentType)) { dataName = string.Format(Constants.TexDeclarationSRPMacros[m_currentType], PropertyName); dataType = string.Empty; fullValue = true; return(true); } } else if (Constants.TexDeclarationStandardMacros.ContainsKey(m_currentType)) { dataName = string.Format(Constants.TexDeclarationStandardMacros[m_currentType], PropertyName); dataType = string.Empty; fullValue = true; return(true); } } if (m_currentType == TextureType.Texture2DArray) { MasterNode masterNode = UIUtils.CurrentWindow.OutsideGraph.CurrentMasterNode; if (masterNode.CurrentDataCollector.IsTemplate && masterNode.CurrentDataCollector.IsSRP) { dataType = "TEXTURE2D_ARRAY( " + PropertyName + ""; dataName = ");\nuniform SAMPLER( sampler" + PropertyName + " )"; return(true); } dataType = "UNITY_DECLARE_TEX2DARRAY("; dataName = m_propertyName + " )"; return(true); } dataType = UIUtils.TextureTypeToCgType(m_currentType); dataName = m_propertyName; return(true); }
public override bool GetUniformData(out string dataType, out string dataName) { if (m_currentType == TextureType.Texture2DArray) { MasterNode masterNode = UIUtils.CurrentWindow.OutsideGraph.CurrentMasterNode; if (masterNode.CurrentDataCollector.IsTemplate && masterNode.CurrentDataCollector.IsSRP) { dataType = "TEXTURE2D_ARRAY( " + PropertyName + ""; dataName = ");\nuniform SAMPLER( sampler" + PropertyName + " )"; return(true); } dataType = "UNITY_DECLARE_TEX2DARRAY("; dataName = m_propertyName + " )"; return(true); } dataType = UIUtils.TextureTypeToCgType(m_currentType); dataName = m_propertyName; return(true); }
public override void SetupNodeCategories() { //base.SetupNodeCategories(): ContainerGraph.ResetNodesData(): MasterNode masterNode = ContainerGraph.ParentWindow.CurrentGraph.CurrentMasterNode: if( masterNode != null ) { int count = m_inputPorts.Count: for( int i = 0: i < count: i++ ) { if( m_inputPorts[ i ].IsConnected ) { NodeData nodeData = new NodeData( m_inputPorts[ i ].Category ): ParentNode node = m_inputPorts[ i ].GetOutputNode(): MasterNodeDataCollector temp = masterNode.CurrentDataCollector: node.PropagateNodeData( nodeData, ref temp ): temp = null: } } } }
public override void OnMasterNodeReplaced(MasterNode newMasterNode) { base.OnMasterNodeReplaced(newMasterNode); if (newMasterNode.CurrentMasterNodeCategory == AvailableShaderTypes.Template) { FetchMultiPassTemplate(newMasterNode); m_inputCountHelper = RefreshInputCountHelper(); if (m_inputPorts.Count != m_inputCountHelper) { CreateInputPorts(); } else { RefreshInputPorts(); } } else { DeleteAllInputConnections(true); } }
public string CreateDepthInfo() { string result = string.Empty; if (m_zWriteMode != 0) { MasterNode.AddRenderState(ref result, "ZWrite", ZWriteModeValues[m_zWriteMode]); } if (m_zTestMode != 0) { MasterNode.AddRenderState(ref result, "ZTest", ZTestModeValues[m_zTestMode]); } if (m_offsetEnabled) { MasterNode.AddRenderState(ref result, "Offset ", m_offsetFactor + " , " + m_offsetUnits); } return(result); }
public override void Draw(DrawInfo drawInfo) { base.Draw(drawInfo); if (m_containerGraph.CurrentCanvasMode != NodeAvailability.TemplateShader) { return; } if (m_interpolatorData == null || m_interpolatorData.Count == 0) { MasterNode masterNode = m_containerGraph.CurrentMasterNode; if (masterNode.CurrentMasterNodeCategory == AvailableShaderTypes.Template) { TemplateData currentTemplate = (masterNode as TemplateMasterNode).CurrentTemplate; if (currentTemplate != null) { m_inVarName = currentTemplate.FragFunctionData.InVarName + "."; m_interpolatorData = currentTemplate.InterpolatorData.Interpolators; m_fetchDataId = true; } } } if (m_fetchDataId) { m_fetchDataId = false; FetchDataId(); } if (m_currentDataIdx > -1) { EditorGUI.BeginChangeCheck(); m_currentDataIdx = m_upperLeftWidgetHelper.DrawWidget(this, m_currentDataIdx, m_dataLabels); if (EditorGUI.EndChangeCheck()) { UpdateFromId(); } } }
public override void OnMasterNodeReplaced(MasterNode newMasterNode) { base.OnMasterNodeReplaced(newMasterNode); if (newMasterNode.CurrentMasterNodeCategory == AvailableShaderTypes.Template) { TemplateData currentTemplate = (newMasterNode as TemplateMasterNode).CurrentTemplate; if (currentTemplate != null) { m_localVarsData = currentTemplate.LocalVarsList; FetchDataId(); } else { m_localVarsData = null; m_currentDataIdx = -1; } } else { m_localVarsData = null; m_currentDataIdx = -1; } }
public override void OnMasterNodeReplaced( MasterNode newMasterNode ) { base.OnMasterNodeReplaced( newMasterNode ): m_functionGraph.FireMasterNodeReplacedEvent( newMasterNode ): StandardSurfaceOutputNode surface = newMasterNode as StandardSurfaceOutputNode: if( surface != null ) { surface.AdditionalDirectives.AddShaderFunctionItems( Function.AdditionalDirectives.DirectivesList ): } else { if( ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.Count > 0 ) { List<TemplateMultiPassMasterNode> nodes = ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.NodesList: int count = nodes.Count: for( int i = 0: i < count: i++ ) { nodes[ i ].PassModule.AdditionalDirectives.AddShaderFunctionItems( Function.AdditionalDirectives.DirectivesList ): } } } }
public override void OnMasterNodeReplaced(MasterNode newMasterNode) { base.OnMasterNodeReplaced(newMasterNode); if (newMasterNode.CurrentMasterNodeCategory == AvailableShaderTypes.Template) { TemplateData currentTemplate = (newMasterNode as TemplateMasterNode).CurrentTemplate; if (currentTemplate != null) { m_inVarName = currentTemplate.FragFunctionData.InVarName + "."; m_interpolatorData = currentTemplate.InterpolatorData.Interpolators; FetchDataId(); } else { m_interpolatorData = null; m_currentDataIdx = -1; } } else { m_interpolatorData = null; m_currentDataIdx = -1; } }
public void CopyPropertyListFrom(MasterNode masterNode) { m_lastCount = masterNode.ReordableListLastCount; m_propertyNodesVisibleList.Clear(); m_propertyNodesVisibleList.AddRange(masterNode.PropertyNodesVisibleList); }
public void DuplicateMe() { bool previewOpen = m_showPreview; string allOptions = m_allFunctionSwitches.Count.ToString(); for (int i = 0; i < m_allFunctionSwitches.Count; i++) { allOptions += "," + m_allFunctionSwitches[i].UniqueId + "," + m_allFunctionSwitches[i].GetCurrentSelectedInput(); } ReadOptionsHelper = allOptions.Split(','); ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph; ContainerGraph.ParentWindow.CustomGraph = null; MasterNode masterNode = ContainerGraph.ParentWindow.CurrentGraph.CurrentMasterNode; if (masterNode != null) { masterNode.InvalidateMaterialPropertyCount(); } ContainerGraph.ParentWindow.CustomGraph = cachedGraph; ParentNode newNode = ContainerGraph.CreateNode(m_function, false, Vec2Position); newNode.ShowPreview = previewOpen; (newNode as FunctionNode).ReadOptionsHelper = ReadOptionsHelper; newNode.RefreshExternalReferences(); if ((newNode as FunctionNode).m_reordenator && m_reordenator) { (newNode as FunctionNode).m_reordenator.OrderIndex = m_reordenator.OrderIndex; } for (int i = 0; i < m_outputPorts.Count; i++) { if (m_outputPorts[i].IsConnected) { OutputPort newOutputPort = newNode.GetOutputPortByUniqueId(m_outputPorts[i].PortId); if (newNode.OutputPorts != null && newOutputPort != null) { for (int j = m_outputPorts[i].ExternalReferences.Count - 1; j >= 0; j--) { ContainerGraph.CreateConnection(m_outputPorts[i].ExternalReferences[j].NodeId, m_outputPorts[i].ExternalReferences[j].PortId, newOutputPort.NodeId, newOutputPort.PortId); } } } //else //{ //if( newNode.OutputPorts != null && newNode.OutputPorts[ i ] != null ) //{ // ContainerGraph.DeleteConnection( false, newNode.UniqueId, newNode.OutputPorts[ i ].PortId, false, false, false ); //} //} } for (int i = 0; i < m_inputPorts.Count; i++) { if (m_inputPorts[i].IsConnected) { InputPort newInputPort = newNode.GetInputPortByUniqueId(m_inputPorts[i].PortId); if (newNode.InputPorts != null && newInputPort != null) { ContainerGraph.CreateConnection(newInputPort.NodeId, newInputPort.PortId, m_inputPorts[i].ExternalReferences[0].NodeId, m_inputPorts[i].ExternalReferences[0].PortId); } } } ContainerGraph.OnDuplicateEvent -= DuplicateMe; if (Selected) { ContainerGraph.DeselectNode(this); ContainerGraph.SelectNode(newNode, true, false); } ContainerGraph.DestroyNode(this, false); }
public override void RefreshExternalReferences() { base.RefreshExternalReferences(); if (Function == null) { return; } //Debug.Log( "RefreshExternalReferences " + m_function.FunctionName + " " + UIUtils.CurrentWindow.IsShaderFunctionWindow ); Function.UpdateDirectivesList(); MasterNode masterNode = UIUtils.CurrentWindow.OutsideGraph.CurrentMasterNode; StandardSurfaceOutputNode surface = masterNode as StandardSurfaceOutputNode; if (surface != null) { //for( int i = 0; i < Function.AdditionalIncludes.IncludeList.Count; i++ ) //{ // //ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Add( Function.AdditionalIncludes.IncludeList[ i ] ); // ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.AddShaderFunctionItem( AdditionalLineType.Include, Function.AdditionalIncludes.IncludeList[ i ] ); // m_includes.Add( Function.AdditionalIncludes.IncludeList[ i ] ); //} //for( int i = 0; i < Function.AdditionalPragmas.PragmaList.Count; i++ ) //{ // //ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Add( Function.AdditionalPragmas.PragmaList[ i ] ); // ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.AddShaderFunctionItem(AdditionalLineType.Pragma, Function.AdditionalPragmas.PragmaList[ i ] ); // m_pragmas.Add( Function.AdditionalPragmas.PragmaList[ i ] ); //} surface.AdditionalDirectives.AddShaderFunctionItems(Function.AdditionalDirectives.DirectivesList); } else { if (ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.Count > 0) { List <TemplateMultiPassMasterNode> nodes = ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.NodesList; int count = nodes.Count; for (int i = 0; i < count; i++) { nodes[i].PassModule.AdditionalDirectives.AddShaderFunctionItems(Function.AdditionalDirectives.DirectivesList); } } else { // Assuring that we're not editing a Shader Function, as directives setup is not needed there if (!UIUtils.CurrentWindow.IsShaderFunctionWindow) { // This function is nested inside a shader function itself and this method // was called before the main output node was created. // This is possible since all nodes RefreshExternalReferences(...) are called at the end // of a LoadFromMeta // Need to delay this setup to after all nodes are loaded to then setup the directives m_lateRefresh = true; return; } } } m_directives.AddRange(Function.AdditionalDirectives.DirectivesList); if (m_refreshIdsRequired) { m_refreshIdsRequired = false; int inputCount = m_inputPorts.Count; for (int i = 0; i < inputCount; i++) { m_inputPorts[i].ChangePortId(m_allFunctionInputs[i].UniqueId); } int outputCount = m_outputPorts.Count; for (int i = 0; i < outputCount; i++) { m_outputPorts[i].ChangePortId(m_allFunctionOutputs[i].UniqueId); } } if (ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph) { ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount += m_functionGraph.InstancePropertyCount; } ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph; ContainerGraph.ParentWindow.CustomGraph = m_functionGraph; if (ReadOptionsHelper.Length > 2) { for (int i = 1; i < ReadOptionsHelper.Length; i += 2) { int optionId = Convert.ToInt32(ReadOptionsHelper[i]); int optionValue = Convert.ToInt32(ReadOptionsHelper[i + 1]); for (int j = 0; j < m_allFunctionSwitches.Count; j++) { if (m_allFunctionSwitches[j].UniqueId == optionId) { m_allFunctionSwitches[j].SetCurrentSelectedInput(optionValue, m_allFunctionSwitches[j].GetCurrentSelectedInput()); break; } } } } ContainerGraph.ParentWindow.CustomGraph = cachedGraph; m_portsChanged = true; }
public void Draw(Rect graphArea, Vector2 mousePos, Shader currentShader, Material currentMaterial, float usableArea, float leftPos, float rightPos /*, bool showLastSelection*/) { if (m_init) { m_init = false; GUIStyle shaderModeTitle = UIUtils.GetCustomStyle(CustomStyle.ShaderModeTitle); GUIStyle shaderModeNoShader = UIUtils.GetCustomStyle(CustomStyle.ShaderModeNoShader); GUIStyle materialModeTitle = UIUtils.GetCustomStyle(CustomStyle.MaterialModeTitle); GUIStyle shaderNoMaterialModeTitle = UIUtils.GetCustomStyle(CustomStyle.ShaderNoMaterialModeTitle); ConfigStyle(shaderModeTitle); ConfigStyle(shaderModeNoShader); ConfigStyle(materialModeTitle); ConfigStyle(shaderNoMaterialModeTitle); } Color buffereredColor = GUI.color; MasterNode currentMasterNode = ParentWindow.CurrentGraph.CurrentMasterNode; // Shader Mode if (currentMasterNode != null) { m_leftButtonStyle = UIUtils.GetCustomStyle(currentShader == null ? CustomStyle.ShaderModeNoShader : CustomStyle.ShaderModeTitle); m_leftButtonRect = graphArea; m_leftButtonRect.x = 10 + leftPos; m_leftButtonRect.y += m_leftButtonRect.height - 38 - 15; string shaderName = (currentShader != null) ? (currentShader.name) : NoShaderStr; m_auxContent = new GUIContent("<size=20>SHADER</size>\n" + shaderName); m_auxVector2 = m_leftButtonStyle.CalcSize(m_auxContent); m_leftButtonRect.width = m_auxVector2.x + 30 + 4; m_leftButtonRect.height = 38; GUI.color = m_leftButtonRect.Contains(mousePos) ? OverallColorOn : OverallColorOff; if (GUI.Button(m_leftButtonRect, m_auxContent, m_leftButtonStyle) && currentShader != null) { Selection.activeObject = currentShader; EditorGUIUtility.PingObject(Selection.activeObject); } // Material Mode if (currentMaterial != null) { m_rightButtonStyle = UIUtils.GetCustomStyle(CustomStyle.MaterialModeTitle); m_rightButtonRect = graphArea; string matName = (currentMaterial != null) ? (currentMaterial.name) : NoMaterialStr; m_auxContent = new GUIContent("<size=20>MATERIAL</size>\n" + matName); m_auxVector2 = m_rightButtonStyle.CalcSize(m_auxContent); m_rightButtonRect.width = m_auxVector2.x + 30 + 4; m_rightButtonRect.height = 38; m_rightButtonRect.x = graphArea.xMax - m_rightButtonRect.width - rightPos - 10; m_rightButtonRect.y = graphArea.yMax - 38 - 15; GUI.color = m_rightButtonRect.Contains(mousePos) ? OverallColorOn : OverallColorOff; if (GUI.Button(m_rightButtonRect, m_auxContent, m_rightButtonStyle)) { Selection.activeObject = currentMaterial; EditorGUIUtility.PingObject(Selection.activeObject); } } } // Shader Function else if (currentMasterNode == null && ParentWindow.CurrentGraph.CurrentOutputNode != null) { m_leftButtonStyle = UIUtils.GetCustomStyle(CustomStyle.ShaderFunctionMode); m_leftButtonRect = graphArea; m_leftButtonRect.x = 10 + leftPos; m_leftButtonRect.y += m_leftButtonRect.height - 38 - 15; string functionName = (ParentWindow.CurrentGraph.CurrentShaderFunction != null) ? (ParentWindow.CurrentGraph.CurrentShaderFunction.name) : "No Shader Function"; m_auxContent = new GUIContent("<size=20>SHADER FUNCTION</size>\n" + functionName); m_auxVector2 = m_leftButtonStyle.CalcSize(m_auxContent); m_leftButtonRect.width = m_auxVector2.x + 30 + 4; m_leftButtonRect.height = 38; GUI.color = m_leftButtonRect.Contains(mousePos) ? OverallColorOn : OverallColorOff; if (GUI.Button(m_leftButtonRect, m_auxContent, m_leftButtonStyle) && ParentWindow.CurrentGraph.CurrentShaderFunction != null) { Selection.activeObject = ParentWindow.CurrentGraph.CurrentShaderFunction; EditorGUIUtility.PingObject(Selection.activeObject); } } GUI.color = buffereredColor; }
public override void RefreshExternalReferences() { base.RefreshExternalReferences(); if( Function == null ) return; Function.UpdateDirectivesList(); MasterNode masterNode = ContainerGraph.ParentWindow.OutsideGraph.CurrentMasterNode; StandardSurfaceOutputNode surface = masterNode as StandardSurfaceOutputNode; if( surface != null ) { //for( int i = 0; i < Function.AdditionalIncludes.IncludeList.Count; i++ ) //{ // //ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Add( Function.AdditionalIncludes.IncludeList[ i ] ); // ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.AddShaderFunctionItem( AdditionalLineType.Include, Function.AdditionalIncludes.IncludeList[ i ] ); // m_includes.Add( Function.AdditionalIncludes.IncludeList[ i ] ); //} //for( int i = 0; i < Function.AdditionalPragmas.PragmaList.Count; i++ ) //{ // //ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Add( Function.AdditionalPragmas.PragmaList[ i ] ); // ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.AddShaderFunctionItem(AdditionalLineType.Pragma, Function.AdditionalPragmas.PragmaList[ i ] ); // m_pragmas.Add( Function.AdditionalPragmas.PragmaList[ i ] ); //} surface.AdditionalDirectives.AddShaderFunctionItems( Function.AdditionalDirectives.DirectivesList ); } else { if( ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.Count > 0 ) { List<TemplateMultiPassMasterNode> nodes = ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.NodesList; int count = nodes.Count; for( int i = 0; i < count; i++ ) { nodes[ i ].PassModule.AdditionalDirectives.AddShaderFunctionItems( Function.AdditionalDirectives.DirectivesList ); } } } m_directives.AddRange( Function.AdditionalDirectives.DirectivesList ); if( m_refreshIdsRequired ) { m_refreshIdsRequired = false; int inputCount = m_inputPorts.Count; for( int i = 0; i < inputCount; i++ ) { m_inputPorts[ i ].ChangePortId( m_allFunctionInputs[ i ].UniqueId ); } int outputCount = m_outputPorts.Count; for( int i = 0; i < outputCount; i++ ) { m_outputPorts[ i ].ChangePortId( m_allFunctionOutputs[ i ].UniqueId ); } } if( ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph ) ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount += m_functionGraph.InstancePropertyCount; ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph; ContainerGraph.ParentWindow.CustomGraph = m_functionGraph; if( ReadOptionsHelper.Length > 2 ) { for( int i = 1; i < ReadOptionsHelper.Length; i += 2 ) { int optionId = Convert.ToInt32( ReadOptionsHelper[ i ] ); int optionValue = Convert.ToInt32( ReadOptionsHelper[ i + 1 ] ); for( int j = 0; j < m_allFunctionSwitches.Count; j++ ) { if( m_allFunctionSwitches[ j ].UniqueId == optionId ) { m_allFunctionSwitches[ j ].SetCurrentSelectedInput( optionValue, m_allFunctionSwitches[ j ].GetCurrentSelectedInput() ); break; } } } } ContainerGraph.ParentWindow.CustomGraph = cachedGraph; m_portsChanged = true; }
public void Draw(Rect graphArea, Vector2 mousePos, Shader currentShader, Material currentMaterial, float usableArea, float leftPos, float rightPos /*, bool showLastSelection*/) { EventType currentEventType = Event.current.type; if (!(currentEventType == EventType.Repaint || currentEventType == EventType.MouseDown)) { return; } if (m_init) { m_init = false; GUIStyle shaderModeTitle = UIUtils.GetCustomStyle(CustomStyle.ShaderModeTitle); GUIStyle shaderModeNoShader = UIUtils.GetCustomStyle(CustomStyle.ShaderModeNoShader); GUIStyle materialModeTitle = UIUtils.GetCustomStyle(CustomStyle.MaterialModeTitle); GUIStyle shaderNoMaterialModeTitle = UIUtils.GetCustomStyle(CustomStyle.ShaderNoMaterialModeTitle); ConfigStyle(shaderModeTitle); ConfigStyle(shaderModeNoShader); ConfigStyle(materialModeTitle); ConfigStyle(shaderNoMaterialModeTitle); } Color buffereredColor = GUI.color; MasterNode currentMasterNode = ParentWindow.CurrentGraph.CurrentMasterNode; // Shader Mode if (currentMasterNode != null) { m_leftButtonStyle = UIUtils.GetCustomStyle(currentShader == null ? CustomStyle.ShaderModeNoShader : CustomStyle.ShaderModeTitle); m_leftButtonRect = graphArea; m_leftButtonRect.x = 10 + leftPos; m_leftButtonRect.y += m_leftButtonRect.height - 38 - 15; string shaderName = (currentShader != null) ? (currentShader.name) : NoShaderStr; if (m_previousShaderName != shaderName) { m_previousShaderName = shaderName; m_leftAuxContent.text = "<size=20>SHADER</size>\n" + shaderName; } m_auxVector2 = m_leftButtonStyle.CalcSize(m_leftAuxContent); m_leftButtonRect.width = m_auxVector2.x + 30 + 4; m_leftButtonRect.height = 38; bool mouseOnTop = m_leftButtonRect.Contains(mousePos); GUI.color = mouseOnTop ? OverallColorOn : OverallColorOff; GUI.Label(m_leftButtonRect, m_leftAuxContent, m_leftButtonStyle); if (currentEventType == EventType.MouseDown && mouseOnTop && currentShader != null) { Event.current.Use(); Selection.activeObject = currentShader; EditorGUIUtility.PingObject(Selection.activeObject); } // Material Mode if (currentMaterial != null) { m_rightButtonStyle = UIUtils.GetCustomStyle(CustomStyle.MaterialModeTitle); m_rightButtonRect = graphArea; string matName = (currentMaterial != null) ? (currentMaterial.name) : NoMaterialStr; if (m_previousMaterialName != matName) { m_previousMaterialName = matName; m_rightAuxContent.text = "<size=20>MATERIAL</size>\n" + matName; } m_auxVector2 = m_rightButtonStyle.CalcSize(m_rightAuxContent); m_rightButtonRect.width = m_auxVector2.x + 30 + 4; m_rightButtonRect.height = 38; m_rightButtonRect.x = graphArea.xMax - m_rightButtonRect.width - rightPos - 10; m_rightButtonRect.y = graphArea.yMax - 38 - 15; bool mouseOnTopRight = m_rightButtonRect.Contains(mousePos); GUI.color = mouseOnTopRight ? OverallColorOn : OverallColorOff; GUI.Label(m_rightButtonRect, m_rightAuxContent, m_rightButtonStyle); if (currentEventType == EventType.MouseDown && mouseOnTopRight) { Event.current.Use(); Selection.activeObject = currentMaterial; EditorGUIUtility.PingObject(Selection.activeObject); } } } // Shader Function else if (currentMasterNode == null && ParentWindow.CurrentGraph.CurrentOutputNode != null) { m_leftButtonStyle = UIUtils.GetCustomStyle(CustomStyle.ShaderFunctionMode); m_leftButtonRect = graphArea; m_leftButtonRect.x = 10 + leftPos; m_leftButtonRect.y += m_leftButtonRect.height - 38 - 15; string functionName = (ParentWindow.CurrentGraph.CurrentShaderFunction != null) ? (ParentWindow.CurrentGraph.CurrentShaderFunction.name) : "No Shader Function"; if (m_previousShaderFunctionName != functionName) { m_previousShaderFunctionName = functionName; m_leftAuxContent.text = "<size=20>SHADER FUNCTION</size>\n" + functionName; } m_auxVector2 = m_leftButtonStyle.CalcSize(m_leftAuxContent); m_leftButtonRect.width = m_auxVector2.x + 30 + 4; m_leftButtonRect.height = 38; bool mouseOnTop = m_leftButtonRect.Contains(mousePos); GUI.color = mouseOnTop ? OverallColorOn : OverallColorOff; GUI.Label(m_leftButtonRect, m_leftAuxContent, m_leftButtonStyle); if (currentEventType == EventType.MouseDown && mouseOnTop && ParentWindow.CurrentGraph.CurrentShaderFunction != null) { Event.current.Use(); Selection.activeObject = ParentWindow.CurrentGraph.CurrentShaderFunction; EditorGUIUtility.PingObject(Selection.activeObject); } } GUI.color = buffereredColor; }