From a44532b94a0a3cdcaac7964d6d874d388ac5ba85 Mon Sep 17 00:00:00 2001 From: CoudronJerome Date: Wed, 29 Mar 2023 19:17:42 +0200 Subject: [PATCH] Changed GetCurrentModel to return the model instead of the tuple --- Assets/Common/Interfaces/ModelList.cs | 5 ++--- Assets/Common/Tests/ModelListTest.cs | 7 +++++-- Assets/MediaPipeUnity/Scripts/SignPredictor.cs | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Assets/Common/Interfaces/ModelList.cs b/Assets/Common/Interfaces/ModelList.cs index 98ec086..d2a4de9 100644 --- a/Assets/Common/Interfaces/ModelList.cs +++ b/Assets/Common/Interfaces/ModelList.cs @@ -41,10 +41,9 @@ public class ModelList : ScriptableObject /// /// ModelIndex of the model /// Model associated with this index, null if no model was found - public ModelTuple GetCurrentModel() + public NNModel GetCurrentModel() { - //if(currentModelIndex < models.Find) - return models.Find(x => x.model == models[currentModelIndex].model); + return models.Find(x => x.model == models[currentModelIndex].model)?.model; } /// diff --git a/Assets/Common/Tests/ModelListTest.cs b/Assets/Common/Tests/ModelListTest.cs index a988913..8ea900c 100644 --- a/Assets/Common/Tests/ModelListTest.cs +++ b/Assets/Common/Tests/ModelListTest.cs @@ -35,14 +35,17 @@ public class ModelListTest } } } - + /// + /// Check if current model can be correctly gotten as current via GetCurrentModel + /// + [Test] public void TestGetCurrentModel() { System.Random random = new System.Random(); ModelIndex value = (ModelIndex)random.Next(modelList.models.Count); modelList.SetCurrentModel(value); - Assert.AreEqual(value, modelList.GetCurrentModel().index); + Assert.AreEqual(modelList.models[modelList.currentModelIndex].model, modelList.GetCurrentModel()); // Check if empty model fails gracefully (returns null) Assert.IsNull(ScriptableObject.CreateInstance().GetCurrentModel()); diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs index 8beb2dd..2ec4263 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs @@ -210,7 +210,7 @@ namespace Mediapipe.Unity.Tutorial // check if model exists at path //var model = ModelLoader.Load(Resources.Load("Models/Fingerspelling/model_A-L")); - worker = modelList.GetCurrentModel().model.CreateWorker(); + worker = modelList.GetCurrentModel().CreateWorker(); StartCoroutine(SignRecognitionCoroutine()); StartCoroutine(MediapipeCoroutine()); @@ -223,7 +223,7 @@ namespace Mediapipe.Unity.Tutorial worker?.Dispose(); // Add a new worker for the new model - worker = modelList.GetCurrentModel().model.CreateWorker(); + worker = modelList.GetCurrentModel().CreateWorker(); } ///