예제 #1
0
        //todo: Add GetExpressionState and GetEmotionState

        /// <summary>
        /// Add Event to the queue for callback
        /// </summary>
        /// <param name="e"></param>
        internal void AddEvent(NativeEvent e)
        {
            lock (eventLock)
            {
                if (IsRunning)
                {
                    if (nativeEvents == null)
                    {
                        nativeEvents = new List <NativeEvent>();
                    }

                    nativeEvents.Add(e);
                    hasEvents = true;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Loops to listen for events received from native threads
        /// </summary>
        /// <returns></returns>
        private IEnumerator ListenForEvents()
        {
            nativeEvents = new List <NativeEvent>();
            while (enabled)
            {
                yield return(new WaitForEndOfFrame());

                if (hasEvents)
                {
                    //dispatch all events stored up!
                    lock (eventLock)
                    {
                        while (nativeEvents.Count > 0)
                        {
                            NativeEvent e = nativeEvents[0];
                            nativeEvents.RemoveAt(0);

                            if (e.type == NativeEventType.ImageResults)
                            {
                                if (Listener != null)
                                {
                                    Listener.onImageResults((Dictionary <int, Face>)e.eventData);
                                }
                            }
                            else if (e.type == NativeEventType.FaceFound)
                            {
                                if (Listener != null)
                                {
                                    Listener.onFaceFound(Time.realtimeSinceStartup, (int)e.eventData);
                                }
                            }
                            else if (e.type == NativeEventType.FaceLost)
                            {
                                if (Listener != null)
                                {
                                    Listener.onFaceLost(Time.realtimeSinceStartup, (int)e.eventData);
                                }
                            }
                        }

                        hasEvents = false;
                    }
                }
            }
        }