void HandleStartPoint(Standard standardInput, ConsumeControlDelegate consumeControl) { // HandleStartPoint can be called before Start()? if (m_GridModule == null) { return; } GameObject first = this.GetFirstGameObject(rayOrigin); pb_Object pb = first != null?first.GetComponent <pb_Object>() : null; Vector3 rayCollisionPoint = Vector3.zero; Ray ray = new Ray(rayOrigin.position, rayForwardSmoothed.Add(rayOrigin.forward)); if (pb != null && pb_HandleUtility.FaceRaycast(ray, pb, out m_RaycastHit)) { if (m_HoveredObject == null) { m_HoveredObject = pb; } rayCollisionPoint = pb.transform.TransformPoint(m_RaycastHit.point); rayCollisionPoint = Snapping.Snap(rayCollisionPoint, m_SnapIncrement, Vector3.one); m_Plane.SetNormalAndPosition(pb.transform.TransformDirection(m_RaycastHit.normal).normalized, rayCollisionPoint); } else { if (m_HoveredObject != null) { m_HoveredObject = null; m_Plane.SetNormalAndPosition(Vector3.up, Vector3.zero); } } if (m_HoveredObject != null || VRMath.GetPointOnPlane(ray, m_Plane, out rayCollisionPoint)) { m_ProxyRay.SetLength(Vector3.Distance(rayCollisionPoint, ray.origin)); m_GridModule.SetVisible(true); m_GridModule.transform.position = Snapping.Snap(rayCollisionPoint, m_SnapIncrement, Vector3.one); m_GridModule.transform.localRotation = Quaternion.LookRotation(m_Plane.normal); // Calculate the snap increment based on distance from viewer. Split into 4 segments. float distance = Mathf.Clamp(Vector3.Distance(m_GridModule.transform.position, cameraRig.position), 0f, 10f) / 10f; m_SnapIncrement = Snapping.DEFAULT_INCREMENT * System.Math.Max(1, Mathf.Pow(2, (int)(distance * 4))); m_GridModule.SetSnapIncrement(m_SnapIncrement); AShapeCreator.SetSnapIncrement(m_SnapIncrement); m_GuideModule.transform.position = m_GridModule.transform.position; m_GuideModule.transform.localRotation = m_GridModule.transform.localRotation; } else { m_GridModule.SetVisible(false); } if (standardInput != null && standardInput.action.wasJustPressed) { // @todo switch (m_Shape) { default: m_CurrentShape = new CreateCube(); break; } // If shape initialization failed no gameobject will have been created, // so don't worry about cleaning up. if (m_CurrentShape.HandleStart(ray, m_Plane)) { m_AudioModule.Play(m_TriggerReleased, true); m_CurrentShape.onShapeChanged = (v) => { m_GuideModule.transform.position = v; m_AudioModule.Play(m_DragAudio); }; m_CurrentShape.gameObject.GetComponent <MeshRenderer>().sharedMaterial = m_HighlightMaterial; m_State = ShapeCreationState.EndPoint; this.AddToSpatialHash(m_CurrentShape.gameObject); consumeControl(standardInput.action); } } }