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
|
using System;
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace AmplifyShaderEditor
{
[Serializable]
public class AdditionalSurfaceOptionsHelper
{
private const string AdditionalOptionsStr = " Additional Surface Options";
private const float ShaderKeywordButtonLayoutWidth = 15;
private ParentNode m_currentOwner;
[SerializeField]
private List<string> m_availableOptions = new List<string>();
public void Draw( ParentNode owner )
{
m_currentOwner = owner;
bool value = owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedAdditionalSurfaceOptions;
NodeUtils.DrawPropertyGroup( ref value, AdditionalOptionsStr, DrawMainBody, DrawButtons );
owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedAdditionalSurfaceOptions = value;
}
void DrawButtons()
{
EditorGUILayout.Separator();
// Add tag
if( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ShaderKeywordButtonLayoutWidth ) ) )
{
m_availableOptions.Add( string.Empty );
EditorGUI.FocusTextInControl( null );
}
//Remove tag
if( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ShaderKeywordButtonLayoutWidth ) ) )
{
if( m_availableOptions.Count > 0 )
{
m_availableOptions.RemoveAt( m_availableOptions.Count - 1 );
EditorGUI.FocusTextInControl( null );
}
}
}
void DrawMainBody()
{
EditorGUILayout.Separator();
int itemCount = m_availableOptions.Count;
if( itemCount == 0 )
{
EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add one.", MessageType.Info );
}
int markedToDelete = -1;
float originalLabelWidth = EditorGUIUtility.labelWidth;
for( int i = 0; i < itemCount; i++ )
{
EditorGUI.indentLevel += 1;
EditorGUIUtility.labelWidth = 62;
EditorGUILayout.BeginHorizontal();
//Option
EditorGUI.BeginChangeCheck();
m_availableOptions[ i ] = EditorGUILayout.TextField( "["+i+"] -", m_availableOptions[ i ] );
if( EditorGUI.EndChangeCheck() )
{
m_availableOptions[ i ] = UIUtils.RemoveShaderInvalidCharacters( m_availableOptions[ i ] );
}
EditorGUIUtility.labelWidth = originalLabelWidth;
{
// Add new port
if( m_currentOwner.GUILayoutButton( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ShaderKeywordButtonLayoutWidth ) ) )
{
m_availableOptions.Insert( i + 1, string.Empty );
EditorGUI.FocusTextInControl( null );
}
//Remove port
if( m_currentOwner.GUILayoutButton( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ShaderKeywordButtonLayoutWidth ) ) )
{
markedToDelete = i;
}
}
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel -= 1;
}
if( markedToDelete > -1 )
{
if( m_availableOptions.Count > markedToDelete )
{
m_availableOptions.RemoveAt( markedToDelete );
EditorGUI.FocusTextInControl( null );
}
}
EditorGUILayout.Separator();
}
public void ReadFromString( ref uint index, ref string[] nodeParams )
{
int count = Convert.ToInt32( nodeParams[ index++ ] );
for( int i = 0; i < count; i++ )
{
m_availableOptions.Add( nodeParams[ index++ ] );
}
}
public void WriteToString( ref string nodeInfo )
{
int optionsCount = m_availableOptions.Count;
IOUtils.AddFieldValueToString( ref nodeInfo, optionsCount );
for( int i = 0; i < optionsCount; i++ )
{
IOUtils.AddFieldValueToString( ref nodeInfo, m_availableOptions[ i ].ToString() );
}
}
public void WriteToOptionalSurfaceOptions( ref string currentOptions )
{
int tagsCount = m_availableOptions.Count;
if( tagsCount == 0 )
return;
string result = " ";
for( int i = 0; i < tagsCount; i++ )
{
result += m_availableOptions[ i ];
if( i < tagsCount - 1 )
{
result += " ";
}
}
currentOptions = currentOptions + result;
}
public void Destroy()
{
m_availableOptions.Clear();
m_availableOptions = null;
m_currentOwner = null;
}
}
}
|