Exemple #1
0
        /// <summary>
        ///录入关节信息
        /// </summary>
        /// <param name="playerGesture"></param>
        public void SetGestureJointData(PlayerGestureInfo.GestureType gestureType, PlayerGestureData playerGesture)
        {
            SetGestureJointPos(gestureType, playerGesture, HandRightJoints);
            SetGestureJointPos(gestureType, playerGesture, HandLeftJoints);
            SetGestureJointPos(gestureType, playerGesture, FootRightJoints);
            SetGestureJointPos(gestureType, playerGesture, FootLeftJoints);
            byte[] buff = KINECTManager.Instance.GetOrbbecImage(KinectImageType.colour).ScaleTexture(192, 108).EncodeToJPG(10);

            Texture2D texture2D = new Texture2D(0, 0);

            texture2D.LoadImage(buff);
            texture2D.Apply();

            switch (gestureType)
            {
            case PlayerGestureInfo.GestureType.End:
                playerGesture.playerGestureInfo.intoPhotoBase64 = new _Texture2D(texture2D);   //保存当前图像成Base64作为识别手势的标准
                break;

            case PlayerGestureInfo.GestureType.Start:
                playerGesture.playerGestureInfo.leavePhotoBase64 = new _Texture2D(texture2D);    //保存当前图像成Base64作为识别手势的标准
                break;

            default:
                break;
            }

            GC.Collect();
            Resources.UnloadUnusedAssets();//内存释放
        }
Exemple #2
0
 /// <summary>
 /// 恢复定义发现玩家手势选项,发现玩家只能用一种手势,但第一了其他手势为识别玩家时,其他的手势更新为默认False
 /// </summary>
 /// <param name="playerGesture"></param>
 public void ReturnFindGesture(PlayerGestureData playerGesture)
 {
     foreach (var item in playerGestureDatas)
     {
         if (item != playerGesture)
         {
             item.playerGestureInfo.isFindGesture = false;
         }
     }
     PlayerManager.Instance.RecognitionGestureName = playerGesture.playerGestureInfo.GestureName;
 }
Exemple #3
0
        //封装设置关节方向方法,
        private void SetGestureJointPos(PlayerGestureInfo.GestureType gestureType, PlayerGestureData playerGesture, KinectInterop.JointType[] jointTypes)
        {
            for (int i = 0; i < jointTypes.Length - 1; i++)
            {
                Vector3  pos1 = KINECTManager.Instance.GetIndexJointPos(0, jointTypes[i], Camera.main, new Rect(0, 0, 1920, 1080));
                Vector3  pos2 = KINECTManager.Instance.GetIndexJointPos(0, jointTypes[i + 1], Camera.main, new Rect(0, 0, 1920, 1080));
                _Vector3 dis  = new _Vector3((pos2 - pos1).normalized);

                playerGesture.playerGestureInfo.SetPlayerGestureJointData(gestureType, jointTypes[i], dis);
            }
        }
