From b82da95b5181ac8bbae38efb13e950d5e88a4caa Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 23 Oct 2020 13:08:43 +0800 Subject: =?UTF-8?q?*=E7=A7=BB=E5=8A=A8amplify=20shader=20editor=E5=88=B0th?= =?UTF-8?q?ird=20party=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/Templates/TemplateOptionsPort.cs | 174 +++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateOptionsPort.cs (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateOptionsPort.cs') diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateOptionsPort.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateOptionsPort.cs new file mode 100644 index 00000000..04c11872 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateOptionsPort.cs @@ -0,0 +1,174 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda + +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace AmplifyShaderEditor +{ + // PORT CONTROLLERS + [Serializable] + public class TemplateOptionPortItem + { + [SerializeField] + private int m_portId = -1; + + [SerializeField] + private TemplateOptionsItem m_options; + + public TemplateOptionPortItem( TemplateMultiPassMasterNode owner, TemplateOptionsItem options ) + { + m_options = options; + InputPort port = owner.InputPorts.Find( x => x.Name.Equals( options.Name ) ); + if( port != null ) + { + m_portId = port.PortId; + } + } + + public void FillDataCollector( TemplateMultiPassMasterNode owner, ref MasterNodeDataCollector dataCollector ) + { + InputPort port = null; + if( m_portId > -1 ) + { + port = owner.GetInputPortByUniqueId( m_portId ); + } + else + { + port = owner.InputPorts.Find( x => x.Name.Equals( m_options.Name ) ); + } + + if( port != null ) + { + int optionId = port.HasOwnOrLinkConnection ? 0 : 1; + for( int i = 0; i < m_options.ActionsPerOption[ optionId ].Length; i++ ) + { + switch( m_options.ActionsPerOption[ optionId ][ i ].ActionType ) + { + case AseOptionsActionType.SetDefine: + { + List nodes = owner.ContainerGraph.GetMultiPassMasterNodes( owner.LODIndex ); + int count = nodes.Count; + for( int nodeIdx = 0; nodeIdx < count; nodeIdx++ ) + { + nodes[ nodeIdx ].OptionsDefineContainer.AddDefine( "#define "+m_options.ActionsPerOption[ optionId ][ i ].ActionData, false ); + } + //dataCollector.AddToDefines( -1, m_options.ActionsPerOption[ optionId ][ i ].ActionData ); + } + break; + case AseOptionsActionType.SetUndefine: + { + List nodes = owner.ContainerGraph.GetMultiPassMasterNodes( owner.LODIndex ); + int count = nodes.Count; + for( int nodeIdx = 0; nodeIdx < count; nodeIdx++ ) + { + nodes[ nodeIdx ].OptionsDefineContainer.AddDefine( "#undef " + m_options.ActionsPerOption[ optionId ][ i ].ActionData, false ); + } + //dataCollector.AddToDefines( -1, m_options.ActionsPerOption[ optionId ][ i ].ActionData, false ); + } + break; + case AseOptionsActionType.SetShaderProperty: + { + TemplateShaderPropertyData data = owner.CurrentTemplate.GetShaderPropertyData( m_options.ActionsPerOption[ optionId ][ i ].ActionData ); + if( data != null ) + { + string newPropertyValue = data.CreatePropertyForValue( m_options.ActionsPerOption[ optionId ][ i ].ActionBuffer ); + owner.CurrentTemplate.IdManager.SetReplacementText( data.FullValue, newPropertyValue ); + } + } + break; + } + } + } + } + + public void SubShaderFillDataCollector( TemplateMultiPassMasterNode owner, ref MasterNodeDataCollector dataCollector ) + { + + //TemplateMultiPassMasterNode targetNode = string.IsNullOrEmpty(m_options.Id) ? owner:owner.ContainerGraph.GetMasterNodeOfPass( m_options.Id , owner.LODIndex ); + TemplateMultiPassMasterNode targetNode = string.IsNullOrEmpty( m_options.Id ) ? + owner.ContainerGraph.GetMainMasterNodeOfLOD( owner.LODIndex ) : + owner.ContainerGraph.GetMasterNodeOfPass( m_options.Id , owner.LODIndex ); + + InputPort port = null; + if( m_portId > -1 ) + { + port = targetNode.GetInputPortByUniqueId( m_portId ); + } + else + { + port = targetNode.InputPorts.Find( x => x.Name.Equals( m_options.Name ) ); + } + + if( port != null ) + { + int optionId = port.HasOwnOrLinkConnection ? 0 : 1; + for( int i = 0; i < m_options.ActionsPerOption[ optionId ].Length; i++ ) + { + if( string.IsNullOrEmpty( m_options.ActionsPerOption[ optionId ][ i ].PassName ) || + m_options.ActionsPerOption[ optionId ][ i ].PassName.Equals( owner.PassName ) ) + { + switch( m_options.ActionsPerOption[ optionId ][ i ].ActionType ) + { + case AseOptionsActionType.SetDefine: + { + owner.OptionsDefineContainer.AddDefine( "#define " + m_options.ActionsPerOption[ optionId ][ i ].ActionData, true ); + } + break; + case AseOptionsActionType.SetUndefine: + { + owner.OptionsDefineContainer.AddDefine( "#undef " + m_options.ActionsPerOption[ optionId ][ i ].ActionData, true ); + } + break; + case AseOptionsActionType.SetShaderProperty: + { + TemplateShaderPropertyData data = owner.CurrentTemplate.GetShaderPropertyData( m_options.ActionsPerOption[ optionId ][ i ].ActionData ); + if( data != null ) + { + string newPropertyValue = data.CreatePropertyForValue( m_options.ActionsPerOption[ optionId ][ i ].ActionBuffer ); + owner.CurrentTemplate.IdManager.SetReplacementText( data.FullValue, newPropertyValue ); + } + } + break; + } + } + } + } + } + + public void CheckImediateActionsForPort( TemplateMultiPassMasterNode owner, int portId ) + { + if( portId != m_portId ) + return; + + InputPort port = null; + if( m_portId > -1 ) + { + port = owner.GetInputPortByUniqueId( m_portId ); + } + else + { + port = owner.InputPorts.Find( x => x.Name.Equals( m_options.Name ) ); + } + + if( port != null ) + { + int optionId = port.HasOwnOrLinkConnection ? 0 : 1; + for( int i = 0; i < m_options.ActionsPerOption[ optionId ].Length; i++ ) + { + switch( m_options.ActionsPerOption[ optionId ][ i ].ActionType ) + { + case AseOptionsActionType.SetPortName: + { + port.Name = m_options.ActionsPerOption[ optionId ][ i ].ActionData; + owner.SizeIsDirty = true; + } + break; + } + } + } + } + public TemplateOptionsItem Options { get { return m_options; } } + } +} -- cgit v1.1-26-g67d0