示例#1
0
        // Awake
        private void Awake()
        {
            ModelController = gameObject.GetComponent <ModelController>();
            DialogRouter    = new DialogRouter();

            IntentExtractor = gameObject.GetComponent <IIntentExtractor>();
            IntentExtractor.Configure();

            // Use local store when no UserStore attached
            UserStore = gameObject.GetComponent <IUserStore>() ?? gameObject.AddComponent <LocalUserStore>();

            // Use local store when no ContextStore attached
            ContextStore = gameObject.GetComponent <IContextStore>() ?? gameObject.AddComponent <LocalContextStore>();

            // Register request providers for each input type
            RequestProviders = new Dictionary <RequestType, IRequestProvider>();
            foreach (var rp in gameObject.GetComponents <IRequestProvider>())
            {
                if (((MonoBehaviour)rp).enabled)
                {
                    RequestProviders[rp.RequestType] = rp;
                }
            }

            // Register intents and its processor
            foreach (var dp in gameObject.GetComponents <IDialogProcessor>())
            {
                DialogRouter.RegisterIntent(dp.TopicName, dp);
            }
        }
示例#2
0
#pragma warning restore CS1998

        // Awake
        private void Awake()
        {
            // Use local store when no UserStore attached
            UserStore = gameObject.GetComponent <IUserStore>() ?? gameObject.AddComponent <LocalUserStore>();

            // Use local store when no ContextStore attached
            ContextStore = gameObject.GetComponent <IContextStore>() ?? gameObject.AddComponent <MemoryContextStore>();

            // Register request providers for each input type
            RequestProviders = new Dictionary <RequestType, IRequestProvider>();
            var requestProviders = gameObject.GetComponents <IRequestProvider>();

            if (requestProviders != null)
            {
                foreach (var rp in requestProviders)
                {
                    if (((MonoBehaviour)rp).enabled)
                    {
                        RequestProviders[rp.RequestType] = rp;
                    }
                }
            }
            else
            {
                Debug.LogError("RequestProviders are missing");
            }

            // Configure router
            DialogRouter = gameObject.GetComponent <IDialogRouter>() ?? gameObject.AddComponent <StaticDialogRouter>();
            DialogRouter.Configure();

            // Register intents and its processor
            var dialogProcessors = gameObject.GetComponents <IDialogProcessor>();

            if (dialogProcessors != null)
            {
                foreach (var dp in dialogProcessors)
                {
                    DialogRouter.RegisterIntent(dp.TopicName, dp);
                    Debug.Log($"Intent '{dp.TopicName}' registered successfully");
                }
            }
            else
            {
                Debug.LogError("DialogProcessors are missing");
            }

            // ModelController
            ModelController = gameObject.GetComponent <ModelController>();
        }