示例#1
0
            public void Activate()
            {
                shouldActive = true;

                if (activity == FeatureActivity.Stopped)
                {
                    LiteCoroutine.StartCoroutine(ref coroutineHandle, new LiteTask(ActivateCoroutine(), false));
                }
            }
        public virtual void OnColliderEventPressDown(ColliderButtonEventData eventData)
        {
            if (!IsValidGrabButton(eventData))
            {
                return;
            }

            Grabber grabber;

            if (TryGetExistsGrabber(eventData, out grabber))
            {
                return;
            }

            var currentFrame = Time.frameCount;
            ButtonProcessedState pState;

            if (m_buttonProcessedFrame.TryGetValue(eventData, out pState))
            {
                // skip if button was just processed for release
                if (pState.processedFrame == currentFrame)
                {
                    Debug.Assert(!pState.isGrabbing);
                    return;
                }
            }

            if (!m_allowMultipleGrabbers)
            {
                ClearGrabbers();
            }

            if (m_grabOnLastEntered && !eventData.eventCaster.lastEnteredCollider.transform.IsChildOf(transform))
            {
                return;
            }

            if (AddGrabber(eventData))
            {
                m_buttonProcessedFrame[eventData] = new ButtonProcessedState()
                {
                    isGrabbing     = true,
                    processedFrame = currentFrame
                };

                if (m_updateCoroutine.IsNullOrDone())
                {
                    LiteCoroutine.StartCoroutine(ref m_updateCoroutine, GrabUpdate(), false);

                    if (moveByVelocity)
                    {
                        LiteCoroutine.StartCoroutine(ref m_physicsCoroutine, PhysicsGrabUpdate(), false);
                    }
                }
            }
        }
示例#3
0
    public virtual void OnBeginDrag(PointerEventData eventData)
    {
        if (AddGrabber(eventData))
        {
            if (m_updateCoroutine.IsNullOrDone())
            {
                LiteCoroutine.StartCoroutine(ref m_updateCoroutine, DragUpdate(), false);

                if (moveByVelocity)
                {
                    LiteCoroutine.StartCoroutine(ref m_physicsCoroutine, PhysicsGrabUpdate(), false);
                }
            }
        }
    }
        private IEnumerator Start()
        {
            // Start coroutine using static function
            Debug.Log("### Start Coroutine with Static Function");
            LiteCoroutine coroutineHandle1 = LiteCoroutine.StartCoroutine(PromptCoroutine());

            yield return(coroutineHandle1);

            // Stop/Interrupt coroutine
            Debug.Log("### Stop Coroutine");
            LiteCoroutine coroutineHandle2 = LiteCoroutine.StartCoroutine(PromptCoroutine());

            yield return(NewWaitInstruction(2.5f));

            coroutineHandle2.Stop();
            yield return(coroutineHandle2);

            // IsNullOrDone works on null handle
            if (m_handle.IsNullOrDone())
            {
                // Create & Assign new handle since m_handle is null
                Debug.Log("### Initiate Coroutine Handle and Start New Coroutine");
                LiteCoroutine.StartCoroutine(ref m_handle, PromptCoroutine());
                yield return(m_handle);

                // Reuse m_handle since m_handle is no null
                Debug.Log("### Reuse Coroutine Handle and Start New Coroutine");
                LiteCoroutine.StartCoroutine(ref m_handle, PromptCoroutine());

                // Stop & Restart using existing coroutine handle
                yield return(NewWaitInstruction(2.5f));

                Debug.Log("### Stop and Restart Coroutine Using Existing Handle");
                LiteCoroutine.StartCoroutine(ref m_handle, PromptCoroutine());
            }

            // Manually wait for coroutine handle finished
            while (!m_handle.IsDone)
            {
                yield return(null);
            }
            Debug.Log("### Manually Wait for Coroutine Handle to be Finished");
        }
