これのつづき
VPM開発する環境ができたのでNDMFを実装してみよう
基本的に普通のAssets開発と変わりませんが、最初だけasmdefというファイルの定義が必要です
空のRuntimeの実装
-
名称をVPMの逆ドメイン名.runtimeにする。ここでは「com.github.pandrabox.emoteprefab.runtime」
-
ダブルクリックで開き、次を参考に設定(これはMAを参考に設定した) asmdef公式情報
{
"name": "com.github.pandrabox.emoteprefab.runtime",
"references": [
"nadena.dev.ndmf.runtime"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": true,
"precompiledReferences": [
"VRCSDKBase.dll",
"VRCSDK3A.dll",
"VRC.Dynamics.dll",
"VRC.SDK3.Dynamics.Contact.dll",
"VRC.SDK3.Dynamics.PhysBone.dll",
"System.Collections.Immutable.dll"
],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
MyTest.cs
using UnityEngine;
namespace com.github.pandrabox.emoteprefab.runtime
{
[AddComponentMenu("Pan/MyTest")]
public class MyTest : MonoBehaviour, VRC.SDKBase.IEditorOnly
{
}
}
VPMの更新をしてテスト環境で確認
- この程度別にいいやと思ったら飛ばして下さい
- package.jsonのバージョンを上げる
- Github desktopでCommit→Push
- 適当な別プロジェクトで開発しているVPMを使用設定しておく(下は既にしてあったので今あげたバージョンになった)
- さっき作ったRuntimeが動いている。OK。これは閉じてPackage開発用のUnityに戻る
Editorの開発
- Runtime同様にフォルダ、asmdefを作成する。今度の内容は次を参考に
{
"name": "com.github.pandrabox.emoteprefab.editor",
"references": [
"nadena.dev.modular-avatar.core",
"nadena.dev.modular_avatar.core.editor",
"VRC.SDK3A",
"VRC.SDKBase",
"nadena.dev.ndmf",
"nadena.dev.ndmf.vrchat",
"VRC.SDK3A.Editor",
"com.github.pandrabox.emoteprefab.runtime"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"Newtonsoft.Json.dll",
"System.Collections.Immutable.dll",
"VRCSDKBase.dll",
"VRCSDKBase-Editor.dll",
"VRCSDK3A.dll",
"VRCSDK3A-Editor.dll",
"VRC.Dynamics.dll",
"VRC.SDK3.Dynamics.Contact.dll",
"VRC.SDK3.Dynamics.Contact.Editor.dll",
"VRC.SDK3.Dynamics.PhysBone.dll",
"VRC.SDK3.Dynamics.PhysBone.Editor.dll",
"VRCCore-Editor.dll"
],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
MyTest.cs
using System;
using System.Linq;
using System.Collections.Generic;
using nadena.dev.ndmf;
using nadena.dev.modular_avatar.core;
using nadena.dev.modular_avatar.core.editor;
using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;
using VRC.SDK3.Avatars.Components;
using com.github.pandrabox.emoteprefab.runtime;
using com.github.pandrabox.emoteprefab.editor;
[assembly: ExportsPlugin(typeof(MyTestPass))]
namespace com.github.pandrabox.emoteprefab.editor
{
/// <summary>
/// To call from Unity menu (Debug Only, Comment out upon release.)
/// </summary>
public class MyTestUnityMenu : MonoBehaviour
{
[MenuItem("PanDev/MyTest")]
static void GenMyTest()
{
new MyTestMain().Run(Selection.activeGameObject);
}
}
/// <summary>
/// To call from NDMF
/// </summary>
public class MyTestPass : Plugin<MyTestPass>
{
protected override void Configure()
{
try
{
InPhase(BuildPhase.Transforming).BeforePlugin("nadena.dev.modular-avatar").Run("PanMyTest", ctx =>
{
var TargetComponents = ctx.AvatarRootTransform.GetComponentsInChildren<MyTest>(false);
foreach (var T in TargetComponents)
{
new MyTestMain().Run(T.gameObject);
}
});
}
catch (Exception e)
{
Debug.LogError($@"[Pan:MyTest]{e}");
}
}
}
/// <summary>
/// Actual operation
/// Retrieving ctx is not recommended to maintain debug availability.
/// </summary>
public class MyTestMain : MonoBehaviour
{
public void Run(GameObject Target)
{
Target.SetActive(false);
Debug.LogWarning($@"MyTest:{Target.name}");
}
}
}