private void OnGUI()
        {
            //GUIStyle fontStyle = new GUIStyle();

            GUI.skin.button.fontSize = 30;
            if (GUI.Button(new Rect(40, 40, 100, 60), "切换"))
            {
                BaiduARWebCamera aw = FindObjectOfType <BaiduARWebCamera>();
                aw.SwitchCamera();
                //CheckEffect(0, lstVets[0].VectorScreenPos, lstVets[1].VectorScreenPos, lstVets[2].VectorScreenPos);
            }

            if (GUI.Button(new Rect(300, 40, 100, 60), "暂停"))
            {
                BaiduARHumanPose aw = FindObjectOfType <BaiduARHumanPose>();
                aw.PauseAR();

                objs.Clear();
                electRoot.HideElectric();
                //CheckEffect(0, lstVets[0].VectorScreenPos, lstVets[1].VectorScreenPos, lstVets[2].VectorScreenPos);
            }

            if (GUI.Button(new Rect(450, 40, 100, 60), "继续"))
            {
                BaiduARHumanPose aw = FindObjectOfType <BaiduARHumanPose>();
                aw.ResumeAR();
                //CheckEffect(0, lstVets[0].VectorScreenPos, lstVets[1].VectorScreenPos, lstVets[2].VectorScreenPos);
            }
        }
        // Use this for initialization
        void Awake()
        {
            electRoot = FindObjectOfType <ARHumanExampleElectric>();
            footRoot  = FindObjectOfType <ARHumanExampleFootLift>();
            BaiduARHumanPose humanPose = FindObjectOfType <BaiduARHumanPose>();

            exampleUI = FindObjectOfType <ARExampleUI>();
            humanPose.InvokeErrorMessage(delegate(string errNum, string errMsg)
            {
                exampleUI.ErrorInfo(errNum, errMsg);
                ARDebug.LogError("errMsg = " + errMsg);
            });

            humanPose.InvokeClearMessage(delegate()
            {
                ARDebug.Log("InvokeClearMessage ");
                objs.Clear();
            });
            humanPose.InvokePosMessage(delegate(List <OutPutData> lstVet)
            {
                if (lstVet[1].score > 0 && lstVet[8].score > 0)
                {
                    ARHumanBodyDataParse.lengthShoulder = Vector2.Distance(lstVet[1].VectorScreenPos, lstVet[8].VectorScreenPos);
                    ARDebug.Log("datas lengthShoulder = " + ARHumanBodyDataParse.lengthShoulder);

                    if (lstVet[10].score > 0 && lstVet[13].score > 0)
                    {
                        float left  = Vector2.Distance(lstVet[10].VectorScreenPos, lstVet[8].VectorScreenPos);
                        float right = Vector2.Distance(lstVet[13].VectorScreenPos, lstVet[11].VectorScreenPos);
                        if (right < ARHumanBodyDataParse.lengthShoulder && left < ARHumanBodyDataParse.lengthShoulder)
                        {
                            return;
                        }
                    }
                }



                int z = (int)(ARHumanBodyDataParse.lengthShoulder / 60);

                int ZeroCount = 0;
                for (int i = 0; i < lstVet.Count; i++)
                {
                    if (lstVet[i].score > 0.6)
                    {
                        //  if ( i == 4 ||  i == 2 || i == 7  || i ==5)
                        {
                            //GameObject item = objs.GetItem();
                            //if (item == null)
                            //{
                            //    item = CreateCircleGame(z);
                            //    objs.Add(item);
                            //}
                            //item.transform.localScale = Vector3.one * z;
                            //item.SetActive(true);
                            //// item.transform.position = GameObject.Find("UICamera").GetComponent<Camera>().ScreenToWorldPoint(lstVet[i].VectorScreenPos);//lstVet[i].VectorWorldPos;
                            //item.transform.position = FindObjectOfType<ARWebCamera>().GetComponent<Camera>().ScreenToWorldPoint(lstVet[i].VectorScreenPos);//lstVet[i].VectorWorldPos;
                        }
                    }
                    else
                    {
                        ZeroCount++;
                    }
                }
                if (ZeroCount > 15)
                {
                    objs.Clear();
                }

                if (ARHumanBodyDataParse.foots[0] == null)
                {
                    ARHumanBodyDataParse.foots[0] = new Queue <float>();
                    ARHumanBodyDataParse.foots[1] = new Queue <float>();
                }
                if (ARHumanBodyDataParse.foots[0].Count < ARHumanBodyDataParse.footsize)
                {
                    ARHumanBodyDataParse.foots[0].Enqueue(lstVet[10].VectorScreenPos.y);
                    ARHumanBodyDataParse.foots[1].Enqueue(lstVet[13].VectorScreenPos.y);
                }
                else
                {
                    ARHumanBodyDataParse.foots[0].Dequeue();
                    ARHumanBodyDataParse.foots[1].Dequeue();

                    ARHumanBodyDataParse.foots[0].Enqueue(lstVet[10].VectorScreenPos.y);
                    ARHumanBodyDataParse.foots[1].Enqueue(lstVet[13].VectorScreenPos.y);
                }

                electRoot.Electric(lstVet);
                StaticPose(lstVet);

                if (lstVet[10].score > 0 && lstVet[13].score > 0)
                {
                    float left  = Vector2.Distance(lstVet[10].VectorScreenPos, lstVet[8].VectorScreenPos);
                    float right = Vector2.Distance(lstVet[13].VectorScreenPos, lstVet[11].VectorScreenPos);
                    if (right < ARHumanBodyDataParse.lengthShoulder && left < ARHumanBodyDataParse.lengthShoulder)
                    {
                        lastNosePose = lstVet[0].VectorScreenPos;
                        return;
                    }

                    if (!lastNosePose.Equals(Vector2.one))
                    {
                        float Distan = Vector2.Distance(lastNosePose, lstVet[0].VectorScreenPos);
                        lastNosePose = lstVet[0].VectorScreenPos;
                        //Debug.Log("Distan="+Distan);
                        if (Distan > ARHumanBodyDataParse.lengthShoulder / 10)
                        {
                            ARHumanBodyDataParse.foots[0].Clear();
                            ARHumanBodyDataParse.foots[1].Clear();
                            return;
                        }
                    }
                }
                lastNosePose = lstVet[0].VectorScreenPos;
                footRoot.FootLift(lstVet);
            });
        }
