Added camera movement and home button to bring user back to module structure

This commit is contained in:
Christen
2026-02-09 20:53:23 -05:00
parent 17d117859a
commit 93e0ec0ed9
7 changed files with 801 additions and 84 deletions

View File

@@ -1,49 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
public class ModuleSelector : MonoBehaviour
{
public Camera mainCamera;
public Cinemachine.CinemachineVirtualCamera virtualCamera;
private ModuleBase prevModule; //Store previous module then when unselected call that module's unselect function to make panel disappear or something
public UserCameraControl cameraController;
[System.NonSerialized]
public ModuleBase prevModule;
// Update is called once per frame
void Update()
{
// If user is moving the camera, deselect current module
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) ||
Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D))
{
ClearSelection();
return;
}
if (Input.GetMouseButtonDown(0))
{
// Don't process any clicks if the click is over UI element
if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
// Ignore clicks over UI
if (EventSystem.current != null &&
EventSystem.current.IsPointerOverGameObject())
return;
if (prevModule != null)
{
prevModule.DeSelect();
virtualCamera.LookAt = null;
virtualCamera.Follow = null;
}
ClearSelection();
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
ModuleBase module = hit.collider.GetComponentInParent<ModuleBase>();
if (module != null && module != prevModule)
if (module != null)
{
module.OnSelect();
prevModule = module;
virtualCamera.LookAt = module.transform;
virtualCamera.Follow = module.transform;
}
else
{
prevModule = null;
// Servo highlighting support
ServoMotorModule servo = module.GetComponent<ServoMotorModule>();
ServoMotorModule.selectedModule = servo;
// tell camera to look at module
if (cameraController != null)
cameraController.LookAtTarget(module.transform);
}
}
else
{
prevModule = null;
ClearSelection();
}
}
}
}
// Deselect current module and clear selection state
void ClearSelection()
{
if (prevModule != null)
{
prevModule.DeSelect();
prevModule = null;
}
ServoMotorModule.selectedModule = null;
if (EventSystem.current != null)
EventSystem.current.SetSelectedGameObject(null);
}
}