-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: retrievable types is preserved automatically
- Loading branch information
1 parent
f64afaa
commit 70abca4
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Xml; | ||
using UnityEditor; | ||
using UnityEditor.Build; | ||
using UnityEditor.Build.Reporting; | ||
using UnityEngine; | ||
using UnityEngine.Assertions; | ||
namespace com.bbbirder.unityeditor | ||
{ | ||
class BuildPreprocessor : IPreprocessBuildWithReport | ||
{ | ||
public int callbackOrder => 0; | ||
|
||
public void OnPreprocessBuild(BuildReport report) | ||
{ | ||
var assemblies = AppDomain.CurrentDomain.GetAssemblies() | ||
.Where(a => a.IsDefined(typeof(GeneratedDirectRetrieveAttribute))) | ||
; | ||
|
||
|
||
XmlDocument doc = new XmlDocument(); | ||
var eleLinker = doc.CreateElement("linker"); | ||
doc.AppendChild(eleLinker); | ||
foreach (var assembly in assemblies) | ||
{ | ||
var types = assembly.GetCustomAttributes<GeneratedDirectRetrieveAttribute>() | ||
.Select(dra => dra.type) | ||
; | ||
var eleAsm = doc.CreateElement("assembly"); | ||
eleAsm.SetAttribute("fullname", assembly.GetName().Name); | ||
eleLinker.AppendChild(eleAsm); | ||
foreach (var t in types) | ||
{ | ||
var eleType = doc.CreateElement("type"); | ||
eleType.SetAttribute("preserve", "all"); | ||
eleType.SetAttribute("fullname", t.FullName); | ||
eleAsm.AppendChild(eleType); | ||
} | ||
} | ||
|
||
var targetPath = $"Assets/Generated/{PackageUtils.GetPackageName()}/link.xml"; | ||
var targetDir = Path.GetDirectoryName(targetPath); | ||
if (!Directory.Exists(targetDir)) Directory.CreateDirectory(targetDir); | ||
File.WriteAllText(targetPath, doc.InnerXml); | ||
|
||
AssetDatabase.ImportAsset(targetPath); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "com.bbbirder.directattribute", | ||
"description": "Retrieve attributes and subtypes efficiently, meanwhile, retrieve target type and member directly from an attribute", | ||
"displayName": "Direct Attribute", | ||
"version": "1.1.6", | ||
"version": "1.1.8", | ||
"hideInEditor": false, | ||
"author": "bbbirder <[email protected]>" | ||
} |