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
|
using UnityEngine;
using UnityEditor;
using System;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic;
namespace AmplifyShaderEditor
{
[CustomEditor( typeof( AmplifyShaderFunction ) )]
public class AmplifyShaderFunctionEditor : Editor
{
class FunctionDependency
{
public string AssetName;
public string AssetPath;
public FunctionDependency(string name, string path)
{
AssetName = name;
AssetPath = path;
}
}
AmplifyShaderFunction m_target;
List<FunctionDependency> m_dependencies = new List<FunctionDependency>();
void OnEnable()
{
m_target = ( target as AmplifyShaderFunction );
}
public override void OnInspectorGUI()
{
//base.OnInspectorGUI();
//base.serializedObject.Update();
if( GUILayout.Button( "Open in Shader Editor" ) )
{
#if UNITY_2018_3_OR_NEWER
ASEPackageManagerHelper.SetupLateShaderFunction( m_target );
#else
AmplifyShaderEditorWindow.LoadShaderFunctionToASE( m_target, false );
#endif
}
//EditorGUILayout.Separator();
//m_target.FunctionInfo = EditorGUILayout.TextArea( m_target.FunctionInfo );
if( m_target.Description.Length > 0 )
{
EditorGUILayout.HelpBox( m_target.Description, MessageType.Info );
}
EditorGUILayout.Space();
if( GUILayout.Button( "Search Direct Dependencies" ) )
{
m_dependencies.Clear();
string guid = AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath( m_target ) );
string[] allSFs = AssetDatabase.FindAssets( "t:AmplifyShaderFunction", null );
foreach( string guid1 in allSFs )
{
string sfPath = AssetDatabase.GUIDToAssetPath( guid1 );
bool found = SearchForGUID( guid, sfPath );
if( found )
{
//string n = Regex.Replace( sfPath, @"(\.\w+|[\w\d\/]+\/)", "" );
string n = Regex.Replace( sfPath, @"[\w\d\/]+\/", "" );
m_dependencies.Add(new FunctionDependency( n, sfPath ) );
}
}
string[] allSHs = AssetDatabase.FindAssets( "t:Shader", null );
foreach( string guid1 in allSHs )
{
string shPath = AssetDatabase.GUIDToAssetPath( guid1 );
bool found = SearchForGUID( guid, shPath );
if( found )
{
string n = Regex.Replace( shPath, @"[\w\d\/]+\/", "" );
m_dependencies.Add( new FunctionDependency( n, shPath ) );
}
}
}
EditorGUILayout.Space();
for( int i = 0; i < m_dependencies.Count; i++ )
{
EditorGUILayout.BeginHorizontal();
if( GUILayout.Button( m_dependencies[ i ].AssetName, "minibuttonleft" ) )
{
SelectAtPath( m_dependencies[ i ].AssetPath );
}
if( GUILayout.Button( "edit", "minibuttonright", GUILayout.Width(100) ) )
{
if( m_dependencies[ i ].AssetName.EndsWith( ".asset" ) )
{
var obj = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( m_dependencies[ i ].AssetPath );
AmplifyShaderEditorWindow.LoadShaderFunctionToASE( obj, false );
}
else
{
var obj = AssetDatabase.LoadAssetAtPath<Shader>( m_dependencies[ i ].AssetPath );
AmplifyShaderEditorWindow.ConvertShaderToASE( obj );
}
}
EditorGUILayout.EndHorizontal();
}
}
public void SelectAtPath( string path )
{
var obj = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>( path );
EditorGUIUtility.PingObject( obj );
}
public static bool SearchForGUID( string guid, string pathName )
{
bool result = false;
int count = 0;
if( !string.IsNullOrEmpty( pathName ) && File.Exists( pathName ) )
{
StreamReader fileReader = null;
try
{
fileReader = new StreamReader( pathName );
string line;
int index = -1;
while( ( line = fileReader.ReadLine() ) != null )
{
index = line.IndexOf( guid );
count++;
if( index > -1 )
{
result = true;
break;
}
}
}
catch( Exception e )
{
Debug.LogException( e );
}
finally
{
if( fileReader != null )
fileReader.Close();
}
}
return result;
}
}
}
|