2025-10-16 10:24:29 +09:00
|
|
|
using Simulator.Data;
|
2025-12-16 17:57:20 +09:00
|
|
|
using System;
|
2025-10-16 10:24:29 +09:00
|
|
|
using UnityEngine;
|
2025-11-11 11:27:39 +09:00
|
|
|
using UnityEngine.EventSystems;
|
2025-10-16 10:24:29 +09:00
|
|
|
using UVC.Data.Core;
|
|
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
namespace Simulator.Data
|
2025-10-16 10:24:29 +09:00
|
|
|
{
|
2026-02-25 16:30:12 +09:00
|
|
|
public enum ComponentType
|
|
|
|
|
{
|
|
|
|
|
Source,
|
|
|
|
|
Sink,
|
|
|
|
|
Rack,
|
|
|
|
|
Queue,
|
|
|
|
|
ASRS,
|
|
|
|
|
RobotArm,
|
|
|
|
|
Processor,
|
|
|
|
|
Worker
|
|
|
|
|
}
|
2025-10-16 10:24:29 +09:00
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
public class ComponentBase : MonoBehaviour, IPointerClickHandler
|
2025-10-16 10:24:29 +09:00
|
|
|
{
|
2026-02-25 16:30:12 +09:00
|
|
|
protected ComponentDataBase data;
|
|
|
|
|
protected ModelDataBase modelData;
|
|
|
|
|
public ComponentType componentType;
|
|
|
|
|
public Action<ComponentType, ComponentDataBase> onComponentClicked;
|
|
|
|
|
public GameObject pivot;
|
|
|
|
|
|
|
|
|
|
public void SetPosition()
|
2026-02-03 11:40:26 +09:00
|
|
|
{
|
2026-02-25 16:30:12 +09:00
|
|
|
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);
|
|
|
|
|
}
|
2026-02-03 11:40:26 +09:00
|
|
|
}
|
2026-02-25 16:30:12 +09:00
|
|
|
|
|
|
|
|
public void SetRotation()
|
2026-02-03 11:40:26 +09:00
|
|
|
{
|
2026-02-25 16:30:12 +09:00
|
|
|
if (pivot != null)
|
|
|
|
|
{
|
|
|
|
|
pivot.transform.rotation = Quaternion.Euler(0, data.physical.orientation, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
transform.rotation = Quaternion.Euler(0, data.physical.orientation, 0);
|
|
|
|
|
}
|
2026-02-03 11:40:26 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
public virtual void GetModelData(DataObject modelData)
|
2026-02-03 11:40:26 +09:00
|
|
|
{
|
|
|
|
|
}
|
2026-02-25 16:30:12 +09:00
|
|
|
|
|
|
|
|
public virtual void DecreaseEntity(Entity entity)
|
2026-02-03 11:40:26 +09:00
|
|
|
{
|
|
|
|
|
}
|
2025-10-16 10:24:29 +09:00
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
public virtual void GetPath()
|
|
|
|
|
{
|
|
|
|
|
}
|
2025-11-04 11:02:02 +09:00
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
public virtual void SetEntity(string key, string name = "")
|
|
|
|
|
{
|
|
|
|
|
}
|
2025-11-11 11:27:39 +09:00
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
protected void FitCollider()
|
|
|
|
|
{
|
|
|
|
|
var renderers = GetComponentsInChildren<Renderer>();
|
|
|
|
|
if (renderers.Length == 0) return;
|
2025-12-17 11:42:57 +09:00
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
Bounds bounds = renderers[0].bounds;
|
|
|
|
|
foreach (var r in renderers)
|
|
|
|
|
{
|
|
|
|
|
if (r.gameObject.name.Contains("StackerCrane"))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
bounds.Encapsulate(r.bounds);
|
|
|
|
|
}
|
2026-02-10 17:01:25 +09:00
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
BoxCollider collider = GetComponent<BoxCollider>();
|
|
|
|
|
if (!collider) collider = gameObject.AddComponent<BoxCollider>();
|
2025-11-11 11:27:39 +09:00
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
if (pivot != null)
|
2026-02-10 17:01:25 +09:00
|
|
|
{
|
2026-02-25 16:30:12 +09:00
|
|
|
gameObject.transform.parent = null;
|
|
|
|
|
Destroy(pivot.gameObject);
|
2026-02-10 17:01:25 +09:00
|
|
|
}
|
2026-02-25 16:30:12 +09:00
|
|
|
pivot = new GameObject($"{this.gameObject.name}pivot");
|
|
|
|
|
pivot.transform.position = new Vector3(bounds.center.x, 0, bounds.center.z);
|
|
|
|
|
gameObject.transform.parent = pivot.transform;
|
2026-02-10 17:01:25 +09:00
|
|
|
}
|
2025-11-11 11:27:39 +09:00
|
|
|
|
2026-02-25 16:30:12 +09:00
|
|
|
protected virtual void OnDestroy()
|
2026-02-03 11:40:26 +09:00
|
|
|
{
|
2026-02-25 16:30:12 +09:00
|
|
|
if (data != null)
|
|
|
|
|
{
|
|
|
|
|
data.physical.position.onChanged -= SetPosition;
|
|
|
|
|
data.physical.onOrientationChanged -= SetRotation;
|
|
|
|
|
}
|
2026-02-03 11:40:26 +09:00
|
|
|
}
|
2026-02-25 16:30:12 +09:00
|
|
|
|
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
2026-02-10 17:01:25 +09:00
|
|
|
{
|
2026-02-25 16:30:12 +09:00
|
|
|
GameObject clickedObject = eventData.pointerCurrentRaycast.gameObject;
|
|
|
|
|
GetPath();
|
2026-02-10 17:01:25 +09:00
|
|
|
}
|
2025-11-11 11:27:39 +09:00
|
|
|
}
|
2025-10-16 10:24:29 +09:00
|
|
|
}
|