78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using NatML;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// This scriptable will hold tupples of Courseindices and models
|
|
/// </summary>
|
|
[CreateAssetMenu(menuName = "Create new Scriptable/ModelList")]
|
|
public class ModelList : ScriptableObject
|
|
{
|
|
/// <summary>
|
|
/// Small class to link a model to a courseIndex irrespective of its position in a list
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ModelTuple
|
|
{
|
|
/// <summary>
|
|
/// ModelIndex to which the model corresponds
|
|
/// </summary>
|
|
public ModelIndex index;
|
|
/// <summary>
|
|
/// The model itself
|
|
/// </summary>
|
|
public MLModelData modelWINDOWS;
|
|
/// <summary>
|
|
/// The model itself
|
|
/// </summary>
|
|
public MLModelData modelMAC;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// A list of all the models
|
|
/// </summary>
|
|
public List<ModelTuple> models = new List<ModelTuple>();
|
|
|
|
/// <summary>
|
|
/// Index of the currently active model
|
|
/// </summary>
|
|
public int currentModelIndex = 0;
|
|
|
|
/// <summary>
|
|
/// Get a model by modelindex
|
|
/// </summary>
|
|
/// <param name="modelIndex">ModelIndex of the model</param>
|
|
/// <returns>Model associated with this index, null if no model was found</returns>
|
|
public MLModelData GetCurrentModel()
|
|
{
|
|
|
|
// Select Model based on OS
|
|
#if (UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN)
|
|
return models.Find(x => x.modelWINDOWS == models[currentModelIndex].modelWINDOWS)?.modelWINDOWS;
|
|
#elif (UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX)
|
|
return models.Find(x => x.modelMAC == models[currentModelIndex].modelMAC)?.modelMAC;
|
|
#endif
|
|
return null;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Function to check if the modelIndex has been set
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool HasValidModel()
|
|
{
|
|
return models[currentModelIndex].index != (int)ModelIndex.NONE;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Function to find a model-index in the list based on its index
|
|
/// </summary>
|
|
/// <param name="title"></param>
|
|
public void SetCurrentModel(ModelIndex index)
|
|
{
|
|
currentModelIndex = models.FindIndex((m) => m.index == index);
|
|
}
|
|
}
|