Share
Embed
Transcript
18 slides
-
こんなこといいな できたらいいな ファイルのドロップ 慣れたダイアログでファイルを開く ウィンドウの位置/サイズ変更 任意形状のウィンドウ
(非矩形ウィンドウ) Unityでも 2 -
こんなこといいな できたらいいな ファイルのドロップ 慣れたダイアログでファイルを開く ウィンドウの位置/サイズ変更 任意形状のウィンドウ
(非矩形ウィンドウ) Unityでも 3 Windows API ※ Windowsの場合 -
でも、C++ とかでプラグイン 別途ビルドが必要では? Unity上でC#スクリプトを作るだけでも可 ※ 実際はC#の知識だけでは無理がありますが… 4 //
WindowRotator.cs ウィンドウをぐるぐる回す using UnityEngine; using System; using System.Runtime.InteropServices; public class WindowRotator : MonoBehaviour { [DllImport("user32.dll")] static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWIA, int x, int y, int cx, int cy, uint uFlags); [DllImport("user32.dll")] static extern IntPtr GetActiveWindow(); IntPtr hWnd; void Awake() { hWnd = GetActiveWindow(); } void Update() { int x = (int)(200f + 100f * Mathf.Cos(Time.time)); int y = (int)(200f + 100f * Mathf.Sin(Time.time)); SetWindowPos(hWnd, IntPtr.Zero, x, y, 0, 0, 0x4015); } } 例: WindowRotator.cs このスクリプトを何かにアタッチ -
でも、C++ とかでプラグイン 別途ビルドが必要では? Unity上でC#スクリプトを作るだけでも可 ※ 実際はC#の知識だけでは無理がありますが… 5 //
WindowRotator.cs ウィンドウをぐるぐる回す using UnityEngine; using System; using System.Runtime.InteropServices; public class WindowRotator : MonoBehaviour { [DllImport("user32.dll")] static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWIA, int x, int y, int cx, int cy, uint uFlags); [DllImport("user32.dll")] static extern IntPtr GetActiveWindow(); IntPtr hWnd; void Awake() { hWnd = GetActiveWindow(); } void Update() { int x = (int)(200f + 100f * Mathf.Cos(Time.time)); int y = (int)(200f + 100f * Mathf.Sin(Time.time)); SetWindowPos(hWnd, IntPtr.Zero, x, y, 0, 0, 0x4015); } } ウィンドウが勝手に移動 -
DLLはWindowsが 用意してくれている 6 [DllImport("user32.dll")] static extern bool SetWindowPos(IntPtr hWnd, IntPtr
hWIA, int x, int y, int cx, int cy, uint uFlags); Pluginsフォルダに置かずに呼び出せる -
別の例: UniVRM-samples 現時点の UniVRM-samples-0.53.0 では モデル読込に Windows のダイアログ使用 7
FileDialogWindow.cs Comdlg32.dll 内の関数を利用 -
ゆにうぃなぴ UniWinApi https://github.com/kirurobo/UniWinApi 本体はこっち https://github.com/kirurobo/UniWinApiAsset CC0 (パブリックドメイン)※本体について
クレジット表示も不要で自由に使える VRMファイルビューアのサンプルを用意 8 色々寄せ集めて 公開したもの -
UniWinApi の注意点 Unityエディタでは無効な機能がある ウィンドウ透過はビルドしないと使えない 個人の実験的プロジェクト これできるかな、と試しているもの
質は保証できない 仕様が勝手に変わったりする サブモジュールに分かれている それぞれプルが必要 9 そのままアプリに使える 自信はないのでCC0なのです -
公開した狙い もっと良いライブラリを誰か作ってほしい 例 @satoya_123 さん Desktop Mascot Maker
みたいな 新しめの Unity でも対応いただけると… 需要や、もっと良い実装を知りたい schedul-xor さん タッチ対応について @baku_dreameater さん ヒットテストの ReadPixels 遅いという話 スマートな半透明処理が参考になります! 10 -
ファイルを開くダイアログ UnityStandaloneFileBrowser gkngkc さん MIT ライセンス
Windows / Mac / Linux でネイティブのファイ ル選択ダイアログを出せる WebGL でも出せる 16 -
ファイルドロップ UnityWindowsFileDrag-Drop Bunny83 さん MIT ライセンス
シンプルな実装でファイルドロップ受付 17