private void SavePreprocessShaders() { ShaderToolsSetting.GetInstance().PreprocessShadersSettings.Clear(); for (int iPreprocessShaders = 0; iPreprocessShaders < m_PreprocessShadersForGUIs.Count; iPreprocessShaders++) { PreprocessShadersForGUI iterPreprocessShadersForGUI = m_PreprocessShadersForGUIs[iPreprocessShaders]; if (iterPreprocessShadersForGUI.Script == null || iterPreprocessShadersForGUI.Setting == null) { continue; } try { iterPreprocessShadersForGUI.Setting.OnSaveByGUI(); PreprocessShadersSetting preprocessShadersSetting = new PreprocessShadersSetting(); preprocessShadersSetting.MonoScriptGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(iterPreprocessShadersForGUI.Script)); preprocessShadersSetting.MonoScriptTypeFullName = iterPreprocessShadersForGUI.Script.GetClass().FullName; preprocessShadersSetting.SettingJson = JsonUtility.ToJson(iterPreprocessShadersForGUI.Setting); ShaderToolsSetting.GetInstance().PreprocessShadersSettings.Add(preprocessShadersSetting); } catch (Exception e) { MDebug.LogWarning("Shader", $"保存Shader处理失败\n{e.ToString()}"); } } }
public static ShaderToolsSetting GetInstance() { if (ms_Instance == null) { ms_Instance = Load <ShaderToolsSetting>(SETTING_NAME); } return(ms_Instance); }
private void LoadPreprocessShaders() { m_PreprocessShadersForGUIs.Clear(); List <PreprocessShadersSetting> preprocessShadersSettings = ShaderToolsSetting.GetInstance().PreprocessShadersSettings; for (int iPreprocessShaders = 0; iPreprocessShaders < preprocessShadersSettings.Count; iPreprocessShaders++) { PreprocessShadersSetting iterPreprocessShadersSetting = preprocessShadersSettings[iPreprocessShaders]; try { PreprocessShadersForGUI preprocessShadersForGUI = new PreprocessShadersForGUI(); preprocessShadersForGUI.Script = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(iterPreprocessShadersSetting.MonoScriptGUID)) as MonoScript; if (preprocessShadersForGUI.Script == null) { continue; } Type baseType = preprocessShadersForGUI.Script.GetClass(); while (true) { baseType = baseType.BaseType; if (baseType.IsGenericType) { break; } } Type settingType = baseType.GenericTypeArguments[0]; preprocessShadersForGUI.Setting = JsonUtility.FromJson(iterPreprocessShadersSetting.SettingJson , settingType) as BasePreprocessShadersSetting; if (preprocessShadersForGUI.Setting == null) { continue; } preprocessShadersForGUI.Setting.OnLoadByGUI(); m_PreprocessShadersForGUIs.Add(preprocessShadersForGUI); } catch (Exception e) { MDebug.LogWarning("Shader", $"加载Shader处理失败\n{e.ToString()}"); } } }
private void OnGUI_PreprocessShaders() { ShaderToolsSetting setting = ShaderToolsSetting.GetInstance(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("添加Shader处理")) { m_PreprocessShadersForGUIs.Add(new PreprocessShadersForGUI()); } if (GUILayout.Button("打包后")) { PreprocessShadersUtility.OnAfter(); } EditorGUILayout.EndHorizontal(); for (int iPreprocessShaders = 0; iPreprocessShaders < m_PreprocessShadersForGUIs.Count; iPreprocessShaders++) { PreprocessShadersForGUI iterPreprocessShadersForGUI = m_PreprocessShadersForGUIs[iPreprocessShaders]; EditorGUILayout.BeginHorizontal(); if (EGLUtility.ObjectField(out iterPreprocessShadersForGUI.Script, "处理脚本", iterPreprocessShadersForGUI.Script, true)) { if (iterPreprocessShadersForGUI.Script != null) { TryGenerateSetting(iPreprocessShaders, iterPreprocessShadersForGUI); } } if (GUILayout.Button("X", GUILayout.Width(32))) { m_PreprocessShadersForGUIs.RemoveAt(iPreprocessShaders); iPreprocessShaders--; continue; } EditorGUILayout.EndHorizontal(); if (iterPreprocessShadersForGUI.Setting != null) { iterPreprocessShadersForGUI.Setting.OnGUI(); } EditorGUILayout.Space(); } }
public override void OnGUI(string searchContext) { base.OnGUI(searchContext); if (GUILayout.Button("保存")) { SavePreprocessShaders(); ShaderToolsSetting.GetInstance().Save(); LoadPreprocessShaders(); } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); m_PreprocessShadersFoldout.Set(EditorGUILayout.Foldout(m_PreprocessShadersFoldout, "打包时Shader处理")); EditorGUILayout.EndHorizontal(); if (m_PreprocessShadersFoldout) { EditorGUI.indentLevel++; OnGUI_PreprocessShaders(); EditorGUI.indentLevel--; } }