示例#5
0
        protected override void OnUpdateDeviceConnectionAndPoses()
        {
            lock (this)
            {
                if (!isStarted && retryCount > 0 && startDetectionTask.IsDone)
                {
                    // try start engine detection
                    LiteCoroutine.StartCoroutine(ref startDetectionCoroutine, startDetectionTask.RestartTask(StartDetectionCoroutine()));
                }

                if (!isStarted)
                {
                    return;
                }
            }

            var hmdPose = VRModule.GetDeviceState(VRModule.HMD_DEVICE_INDEX).pose;

            GestureInterface.SetCameraTransform(hmdPose.pos, hmdPose.rot);

            // fetch raw data from engine
            IntPtr resultPtr;
            int    resultFrame;
            var    resultSize = GestureInterface.GetGestureResult(out resultPtr, out resultFrame);

            if (resultFrame < 0)
            {
                Debug.Log(LOG_PREFIX + "Detection stopped");
                isStarted = false;
                return;
            }
            else if (resultFrame <= lastResultFrame)
            {
                // skip frame
                return;
            }

            lastResultFrame = resultFrame;

            leftResult.isConnected  = false;
            rightResult.isConnected = false;

            for (int i = 0, imax = resultSize; i < imax; ++i)
            {
                var result = (GestureResult)Marshal.PtrToStructure(resultPtr, typeof(GestureResult));
                if (result.isLeft)
                {
                    leftResult = new HandResultData()
                    {
                        isConnected = true,
                        rawData     = result,
                    };
                }
                else
                {
                    rightResult = new HandResultData()
                    {
                        isConnected = true,
                        rawData     = result,
                    };
                }
#if NET_4_6
                resultPtr = IntPtr.Add(resultPtr, sizeofGestureResult);
#else
                resultPtr = new IntPtr(resultPtr.ToInt64() + sizeofGestureResult);
#endif
            }

            UpdateDeviceConnectionAndPoses(ref leftResult, ref leftDeviceIndex, true);
            UpdateDeviceConnectionAndPoses(ref rightResult, ref rightDeviceIndex, false);
        }
        private IEnumerator Start()
        {
            mainThread = Thread.CurrentThread;

            // LiteTask allow you to run heavy script in background thread without blocking Unity main thread
            Debug.Log("### LiteTask in Background Thread");
            var task = new LiteTask(HeavyTask());

            StartCoroutine(task);
            yield return(MainThreadWaiting(task));


            // LiteTask also works with LiteCoroutine as well
            Debug.Log("### LiteTask in Background Thread with LiteCoroutine");
            task = new LiteTask(SleepTask());
            var handle = LiteCoroutine.StartCoroutine(task);

            yield return(MainThreadWaiting(task));


            // Stop/Cancel LiteTask
            Debug.Log("### Cancelling LiteTask");
            task = new LiteTask(HeavyTask());
            LiteCoroutine.StartCoroutine(ref handle, task);
            yield return(new WaitForSecondsUnscaledTime(2.5f));

            task.Cancel();
            yield return(task.Wait());

            Debug.Log("Background task is cancelled");


            // Restart & Reuse LiteTask
            Debug.Log("### Restarting LiteTask");
            task = new LiteTask(HeavyTask());
            LiteCoroutine.StartCoroutine(ref handle, task);
            yield return(new WaitForSecondsUnscaledTime(1.5f));

            try
            {
                task.RestartTask(HeavyTask());
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Debug.Log("Can't restart new task when task isn't done yet!");
            }
            yield return(task.Wait());

            Debug.Log("Must restart new task after task is done...");
            yield return(LiteCoroutine.StartCoroutine(ref handle, task.RestartTask(SleepTask())));


            // Exception in background thread
            Debug.Log("### Invalid Operation in Background Thread");
            yield return(LiteCoroutine.StartCoroutine(ref handle, task.RestartTask(InvalidOperationInBackground())));


            // Jump between Main & Background thread
            Debug.Log("### Jump Between Main & Background Thread");
            yield return(LiteCoroutine.StartCoroutine(ref handle, task.RestartTask(JumpToMainThread())));


            // Nested background task
            Debug.Log("### Nested Background Task");
            yield return(LiteCoroutine.StartCoroutine(ref handle, task.RestartTask(NestedTasks())));

            // tobackground can interrupt
            // jump only works in LiteTask
            // nested background task
            // pool
        }