public void Clear() { if (spawnedObject != null) { // Destroy existing object Destroy(spawnedObject); ObjectPlaced?.Invoke(null); } }
public void Place(BoardObject obj, Vector2Int position) { if (objects.ContainsKey(position)) { Debug.LogError($"Position {position} already contains object."); return; } if (objects.ContainsValue(obj)) { objects.Remove(GetPosition(obj)); } objects[position] = obj; ObjectPlaced?.Invoke(obj, position); }
void Update() { if (Input.touchCount == 0) { return; } Touch touch = Input.GetTouch(0); if (IsTouchOverUIObject(touch)) { return; } if (touch.phase == TouchPhase.Began) { if (m_RaycastManager.Raycast(touch.position, m_Hits, TrackableType.PlaneWithinPolygon)) { Pose hitPose = m_Hits[0].pose; if (spawnedObject != null) { // Destroy existing object Destroy(spawnedObject); } spawnedObject = Instantiate(placedPrefab, hitPose.position, hitPose.rotation); // content face the user Vector3 lookVector = Camera.main.transform.position - spawnedObject.transform.position; spawnedObject.transform.rotation = Quaternion.LookRotation(lookVector, Vector3.up); spawnedObject.transform.rotation = new Quaternion(0, spawnedObject.transform.rotation.y, 0, spawnedObject.transform.rotation.w) * Quaternion.Euler(0, 180, 0); ObjectPlacementHandler objectPlacementHandler = spawnedObject.GetComponent <ObjectPlacementHandler>(); objectPlacementHandler.SetObject(hitPose.position); m_UIPanelRoot.SetActive(true); ObjectPlaced?.Invoke(objectPlacementHandler); } } }