Ejemplo n.º 1
0
        //单人标定检测
        void ProcessTrackingSingle()
        {
            //标定成功
            if (tplayer1.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked)
            {
                player1     = tplayer1.ToOrbbecPlayer();
                tplayer1    = null;
                tplayer2    = null;
                _isTracking = false;

                MotoOnTracked();

                //标定成功 回调
                if (trackedAction != null)
                {
                    trackedAction();
                }
                return;
            }

            //标定玩家1
            TrackingPlayer(tplayer1);

            if (showTrackingUI)
            {
                orbbecTrackingUI.gameObject.SetActive(true);

                RefreshTrackingView();
            }
            else
            {
                orbbecTrackingUI.gameObject.SetActive(false);
            }
        }
Ejemplo n.º 2
0
        //双人标定检测
        void ProcessTrackingTwo()
        {
            //标定成功
            if (tplayer1.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked &&
                tplayer2.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked)
            {
                //根据胸点,区分左右。
                OrbbecPlayerOnTracking lplayer;
                OrbbecPlayerOnTracking rplayer;

                if (tplayer1.torsoPos.x <= tplayer2.torsoPos.x)
                {
                    lplayer = tplayer1;
                    rplayer = tplayer2;
                }
                else
                {
                    lplayer = tplayer2;
                    rplayer = tplayer1;
                }

                player1     = lplayer.ToOrbbecPlayer();
                player2     = rplayer.ToOrbbecPlayer();
                tplayer1    = null;
                tplayer2    = null;
                lplayer     = null;
                rplayer     = null;
                _isTracking = false;

                MotoOnTracked();

                //标定成功 回调
                if (trackedAction != null)
                {
                    trackedAction();
                }
                return;
            }

            //标定玩家1
            TrackingPlayer(tplayer1);

            //标定玩家2
            TrackingPlayer(tplayer2);

            if (showTrackingUI)
            {
                orbbecTrackingUI.gameObject.SetActive(true);

                RefreshTrackingView();
            }
            else
            {
                orbbecTrackingUI.gameObject.SetActive(false);
            }
        }
Ejemplo n.º 3
0
        public static OrbbecPlayerOnTracking FromOrbbecPlayer(OrbbecPlayer oplayer)
        {
            OrbbecPlayerOnTracking tplayer = new OrbbecPlayerOnTracking();

            tplayer.bindUser = oplayer.bindUser;
            tplayer._trackingBoneWorldPosDict         = oplayer.trackingBoneWorldPosDict;
            tplayer._trackingBoneScreenPercentPosDict = oplayer.trackingBoneScreenPercentPosDict;
            tplayer.torsoPos      = oplayer.GetTrackingWorldPos(SkeletonType.Torso);
            tplayer.trackingState = TrackingState.tracked;
            return(tplayer);
        }
