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
|
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace AmplifyShaderEditor
{
[Serializable]
public class AdditionalPragmasHelper
{
private const string AdditionalPragmasStr = " Additional Pragmas";
private const float ShaderKeywordButtonLayoutWidth = 15;
private ParentNode m_currentOwner;
[SerializeField]
private List<string> m_additionalPragmas = new List<string>();
public List<string> PragmaList { get { return m_additionalPragmas; } set { m_additionalPragmas = value; } }
[SerializeField]
private List<string> m_outsidePragmas = new List<string>();
public List<string> OutsideList { get { return m_outsidePragmas; } set { m_outsidePragmas = value; } }
public void Draw( ParentNode owner )
{
m_currentOwner = owner;
bool value = owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedAdditionalPragmas;
NodeUtils.DrawPropertyGroup( ref value, AdditionalPragmasStr, DrawMainBody, DrawButtons );
owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedAdditionalPragmas = value;
}
void DrawButtons()
{
EditorGUILayout.Separator();
// Add keyword
if( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ShaderKeywordButtonLayoutWidth ) ) )
{
m_additionalPragmas.Add( string.Empty );
EditorGUI.FocusTextInControl( null );
}
//Remove keyword
if( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ShaderKeywordButtonLayoutWidth ) ) )
{
if( m_additionalPragmas.Count > 0 )
{
m_additionalPragmas.RemoveAt( m_additionalPragmas.Count - 1 );
EditorGUI.FocusTextInControl( null );
}
}
}
void DrawMainBody()
{
EditorGUILayout.Separator();
int itemCount = m_additionalPragmas.Count;
int markedToDelete = -1;
for( int i = 0; i < itemCount; i++ )
{
EditorGUILayout.BeginHorizontal();
{
EditorGUI.BeginChangeCheck();
m_additionalPragmas[ i ] = EditorGUILayout.TextField( m_additionalPragmas[ i ] );
if( EditorGUI.EndChangeCheck() )
{
m_additionalPragmas[ i ] = UIUtils.RemoveShaderInvalidCharacters( m_additionalPragmas[ i ] );
}
// Add new port
if( m_currentOwner.GUILayoutButton( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ShaderKeywordButtonLayoutWidth ) ) )
{
m_additionalPragmas.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();
}
if( markedToDelete > -1 )
{
if( m_additionalPragmas.Count > markedToDelete )
{
m_additionalPragmas.RemoveAt( markedToDelete );
EditorGUI.FocusTextInControl( null );
}
}
EditorGUILayout.Separator();
EditorGUILayout.HelpBox( "Please add your pragmas without the #pragma keywords", MessageType.Info );
}
public void ReadFromString( ref uint index, ref string[] nodeParams )
{
int count = Convert.ToInt32( nodeParams[ index++ ] );
for( int i = 0; i < count; i++ )
{
m_additionalPragmas.Add( nodeParams[ index++ ] );
}
}
public void WriteToString( ref string nodeInfo )
{
IOUtils.AddFieldValueToString( ref nodeInfo, m_additionalPragmas.Count );
for( int i = 0; i < m_additionalPragmas.Count; i++ )
{
IOUtils.AddFieldValueToString( ref nodeInfo, m_additionalPragmas[ i ] );
}
}
public void AddToDataCollector( ref MasterNodeDataCollector dataCollector )
{
for( int i = 0; i < m_additionalPragmas.Count; i++ )
{
if( !string.IsNullOrEmpty( m_additionalPragmas[ i ] ) )
dataCollector.AddToPragmas( -1, m_additionalPragmas[ i ] );
}
for( int i = 0; i < m_outsidePragmas.Count; i++ )
{
if( !string.IsNullOrEmpty( m_outsidePragmas[ i ] ) )
dataCollector.AddToPragmas( -1, m_outsidePragmas[ i ] );
}
}
public void Destroy()
{
m_additionalPragmas.Clear();
m_additionalPragmas = null;
m_currentOwner = null;
}
}
}
|