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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEditor;
using UnityEngine;
namespace AmplifyShaderEditor
{
[System.Serializable]
public sealed class OutputPort : WirePort
{
public delegate void OnNewPreviewRTCreated();
public OnNewPreviewRTCreated OnNewPreviewRTCreatedEvent;
[SerializeField]
private bool m_connectedToMasterNode;
[SerializeField]
private bool[] m_isLocalValue = { false, false};
[SerializeField]
private string[] m_localOutputValue = { string.Empty,string.Empty};
//[SerializeField]
//private int m_isLocalWithPortType = 0;
private RenderTexture m_outputPreview = null;
private Material m_outputMaskMaterial = null;
private int m_indexPreviewOffset = 0;
public OutputPort( ParentNode owner, int nodeId, int portId, WirePortDataType dataType, string name ) : base( nodeId, portId, dataType, name )
{
LabelSize = Vector2.zero;
OnNewPreviewRTCreatedEvent += owner.SetPreviewDirtyFromOutputs;
}
public string ErrorValue
{
get
{
string value = string.Empty;
switch( m_dataType )
{
default:
case WirePortDataType.OBJECT:
case WirePortDataType.INT:
case WirePortDataType.FLOAT: value = "(0)"; break;
case WirePortDataType.FLOAT2: value = "half2(0,0)"; break;
case WirePortDataType.FLOAT3: value = "half3(0,0,0)"; break;
case WirePortDataType.COLOR:
case WirePortDataType.FLOAT4: value = "half4(0,0,0,0)"; break;
case WirePortDataType.FLOAT3x3: value = "half3x3(0,0,0,0,0,0,0,0,0)"; break;
case WirePortDataType.FLOAT4x4: value = "half4x4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)"; break;
}
return value;
}
}
public bool ConnectedToMasterNode
{
get { return m_connectedToMasterNode; }
set { m_connectedToMasterNode = value; }
}
public override void FullDeleteConnections()
{
UIUtils.DeleteConnection( false, m_nodeId, m_portId, true, true );
}
public bool HasConnectedNode
{
get
{
int count = m_externalReferences.Count;
for( int i = 0; i < count; i++ )
{
if( UIUtils.GetNode( m_externalReferences[ i ].NodeId ).IsConnected )
return true;
}
return false;
}
}
public InputPort GetInputConnection( int connID = 0 )
{
if( connID < m_externalReferences.Count )
{
return UIUtils.GetNode( m_externalReferences[ connID ].NodeId ).GetInputPortByUniqueId( m_externalReferences[ connID ].PortId );
}
return null;
}
public ParentNode GetInputNode( int connID = 0 )
{
if( connID < m_externalReferences.Count )
{
return UIUtils.GetNode( m_externalReferences[ connID ].NodeId );
}
return null;
}
public override void NotifyExternalRefencesOnChange()
{
for( int i = 0; i < m_externalReferences.Count; i++ )
{
ParentNode node = UIUtils.GetNode( m_externalReferences[ i ].NodeId );
if( node )
{
node.CheckSpherePreview();
InputPort port = node.GetInputPortByUniqueId( m_externalReferences[ i ].PortId );
port.UpdateInfoOnExternalConn( m_nodeId, m_portId, m_dataType );
node.OnConnectedOutputNodeChanges( m_externalReferences[ i ].PortId, m_nodeId, m_portId, m_name, m_dataType );
}
}
}
public void ChangeTypeWithRestrictions( WirePortDataType newType, int restrictions )
{
if( m_dataType != newType )
{
DataType = newType;
for( int i = 0; i < m_externalReferences.Count; i++ )
{
ParentNode inNode = UIUtils.GetNode( m_externalReferences[ i ].NodeId );
InputPort inputPort = inNode.GetInputPortByUniqueId( m_externalReferences[ i ].PortId );
bool valid = false;
if( restrictions == 0 )
{
valid = true;
}
else
{
valid = ( restrictions & (int)inputPort.DataType ) != 0;
}
if( valid )
{
inNode.CheckSpherePreview();
inputPort.UpdateInfoOnExternalConn( m_nodeId, m_portId, m_dataType );
inNode.OnConnectedOutputNodeChanges( m_externalReferences[ i ].PortId, m_nodeId, m_portId, m_name, m_dataType );
}
else
{
InvalidateConnection( m_externalReferences[ i ].NodeId, m_externalReferences[ i ].PortId );
inputPort.InvalidateConnection( NodeId, PortId );
i--;
}
}
}
}
public override void ChangePortId( int newPortId )
{
if( IsConnected )
{
int count = ExternalReferences.Count;
for( int connIdx = 0; connIdx < count; connIdx++ )
{
int nodeId = ExternalReferences[ connIdx ].NodeId;
int portId = ExternalReferences[ connIdx ].PortId;
ParentNode node = UIUtils.GetNode( nodeId );
if( node != null )
{
InputPort inputPort = node.GetInputPortByUniqueId( portId );
int inputCount = inputPort.ExternalReferences.Count;
for( int j = 0; j < inputCount; j++ )
{
if( inputPort.ExternalReferences[ j ].NodeId == NodeId &&
inputPort.ExternalReferences[ j ].PortId == PortId )
{
inputPort.ExternalReferences[ j ].PortId = newPortId;
}
}
}
}
}
PortId = newPortId;
}
public string ConfigOutputLocalValue( PrecisionType precisionType, string value, string customName, MasterNodePortCategory category )
{
int idx = UIUtils.PortCategorytoAttayIdx( category );
ParentGraph currentGraph = UIUtils.GetNode( NodeId ).ContainerGraph;
string autoGraphId = currentGraph.GraphId > 0 ? "_g" + currentGraph.GraphId : string.Empty;
m_localOutputValue[idx] = string.IsNullOrEmpty( customName ) ? ( "temp_output_" + m_nodeId + "_" + PortId + autoGraphId ) : customName;
m_isLocalValue[idx] = true;
//m_isLocalWithPortType |= (int)category;
return string.Format( Constants.LocalValueDecWithoutIdent, UIUtils.PrecisionWirePortToCgType( precisionType, DataType ), m_localOutputValue[idx], value );
}
public void SetLocalValue( string value, MasterNodePortCategory category )
{
int idx = UIUtils.PortCategorytoAttayIdx( category );
m_isLocalValue[idx] = true;
m_localOutputValue[ idx ] = value;
//m_isLocalWithPortType |= (int)category;
}
public void ResetLocalValue()
{
for( int i = 0; i < m_localOutputValue.Length; i++ )
{
m_localOutputValue[ i ] = string.Empty;
m_isLocalValue[i] = false;
}
//m_isLocalWithPortType = 0;
}
public void ResetLocalValueIfNot( MasterNodePortCategory category )
{
int idx = UIUtils.PortCategorytoAttayIdx( category );
for( int i = 0; i < m_localOutputValue.Length; i++ )
{
if( i != idx )
{
m_localOutputValue[ i ] = string.Empty;
m_isLocalValue[ i ] = false;
}
}
}
public void ResetLocalValueOnCategory( MasterNodePortCategory category )
{
int idx = UIUtils.PortCategorytoAttayIdx( category );
m_localOutputValue[ idx ] = string.Empty;
m_isLocalValue[ idx ] = false;
}
public bool IsLocalOnCategory( MasterNodePortCategory category )
{
int idx = UIUtils.PortCategorytoAttayIdx( category );
return m_isLocalValue[ idx ];
//return ( m_isLocalWithPortType & (int)category ) != 0; ;
}
public override void ForceClearConnection()
{
UIUtils.DeleteConnection( false, m_nodeId, m_portId, false, true );
}
public bool IsLocalValue( MasterNodePortCategory category )
{
int idx = UIUtils.PortCategorytoAttayIdx( category );
return m_isLocalValue[ idx ];
}
public string LocalValue(MasterNodePortCategory category)
{
int idx = UIUtils.PortCategorytoAttayIdx( category );
return m_localOutputValue[idx];
}
public RenderTexture OutputPreviewTexture
{
get
{
if( m_outputPreview == null )
{
m_outputPreview = new RenderTexture( 128, 128, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear );
m_outputPreview.wrapMode = TextureWrapMode.Repeat;
if( OnNewPreviewRTCreatedEvent != null )
OnNewPreviewRTCreatedEvent();
}
return m_outputPreview;
}
set { m_outputPreview = value; }
}
public int IndexPreviewOffset
{
get { return m_indexPreviewOffset; }
set { m_indexPreviewOffset = value; }
}
public override void Destroy()
{
base.Destroy();
if( m_outputPreview != null )
UnityEngine.ScriptableObject.DestroyImmediate( m_outputPreview );
m_outputPreview = null;
if( m_outputMaskMaterial != null )
UnityEngine.ScriptableObject.DestroyImmediate( m_outputMaskMaterial );
m_outputMaskMaterial = null;
OnNewPreviewRTCreatedEvent = null;
}
public Material MaskingMaterial
{
get
{
if( m_outputMaskMaterial == null )
{
//m_outputMaskMaterial = new Material( AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "9c34f18ebe2be3e48b201b748c73dec0" ) ) );
m_outputMaskMaterial = new Material( UIUtils.MaskingShader );
}
return m_outputMaskMaterial;
}
//set { m_outputMaskMaterial = value; }
}
}
}
|