From b82da95b5181ac8bbae38efb13e950d5e88a4caa Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 23 Oct 2020 13:08:43 +0800 Subject: =?UTF-8?q?*=E7=A7=BB=E5=8A=A8amplify=20shader=20editor=E5=88=B0th?= =?UTF-8?q?ird=20party=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/Menu/AmplifyShaderFunctionEditor.cs | 152 +++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Menu/AmplifyShaderFunctionEditor.cs (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Menu/AmplifyShaderFunctionEditor.cs') diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Menu/AmplifyShaderFunctionEditor.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Menu/AmplifyShaderFunctionEditor.cs new file mode 100644 index 00000000..b5e3e4d4 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Menu/AmplifyShaderFunctionEditor.cs @@ -0,0 +1,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 m_dependencies = new List(); + + 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( m_dependencies[ i ].AssetPath ); + AmplifyShaderEditorWindow.LoadShaderFunctionToASE( obj, false ); + } + else + { + var obj = AssetDatabase.LoadAssetAtPath( m_dependencies[ i ].AssetPath ); + AmplifyShaderEditorWindow.ConvertShaderToASE( obj ); + } + } + EditorGUILayout.EndHorizontal(); + } + } + + public void SelectAtPath( string path ) + { + var obj = AssetDatabase.LoadAssetAtPath( 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; + } + } +} -- cgit v1.1-26-g67d0