/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal { using System; using System.Collections.Generic; /// A controller provider factory. internal static class ControllerProviderFactory { private static Dictionary m_ControllerProviderDict = new Dictionary(); /// Type of the android controller provider. public static Type controllerProviderType { get { #if UNITY_EDITOR return typeof(EditorControllerProvider); #else return typeof(NRControllerProvider); #endif } } /// Creates controller provider. /// The states. /// The new controller provider. public static ControllerProviderBase CreateControllerProvider(ControllerState[] states) { ControllerProviderBase provider = GetOrCreateControllerProvider(controllerProviderType, states); return provider; } /// Creates controller provider. /// Type of the provider. /// The states. /// The new controller provider. internal static ControllerProviderBase GetOrCreateControllerProvider(Type providerType, ControllerState[] states) { if (providerType != null) { if (m_ControllerProviderDict.ContainsKey(providerType)) { return m_ControllerProviderDict[providerType]; } object parserObj = Activator.CreateInstance(providerType, new object[] { states }); if (parserObj is ControllerProviderBase) { var controllerProvider = parserObj as ControllerProviderBase; m_ControllerProviderDict.Add(providerType, controllerProvider); return controllerProvider; } } return null; } } }