예제 #1
0
        //float minX;
        //float maxX;

        public void Init(RectTransform container, KinectAgent agentPrefab, MagicWallManager manager)
        {
            _parentRectTransform = container;
            _kinectAgentPrefab   = agentPrefab.gameObject;
            _manager             = manager;
            //print("KinectService Init");
        }
예제 #2
0
        /// <summary>
        ///     进入了点开卡片的影响范围
        /// </summary>
        /// <param name="kinectAgent"></param>
        /// <returns></returns>
        public bool HasEnterCardRange(KinectAgent kinectAgent)
        {
            var screenPosition = kinectAgent.GetRefPosition();
            var position       = Camera.main.ScreenToWorldPoint(screenPosition);


            bool hasEnter = false;

            for (int i = 0; i < _manager.operateCardManager.EffectAgents.Count; i++)
            {
                var agent    = _manager.operateCardManager.EffectAgents[i];
                var distance = Vector2.Distance(agent.transform.position, position);
                if (distance < safeDistance)
                {
                    hasEnter = true;
                }
            }

            return(hasEnter);
        }
예제 #3
0
        /// <summary>
        /// 增加一个新的体感卡片
        /// </summary>
        /// <param name="kinectAgent"></param>
        public KinectAgent AddKinectAgents(Vector2 screenPosition, long userId)
        {
            var item = GetAgentById(userId);

            //最多出现体感球
            if (item != null || kinectAgents.Count > 1)
            {
                return(null);
            }
            else
            {
                // 屏幕坐标转UI坐标
                Vector2 rectPosition = new Vector2();
                RectTransformUtility.ScreenPointToLocalPointInRectangle(_agentContainer, screenPosition, null, out rectPosition);

                KinectAgent kinectAgent = Instantiate(_kinectAgentPrefab, _agentContainer);
                kinectAgent.GetComponent <RectTransform>().anchoredPosition = rectPosition;
                kinectAgent.Init(userId, _manager);
                _manager.collisionManager.AddCollisionEffectAgent(kinectAgent);
                _kinectAgents.Add(kinectAgent);
                return(kinectAgent);
            }
        }
예제 #4
0
        /// <summary>
        ///     进入了体感卡片的影响范围
        /// </summary>
        /// <param name="kinectAgent"></param>
        /// <returns></returns>
        public KinectAgent HasEnterKinectCardRange(KinectAgent kinectAgent)
        {
            var screenPosition = kinectAgent.GetRefPosition();
            var position       = Camera.main.ScreenToWorldPoint(screenPosition);

            KinectAgent targetKinectAgent = null;

            for (int i = 0; i < _kinectAgents.Count; i++)
            {
                var agent = _kinectAgents[i];

                if ((agent.userId != kinectAgent.userId) && agent.status == KinectAgentStatusEnum.Normal)
                {
                    var distance = Vector2.Distance(agent.transform.position, position);
                    if (distance < safeDistance)
                    {
                        targetKinectAgent = agent;
                    }
                }
            }

            return(targetKinectAgent);
        }
예제 #5
0
        /// <summary>
        /// REF: https://www.yuque.com/u314548/fc6a5l/dozp0e
        /// </summary>
        /// <param name="flockAgent"></param>
        private void DoChooseForKinect(FlockAgent flockAgent)
        {
            int _data_id  = flockAgent.DataId;
            var _dataType = flockAgent.dataTypeEnum;

            CardAgent _cardAgent;

            if (CanChoose(flockAgent))
            {
                flockAgent.flockStatus = FlockStatusEnum.TOHIDE;

                var           flockAgentPosition = flockAgent.GetComponent <RectTransform>().transform.position;
                RectTransform flockRect          = flockAgent.GetComponent <RectTransform>();

                // 获取kinect obj 的位置
                var         agents            = _manager.kinectManager.kinectAgents;
                var         distance          = 3000f;
                KinectAgent targetKinectAgent = null;
                for (int i = 0; i < agents.Count; i++)
                {
                    var kinectPosition = agents[i].GetComponent <RectTransform>().transform.position;
                    var d = Vector2.Distance(kinectPosition, flockAgentPosition);

                    // 添加了安全距离
                    if (d < distance && d < 1500f)
                    {
                        targetKinectAgent = agents[i];
                        distance          = d;
                    }
                }


                if (targetKinectAgent == null)
                {
                    flockAgent.flockStatus = FlockStatusEnum.NORMAL;
                    DoChooseForCommon(flockAgent);
                    return;
                }


                /// 遮罩中存在贴附的卡片
                if (targetKinectAgent.refFlockAgent != null)
                {
                    var refFlockAgent = targetKinectAgent.refFlockAgent;
                    targetKinectAgent.RecoverColliderEffect();

                    RemoveRefCard(targetKinectAgent.refFlockAgent);
                }

                targetKinectAgent.refFlockAgent = flockAgent;

                if (targetKinectAgent.status == KinectAgentStatusEnum.Small)
                {
                    // 恢复大小并打开检测
                    targetKinectAgent.SetDisableEffect(false);
                    targetKinectAgent.status = KinectAgentStatusEnum.Recovering;
                    targetKinectAgent.GetComponent <RectTransform>().DOScale(1f, 0.5f).OnComplete(
                        () => {
                        targetKinectAgent.status = KinectAgentStatusEnum.Hide;
                    }
                        );
                }

                if (targetKinectAgent.status == KinectAgentStatusEnum.Destoring)
                {
                    targetKinectAgent.SetDisableEffect(false);
                    targetKinectAgent.CancelClose();
                }

                // 点击的卡片移动至遮罩位置,生成卡片并放大

                targetKinectAgent.status = KinectAgentStatusEnum.WaitingHiding;
                targetKinectAgent.SetDisableEffect(false);

                var ani_time = 1.5f;
                var scaleAni = flockAgent.transform.DOScale(new Vector3(0.2f, 0.2f, 0.2f), ani_time - 0.2f);
                var moveAni  = flockAgent.transform.DOMove(targetKinectAgent.transform.position, ani_time)
                               .OnUpdate(() => {})
                               .OnComplete(() => {
                    flockAgent.transform.SetParent(_manager.OperationPanel);

                    targetKinectAgent.Hide();
                    flockAgent.flockStatus = FlockStatusEnum.HIDE;
                    flockAgent.gameObject.SetActive(false);

                    var _cardGenPos = flockAgent.GetComponent <RectTransform>().anchoredPosition;

                    // 创建卡片
                    _cardAgent = _manager.operateCardManager.CreateNewOperateCard(_data_id, _dataType, _cardGenPos, flockAgent);
                    _cardAgent.SetDisableEffect(true);

                    _cardAgent.GoToFront(() => {
                        _cardAgent.SetDisableEffect(false);
                        //targetKinectAgent.SetDisableEffect(true);
                    });
                });

                flockAgent.flockTweenerManager.Add(FlockTweenerManager.Kinnect_Choose_Scale, scaleAni);
                flockAgent.flockTweenerManager.Add(FlockTweenerManager.Kinnect_Choose_Move, moveAni);
            }
        }
