In the event that the position that it is in is not the position that it wasn't, the system has acquired a variation, the variation being the difference between where the missile is, and where it wasn't. If variation is considered to be a significant factor, it too may be corrected by the GEA. However, the missile must also know where it was. The missile guidance computer scenario works as follows. Because a variation has modified some of the information the missile has obtained, it is not sure just where it is. However, it is sure where it isn't, within reason, and it knows where it was. It now subtracts where it should be from where it wasn't, or vice-versa, and by differentiating this from the algebraic sum of where it shouldn't be, and where it was, it is able to obtain the deviation and its variation, which is called error.
183 lines
6.2 KiB
C#
183 lines
6.2 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine.Serialization;
|
|
|
|
public class ModelManager : MonoBehaviour, IResettable
|
|
{
|
|
private Dictionary<string, HashSet<ChildModel>> _portDict; //port mapped on
|
|
private Dictionary<string, ChildModel> _childModelDict; //childModels by their ID
|
|
|
|
public List<BaseModel> BaseModelList; //available BaseModels
|
|
|
|
public GameObject baseModelGO; //GameObject of the BaseModel
|
|
public BaseModel BaseModel //current baseModel Phenotype
|
|
{
|
|
get { return baseModelGO.GetComponent<BaseModelBehaviour>().BaseModel; }
|
|
}
|
|
public BaseModelBehaviour BaseModelBehaviour
|
|
{
|
|
get { return baseModelGO.GetComponent<BaseModelBehaviour>(); }
|
|
}
|
|
public BaseModelSelector baseModelSelector;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
Debug.Log("ModelManager: " + gameObject.name);
|
|
_portDict = new Dictionary<string, HashSet<ChildModel>>();
|
|
_childModelDict = new Dictionary<string, ChildModel>();
|
|
BaseModelList = new List<BaseModel>();
|
|
//baseModelSelector = FindFirstObjectByType<BaseModelSelector>();
|
|
|
|
foreach (var baseModel in ModelList.BaseModels)
|
|
{
|
|
RegisterBaseModel(baseModel);
|
|
}
|
|
|
|
foreach (var childModel in ModelList.ChildModels)
|
|
{
|
|
RegisterChildModel(childModel);
|
|
}
|
|
if (baseModelGO == null) //set in the editor
|
|
{
|
|
//TODO: send into model selection
|
|
Debug.LogError("baseModel is null, fix the configuration");
|
|
}
|
|
/*
|
|
var originalGlasMat = Resources.Load<Material>("Material/Glas");
|
|
if (originalGlasMat != null)
|
|
{
|
|
var glasMatInstance = new Material(originalGlasMat); // Kopie erzeugen
|
|
var urpLit = Shader.Find("URP/UI/Prerendered");
|
|
if (urpLit != null)
|
|
{
|
|
glasMatInstance.shader = urpLit;
|
|
glasMatInstance.SetFloat("_Smoothness", 0.9f);
|
|
glasMatInstance.SetFloat("_Metallic", 0.0f);
|
|
glasMatInstance.SetFloat("_Surface", 1);
|
|
glasMatInstance.SetFloat("_Blend", 0);
|
|
glasMatInstance.SetColor("_BaseColor", new Color(0.2f, 0.2f, 0.2f, 0.45f));
|
|
}
|
|
var fensterGO = GameObject.Find("portErlbachWindow"); // Name des Fenster-Objekts
|
|
if (fensterGO != null)
|
|
{
|
|
var renderer = fensterGO.GetComponent<Renderer>();
|
|
if (renderer != null)
|
|
{
|
|
renderer.material = glasMatInstance;
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
|
|
void RegisterChildModel(ChildModel model)
|
|
{
|
|
Debug.Log($"Registering {model.NameId} for Port {model.ParentPort} ({model})");
|
|
//childModelDict
|
|
if (_childModelDict.ContainsKey(model.NameId))
|
|
{
|
|
Debug.LogWarning("Model " + model.NameId + " already registered! [childModelDict] Skipping...");
|
|
return;
|
|
}
|
|
_childModelDict[model.NameId] = model;
|
|
|
|
//portDict
|
|
if (string.IsNullOrEmpty(model.ParentPort))
|
|
{
|
|
Debug.LogWarning("Model " + model.NameId + " has no Port! [portDict] Skipping...");
|
|
return;
|
|
}
|
|
if (!_portDict.ContainsKey(model.ParentPort))
|
|
{
|
|
_portDict.Add(model.ParentPort, new HashSet<ChildModel>());
|
|
}
|
|
if (_portDict[model.ParentPort].Contains(model))
|
|
{
|
|
Debug.LogWarning("Model " + model.NameId + " already registered! [portDict] Skipping...");
|
|
return;
|
|
}
|
|
_portDict[model.ParentPort].Add(model);
|
|
}
|
|
|
|
void RegisterBaseModel(BaseModel baseModel)
|
|
{
|
|
if (baseModel == null)
|
|
{
|
|
return;
|
|
}
|
|
BaseModelList ??= new List<BaseModel>();
|
|
BaseModelList.Add(baseModel);
|
|
}
|
|
|
|
public HashSet<ChildModel> GetChildModelsForPort(string port)
|
|
{
|
|
// Check if key exists in the dictionary
|
|
if (_portDict.TryGetValue(port, out HashSet<ChildModel> childModels))
|
|
{
|
|
return childModels; // Return childModels of the port
|
|
}
|
|
else
|
|
{
|
|
// Warning and return empty set if key not found
|
|
Debug.LogWarning($"No model found for port {port}.");
|
|
return new HashSet<ChildModel>();
|
|
}
|
|
}
|
|
|
|
public ChildModel GetById(string id)
|
|
{
|
|
return _childModelDict[id];
|
|
}
|
|
|
|
public void LoadSelectedModel(BaseModel baseModel)
|
|
{
|
|
Debug.Log($"Model {baseModel.NameHuman} started loading.");
|
|
//create if doesn't exist
|
|
if (baseModelGO == null)
|
|
{
|
|
Debug.Log($"Spawning BaseModelGO.");
|
|
baseModelGO = new GameObject(baseModel.NameId);
|
|
baseModelGO.AddComponent<BaseModelBehaviour>();
|
|
baseModelGO.transform.position = new Vector3(0, 0, 1);
|
|
baseModelGO.transform.localRotation = Quaternion.Euler(0, 90, 0);
|
|
baseModelGO.SetActive(true);
|
|
Debug.Log($"Spawned BaseModelGO.");
|
|
}
|
|
baseModelGO.GetComponent<BaseModelBehaviour>().BaseModel = baseModel;
|
|
baseModelGO.SetActive(true);
|
|
Debug.Log($"Model {baseModel.NameHuman} lock and loaded.");
|
|
}
|
|
|
|
public void OpenSelector()
|
|
{
|
|
Debug.Log("Open Selector");
|
|
|
|
baseModelGO.SetActive(false);
|
|
baseModelSelector.Activate();
|
|
}
|
|
|
|
/// <summary>
|
|
/// The Export function that should be called by the Button. Will get changed later to export to a REST/MQTT Service
|
|
/// </summary>
|
|
public void Export()
|
|
{
|
|
string path = Path.GetDirectoryName(Application.dataPath) + "/export.json";
|
|
Debug.Log($"Exporting current model to {path}...");
|
|
if (File.Exists(path))
|
|
{
|
|
//this doesn't matter since later the export will get sent to an server anyways
|
|
Debug.LogWarning($"File {path} already exists. Overwriting...");
|
|
}
|
|
var fs = File.Create(path);
|
|
TextWriter tw = new StreamWriter(fs);
|
|
tw.Write(BaseModelBehaviour.ExportJson());
|
|
tw.Close();
|
|
}
|
|
|
|
public void ResetThis()
|
|
{
|
|
OpenSelector();
|
|
}
|
|
}
|