Exemplo n.º 1
0
        //Private Methods:
        private void GetControl()
        {
            for (int i = 0; i < 2; ++i)
            {
                MLInput.Controller control = MLInput.GetController(i);
                if (control.Type == MLInput.Controller.ControlType.Control)
                {
                    switch (handedness)
                    {
                    case ControlHandedness.Any:
                        Initialize(control);
                        break;

                    case ControlHandedness.Left:
                        if (control.Hand == MLInput.Hand.Left)
                        {
                            Initialize(control);
                        }
                        break;

                    case ControlHandedness.Right:
                        if (control.Hand == MLInput.Hand.Right)
                        {
                            Initialize(control);
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void HandleControlConnected(byte controlId)
        {
            //we just want to work with the control:
            MLInput.Controller connectedControl = MLInput.GetController(controlId);

            switch (handedness)
            {
            case ControlHandedness.Any:
                Initialize(MLInput.GetController(controlId));
                break;

            case ControlHandedness.Left:
                if (connectedControl.Hand == MLInput.Hand.Left)
                {
                    Initialize(MLInput.GetController(controlId));
                }
                break;

            case ControlHandedness.Right:
                if (connectedControl.Hand == MLInput.Hand.Right)
                {
                    Initialize(MLInput.GetController(controlId));
                }
                break;
            }
        }
        private void Start()
        {
            if (!MLInput.IsStarted)
            {
                bool enable6DOF = true;
                bool enabledCFUIDTracking = true;

                MLInput.Configuration configuration = new MLInput.Configuration(enable6DOF)
                {
                    EnableCFUIDTracking = enabledCFUIDTracking
                };

                MLResult inputStartResult = MLInput.Start(configuration);
                switch (inputStartResult.Result)
                {
                    case MLResult.Code.Ok:
                        commonStart();
                        break;
                    case MLResult.Code.InvalidParam:
                        throw new System.NotImplementedException();
                    case MLResult.Code.PrivilegeDenied:
                        throw new System.NotImplementedException();
                }
            }
            else
            {
                commonStart();
            }
        }
Exemplo n.º 4
0
    void Awake()
    {
        MLInput.Start();
        MLInput.OnControllerButtonDown += OnButtonDown;
        MLInput.OnControllerButtonUp   += OnButtonUp;
        soldier.SetActive(false);

        _controller = MLInput.GetController(MLInput.Hand.Left);
        zoominDic.Add(CameraState.OverviewMain, CameraState.CloseUpMain);
        zoominDic.Add(CameraState.CloseUpMain, CameraState.FirstPersonMain);
        zoominDic.Add(CameraState.OverviewIslandOne, CameraState.CloseUpIslandOne);
        zoominDic.Add(CameraState.CloseUpIslandOne, CameraState.FirstPersonIslandOne);
        zoominDic.Add(CameraState.OverviewIslandTwo, CameraState.CloseUpIslandTwo);
        zoominDic.Add(CameraState.CloseUpIslandTwo, CameraState.FirstPersonIslandTwo);
        zoominDic.Add(CameraState.OverviewResIslandOne, CameraState.CloseUpResIslandOne);
        zoominDic.Add(CameraState.OverviewResIslandTwo, CameraState.CloseUpResIslandTwo);

        zoomoutDic.Add(CameraState.FirstPersonMain, CameraState.CloseUpMain);
        zoomoutDic.Add(CameraState.CloseUpMain, CameraState.OverviewMain);
        zoomoutDic.Add(CameraState.FirstPersonIslandOne, CameraState.CloseUpIslandOne);
        zoomoutDic.Add(CameraState.CloseUpIslandOne, CameraState.OverviewIslandOne);
        zoomoutDic.Add(CameraState.FirstPersonIslandTwo, CameraState.CloseUpIslandTwo);
        zoomoutDic.Add(CameraState.CloseUpIslandTwo, CameraState.OverviewIslandTwo);
        zoomoutDic.Add(CameraState.CloseUpResIslandOne, CameraState.OverviewResIslandOne);
        zoomoutDic.Add(CameraState.CloseUpResIslandTwo, CameraState.OverviewResIslandTwo);

        zoomoutReadyTM      = zoomoutReady.GetComponent <TextMeshPro>();
        zoomoutReadyTM.text = "Zoomout Ready";
        zoomoutReady.SetActive(false);
    }
Exemplo n.º 5
0
        private void InitializeMLInputIfNeeded()
        {
            if (_hasInitialized)
            {
                return;
            }

            if (!MLInput.IsStarted)
            {
                Debug.Log("<<<< MLInput hasn't started >>>>");
                return;
            }

            MLResult result = MLInput.Start();

            if (!result.IsOk)
            {
                Debug.LogError("MLInput won't start.");
                return;
            }

            _hasInitialized = true;

            MLInput.OnTriggerDown         += HandleOnTriggerDown;
            MLInput.OnTriggerUp           += HandleOnTriggerUp;
            MLInput.OnControllerConnected += HandleOnControllerConnected;

            TryGetController();

            Debug.Log(_inputController);

            Debug.Log("<<<< Sccessed to initialize MLInput >>>>");
        }
Exemplo n.º 6
0
 void Start()
 {
     //Start receiving input by the Control
     MLInput.Start();
     MLInput.OnControllerButtonDown += OnButtonDown;
     _controller = MLInput.GetController(MLInput.Hand.Left);
 }
Exemplo n.º 7
0
        public override void Disable()
        {
#if PLATFORM_LUMIN
            if (MLControllerCallbacksActive)
            {
                RemoveAllControllerDevices();
                MLInput.OnControllerConnected    -= MLControllerConnected;
                MLInput.OnControllerDisconnected -= MLControllerDisconnected;
                MLInput.Stop();

                MLControllerCallbacksActive = false;
            }

            if (MLHandTrackingActive)
            {
                RemoveAllHandDevices();
                MLHandTracking.Stop();

                MLHandTrackingActive = true;
            }

            if (Instance == this)
            {
                Instance = null;
            }
#endif
        }
Exemplo n.º 8
0
 // Start is called before the first frame update
 void Start()
 {
     MLInput.Start();
     controller = MLInput.GetController(MLInput.Hand.Left);
     controller.OnButtonDown += HandleButtonDown;
     currentMenu              = objectsToPlace[0];
 }
Exemplo n.º 9
0
        /// <summary>
        /// Check editor set variables for null references.
        /// </summary>
        void Awake()
        {
            if (_numberOfPlanesText == null)
            {
                Debug.LogError("Error PlanesExample._numberOfPlanesText is not set, disabling script.");
                enabled = false;
                return;
            }
            if (_boundedExtentsText == null)
            {
                Debug.LogError("Error PlanesExample._boundedExtentsText is not set, disabling script.");
                enabled = false;
                return;
            }
            if (_boundsWireframeCube == null)
            {
                Debug.LogError("Error PlanesExample._boundsWireframeCube is not set, disabling script.");
                enabled = false;
                return;
            }
            MLResult result = MLInput.Start();

            if (!result.IsOk)
            {
                Debug.LogError("Error PlanesExample starting MLInput, disabling script.");
                enabled = false;
                return;
            }

            MLInput.OnControllerButtonDown += OnButtonDown;

            _planesComponent = GetComponent <Planes>();
            _camera          = Camera.main;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="registrar">The <see cref="IMixedRealityServiceRegistrar"/> instance that loaded the data provider.</param>
        /// <param name="inputSystem">The <see cref="Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputSystem"/> instance that receives data from this provider.</param>
        /// <param name="name">Friendly name of the service.</param>
        /// <param name="priority">Service priority. Used to determine order of instantiation.</param>
        /// <param name="profile">The service's configuration profile.</param>
        public MagicLeapDeviceManager(
            IMixedRealityInputSystem inputSystem,
            string name   = null,
            uint priority = DefaultPriority,
            BaseMixedRealityProfile profile = null) : base(inputSystem, name, priority, profile)
        {
#if PLATFORM_LUMIN && !UNITY_EDITOR
            if (!MLControllerCallbacksActive && MLInput.Start().IsOk)
            {
                MLInput.OnControllerConnected    += MLControllerConnected;
                MLInput.OnControllerDisconnected += MLControllerDisconnected;

                MLControllerCallbacksActive = true;
            }

            if (!MLHandTrackingActive && MLHandTracking.Start().IsOk)
            {
                MLHandTracking.KeyPoseManager.SetKeyPointsFilterLevel(MLHandTracking.KeyPointFilterLevel.Smoothed);
                MLHandTracking.KeyPoseManager.EnableKeyPoses(supportedGestures, true, false);

                MLHandTrackingActive = true;
            }
#endif

            if (Instance == null)
            {
                Instance = this;
            }
        }
Exemplo n.º 11
0
    public float[] ExpertDecide(List <float> vectorObs)
    {
        System.Random r = new System.Random();

        if (r.NextDouble() < noise)
        {
            return(new float[] { r.Next(0, 5) });
        }

        MLInput input = new MLInput(vectorObs.ToArray());

        if (input.GetOpponentAction() == MLAction.DODGE_LEFT)
        {
            return(MLActionFactory.GetVectorAction(MLAction.PUNCH_RIGHT));
        }

        if (input.GetOpponentAction() == MLAction.DODGE_RIGHT)
        {
            return(MLActionFactory.GetVectorAction(MLAction.PUNCH_LEFT));
        }

        if (input.GetOpponentAction() == MLAction.PUNCH_LEFT)
        {
            return(MLActionFactory.GetVectorAction(MLAction.DODGE_LEFT));
        }

        if (input.GetOpponentAction() == MLAction.PUNCH_RIGHT)
        {
            return(MLActionFactory.GetVectorAction(MLAction.DODGE_RIGHT));
        }

        return(new float[] { 0f });
    }
Exemplo n.º 12
0
 void Start()
 {
     //Start receiving input by the Control
     MLInput.Start();
     _controller = MLInput.GetController(MLInput.Hand.Left);
     _renderer   = GetComponent <Renderer>();
 }
Exemplo n.º 13
0
        /// <summary>
        /// Once privileges have been granted, enable the camera and callbacks.
        /// </summary>
        private void StartCapture()
        {
            if (!_hasStarted)
            {
                MLResult result = MLInput.Start();
                if (!result.IsOk)
                {
                    Debug.LogError("Failed to start MLInput on ImageCapture component. Disabling the script.");
                    enabled = false;
                    return;
                }

                updateImageTrackerBehaviours(true);

                if (_visualizers.Length < 1)
                {
                    Debug.LogError("Error ImageTrackingExample._visualizers not set, disabling script.");
                    enabled = false;
                    return;
                }
                if (null == _statusLabel)
                {
                    Debug.LogError("Error ImageTrackingExample._statusLabel is not set, disabling script.");
                    enabled = false;
                    return;
                }

                MLInput.OnControllerButtonDown += HandleOnButtonDown;

                _hasStarted = true;
            }
        }
Exemplo n.º 14
0
    private MLAction runMoves(List <float> vectorObs, MLAction[] moves)
    {
        MLInput input = new MLInput(vectorObs.ToArray());

        var currentMove = moves[moveIdx];

        if (currentMove == MLAction.NOTHING && Time.time - nothingStartTime >= nothingDuration)
        {
            // Doing nothing ended
            return(runNextMove(moves, input));
        }
        else if (didAction && MLActionFactory.IsPunch(currentMove) && input.GetMyMove() == MLAction.NOTHING)
        {
            // Punch ended
            return(runNextMove(moves, input));
        }
        else if (didAction && MLActionFactory.IsDodge(currentMove) && input.GetMyMove() == MLAction.NOTHING)
        {
            // Dodge ended
            return(runNextMove(moves, input));
        }

        if (!didAction && MLActionFactory.IsPunch(currentMove))
        {
            didAction = input.IsPunchReady();
        }
        else if (!didAction && MLActionFactory.IsDodge(currentMove))
        {
            didAction = input.IsDodgeReady();
        }

        return(moves[moveIdx]);
    }
        public static MLInput.Controller.ControlType determineControllerType(byte controllerId)
        {
            //
            // The first controller is considered the left handed controller, even though
            // we may hold the controller in our right hand :)
            //
            MLInput.Controller leftHandController  = MLInput.GetController(MLInput.Hand.Left);
            MLInput.Controller rightHandController = MLInput.GetController(MLInput.Hand.Right);

            bool isMobileAppLeft  = (leftHandController != null && leftHandController.Type == MLInput.Controller.ControlType.MobileApp);
            bool isMobileAppRight = (rightHandController != null && rightHandController.Type == MLInput.Controller.ControlType.MobileApp);

            bool isControllerLeft  = (leftHandController != null && leftHandController.Type == MLInput.Controller.ControlType.Control);
            bool isControllerRight = (rightHandController != null && rightHandController.Type == MLInput.Controller.ControlType.Control);

            bool isMobileApp  = (isMobileAppLeft || isMobileAppRight);
            bool isController = (isControllerLeft || isControllerRight);

            if (isMobileApp)
            {
                return(MLInput.Controller.ControlType.MobileApp);
            }
            if (isController)
            {
                return(MLInput.Controller.ControlType.Control);
            }
            return(MLInput.Controller.ControlType.None);
        }
        /// <summary>
        /// Validate variables
        /// </summary>
        void Start()
        {
            if (null == _visualizer)
            {
                Debug.LogError("MasterMaterialController._visualizer not set, disabling script");
                enabled = false;
                return;
            }

            _materialControllers = GetComponents <MaterialController>();
            if (_materialControllers.Length < 1)
            {
                Debug.LogError("MasterMaterialController._materialControllers is empty, disabling script.");
                enabled = false;
                return;
            }
            if (!MLInput.Start())
            {
                Debug.LogError("Error MasterMaterialController starting MLInput, disabling script.");
                enabled = false;
                return;
            }

            _statusText.text              = "";
            _controller                   = MLInput.GetController(MLInput.Hand.Left);
            MLInput.OnControllerButtonUp += HandleOnButtonUp;
        }
Exemplo n.º 17
0
 private void OnDestroy()
 {
     if (MLInput.IsStarted)
     {
         MLInput.Stop();
     }
 }
 void Awake()
 {
     MLInput.Start();
     MLInput.OnControllerButtonDown += OnButtonDown;
     MLInput.OnControllerButtonUp   += OnButtonUp;
     _controller = MLInput.GetController(MLInput.Hand.Left);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Unregister callbacks and stop input API.
        /// </summary>
        void OnDisable()
        {
            MLInput.OnControllerButtonDown -= OnButtonDown;
            MLInput.Stop();

            DisableMLCamera();
        }
Exemplo n.º 20
0
 /// <summary>
 /// Cleans up the component.
 /// </summary>
 void OnDestroy()
 {
     MLInput.OnControllerTouchpadGestureStart -= OnTouchpadGestureStart;
     MLInput.OnTriggerDown          -= OnTriggerDown;
     MLInput.OnControllerButtonDown -= OnButtonDown;
     MLInput.Stop();
 }
 private void HandleControllerConnected(byte controllerID)
 {
     if (controller == null)
     {
         controller = MLInput.GetController(controllerID);
         Debug.Log("ML controller with ID: " + controller.Id + " connected!");
     }
 }
Exemplo n.º 22
0
 private void Start()
 {
     MLInput.Start();                                        // to start receiving input from the controller
     _controller = MLInput.GetController(MLInput.Hand.Left); //left or right it doesn’t really matter
     Debug.Log("Starting...");
     //MusicSource.Play();
     MusicSource.loop = true;
 }
 private void OnDestroy()
 {
     if (MLInput.IsStarted)
     {
         UnregisterHandlers();
         MLInput.Stop();
     }
 }
Exemplo n.º 24
0
 /// <summary>
 /// Cleans up the component.
 /// </summary>
 void OnDestroy()
 {
     if (MLInput.IsStarted)
     {
         MLInput.OnControllerButtonDown -= OnButtonDown;
         MLInput.Stop();
     }
 }
Exemplo n.º 25
0
 private void OnDestroy()
 {
     //turn off inputs:
     if (MLInput.IsStarted)
     {
         MLInput.Stop();
     }
 }
Exemplo n.º 26
0
 private void OnDisable()
 {
     if (_controller != null)
     {
         MLInput.Stop();
         _controller = null;
     }
 }
Exemplo n.º 27
0
 /// <summary>
 /// Handles the event for controller connected.
 /// </summary>
 /// <param name="controllerId"> The id of the controller. </param>
 private void HandleOnControllerConnected(byte controllerId)
 {
     // Type not available on OnControllerConnected, checking on update.
     if (_hand == MLInput.GetController(controllerId).Hand&& _mlInputController == null)
     {
         _mlInputController = MLInput.GetController(controllerId);
     }
 }
 /// <summary>
 /// Cleans up the component.
 /// </summary>
 void OnDestroy()
 {
     #if PLATFORM_LUMIN
     MLInput.OnTriggerUp   -= OnTriggerUp;
     MLInput.OnTriggerDown -= OnTriggerDown;
     MLInput.Stop();
     #endif
 }
Exemplo n.º 29
0
    void Awake()
    {
        Debug.Log("AWAKE");

        MLInput.Start();
        MLInput.OnControllerButtonUp += OnButtonUp;
        _controller = MLInput.GetController(MLInput.Hand.Left);
    }
Exemplo n.º 30
0
    // Start is called before the first frame update
    void Start()
    {
        MLInput.Start();
        _ctrl = MLInput.GetController(MLInput.Hand.Left);

        MLInput.OnTriggerDown += HandleOnTriggerDown;
        MLInput.OnTriggerUp   += HandleOnTriggerUp;
    }