Esempio n. 1
0
    void ontest()
    {
        gameObject.AddGrabObject(onGrab);
        gameObject.RemoveGrabObject(onGrab);
        gameObject.RemoveGrabObjectAll();

        gameObject.AddReleaseObject(OnRelease);
        gameObject.RemoveReleaseObject(OnRelease);
        gameObject.RemoveReleaseObjectAll();

        gameObject.AddRayTargetEnter(OnTargetEnter);
        gameObject.RemoveRayTargetEnter(OnTargetEnter);
        gameObject.RemoveRayTargetEnter();


        gameObject.AddRayTargetExit(OnTargetExit);
        gameObject.RemoveRayTargetExit();
        gameObject.RemoveRayTargetExit(OnTargetExit);


        EventHandRay.AddListener(onRay);
        EventHandRay.RemoveListener(onRay);

        EventHandRays.AddListener(OnRays);
        EventHandRays.RemoveListener(OnRays);

        EventHandStart.AddListener(onstart);
        EventHandStart.RemoveListener(onstart);

        EventHandStop.AddListener(onstop);
        EventHandStop.RemoveListener(onstop);

        EventHandUIRay.AddListener(onRay);
        EventHandUIRay.RemoveListener(onRay);

        EventCameraZoom.AddListener(onzoom);
        EventCameraZoom.RemoveListener(onzoom);

        EventCameraRotate.AddListener(onrotate);
        EventCameraRotate.RemoveListener(onrotate);

        EventHandGrabObject.AddListener(ongrabobject);
        EventHandGrabObject.RemoveListener(ongrabobject);

        EventHandReleaseObject.AddListener(onreleaseobject);
        EventHandReleaseObject.RemoveListener(onreleaseobject);

        EventHandGrabObjectKey.AddListener(gameObject, onGrab);
        EventHandGrabObjectKey.RemoveListener(gameObject, onGrab);

        EventHandReleaseObjectKey.AddListener(gameObject, OnRelease);
        EventHandReleaseObjectKey.RemoveListener(gameObject, OnRelease);

        EventHandRayTarget.AddListener(onraytarget);
        EventHandRayTarget.RemoveListener(onraytarget);

        EventHandRayTargetEnter.AddListener(gameObject, OnTargetEnter);
        EventHandRayTargetEnter.RemoveListener(gameObject, OnTargetEnter);

        EventHandRayTargetExit.AddListener(gameObject, OnTargetExit);
        EventHandRayTargetExit.RemoveListener(gameObject, OnTargetExit);

        EventHandUIRayEnter.AddListener(gameObject, onuienter);
        EventHandUIRayEnter.RemoveListener(gameObject, onuienter);

        EventHandUIRayExit.AddListener(gameObject, onuiexit);
        EventHandUIRayExit.RemoveListener(gameObject, onuiexit);

        EventHandUIRay.AddListener(onRay);
        EventHandUIRay.RemoveListener(onRay);
    }
Esempio n. 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;
            }
        }
Esempio n. 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;
            }
        }