Exemple #4
0
        private int GetJointPos(GestureJudgeData gestureJudge, PlayerGestureData playerGestureData, KinectInterop.JointType[] jointTypes)
        {
            for (int i = 0; i < jointTypes.Length; i++)
            {
                if (!KinectManager.Instance.IsInitialized())
                {
                    return(0);
                }
            }
            gesturesValue.Clear();
            for (int i = 0; i < 2; i++)
            {
                Vector3 pos1 = KINECTManager.Instance.GetUserIDJointPos(userID, jointTypes[i], Camera.main, new Rect(0, 0, 1920, 1080));     //实时关节位置
                Vector3 pos2 = KINECTManager.Instance.GetUserIDJointPos(userID, jointTypes[i + 1], Camera.main, new Rect(0, 0, 1920, 1080)); //实时关节位置

                _Vector3 dir = new _Vector3((pos2 - pos1).normalized);

                PlayerGestureJointData EndPlayerGestures = playerGestureData.playerGestureInfo.GetPlayerGestureJointData(
                    PlayerGestureInfo.GestureType.End, jointTypes[i]);                                                     //获取本地储存结束的关节数据
                PlayerGestureJointData StartPlayerGestures = playerGestureData.playerGestureInfo.GetPlayerGestureJointData(
                    PlayerGestureInfo.GestureType.Start, jointTypes[i]);                                                   //获取本地储存开始的关节数据

                float EndAngle   = Vector3.Angle(EndPlayerGestures.direction.Get(), dir.Get());
                float StartAngle = Vector3.Angle(StartPlayerGestures.direction.Get(), dir.Get());

                if (EndAngle <= playerGestureData.playerGestureInfo.offset)
                {
                    gesturesValue.Add(2);
                }
                else if (StartAngle <= playerGestureData.playerGestureInfo.offset)
                {
                    gesturesValue.Add(1);
                }
                else
                {
                    gesturesValue.Add(0);
                }
            }

            if (!gesturesValue.Contains(0) && !gesturesValue.Contains(1))
            {
                return(2);
            }
            else if (!gesturesValue.Contains(0) && !gesturesValue.Contains(2))
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Exemple #5
0
 /// <summary>
 /// 初始化按钮
 /// </summary>
 /// <param name="_playerGestureData"></param>
 /// <param name="_setGesturePanel"></param>
 public void Init(PlayerGestureData _playerGestureData, SetGesturePanel _setGesturePanel)
 {
     playerGestureData = _playerGestureData;
     GestureName.text  = _playerGestureData.playerGestureInfo.GestureName;
     if (_setGesturePanel)
     {
         setGesturePanel = _setGesturePanel;
     }
     gestureButton.OnClick.AddListener(() =>
     {
         setGesturePanel.ReturnGestureButton(this);
     });
     if (_playerGestureData.playerGestureInfo.isFindGesture)
     {
         PlayerGestureManager.Instance.ReturnFindGesture(_playerGestureData);
     }
 }
Exemple #6
0
        //添加手势
        private void AddGesture()
        {
            selectionWindow.Recovery();
            eventWindows.Recovery();

            PlayerGestureData playerGesture = new PlayerGestureData();//实例化一个手势数据对象

            playerGesture.playerGestureInfo.GestureName = "GestureName" + gestures.Count;

            Gesture gesture = AddGesture(playerGesture);

            gesture.gestureButton.isChoice = true;
            ReturnGestureButton(gesture);
            gestureWindows.SetPanel(gesture, this);

            PlayerGestureManager.Instance.AddPlayerGestureData(playerGesture);
        }
Exemple #7
0
        //封装手势按钮天机方法,返回当前按钮
        private Gesture AddGesture(PlayerGestureData playerGesture)
        {
            Gesture gesture = SourcesManager.LoadSources <Gesture>("Gesture", Content);//在对象池中生成

            gestures.Add(gesture);
            gesture.Init(playerGesture, this);//初始化按钮
            gesture.gestureButton.OffChoice.AddListener(() =>
            {
                gestureWindows.Recovery();
                selectionWindow.Recovery();
                eventWindows.Recovery();
            });//添加按钮事件
            gesture.gestureButton.OnChoice.AddListener(() =>
            {
                gestureWindows.Recovery();
                eventWindows.Recovery();
                selectionWindow.SetPanel(gesture);
            });
            return(gesture);
        }
Exemple #8
0
 /// <summary>
 /// 删除手势数据
 /// </summary>
 /// <param name="playerGesture"></param>
 public void RemovePlayerGestureData(PlayerGestureData playerGesture)
 {
     playerGestureDatas.Remove(playerGesture);
 }
Exemple #9
0
 /// <summary>
 /// 添加手势数据
 /// </summary>
 /// <param name="playerGesture"></param>
 public void AddPlayerGestureData(PlayerGestureData playerGesture)
 {
     playerGestureDatas.Add(playerGesture);
 }