using Simulator.Data; using System; using UnityEngine; using UnityEngine.EventSystems; using UVC.Data.Core; public enum ComponentType { Source, Sink, Rack, Queue, ASRS, RobotArm, Processor, Worker } public class ComponentBase : MonoBehaviour,IPointerClickHandler { protected ComponentDataBase data; protected ModelDataBase modelData; public ComponentType componentType; public Action onComponentClicked; public GameObject pivot; public void SetPosition() { if (pivot != null) { pivot.transform.position = new Vector3(data.physical.position.x, 0, -data.physical.position.y); } else { transform.position = new Vector3(data.physical.position.x, 0, -data.physical.position.y); } } public void SetRotation() { if (pivot != null) { pivot.transform.rotation = Quaternion.Euler(0, data.physical.orientation, 0); } else { transform.rotation = Quaternion.Euler(0, data.physical.orientation, 0); } } public virtual void GetModelData(DataObject modelData) { } public virtual void DecreaseEntity(Entity entity) { } public virtual void getpath() { } protected 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); collider.size = new Vector3(Mathf.Abs(collider.size.x), Mathf.Abs(collider.size.y), Mathf.Abs(collider.size.z)); collider.isTrigger = true; if (data != null) { data.physical.position.onChanged += SetPosition; data.physical.onOrientationChanged += SetRotation; } pivot = new GameObject($"{this.gameObject.name}pivot"); pivot.transform.position = new Vector3(bounds.center.x,0,bounds.center.z); gameObject.transform.parent = pivot.transform; } public void OnPointerClick(PointerEventData eventData) { if (!PlayerPropertyDataBase.isPlaying) { GameObject clickedObject = eventData.pointerCurrentRaycast.gameObject; getpath(); } } }