1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
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<TemplateMultiPassMasterNode> 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<TemplateMultiPassMasterNode> 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; } }
}
}
|