コード例 #1
0
ファイル: UIManager.cs プロジェクト: HelrenPDM/FaderVR
 void Awake()
 {
     m_Controller = new Controller ();
     if (m_Controller.IsServiceConnected()) {
     } else {
         m_LeapUI = GameObject.Find("UI_LEAP");
         m_LeapUI.SetActive (false);
     }
 }
コード例 #2
0
        // IsConnectedプロパティおよびHasFocusプロパティを利用したイベントの検出
        static void PollingBasics2()
        {
            Controller leap = new Controller();

            bool isPrevConnected = false;
            bool isPrevServiceConnected = false;
            bool hadPrevFocus = false;
            long previousFrameId = -1;

            // 初期化処理(OnInit()相当)をここに書く
            // 無限ループ内で、前回のフレームのIDと比較して新しいフレームを取得する
            while ( true ) {
                var frame = leap.Frame();

                // Leap Motionコントローラーとの接続状態を確認する
                {
                    bool isCurrentConnected = leap.IsConnected;
                    if ( isPrevConnected != isCurrentConnected ) {
                        if ( isCurrentConnected ) {
                            // Leap Motionコントローラーが接続された(OnConnected()相当)
                            Console.WriteLine( "Leap Motion connected." );
                        }
                        else {
                            // Leap Motionコントローラーが抜かれた(OnDisconnected()相当)
                            Console.WriteLine( "Leap Motion disconnected." );
                        }
                    }

                    // 今回の接続状態を保持する
                    isPrevConnected = isCurrentConnected;
                }

                // Leap Motionサービスとの接続状態を確認する
                {
                    bool isCurrentServiceConnected = leap.IsServiceConnected();
                    if ( isPrevServiceConnected != isCurrentServiceConnected ) {
                        if ( isCurrentServiceConnected ) {
                            // Leap Motionサービスが接続された(onServiceConnect()相当)
                            Console.WriteLine( "Leap Motion Service connected." );
                        }
                        else {
                            // Leap Motionサービスが切断された(onServiceDisconnect()相当)
                            Console.WriteLine( "Leap Motion Service disconnected." );
                        }
                    }

                    isPrevServiceConnected = isCurrentServiceConnected;
                }

                // フォーカス状態を確認する
                {
                    bool hadCurrentFocus = leap.HasFocus;
                    if ( hadPrevFocus != hadCurrentFocus ) {
                        if ( hadCurrentFocus ) {
                            // アプリケーションのフォーカスが有効になった(OnFocusGained()相当)
                            Console.WriteLine( "Focus gained." );
                        }
                        else {
                            // アプリケーションのフォーカスが無効になった(OnFocusLost()相当)
                            Console.WriteLine( "Focus lost." );
                        }
                    }

                    // 今回のフォーカス状態を保持する
                    hadPrevFocus = hadCurrentFocus;
                }

                // フレームが更新されていなければ何もしない
                {
                    if ( previousFrameId == frame.Id ) {
                        continue;
                    }

                    previousFrameId = frame.Id;
                }

                // フレーム更新処理(onFrame()相当)をここに書く
            }

            // 終了処理(OnExit()相当)をここに書く
        }