private void OnTouchOrClick(Vector2 p) { float x = p.x / Screen.width; float y = p.y / Screen.height; if (x < RaycastMargins.Left || x > (1 - RaycastMargins.Right)) { return; } if (y < RaycastMargins.Bottom || y > (1 - RaycastMargins.Top)) { return; } var camera = Application.isEditor ? Camera.main : ARLocationManager.Instance.MainCamera; var ray = camera.ScreenPointToRay(p); if (state.AppState == AppState.PlacementMode) { RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject go = null; WorldBuilder.Entry entry = null; var o = hit.collider.transform; while (o.parent) { Debug.Log(o.name); entry = worldBuilder.GetWorld().Entries.Find(e => e.Instance == o.gameObject); if (entry != null) { go = entry.Instance; break; } o = o.parent; } if (go != null && entry != null) { selectedObjectEntry = entry; SetObjectSelectedUIVisible(true); SetMoveMode(); return; } } } float enter; if (RaycastGround(ray, out enter)) { var point = ray.GetPoint(enter); switch (state.AppState) { case AppState.PlacementMode: OnPlacementRaycast(point); break; case AppState.MoveMode: OnMoveModeRaycast(point); break; } } }
void InitListeners() { UiElements.ClearWorldBtn.onClick.AddListener(() => { worldBuilder.ClearWorld(); SetObjectSelectedUIVisible(false); state.AppState = AppState.PlacementMode; }); UiElements.CubeBtn.onClick.AddListener(() => { UiElements.CubeBtn.image.color = UiElements.CubeBtn.colors.pressedColor; UiElements.CylinderBtn.image.color = UiElements.CylinderBtn.colors.normalColor; UiElements.LogoBtn.image.color = UiElements.LogoBtn.colors.normalColor; state.CurrentMeshId = "Cube"; }); UiElements.CylinderBtn.onClick.AddListener(() => { UiElements.CubeBtn.image.color = UiElements.CubeBtn.colors.normalColor; UiElements.CylinderBtn.image.color = UiElements.CylinderBtn.colors.pressedColor; UiElements.LogoBtn.image.color = UiElements.LogoBtn.colors.normalColor; state.CurrentMeshId = "Cylinder"; }); UiElements.LogoBtn.onClick.AddListener(() => { UiElements.CubeBtn.image.color = UiElements.CubeBtn.colors.normalColor; UiElements.CylinderBtn.image.color = UiElements.CylinderBtn.colors.normalColor; UiElements.LogoBtn.image.color = UiElements.LogoBtn.colors.pressedColor; state.CurrentMeshId = "Logo"; }); UiElements.DeselectBtn.onClick.AddListener(() => { state.CurrentMeshId = "Cube"; UiElements.CubeBtn.image.color = UiElements.CubeBtn.colors.pressedColor; UiElements.CylinderBtn.image.color = UiElements.CylinderBtn.colors.normalColor; UiElements.LogoBtn.image.color = UiElements.LogoBtn.colors.normalColor; state.AppState = AppState.PlacementMode; SetObjectSelectedUIVisible(false); selectedObjectEntry = null; }); UiElements.RotateBtn.onClick.AddListener(() => { SetRotateMode(); }); UiElements.MoveBtn.onClick.AddListener(() => { SetMoveMode(); }); UiElements.HeightBtn.onClick.AddListener(() => { SetHeightMode(); }); UiElements.DeleteObjectBtn.onClick.AddListener(() => { worldBuilder.RemoveEntry(selectedObjectEntry); }); }