Ejemplo n.º 4
0
        //显示刷新标定视图
        void RefreshTrackingView()
        {
            orbbecTrackingUI.userLabelImg.texture = OrbbecManager.Instance.GetUserLabelMap();

            if (playerMode == PlayerMode.single)
            {
                orbbecTrackingUI.isSingleMode = true;

                if (tplayer1.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked)
                {
                    orbbecTrackingUI.player1Percent = 1f;
                }
                else
                {
                    orbbecTrackingUI.player1Percent = (tplayer1.trackingTime / needTrackingTime);
                }
            }
            else
            {
                orbbecTrackingUI.isSingleMode = false;

                //双人标定,根据规则,判定左右位置
                int trackCnt = 0;
                if (tplayer1.trackingState != OrbbecPlayerOnTracking.TrackingState.none)
                {
                    trackCnt++;
                }
                if (tplayer2.trackingState != OrbbecPlayerOnTracking.TrackingState.none)
                {
                    trackCnt++;
                }

                //无标定情况,都为0
                orbbecTrackingUI.player1Percent = 0f;
                orbbecTrackingUI.player2Percent = 0f;

                //只有一个人在标定 或者标定成功 根据那个人的胸点左右来判断, 是左边还是右边
                if (trackCnt == 1)
                {
                    OrbbecPlayerOnTracking tplayer = tplayer1;
                    bool isLeft = true;
                    if (tplayer1.trackingState != OrbbecPlayerOnTracking.TrackingState.none)
                    {
                        tplayer = tplayer1;
                    }
                    else if (tplayer2.trackingState != OrbbecPlayerOnTracking.TrackingState.none)
                    {
                        tplayer = tplayer2;
                    }

                    if (tplayer.torsoPos.x <= 0)
                    {
                        isLeft = true;
                    }
                    else
                    {
                        isLeft = false;
                    }

                    if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked)
                    {
                        if (isLeft)
                        {
                            orbbecTrackingUI.player1Percent = 1f;
                        }
                        else
                        {
                            orbbecTrackingUI.player2Percent = 1f;
                        }
                    }
                    else
                    {
                        if (isLeft)
                        {
                            orbbecTrackingUI.player1Percent = (tplayer.trackingTime / needTrackingTime);
                        }
                        else
                        {
                            orbbecTrackingUI.player2Percent = (tplayer.trackingTime / needTrackingTime);
                        }
                    }
                }
                //两个人在标定 或者标定成功 根据2个人的胸点位置,来判断左边还是右边
                else if (trackCnt == 2)
                {
                    OrbbecPlayerOnTracking lplayer;
                    OrbbecPlayerOnTracking rplayer;

                    if (tplayer1.torsoPos.x <= tplayer2.torsoPos.x)
                    {
                        lplayer = tplayer1;
                        rplayer = tplayer2;
                    }
                    else
                    {
                        lplayer = tplayer2;
                        rplayer = tplayer1;
                    }

                    if (lplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked)
                    {
                        orbbecTrackingUI.player1Percent = 1f;
                    }
                    else
                    {
                        orbbecTrackingUI.player1Percent = (lplayer.trackingTime / needTrackingTime);
                    }

                    if (rplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked)
                    {
                        orbbecTrackingUI.player2Percent = 1f;
                    }
                    else
                    {
                        orbbecTrackingUI.player2Percent = (rplayer.trackingTime / needTrackingTime);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        //检测标定
        void TrackingPlayer(OrbbecPlayerOnTracking tplayer)
        {
            //未开始标定,获取新user,启动标定
            if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.none)
            {
                tmpUser = GetNewUser();
                if (tmpUser != null)
                {
                    tplayer.bindUser = tmpUser;
                    tplayer.StartTracking();
                }
            }
            //正在标定,判定是否失去焦点,有焦点则记录信息,失去焦点或不举手则取消标定
            else if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.tracking)
            {
                bool isMissing     = false;
                bool IsRisingHands = false;
                if (OrbbecUtils.IsUserActive(tplayer.bindUser))
                {
                    if (OrbbecManager.Instance.IsRisingHands(tplayer.UserId))
                    {
                        IsRisingHands = true;
                    }
                    else
                    {
                        //允许中途连续丢失3帧举手
                        tplayer.trackingMissCnt++;
                        if (tplayer.trackingMissCnt >= allowTrackingMissCnt)
                        {
                            isMissing = true;
                        }
                    }
                }
                else
                {
                    isMissing = true;
                }

                if (!isMissing)
                {
                    if (IsRisingHands)
                    {
                        tplayer.UpdateTracking(Time.unscaledDeltaTime);                         //lth: 使用unscaledTime以适应游戏中暂停
                        if (tplayer.trackingTime >= needTrackingTime)
                        {
                            tplayer.FinishTracking();
                        }
                    }
                }
                else
                {
                    tplayer.CancelTracking();
                }
            }
            else if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked)
            {
                bool isMissing = false;
                if (!OrbbecUtils.IsUserActive(tplayer.bindUser))
                {
                    isMissing = true;
                }

                if (isMissing)
                {
                    tplayer.CancelTracking();
                }
            }
        }
Ejemplo n.º 6
0
        //Update
        void Update()
        {
            if (!IsDeviceInited)
            {
                return;
            }

            //每帧检测标定,无标定则要求标定
            if (isActive)
            {
                orbbecTrackingUI.gameObject.SetActive(false);
            }
            else
            {
                if (!_isTracking)
                {
                    _isTracking = true;

                    if (playerMode == PlayerMode.single)
                    {
                        //初始化user1
                        tplayer1 = new OrbbecPlayerOnTracking();
                        tplayer2 = new OrbbecPlayerOnTracking();
                    }
                    else
                    {
                        if (isPlayer1Active)
                        {
                            tplayer1 = OrbbecPlayerOnTracking.FromOrbbecPlayer(player1);
                        }
                        else
                        {
                            tplayer1 = new OrbbecPlayerOnTracking();
                        }

                        if (isPlayer2Active)
                        {
                            tplayer2 = OrbbecPlayerOnTracking.FromOrbbecPlayer(player2);
                        }
                        else
                        {
                            tplayer2 = new OrbbecPlayerOnTracking();
                        }
                    }

                    //丢失标定 回调
                    if (!_firstTracking && unTrackedAction != null)
                    {
                        unTrackedAction();
                    }

                    _firstTracking = false;
                }

                if (playerMode == PlayerMode.single)
                {
                    ProcessTrackingSingle();
                }
                else
                {
                    ProcessTrackingTwo();
                }
            }

            //检测出拳
            MotoUpdate();
        }