Exemplo n.º 1
0
    /// <summary>
    /// Initialize our derived MonoBehaviour
    /// </summary>
    void Start()
    {
        // Initialize Program # variables
// For Webplayer plattform and WebGl
#if (UNITY_WEBPLAYER || UNITY_WEBGL)
        ProgramSharpWebplayerCoroutine WebplayerCoroutine = this.gameObject.GetComponent <ProgramSharpWebplayerCoroutine>();
        if (WebplayerCoroutine != null)
        {
            bot = new AIMLbot.Bot(WebplayerCoroutine, Application.dataPath + "/Chatbot/Program #/config/Settings.xml");
        }
        else
        {
            Debug.LogWarning("You need to attatch the Webplayer Component in Webplayer plattform mode.");
        }
// Other plattforms
#else
        // Only for Windows, Linux and Mac OSX
        bot = new AIMLbot.Bot();
#endif
        user    = new AIMLbot.User("User", bot);
        request = new AIMLbot.Request("", user, bot);
        result  = new AIMLbot.Result(user, bot, request);
// Only for Windows, Linux, Mac OSX Android and IOS
#if !(UNITY_WEBPLAYER || UNITY_WEBGL || UNITY_ANDROID || UNITY_IOS)
        // Load Settings from Xml file in config directory. Plattform dependend Path issues may
        // occur.
        bot.loadSettings(Application.dataPath + "/Chatbot/Program #/config/Settings.xml");
        // Load AIML files from AIML path defined in Settings.xml
        bot.loadAIMLFromFiles();
#endif
// Android and IOS release
#if (UNITY_ANDROID || UNITY_IOS)
        // Load Settings from Xml file in config directory within resources folder.
        bot.loadSettings("Chatbot/Program #/config/Settings");
        // Load AIML files from AIML path defined in Settings.xml
        bot.loadAIMLFromFiles();
#endif
        // Define to or not to use JavaScript (Jurassic) in AIML
        if (bot != null)
        {
            bot.UseJavaScript = true;
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Chatbot.Trigger"/> class.
        /// </summary>
        /// <param name="Chatbot">Chatbot.</param>
        public void Initialize(GameObject tmpchatbot)
        {
            // Save delivered GameObject
            chatbot = tmpchatbot;
            // Throw error if not Game Object delivered
            if (!chatbot)
            {
                Debug.LogWarning("To use chatbot you need to attatch ChatbotCore.cs script to a GameObject and pass GameObject to Chatbot. GameObject is empty.");
            }
            // Windows, Linux and Mac OSX
                        #if !(UNITY_WEBPLAYER || UNITY_WEBGL)
            else
            {
                // Initialize Program # variables
                bot     = new AIMLbot.Bot(this);
                user    = new AIMLbot.User("User", bot);
                request = new AIMLbot.Request("", user, bot);
                result  = new AIMLbot.Result(user, bot, request);
                // Global Settings
                Setting[] settings;
                // Gather all attatched settings from Scene
                settings = chatbot.GetComponentsInChildren <Setting>();
                // Loop through settings and
                foreach (Setting setting in settings)
                {
                    // Set global settings in Program# and Jurassic
                    SetGlobalSetting(setting.gameObject.name, setting.value);
                }
                // Load Settings from Scene Setting Components.
                bot.loadSettingsFromScene();
                // Load AIML files from AIML path defined in Settings.xml
                bot.loadAIMLFromFiles();

                // Define to or not to use JavaScript (Jurassic) in AIML
                bot.UseJavaScript = true;
                // Use Program # with Jurassic and Chatbot
                bot.ProgramSharpJSWithChatbot = true;
                // Create Triggers instance
                trigger = new Chatbot.Triggers();
                // Initializes triggers that are attatched
                // to the Chatbot. Needs to pass the
                // Chatbot Gameobject and Triggers instance
                trigger.Initialize(chatbot, this);
                // Create Motives instance
                motive = new Chatbot.Motives();
                // Initialize it
                motive.Initialize(chatbot);
                // Create Planner instance
                planner = new Chatbot.NestedPlanner();
                // Initialize planner
                planner.Initialize(chatbot, this, motive);
            }
                        #else
            // Webplayer plattform or WebGl
            ProgramSharpWebplayerCoroutine WebplayerCoroutine = chatbot.GetComponent <ProgramSharpWebplayerCoroutine>();
            if (WebplayerCoroutine != null && chatbot != null)
            {
                // Load settings from scene
                bot     = new AIMLbot.Bot(WebplayerCoroutine, Application.dataPath + "/Chatbot/Program #/advancedconfig/Settings.xml", true, this);
                user    = new AIMLbot.User("User", bot);
                request = new AIMLbot.Request("", user, bot);
                result  = new AIMLbot.Result(user, bot, request);

                // Define to or not to use JavaScript (Jurassic) in AIML
                bot.UseJavaScript = true;
                // Use Program # with Jurassic and Chatbot
                bot.ProgramSharpJSWithChatbot = true;
                // Create Triggers instance
                trigger = new Chatbot.Triggers();
                // Initializes triggers that are attatched
                // to the Chatbot. Needs to pass the
                // Chatbot Gameobject and Triggers instance
                trigger.Initialize(chatbot, this);
                // Create Motives instance
                motive = new Chatbot.Motives();
                // Initialize it
                motive.Initialize(chatbot);
                // Create Planner instance
                planner = new Chatbot.NestedPlanner();
                // Initialize planner
                planner.Initialize(chatbot, this, motive);
            }
            else
            {
                Debug.LogWarning("You need to attatch the Webplayer Component in Webplayer plattform mode.");
            }
                        #endif
        }