예제 #6
0
        public void Monitoring()
        {
            if (!isInit)
            {
                return;
            }
            if (kinectManager == null)
            {
                kinectManager = KinectManager.Instance;
            }
            //生成体感卡片
            List <long> ids = kinectManager.GetAllUserIds();

            for (int i = 0; i < ids.Count; i++)
            {
                long userid = ids[i];
                //获取关节
                int jointIndex = (int)KinectInterop.JointType.Head;
                //if (!kinectManager.IsJointTracked(userid, jointIndex))
                //{
                //    continue;
                //}
                //当检测到用户时,就获取到用户的位置信息
                Vector3 userPos = kinectManager.GetUserPosition(userid);
                //Vector3 userPos = kinectManager.GetJointKinectPosition(userid, jointIndex);
                //print(userid + "===" + userPos);
                //kinect在背后,x正负值颠倒y
                //userPos = new Vector3(-userPos.x, userPos.y, userPos.z);
                //保留?位小数
                //float x = float.Parse(string.Format("{0:f3}", userPos.x));
                //float y = float.Parse(string.Format("{0:f3}", userPos.y));

                //if (x<minX)
                //{
                //    minX = x;
                //    print("minX"+minX + "---" + userPos.z);
                //}
                //if (x>maxX)
                //{
                //    maxX = x;
                //    print("maxX" + maxX + "---" + userPos.z);
                //}

                //屏幕中心点屏幕坐标
                Vector2 origin = new Vector2(Screen.width / 2, Screen.height / 2);
                //Vector2 userScreenPos = new Vector2(origin.x + basicDistance / 2 / userPos.z * x * Screen.width / 2, origin.y + basicDistance / userPos.z * y * Screen.height / 2); // 正式环境删除400
                Vector2 userScreenPos = new Vector2(origin.x + userPos.x / 4f * Screen.width, userPos.y * Screen.height / 2);


                //Vector2 userScreenPos = new Vector2(origin.x + userPos.x;
                KinectAgent kinectAgent = _manager.kinectManager.GetAgentById(userid);

                if (!InEffectiveRange(new Vector3(userScreenPos.x, userScreenPos.y, userPos.z)))
                {
                    //print("超出边界");
                    if (kinectAgent != null)
                    {
                        kinectAgent.Close();
                    }
                    continue;
                }

                //添加逻辑
                if (kinectAgent == null)
                {
                    if (_manager.kinectManager.CalScreenPositionIsAvailable(userScreenPos))
                    {
                        _manager.kinectManager.AddKinectAgents(userScreenPos, userid);
                    }
                }
                else
                {
                    //移动体感卡片,不进行上下移动
                    Vector2 rectPosition = new Vector2();
                    RectTransformUtility.ScreenPointToLocalPointInRectangle(_parentRectTransform, userScreenPos, null, out rectPosition);
                    float currentY = kinectAgent.GetComponent <RectTransform>().anchoredPosition.y;
                    var   to       = new Vector2(rectPosition.x, currentY);

                    Debug.Log("@@@ kinectAgent 进行移动");

                    kinectAgent.UpdatePos(to);
                    //kinectAgent.UpdatePos(rectPosition);

                    if (_manager.kinectManager.HasEnterCardRange(kinectAgent))
                    {
                        kinectAgent.Close();
                    }
                    KinectAgent target = _manager.kinectManager.HasEnterKinectCardRange(kinectAgent);
                    if (target)
                    {
                        if (kinectAgent.createTime < target.createTime)
                        {
                            kinectAgent.Close();
                        }
                    }
                }
            }


            // 那 ids 去进行校对,返回需要删除的遮罩
            var existAgents = _manager.kinectManager.kinectAgents;

            // 比对ids 和 existagents.userid
            foreach (var item in existAgents)
            {
                if (!ids.Contains(item.userId) && item.status != KinectAgentStatusEnum.Destoring && item.status != KinectAgentStatusEnum.Obsolete)
                {
                    //print("目标被移除:" + item.userId);
                    item.Close();
                }
            }
            // 得出结果,调用kinectAgent.Close();
        }