From 4299b1c5eefcd607e35bfded5605f93f3a6848f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AF=7E?= Date: Tue, 3 Oct 2023 23:25:38 +0200 Subject: [PATCH] Change the way additional data is stored and exposed in AacConfiguration --- .../V1/Editor/Aac.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs index 3758058..30dfaa8 100644 --- a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs +++ b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs @@ -29,34 +29,35 @@ namespace AnimatorAsCode.V1 public Object GenericAssetContainer; public string AssetKey; public IAacDefaultsProvider DefaultsProvider; - public Dictionary AdditionalData; // Nullable + + private Dictionary _additionalData; // Nullable - public Object GetPersistentAssetContainer() - { - var container = AssetContainer != null ? AssetContainer : GenericAssetContainer; - if (container != null && EditorUtility.IsPersistent(container)) return container; - return null; - } - - public AacConfiguration WithAdditonalData(Type key, object value) + public AacConfiguration WithAdditionalData(T value) { var conf = this; - if (AdditionalData == null) conf.AdditionalData = new Dictionary(); - conf.AdditionalData[key] = value; + if (_additionalData == null) conf._additionalData = new Dictionary(); + conf._additionalData[typeof(T)] = value; return conf; } - public bool TryGetAdditionalData(Type key, out object value) + public bool TryGetAdditionalData(out T value) where T : class { - if (AdditionalData != null && AdditionalData.TryGetValue(key, out var result)) + if (_additionalData != null && _additionalData.TryGetValue(typeof(T), out var result)) { - value = result; + value = (T)result; return true; } value = null; return false; } + + internal Object GetPersistentAssetContainer() + { + var container = AssetContainer != null ? AssetContainer : GenericAssetContainer; + if (container != null && EditorUtility.IsPersistent(container)) return container; + return null; + } } public class AacFlLayer