로직 데이터 연동 시작
This commit is contained in:
63
Assets/Scripts/SimulationModels/SimulationModel.cs
Normal file
63
Assets/Scripts/SimulationModels/SimulationModel.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
public class SimulationModel : MonoBehaviour, IClickable
|
||||
{
|
||||
public string modelName;
|
||||
public string modelType;
|
||||
public string modelID;
|
||||
public string nodeID;
|
||||
private bool isQuitting = false;
|
||||
void Awake()
|
||||
{
|
||||
FitCollider();
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
DataManager.I.AddModel(this);
|
||||
StartCoroutine(RunSimulationCoroutine());
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
if (isQuitting) return;
|
||||
DataManager.I.RemoveModel(this);
|
||||
StopAllCoroutines();
|
||||
}
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
isQuitting = true;
|
||||
}
|
||||
public void OnClick()
|
||||
{
|
||||
Debug.Log("Clicked : " + gameObject.name);
|
||||
}
|
||||
void FitCollider()
|
||||
{
|
||||
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);
|
||||
}
|
||||
protected virtual IEnumerator RunSimulationCoroutine()
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
public object GetJsonValue(JToken token, IEnumerable<string> path)
|
||||
{
|
||||
foreach (var key in path)
|
||||
{
|
||||
if (token == null) return null;
|
||||
token = token[key];
|
||||
}
|
||||
return token;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user