Пример #1
0
        /// <summary>
        /// 设置物体被抓取
        /// </summary>
        /// <param name="target"></param>
        /// <param name="zValue"></param>
        public void SetObjectGrab(GameObject target, float zValue)
        {
            //停止手上已经抓取的
            if (OperateObject != null)
            {
                OperateObjectHandler();

                OperateObject = null;
            }

            var feature = target.GetComponent <FeaturesObjectController>();

            if (feature == null)
            {
                throw new Exception("设置被抓取的物体不存在FeatureObjectController脚本");
            }

            operaObject   = feature.Opera;
            OperateObject = HandleGrab(feature.operaType);

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

                //设置物体被抓取
                if (OnSetGrab != null)
                {
                    OnSetGrab(OperateObject, InputHand.HandIndex, zValue);
                }

                EventHandGrabObject.SendListener(OperateObject.GrabObject, InputHand.HandIndex);
                EventHandGrabObjectKey.SendListener(OperateObject.GrabObject, InputHand.HandIndex);
            }
        }
Пример #2
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;
            }
        }
Пример #3
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;
            }
        }