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); }
public bool OnUIRay(Ray ray) { //if (ActionConstraint.IsBind(ActionConstraint.Camera_Rotate_Action)||ActionConstraint.IsBind(ActionConstraint.Camera_Zoom_Action)) return false; //如果不是松手或者握拳,返回false if (!(InputHand.IsIdleStatus || InputHand.IsGripStatus)) { return(false); } //如果不是长按并且握拳,返回false if (!IsButtonPress && (InputHand.IsGripStatus)) { return(false); } if (!IsEnable) { return(false); } RaycastHit hit; //持续按下 if (IsButtonPress && currentButton != null) { currentButton.OnDownStay(InputHand.HandIndex); } if (Physics.Raycast(ray, out hit, 10000, 1 << MOperateManager.layerUI)) { //1、如果照射到了,将此碰撞体加0.5f //2、如果是握拳时,碰撞体范围还是以0.5f为算,如果默认,则以0.5为计算 if (uiObject == null) { uiObject = hit.collider.gameObject; EventHandUIRayEnter.SendListener(uiObject, InputHand.HandIndex); } else if (uiObject != hit.collider.gameObject) { EventHandUIRayExit.SendListener(uiObject, InputHand.HandIndex); uiObject = hit.collider.gameObject; EventHandUIRayEnter.SendListener(uiObject, InputHand.HandIndex); } else { } if (hit.collider.gameObject.CompareTag("button")) { if (!IsButtonPress) { if (rayObject == null) { //移入 currentButton = hit.collider.GetComponent <IButton>(); if (currentButton == null) { return(true); } OnButtonEnter(hit.collider.gameObject); } else if (currentObject == hit.collider.gameObject) { //如果相等,计算下 //currentButton.Collider.IsShake = false; //RaycastHit detectionHit; ////如果在扫描时,不是这个物体则进行清空 //if (Physics.Raycast(ray,out detectionHit,10000,1 << MOperateManager.layerUI)) //{ // if (currentObject != detectionHit.collider.gameObject) // { // ClearButton(); // return true; // } // else // { // currentButton.Collider.IsShake = true; // return true; // } //} //else //{ // NotUIRay(); // return false; //} } else { ClearButton(); //移入 currentButton = hit.collider.GetComponent <IButton>(); if (currentButton == null) { return(true); } OnButtonEnter(hit.collider.gameObject); } } else { rayObject = hit.collider.gameObject; //如果握拳,则进行处理 } } else { NotUIRay(); } return(true); } else { NotUIRay(); return(false); } }
public bool OnUIRay(Ray ray) { if (!IsEnable) { return(false); } RaycastHit hit; //持续按下 if (IsButtonPress && currentButton != null) { currentButton.OnDownStay(InputHand.HandIndex); } if (Physics.Raycast(ray, out hit, 10000, 1 << MOperateManager.layerUI)) { if (uiObject == null) { uiObject = hit.collider.gameObject; EventHandUIRayEnter.SendListener(uiObject, InputHand.HandIndex); } else if (uiObject != hit.collider.gameObject) { EventHandUIRayExit.SendListener(uiObject, InputHand.HandIndex); uiObject = hit.collider.gameObject; EventHandUIRayEnter.SendListener(uiObject, InputHand.HandIndex); } else { } if (hit.collider.gameObject.CompareTag("button")) { //照射到的物体 rayObject = hit.collider.gameObject; if (IsButtonPress || MOperateManager.GetHandStatus(InputHand.HandIndex) != Core.MInputHandStatus.Idle) { return(true); } SetButton(rayObject); } else { //如果没有照射到button,表示没有在UI上了。 rayObject = null; if (IsButtonPress) { return(true); } SetButton(null); } return(true); } else { if (uiObject != null) { EventHandUIRayExit.SendListener(uiObject, InputHand.HandIndex); uiObject = null; } rayObject = null; if (IsButtonPress) { return(true); } SetButton(null); return(false); } }