Exemplo n.º 1
0
        /// <summary>
        /// 照射物体处理
        /// </summary>
        /// <param name="hit"></param>
        void OnRayTarget(RaycastHit hit)
        {
            EventHandRayTarget.SendListener(hit, InputHand.HandIndex);

            switch (InputHand.HandStatus)
            {
            case MInputHandStatus.Idle:

                if (hit.collider == null)
                {
                    OnNoRayTarget();
                    return;
                }

                if (operaObject != null && operaObject.gameObject == hit.collider.gameObject)
                {
                    return;
                }

                if (operaObject != null)
                {
                    //处理之前的
                    OnNoRayTarget();
                }

                operaObject = hit.collider.GetComponent <OperaObject>();
                EventHandRayTargetEnter.SendListener(operaObject.FeaturesObject.gameObject, InputHand.HandIndex);

                if (operaObject == null)
                {
                    return;
                }
                ShowLabel();

                //显示高亮
                ShowHightLight(false);

                break;

            case MInputHandStatus.Grip:

                if (operaObject != null && operaObject.gameObject != hit.collider.gameObject)
                {
                    return;
                }
                HideLabel();

                InputHand.HandStatus = MInputHandStatus.Grab;    //将该手状态设置为抓取状态

                break;

            case MInputHandStatus.Grab:
                if (operaObject == null)
                {
                    InputHand.HandStatus = MInputHandStatus.Idle;
                    return;
                }

                ShowHightLight(true);
                HideLabel();

                OperateObject = HandleGrab(operaObject.FeaturesObject.operaType);

                if (OperateObject != null)
                {
                    OperateObject.HandStatus = MInputHandStatus.Grabing;

                    EventHandGrabObject.SendListener(OperateObject.GrabObject, InputHand.HandIndex);
                    EventHandGrabObjectKey.SendListener(OperateObject.GrabObject, InputHand.HandIndex);
                }

                InputHand.HandStatus = MInputHandStatus.Grabing;

                break;

            case MInputHandStatus.Invalid:
                if (OnInvalid != null)
                {
                    OnInvalid(OperateObject, InputHand.HandIndex);
                }
                break;

            case MInputHandStatus.Error:

                if (OnError != null)
                {
                    OnError(OperateObject, InputHand.HandIndex);
                }

                break;

            case MInputHandStatus.Grabing:
                //不可操作中,表示正在有物体进行操作,不可进行其他操作
                if (OnGrabing != null)
                {
                    OnGrabing(OperateObject, InputHand.HandIndex);
                }

                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 照射物体处理
        /// </summary>
        /// <param name="hit"></param>
        void OnRayTarget(RaycastHit hit, Ray ray)
        {
            switch (InputHand.HandStatus)
            {
            case MInputHandStatus.Idle:

                EventHandRayTarget.SendListener(hit, InputHand.HandIndex);
                ShowHightLight(false);          //现在是每帧检测
                if (operaObject == null)
                {
                    operaObject = hit.collider.GetComponent <OperaObject>();
                    if (operaObject == null)
                    {
                        return;
                    }
                    IdleOperateEnter();
                }
                else if (operaObject.gameObject == hit.collider.gameObject)
                {
                    //operaObject.BoxCollider.IsShake = false;

                    //RaycastHit detectionHit;
                    //if (Physics.Raycast(ray,out detectionHit,10000,1 << MOperateManager.layerRay | 1 << MOperateManager.layerObject))
                    //{
                    //    if (operaObject.gameObject != detectionHit.collider.gameObject)
                    //    {
                    //        OnNoRayTarget();
                    //        return;
                    //    }
                    //    else
                    //    {
                    //        operaObject.BoxCollider.IsShake = true;
                    //        return;
                    //    }
                    //}
                    //else
                    //{
                    //    OnNoRayTarget();
                    //    return;
                    //}
                }
                else
                {
                    OnNoRayTarget();
                    operaObject = hit.collider.GetComponent <OperaObject>();
                    if (operaObject == null)
                    {
                        return;
                    }
                    IdleOperateEnter();
                }


                break;

            case MInputHandStatus.Grip:
                if (operaObject == null || operaObject != null && operaObject.gameObject != hit.collider.gameObject)
                {
                    return;
                }

                HideLabel();

                InputHand.HandStatus = MInputHandStatus.Grab;    //将该手状态设置为抓取状态

                break;

            case MInputHandStatus.Grab:

                if (operaObject == null)
                {
                    return;
                }


                HideLabel();

                OperateObject = HandleGrab(operaObject.FeaturesObject.operaType);

                if (OperateObject != null)
                {
                    OperateObject.HandStatus = MInputHandStatus.Grabing;

                    EventHandGrabObject.SendListener(OperateObject.GrabObject, InputHand.HandIndex);
                    EventHandGrabObjectKey.SendListener(OperateObject.GrabObject, InputHand.HandIndex);
                }

                InputHand.HandStatus = MInputHandStatus.Grabing;

                break;

            case MInputHandStatus.Invalid:
                if (OnInvalid != null)
                {
                    OnInvalid(OperateObject, InputHand.HandIndex);
                }
                break;

            case MInputHandStatus.Error:

                if (OnError != null)
                {
                    OnError(OperateObject, InputHand.HandIndex);
                }

                break;

            case MInputHandStatus.Grabing:
                ShowHightLight(true);
                //不可操作中,表示正在有物体进行操作,不可进行其他操作
                if (OnGrabing != null)
                {
                    OnGrabing(OperateObject, InputHand.HandIndex);
                }

                break;

            default:
                break;
            }
        }