Files
Simulation/Assets/Scripts/SimulationModels/SimulationModel.cs

97 lines
2.7 KiB
C#
Raw Normal View History

using UnityEngine;
2025-05-26 18:06:25 +09:00
using System.Collections;
2025-05-29 02:08:28 +09:00
using Newtonsoft.Json;
2025-05-26 18:06:25 +09:00
using System.Collections.Generic;
2025-05-29 02:08:28 +09:00
using Octopus.Simulator;
2025-06-11 17:40:10 +09:00
using System;
2025-06-05 17:54:18 +09:00
public enum SimulationModelType
{
NoSpecific,
Source,
Move,
Queue,
Process,
Store,
Resource,
Sink
}
2025-06-24 17:02:07 +09:00
public abstract class SimulationModel : MonoBehaviour, IClickable
{
2025-05-12 18:00:37 +09:00
public string modelName;
2025-07-07 09:57:13 +09:00
public string objectName;
2025-06-05 17:54:18 +09:00
public SimulationModelType modelType;
2025-07-07 09:57:13 +09:00
public string prefabName;
2025-05-12 18:00:37 +09:00
public string modelID;
2025-05-26 18:06:25 +09:00
public string nodeID;
2025-07-15 17:35:53 +09:00
public Transform DataBubbleSocket;
protected BubbleUI bubbleUIPrefab;
protected BubbleUI currentBubble;
private bool isQuitting = false;
2025-06-11 17:40:10 +09:00
public Action<SimulationModel> onModelClicked;
2025-07-18 14:42:37 +09:00
protected Panel_SimulationUI simulationUI;
2025-05-12 18:00:37 +09:00
void Awake()
{
2025-07-07 09:57:13 +09:00
init();
prefabName = gameObject.name.Replace("(Clone)", "");
2025-05-29 02:08:28 +09:00
}
private void Start()
{
2025-06-11 17:40:10 +09:00
onModelClicked += FindAnyObjectByType<Panel_ConnectedObject>(FindObjectsInactive.Include).SetConnectedDataItem;
onModelClicked += FindAnyObjectByType<LogicUIManager>(FindObjectsInactive.Include).ModelSelected;
onModelClicked += (value)=>FindAnyObjectByType<Panel_PlacedObject>(FindObjectsInactive.Include).UnsetPlacedObjectDataItem();
2025-05-29 02:08:28 +09:00
}
2025-07-07 09:57:13 +09:00
protected virtual void init()
{
FitCollider();
2025-07-15 17:35:53 +09:00
bubbleUIPrefab = Resources.Load<BubbleUI>("BubbleUI");
DataBubbleSocket = transform.Find("BubbleSocket");
2025-07-18 14:42:37 +09:00
simulationUI = FindAnyObjectByType<Panel_SimulationUI>();
2025-07-15 17:35:53 +09:00
if (!DataBubbleSocket)
{
DataBubbleSocket = this.transform;
}
2025-07-07 09:57:13 +09:00
}
private void OnDestroy()
{
if (isQuitting) return;
DataManager.I.RemoveModel(this);
2025-05-26 18:06:25 +09:00
StopAllCoroutines();
}
void OnApplicationQuit()
{
isQuitting = true;
2025-05-12 18:00:37 +09:00
}
public void OnClick()
{
2025-06-11 17:40:10 +09:00
onModelClicked?.Invoke(this);
2025-05-12 18:00:37 +09:00
}
void FitCollider()
{
if (this as SimulationModelProduct)
return;
2025-05-12 18:00:37 +09:00
var renderers = GetComponentsInChildren<Renderer>();
if (renderers.Length == 0) return;
Bounds bounds = renderers[0].bounds;
foreach (var r in renderers)
bounds.Encapsulate(r.bounds);
BoxCollider collider = GetComponent<BoxCollider>();
if (!collider) collider = gameObject.AddComponent<BoxCollider>();
collider.center = transform.InverseTransformPoint(bounds.center);
collider.size = transform.InverseTransformVector(bounds.size);
2025-07-08 13:42:26 +09:00
collider.size = new Vector3(Mathf.Abs(collider.size.x), Mathf.Abs(collider.size.y),Mathf.Abs(collider.size.z));
2025-05-12 18:00:37 +09:00
}
2025-05-29 02:08:28 +09:00
2025-06-24 17:02:07 +09:00
public abstract void GetData(string data);
2025-07-15 17:35:53 +09:00
public abstract void SetBubble(object data);
}