Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support asmdef Root Namespace option #228

Merged

Conversation

c3-hoge-fuga-piyo
Copy link
Contributor

@c3-hoge-fuga-piyo c3-hoge-fuga-piyo commented May 13, 2021

Unity 2020.2よりアセンブリ定義ファイルに Root Namespace オプションと、それに対応する #ROOTNAMESPACEBEGIN# / #ROOTNAMESPACEEND# というスクリプトテンプレート向けのキーワードが追加されており、LifetimeScope のテンプレートコードでも対応できたらと思いPRを作成させていただきました。

    #ROOTNAMESPACEBEGIN#
class X
{
}
#ROOTNAMESPACEEND#

👇

namespace <Root Namespaceで設定した文字列>
{
    // #ROOTNAMESPACEBEGIN# の前に入れた空白分インデントされる
    class X
    {
    }
}

internal な Unity API が必要なためリフレクションを使用しておりますが、こちらが問題になりそうであれば このコミット だけでも取り入れていただければと思います 🙇 (先にやる必要のない文字列処理を後で行うように変更いたしました)

※リフレクションを避けるためにスクリプトテンプレートをどこかに配置して ProjectWindowUtil. CreateScriptAssetFromTemplateFile を使うような形も検討しましたが、余計なファイルが増えてしまうため現在の形で対応いたしました。

@vercel
Copy link

vercel bot commented May 13, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/hadashia/vcontainer/55bRpPqGKfSwMkKVqWyhdKB55Ekm
✅ Preview: https://vcontainer-git-fork-c3-hoge-fuga-piyo-supportassembl-152009.vercel.app

@hadashiA
Copy link
Owner

hadashiA commented May 17, 2021

内容は 👍 です。ありがとうございます。

internal な Unity API が必要なためリフレクションを使用して

Unityのバージョンによって差異がでた場合の検知や保守が少し不安です 🤔

この機能については、ユーザが自由に書いたテンプレートに対応する必要はなく、
定数文字列 に対しての 変数展開が できれば十分だと思うので、
簡単に自前で RemoveOrInsertNamespace 相当 のもっと簡単な版を書いてしまえば良いかな- と思ったのですが、どうでしょう

( 元のメソッドは あらゆる改行コードやインデント状況に対応していますが、最初から 行のList をキメ打ちで用意してしまうとかでも良いかな- など

@c3-hoge-fuga-piyo
Copy link
Contributor Author

簡単に自前で RemoveOrInsertNamespace 相当 のもっと簡単な版

保守面でのコストやテンプレが固定であり最低限の機能があれば良い点などおっしゃる通りだと思いますので、こちら対応いたします 🙇

@c3-hoge-fuga-piyo
Copy link
Contributor Author

aebf6b5

このような形に簡略化してみました 🙇

AssetDatabase.Refresh();
for (var i = startAt + 1; i < endAt; ++i)
{
lines[i] = $" {lines[i]}";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

現在のテンプレートには空行が存在しないので 空行チェック は省きました

@hadashiA
Copy link
Owner

ありがとうございます 👍

@hadashiA hadashiA merged commit 0619d38 into hadashiA:master May 19, 2021
@c3-hoge-fuga-piyo c3-hoge-fuga-piyo deleted the support_assembly_root_namespace branch May 19, 2021 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants