Created
March 24, 2018 18:23
-
-
Save techgeek1/31e777cc47b1d840ae8153554e1218a8 to your computer and use it in GitHub Desktop.
Post processor for excluding shader files from the csproj unity 2018 generates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SyntaxTree.VisualStudio.Unity.Bridge; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Xml.Linq; | |
using UnityEditor; | |
using UnityEngine; | |
// Post processor for excluding shader files from the csproj unity 2018 generates | |
[InitializeOnLoad] | |
public class CsprojPostProcessor : MonoBehaviour { | |
static CsprojPostProcessor() { | |
ProjectFilesGenerator.ProjectFileGeneration += ModifyProjectFile; | |
} | |
private static string ModifyProjectFile(string name, string content) { | |
XDocument document = XDocument.Parse(content); | |
var itemGroups = document.Root.Descendants() | |
.Where(node => node.Name.LocalName == "ItemGroup"); | |
IEnumerable<XElement> shaderGroups = itemGroups.Select(group => { | |
var child = group.Descendants() | |
.FirstOrDefault(); | |
if (child != null && child.Name.LocalName == "None") | |
return group; | |
return null; | |
}); | |
foreach(XElement group in shaderGroups) { | |
group?.RemoveAll(); | |
} | |
return document.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment