Windowsで動作するUnityのスタンドアロンプレイヤーのメインウィンドウのウィンドウハンドルを取得する機能を提供します
Get the Unity Standalone Player main window handle running on Windows
-
Windows 11(21H2以上)
Windows 11 (version 21H2 or later)
-
Unity 2021.3以上
Unity 2021.3 or later
-
Api Compatibility Level: .NET Standard 2.1
- Windows 11 24H2 (26100)
- Unity 2021.3.45f1, Unity 2022.3.62f1, Unity 6000.0.54f1, Unity 6000.1.13f1
名前空間HW.UnityPlayerWindowHandle
内のUnityPlayerWindow.IsHandleValid
の値がtrue
であれば、UnityPlayerWindow.MainWindowHandle
からスタンドアロンプレイヤーのメインウィンドウのウィンドウハンドルを取得できます
if(HW.UnityPlayerWindowHandle.UnityPlayerWindow.IsHandleValid)
{
// IsHandleValidがtrueであればウィンドウハンドルを取得できる
nint windowHandle = HW.UnityPlayerWindowHandle.UnityPlayerWindow.MainWindowHandle;
// 以下、ウィンドウハンドルを使った処理など
// ...
}
If UnityPlayerWindow.IsHandleValid
(namespace: HW.UnityPlayerWindowVisual
) returns true
, UnityPlayerWindow.MainWindowHandle
(namespace: HW.UnityPlayerWindowVisual
) returns the Unity Standalone Player main window handle
if(HW.UnityPlayerWindowHandle.UnityPlayerWindow.IsHandleValid)
{
// If IsHandleValid returns true, MainWindowHandle is available
nint windowHandle = HW.UnityPlayerWindowHandle.UnityPlayerWindow.MainWindowHandle;
// Process with window handle
// ...
}
-
このパッケージを導入すると
HAS_COMMON_MAIN_WINDOW_HANDLE_GETTER_HW
というDefine Symbolがプロジェクトに設定されます。 また、アンインストールするとHAS_COMMON_MAIN_WINDOW_HANDLE_GETTER_HW
は自動で除去されますWhen install this package, a Define Symbol
HAS_COMMON_MAIN_WINDOW_HANDLE_GETTER_HW
will be added to installed project automatically. And, When uninstall this package,HAS_COMMON_MAIN_WINDOW_HANDLE_GETTER_HW
will be removed from the project automatically -
1.0.1以上では、
SubsystemRegistration
のタイミング(メインウィンドウが表示される前)に自動的にウィンドウハンドルを取得する処理が実行されます。 プロジェクトのDefine SymbolにSUPPRESS_AUTO_GET_WINDOW_HANDLE_HW
を指定すると、自動取得を無効にできますOn 1.0.1 or greater, will be getting Standalone Player main window handle when
SubsystemRegistration
timing. If setSUPPRESS_AUTO_GET_WINDOW_HANDLE_HW
to Define Symbol in Project Setting, auto getting will be disabled
-
Gitをインストールする
-
追加したいプロジェクトを開き、Package Managerを開く
-
以下のGit URLをコピー、またはこのページ上部の「<> Code」からClone URLをコピーする
-
「Package Manager」ウィンドウの左上の「+」ボタンをクリックし、「Install package from git URL...」を選択する
-
入力欄に手順2でコピーしたURLを貼り付け、「Install」ボタンを押す
-
(必要に応じて)Assembly Definition Assetの管理下のエディターコードで利用する場合は、
HW.UnityPlayerWindowHandle
をAssembly Definition Referencesに追加する
-
Install Git to your computer.
-
Open Package Manager in the Unity project to which you want to add this feature.
-
Copy the following Git URL, or copy the Clone URL from "<> Code" at the top of this page
-
Click the "+" button in the "Package Manager" window and select "Install package from git URL...".
-
Paste the URL copied in Step 2 into the input field and press the "Install" button.
-
(If necessary) For use in editor code under the control of Assembly Definition Asset...
Add
HW.UnityPlayerWindowHandle
to "Assembly Definition References" in your Assembly Definition Asset.
MITライセンスです
Using "MIT license"