using Unity.VisualScripting; using UnityEngine; using UnityEngine.EventSystems; public class SimulationModel : MonoBehaviour, IClickable { public string modelName; public string modelType; public string modelID; private bool isQuitting = false; void Awake() { FitCollider(); } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { } // Update is called once per frame void Update() { } private void OnEnable() { DataManager.I.AddModel(this); } private void OnDisable() { if (isQuitting) return; DataManager.I.RemoveModel(this); } void OnApplicationQuit() { isQuitting = true; } public void OnClick() { Debug.Log("Clicked : " + gameObject.name); } void FitCollider() { var renderers = GetComponentsInChildren(); if (renderers.Length == 0) return; Bounds bounds = renderers[0].bounds; foreach (var r in renderers) bounds.Encapsulate(r.bounds); BoxCollider collider = GetComponent(); if (!collider) collider = gameObject.AddComponent(); collider.center = transform.InverseTransformPoint(bounds.center); collider.size = transform.InverseTransformVector(bounds.size); } }