代码设置AlwaysIncludedShaders

作者:追风剑情 发布于:2018-12-11 15:52 分类:Unity3d

示例


// 将shader加到AlwaysIncludedShaders
public static void AlwaysIncludedShaders(Object folder)
{
	if (folder == null)
		return;

	string folder_path = AssetDatabase.GetAssetPath(folder);
	if (!AssetDatabase.IsValidFolder(folder_path)) {
		EditorUtility.DisplayDialog("Error", "请选中Shader所在文件夹", "OK");
		return;
	}
	
	//在用户所选中的文件夹下搜索所有Shader
	Shader[] shaders = Selection.GetFiltered<Shader>(SelectionMode.DeepAssets);
	if (shaders == null || shaders.Length == 0) {
		EditorUtility.DisplayDialog("Error", "未搜索到Shader文件", "OK");
		return;
	}

	//修改GraphicsSettings
	SerializedObject graphicsSettings = new SerializedObject(AssetDatabase.LoadAssetAtPath<Object>("ProjectSettings/GraphicsSettings.asset"));
	SerializedProperty m_AlwaysIncludedShaders = graphicsSettings.FindProperty("m_AlwaysIncludedShaders");
	m_AlwaysIncludedShaders.ClearArray();
	SerializedProperty element;
	for(int i=0; i<shaders.Length; i++) {
		m_AlwaysIncludedShaders.InsertArrayElementAtIndex(i);
		element = m_AlwaysIncludedShaders.GetArrayElementAtIndex(i);
		element.objectReferenceValue = shaders[i];
	}
	graphicsSettings.ApplyModifiedProperties();
}


效果

11111.png

Always-included Shaders中的shader会存放到游戏包中

1111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号   sitemap

川公网安备 51019002001593号