using UnityEngine; using System.Collections; using Newtonsoft.Json; using System.Collections.Generic; using Octopus.Simulator; using System; public enum SimulationModelType { NoSpecific, Source, Move, Queue, Process, Store, Resource, Sink } public abstract class SimulationModel : MonoBehaviour, IClickable { public string modelName; public string objectName; public SimulationModelType modelType; public string prefabName; public string modelID; public string nodeID; public Transform DataBubbleSocket; protected BubbleUI bubbleUIPrefab; protected BubbleUI currentBubble; private bool isQuitting = false; public Action onModelClicked; protected Panel_SimulationUI simulationUI; void Awake() { init(); prefabName = gameObject.name.Replace("(Clone)", ""); } private void Start() { onModelClicked += FindAnyObjectByType(FindObjectsInactive.Include).SetConnectedDataItem; onModelClicked += FindAnyObjectByType(FindObjectsInactive.Include).ModelSelected; onModelClicked += (value)=>FindAnyObjectByType(FindObjectsInactive.Include).UnsetPlacedObjectDataItem(); } protected virtual void init() { FitCollider(); bubbleUIPrefab = Resources.Load("BubbleUI"); DataBubbleSocket = transform.Find("BubbleSocket"); simulationUI = FindAnyObjectByType(); if (!DataBubbleSocket) { DataBubbleSocket = this.transform; } } private void OnDestroy() { if (isQuitting) return; DataManager.I.RemoveModel(this); StopAllCoroutines(); } void OnApplicationQuit() { isQuitting = true; } public void OnClick() { onModelClicked?.Invoke(this); } void FitCollider() { if (this as SimulationModelProduct) return; 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)); } public abstract void GetData(string data); public abstract void SetBubble(object data); }