HandleFactory.cs 1000 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Collections.Generic;
  3. namespace YooAsset
  4. {
  5. internal static class HandleFactory
  6. {
  7. private static readonly Dictionary<Type, Func<ProviderOperation, HandleBase>> _handleFactory = new Dictionary<Type, Func<ProviderOperation, HandleBase>>()
  8. {
  9. { typeof(AssetHandle), op => new AssetHandle(op) },
  10. { typeof(SceneHandle), op => new SceneHandle(op) },
  11. { typeof(SubAssetsHandle), op => new SubAssetsHandle(op) },
  12. { typeof(AllAssetsHandle), op => new AllAssetsHandle(op) },
  13. { typeof(RawFileHandle), op => new RawFileHandle(op) }
  14. };
  15. public static HandleBase CreateHandle(ProviderOperation operation, Type type)
  16. {
  17. if (_handleFactory.TryGetValue(type, out var factory) == false)
  18. {
  19. throw new NotImplementedException($"Handle type {type.FullName} is not supported.");
  20. }
  21. return factory(operation);
  22. }
  23. }
  24. }