Skip to content

プレハブの検査機能を追加#157

Open
ku6ryo wants to merge 15 commits intodevelopfrom
validation
Open

プレハブの検査機能を追加#157
ku6ryo wants to merge 15 commits intodevelopfrom
validation

Conversation

@ku6ryo
Copy link
Collaborator

@ku6ryo ku6ryo commented Sep 9, 2024

  1. Project Windowのプレハブを選択して、コンテキストメニューから「STYLY/Validate Prefab」を実行
  2. 検証項目は PrefabValidatorRunner内に記載
  3. 現時点で検証できる機能は以下の通り - 利用不可能なシェーダーを使用していないか? - 利用不可能なコンポーネントを使用していないか?
  4. 検査結果はConsoleログに出力

1. Project Windowのプレハブを選択して、コンテキストメニューから「STYLY/Validate Prefab」を実行
2. 検証項目は PrefabValidatorRunner内に記載
3. 現時点で検証できる機能は以下の通り
     - 利用不可能なシェーダーを使用していないか?
     - 利用不可能なコンポーネントを使用していないか?
4. 検査結果はConsoleログに出力
Copy link
Collaborator Author

@ku6ryo ku6ryo left a comment

Choose a reason for hiding this comment

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

基本的な設計はいいと思います細かい点コメントしました。

@afjk さんにもレビューを依頼します。

return passed;
}

private string GetGameObjectPath(GameObject obj)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

これはどのクラスでも使いそうなので、どこかで共通で使えるようにしてもらえますでしょか?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Utilityクラスを作成して共有化しました。

string path = obj.name;
while (obj.transform.parent != null)
{
obj = obj.transform.parent.gameObject;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

引数を上書きするとバグが実装されてしまう確率があがるので、別の変数に持ち替えて実装してください。

Copy link
Collaborator

Choose a reason for hiding this comment

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

作業用変数を用意しました。

@ku6ryo ku6ryo requested a review from afjk September 9, 2024 16:47
@ku6ryo
Copy link
Collaborator Author

ku6ryo commented Sep 9, 2024

メニューのラベルについて
「Validate Prefab (Alpha)」として置いてもらえますでしょうか?

動作について、Standard shader を使ったマテリアルの obj を含めましたが、検査に引っ掛かりませんでした。動作バグがあるかもです。
スクリーンショット 2024-09-10 015321

if (material != null && System.Array.IndexOf(allowedShaders, material.shader) == -1)
{
string path = GetGameObjectPath(renderer.gameObject);
Debug.LogWarning($"Using unauthorized shaders: {material.shader.name}, Game Object: {path}");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unauthorized だと、ログイン的な認証されていないものという意味になるので、unsupported に変更できますでしょうか?

Copy link
Collaborator

Choose a reason for hiding this comment

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

変更します。

Copy link
Collaborator

Choose a reason for hiding this comment

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

メニュー名は「Validate Prefab (Alpha)」に変更します。

- メニュー名を「Validate Prefab (Alpha)」に変更
- プレハブ内のパス名の生成関数内の処理において、引数の値を直接変更せずに作業用変数を用意して変更する
@afjk
Copy link
Collaborator

afjk commented Sep 24, 2024

パスについて
/Packages/com.styly.styly-spatial-layer-plugin
がPluginとしての配布パッケージになりますので、Validation機能もこちらに含めていただくようお願いします。

/Assets/Validation/Editor/*

/Packages/com.styly.styly-spatial-layer-plugin/Editor/Validation/*
に移動していただけると。

PrefabValidationManager validationManager = new PrefabValidationManager();

// Added shader verification
Shader[] allowedShaders = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

対応シェーダー一覧は変更される可能性が高いので外部ファイルにしていただけると助かります。

Copy link
Collaborator

Choose a reason for hiding this comment

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

色々と検討しましたが、Configフォルダーを作成して、そちらに機能別にクラスを分けて対応しました。ほかの方法としては、ScriptableObjectにする方法が考えられますが、パッケージ内部にあるScriptableObjectをうまく指定する方法が思いつきませんでした・・・

validationManager.AddValidator(new ShaderValidator(allowedShaders));

// Added forbidden components
System.Type[] forbiddenComponents = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

非対応コンポーネント一覧は頻繁に変更する可能性が高いので外部ファイルにしていただけると助かります。

@afjk
Copy link
Collaborator

afjk commented Sep 24, 2024

検査結果はConsoleログに出力

結果がConsoleに出力されるだけですと、ユーザーは何が起きたのか気づきにくいので成功/失敗ダイアログで通知するなどした方が良いと思います。

@afjk
Copy link
Collaborator

afjk commented Sep 24, 2024

@zabaglione ご対応ありがとうございます。
数点コメントさせていただきました。
ご確認お願いいたします。

@ku6ryo
Copy link
Collaborator Author

ku6ryo commented Oct 2, 2024

動作のチェックをしました。

不具合、修正いただきたい点
** Prefab 内のコンポーネントがすべてチェックされていなそう **
コードを拝見して、Prefab 内の Child の Child など深くまでチェックされていなそうにみえます。(間違っていたら教えてください)

Warning が出そうな prefab を作っても warning がでない。
具体的にチェックした箇所は

  • GoundValidator で Position Y の値が負のオブジェクトを作成したが、Warning がでなかった。
  • Camera component がついているコンポーネントを含めたが、Warning がでなかった。

上記の通り深くまでチェックされていないと思ったので、prefab の GameObject 直下のコンポーネントで確認をしています。

Prefab を選択していないときに「Validate Prefab (Alpha)」が選択できないようにしてほしい。
Build Prefab のメニューの設定コードを参照ください

- このクラスもMonoBehaviourの継承は不要なので削除
@ku6ryo
Copy link
Collaborator Author

ku6ryo commented Oct 7, 2024

Validator 使用しました (mac)

修正していただきたい点

  • ログが埋もれるので、[STYLY Validator] のようなフィルタリングできる文字列を入れる必要があ理想なので追加して欲しい
  • 非推奨のコンポーネントが複数の GameObject についているときに一つしか指摘されない
  • ユーザーが Camera コンポーネントを使用してシーン内のオブジェクトを撮影、RenderTexture でマテリアルに設定するみたいなケースがそこそこあるみたいです。なので Camera は対象から外してください。

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.

3 participants