示例#3
0
        // Use this for initialization
        void Awake()
        {
            //return;
            BaiduARHumanPose humanPose = FindObjectOfType <BaiduARHumanPose>();

            humanPose.InvokeErrorMessage(delegate(string errNum, string errMsg) {
                ARDebug.LogError("errMsg = " + errMsg);
            });


            humanPose.InvokeClearMessage(delegate(){
                ARDebug.Log("InvokeClearMessage ");
                objs.Clear();
            });

            humanPose.InvokePosMessage(delegate(List <OutPutData> lstVet)
            {
                ARDebug.Log("InvokePosMessage Init lstVet = " + lstVet.Count);
                for (int i = 0; i < lstVet.Count; i++)
                {
                    // ARDebug.Log("i = "+i + " score="+lstVet[i].score);
                    if (lstVet[i].score > 0.6)
                    {
                        GameObject item = objs.GetItem();
                        if (item == null)
                        {
                            item = CreateCircleGame();
                            objs.Add(item);
                        }
                        item.SetActive(true);
                        item.transform.position = lstVet[i].VectorWorldPos;
                    }
                }
                if (lstVet.Count < 18)
                {
                    return;
                }
                ARDebug.Log("InvokePosMessage Init22");
                Vector2 vetpos = new Vector2(lstVet[1].VectorScreenPos.x, lstVet[1].VectorScreenPos.y + (lstVet[1].VectorScreenPos.x - lstVet[2].VectorScreenPos.x));
                if (null == collideScript)
                {
                    collideScript = FindObjectOfType <CollideManage>();
                }
                collideScript.SetTexiaoPos(vetpos);


                for (int i = 0; i < lstVet.Count; i++)
                {
                    if (i == 4)  //表示右手腕
                    {
                        Vector2 vet = Vector2.zero;
                        if (IsBound(lstVet[i].VectorScreenPos)) //如果没有检测到点
                        {
                            lstVet[i].VectorScreenPos = lastVet_righthand;
                        }
                        if (IsBound(lstVet[i - 1].VectorScreenPos)) //如果没有检测到点
                        {
                            lstVet[i - 1].VectorScreenPos = lastVet_righthand;
                        }

                        GetHandPos(lstVet[i - 1].VectorScreenPos, lstVet[i].VectorScreenPos, out vet);

                        if (null == collideScript)
                        {
                            collideScript = FindObjectOfType <CollideManage>();
                        }
                        if (!IsBound(vet))
                        {
                            collideScript.HandleData(vet, HumanPoseType.POSE_RIGHTHAND);
                            lastVet_righthand = vet;
                        }
                    }
                    if (i == 7)  //表示左手腕
                    {
                        Vector2 vet = Vector2.zero;
                        if (IsBound(lstVet[i].VectorScreenPos)) //如果没有检测到点
                        {
                            lstVet[i].VectorScreenPos = lastVet_lefthand;
                        }
                        if (IsBound(lstVet[i - 1].VectorScreenPos)) //如果没有检测到点
                        {
                            lstVet[i - 1].VectorScreenPos = lastVet_lefthand;
                        }

                        GetHandPos(lstVet[i - 1].VectorScreenPos, lstVet[i].VectorScreenPos, out vet);

                        if (null == collideScript)
                        {
                            collideScript = FindObjectOfType <CollideManage>();
                        }
                        if (!IsBound(vet))
                        {
                            collideScript.HandleData(vet, HumanPoseType.POSE_LEFTHAND);
                            lastVet_lefthand = vet;
                        }
                        // collideScript.HandleData(lstVet[i].VectorScreenPos);
                    }
                    if (i == 10) //表示右脚
                    {
                        if (null == collideScript)
                        {
                            collideScript = FindObjectOfType <CollideManage>();
                        }
                        if (IsBound(lstVet[i].VectorScreenPos))
                        {
                            lstVet[i].VectorScreenPos = lastVet_rightwrist;
                        }
                        if (!IsBound(lstVet[i].VectorScreenPos))
                        {
                            collideScript.HandleData(lstVet[i].VectorScreenPos, HumanPoseType.POSE_RIGHTWRIST);
                            lastVet_rightwrist = lstVet[i].VectorScreenPos;
                        }
                    }
                    if (i == 13) //表示左脚
                    {
                        if (null == collideScript)
                        {
                            collideScript = FindObjectOfType <CollideManage>();
                        }
                        if (IsBound(lstVet[i].VectorScreenPos))
                        {
                            lstVet[i].VectorScreenPos = lastVet_leftwrist;
                        }
                        if (!IsBound(lstVet[i].VectorScreenPos))
                        {
                            collideScript.HandleData(lstVet[i].VectorScreenPos, HumanPoseType.POSE_LEFTWRIST);
                            lastVet_leftwrist = lstVet[i].VectorScreenPos;
                        }
                    }
                }
            });
        }