Example #1
0
    // Use this for initialization
    private void Start()
    {
        AssetManager.Instance.Bridge = new AssetManagerBridge();

        var streamingAssetsPath = Application.streamingAssetsPath;

#if UNITY_EDITOR || UNITY_STANDALONE
        streamingAssetsPath = "file://" + streamingAssetsPath;
#endif
        if (string.IsNullOrEmpty(IATScenario))
        {
            Debug.LogError("Please specify an IAT scenario file!");
            return;
        }

        iat = IntegratedAuthoringToolAsset.LoadFromFile(IATScenario);
        var characterSources = iat.GetAllCharacterSources().ToList();

        //AGENT 1
        agent1RPC = RolePlayCharacterAsset.LoadFromFile(characterSources[1].Source);
        agent1RPC.LoadAssociatedAssets();
        iat.BindToRegistry(agent1RPC.DynamicPropertiesRegistry);

        //AGENT 2
        agent2RPC = RolePlayCharacterAsset.LoadFromFile(characterSources[2].Source);
        agent2RPC.LoadAssociatedAssets();
        iat.BindToRegistry(agent2RPC.DynamicPropertiesRegistry);

        //PLAYER
        playerRPC = RolePlayCharacterAsset.LoadFromFile(characterSources[0].Source);
        playerRPC.LoadAssociatedAssets();
        iat.BindToRegistry(playerRPC.DynamicPropertiesRegistry);

        playerDialogues = DeterminePlayerDialogues();
        UpdatePlayerDialogOptions(true);

        AgentUtterance.text = String.Empty;

        StartCoroutine(UpdateEmotionalState(1f));
        StartCoroutine(DetermineAgentDialogue(0.2f));

        NextPageButton.onClick.RemoveAllListeners();
        NextPageButton.onClick.AddListener(() => OnNextPage());

        PreviousPageButton.onClick.RemoveAllListeners();
        PreviousPageButton.onClick.AddListener(() => OnPreviousPage());

        RestartButton.onClick.RemoveAllListeners();
        RestartButton.onClick.AddListener(() => RestartScene());
    }
    private IEnumerator LoadScenario(ScenarioData data)
    {
        ClearButtons();

        _iat = data.IAT;

        _introPanel.SetActive(true);
        _introText.text = string.Format("<b>{0}</b>\n\n\n{1}", _iat.ScenarioName, _iat.ScenarioDescription);
        previousState   = "";
        var characterSources = _iat.GetAllCharacterSources().ToList();
        var addedDialogs     = new List <string>();

        _wm = WorldModelAsset.LoadFromFile(_iat.GetWorldModelSource().Source);
        foreach (var source in characterSources)
        {
            var rpc = RolePlayCharacterAsset.LoadFromFile(source.Source);
            rpc.LoadAssociatedAssets();
            if (rpc.CharacterName.ToString() == "Player")
            {
                Player = rpc;
                _iat.BindToRegistry(Player.DynamicPropertiesRegistry);
                continue;
            }
            _iat.BindToRegistry(rpc.DynamicPropertiesRegistry);
            AddButton(characterSources.Count <= 2 ? "Start" : rpc.CharacterName.ToString(),
                      () =>
            {
                Debug.Log("Interacted with the start button");
                var body         = m_bodies.FirstOrDefault(b => b.BodyName == rpc.BodyName);
                _agentController = new AgentControler(data, rpc, _iat, body.CharaterArchtype, m_characterAnchor, m_dialogController);
                StopAllCoroutines();
                _agentController.storeFinalScore(_finalScore);
                _agentController.Start(this, VersionMenu);
                _agentController.startingTime = this.startingTime;

                InstantiateScore();
            });
        }
        if (m_scenarios.Length > 1)
        {
            AddButton("Back to Scenario Selection Menu", () =>
            {
                _iat = null;
                LoadScenarioMenu();
            });
        }
        yield return(nextframe);
    }
    private void LoadScenario(SingleCharacterDemo.ScenarioData data)
    {
        ClearButtons();

        _iat = data.IAT;

        _introPanel.SetActive(true);
        _introText.text = string.Format("<b>{0}</b>\n\n\n{1}", _iat.ScenarioName, _iat.ScenarioDescription);


        var characterSources = _iat.GetAllCharacterSources().ToList();
        int CharacterCount   = 0;

        foreach (var source in characterSources)
        {
            var rpc = RolePlayCharacterAsset.LoadFromFile(source.Source);
            rpc.LoadAssociatedAssets();
            _iat.BindToRegistry(rpc.DynamicPropertiesRegistry);
            rpcList.Add(rpc);
            var body = m_bodies.FirstOrDefault(b => b.BodyName == rpc.BodyName);
            _agentController = new MultiCharacterAgentController(data, rpc, _iat, body.CharaterArchtype, m_characterAnchors[CharacterCount], m_dialogController);
            StopAllCoroutines();

            _agentControllers.Add(_agentController);
            CharacterCount++;
        }


        AddButton("Back to Scenario Selection Menu", () =>
        {
            _iat = null;
            LoadScenarioMenu();
        });

        foreach (var actor in rpcList)
        {
            foreach (var anotherActor in rpcList)
            {
                if (actor != anotherActor)
                {
                    var changed = new[] { EventHelper.ActionEnd(anotherActor.CharacterName.ToString(), "Enters", "Room") };
                    actor.Perceive(changed);
                }
            }
        }

        RandomizeNext();
        SetCamera();
    }
Example #4
0
    public void NextLevel()
    {
        CurrentLevel++;

        _feedbackScores.Clear();
        GetFeedbackEvent?.Invoke(_feedbackScores, FeedbackLevel);
        if (_scenarios.Any(data => data.LevelId.Equals(CurrentLevel)))
        {
            CurrentScenario = _scenarios.First(data => data.LevelId.Equals(CurrentLevel));
        }
        else
        {
            var validPaths = _allScenarioPaths.Where(p => p.Contains('#')).ToArray();
            var prefixes = validPaths.Select(p => p.Substring(0, p.IndexOf('-', p.IndexOf('-') + 1) + 1)).ToList();
            var character = new List <string> {
                "Positive", "Neutral", "Negative"
            }.OrderBy(dto => random.Next()).First();

            var prefix = _isDemo
                                ? _demoScenarioPrefix + _demoUtterance
                                : prefixes.OrderBy(dto => random.Next()).First();

            // MaxPoints currently hardcoded to 8 for random scenarios.
            // TODO Review validity/balance of MaxPoints = 8
            CurrentScenario = new ScenarioData(CurrentLevel, _allScenarioPaths.Where(x => x.Contains(prefix)).ToArray(), character, 8, prefix);
        }
        if (CurrentScenario != null)
        {
            var index = random.Next(CurrentScenario.ScenarioPaths.Length);
            Debug.Log(CurrentScenario.ScenarioPaths[index]);
            string error;

            ScenarioCode = _isDemo
                                ? _demoUtterance.Split('#')[0]
                                : CurrentScenario.ScenarioPaths[index].Replace(CurrentScenario.Prefix, string.Empty).Split('#')[0];

            _integratedAuthoringTool = IntegratedAuthoringToolAsset.LoadFromFile(Path.Combine("Scenarios", CurrentScenario.ScenarioPaths[index]), out error);
            if (!string.IsNullOrEmpty(error))
            {
                Debug.LogError(error);
            }
            CurrentCharacter = RolePlayCharacterAsset.LoadFromFile(_integratedAuthoringTool.GetAllCharacterSources().First(c => c.Source.Contains(CurrentScenario.Character)).Source);
            CurrentCharacter.LoadAssociatedAssets();
            _integratedAuthoringTool.BindToRegistry(CurrentCharacter.DynamicPropertiesRegistry);
            CurrentCharacter.BodyName = random.NextDouble() >= 0.5 ? "Male" : "Female";
        }
    }
Example #5
0
    public void NextQuestionnaire()
    {
        // Pilot logic to set level id to match CurrentLevel divided by 5, as questionnaires occur every 5 levels. Needs changing if occurance rate of questionnaires change
        CurrentScenario = new ScenarioData(CurrentLevel / 5, _allScenarioPaths.Where(x => x.Contains("Questions")).ToArray(), "Neutral", 0, "Questionnaire");
        string error;

        // Pilot logic to set different questionnaire depending on how many levels have been played. Needs changing if expected appearence of questionnaire changes
        ScenarioCode             = (CurrentLevel < LevelMax && LevelMax > 0 ? 1 : 2).ToString();
        _integratedAuthoringTool = IntegratedAuthoringToolAsset.LoadFromFile(Path.Combine("Scenarios", _allScenarioPaths.First(x => x.Contains("Questions" + ScenarioCode))), out error);
        if (!string.IsNullOrEmpty(error))
        {
            Debug.LogError(error);
        }
        CurrentCharacter = RolePlayCharacterAsset.LoadFromFile(_integratedAuthoringTool.GetAllCharacterSources().First(c => c.Source.Contains("Neutral")).Source);
        CurrentCharacter.LoadAssociatedAssets();
        _integratedAuthoringTool.BindToRegistry(CurrentCharacter.DynamicPropertiesRegistry);
    }
        private void buttonTest_Click(object sender, System.EventArgs e)
        {
            var rpcAsset = CloneHelper.Clone(iat.Characters.Where(c => c.CharacterName == (Name)rpcName).First());

            rpcAsset.LoadAssociatedAssets(storage);
            iat.BindToRegistry(rpcAsset.DynamicPropertiesRegistry);

            string[] eventStrings = this.textBoxEvents.Text.Split(
                new[] { Environment.NewLine },
                StringSplitOptions.None).Select(s => s.Trim()).ToArray();

            foreach (var s in eventStrings)
            {
                if (string.IsNullOrWhiteSpace(s))
                {
                    continue;
                }

                if (s.StartsWith("-"))
                {
                    var count = s.Count(c => c == '-');
                    for (int i = 0; i < count; i++)
                    {
                        rpcAsset.Update();
                    }
                }
                else
                {
                    try
                    {
                        var evt = WellFormedNames.Name.BuildName(s);
                        AM.AssertEventNameValidity(evt);
                        rpcAsset.Perceive(evt);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + " " + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            textBoxMood.Text    = rpcAsset.Mood.ToString();
            textBoxTick.Text    = rpcAsset.Tick.ToString();
            emotions.DataSource = rpcAsset.GetAllActiveEmotions().ToList();
            actions.DataSource  = rpcAsset.Decide(wfNameActionLayer.Value).ToList();
        }
Example #7
0
        private void loadScenario(string agentType)
        {
            System.IO.Directory.CreateDirectory(LOGS_PATH);

            var characterSources = _iat.GetAllCharacterSources().ToList();

            foreach (var source in characterSources)
            {
                RolePlayCharacterAsset character = RolePlayCharacterAsset.LoadFromFile(source.Source);
                character.LoadAssociatedAssets();
                if (character.BodyName.ToString() == agentType)
                {
                    _iat.BindToRegistry(character.DynamicPropertiesRegistry);
                    _rpc = character;
                    break;
                }
            }
        }
    private void LoadScenario(SingleCharacterDemo.ScenarioData data)
    {
        ClearButtons();

        _iat = data.IAT;


        if (skipDescription)
        {
            _introPanel.SetActive(true);
            _introText.text = string.Format("<b>{0}</b>\n\n\n{1}", _iat.ScenarioName, _iat.ScenarioDescription);
        }

        if (_iat.m_worldModelSource != null)
        {
            if (_iat.m_worldModelSource.Source != "" && _iat.m_worldModelSource.Source != null)
            {
                _wm = WorldModel.WorldModelAsset.LoadFromFile(_iat.GetWorldModelSource().Source);
            }
        }


        var characterSources = _iat.GetAllCharacterSources().ToList();
        int CharacterCount   = 0;

        foreach (var source in characterSources)
        {
            var rpc = RolePlayCharacterAsset.LoadFromFile(source.Source);
            rpc.LoadAssociatedAssets();
            _iat.BindToRegistry(rpc.DynamicPropertiesRegistry);
            rpcList.Add(rpc);
            var body = m_bodies.FirstOrDefault(b => b.BodyName == rpc.BodyName);

            UnityEngine.Random.InitState((int)System.DateTime.Now.Ticks);

            var r = UnityEngine.Random.Range(0, 30);
            Debug.Log("Going to wait" + r);
            StartCoroutine(JustWait(UnityEngine.Random.Range(0, 3)));

            _agentController = new MultiCharacterAgentController(data, rpc, _iat, body.CharaterArchtype, m_characterAnchors[CharacterCount], m_dialogController);
            // StopAllCoroutines();
            _agentControllers.Add(_agentController);


            if (rpc.CharacterName == _player.CharacterName)
            {
                _player = rpc;
            }

            CharacterCount++;
        }

        foreach (var agent in _agentControllers)
        {
            if (agent.RPC.CharacterName != _player.CharacterName)
            {
                agent.StartBehaviour(this, VersionMenu);
            }
        }


        foreach (var actor in rpcList)
        {
            foreach (var anotherActor in rpcList)
            {
                if (actor != anotherActor)
                {
                    var changed = new[] { EventHelper.ActionEnd(anotherActor.CharacterName.ToString(), "Enters", "Room") };
                    actor.Perceive(changed);
                }
            }
        }
        SetCamera();
        PlayerDecide();
    }
    private void LoadScenario(ScenarioData data)
    {
        ClearButtons();

        _iat = data.IAT;

        _introPanel.SetActive(true);
        _introText.text = string.Format("<b>{0}</b>\n\n\n{1}", _iat.ScenarioName, _iat.ScenarioDescription);



        if (_iat.m_worldModelSource != null)
        {
            if (!string.IsNullOrEmpty(_iat.m_worldModelSource.Source))
            {
                var wat = _iat.GetWorldModelSource();

                string errorsOnLoad;

                //  _wm = WorldModel.WorldModelAsset.LoadFromFile(_iat.GetWorldModelSource().RelativePath);
                _wm = WorldModel.WorldModelAsset.LoadFromFile(_iat.GetWorldModelSource().Source, out errorsOnLoad);

                if (errorsOnLoad != null)
                {
                    throw new Exception(errorsOnLoad);
                }
            }
        }
        var characterSources = _iat.GetAllCharacterSources().ToList();

        foreach (var source in characterSources)
        {
            var rpc = RolePlayCharacterAsset.LoadFromFile(source.Source);
            rpc.LoadAssociatedAssets();
            _iat.BindToRegistry(rpc.DynamicPropertiesRegistry);

            if (rpc.CharacterName.ToString().Contains("Player"))
            {
                Player = rpc;
                continue;
            }
            AddButton(characterSources.Count <= 2 ? "Start" : rpc.CharacterName.ToString(),
                      () =>
            {
                var body         = m_bodies.FirstOrDefault(b => b.BodyName == rpc.BodyName);
                _agentController = new AgentControler(data, rpc, _iat, body.CharaterArchtype, m_characterAnchor, m_dialogController);
                StopAllCoroutines();
                _agentController.Start(this, VersionMenu);

                _background.SetActive(true);
                if (!backgrounds.IsEmpty())
                {
                    if (!backgrounds.ToList().FindAll(x => x.scenarioName == _iat.ScenarioName).IsEmpty())
                    {
                        _background.GetComponent <Renderer>().material = backgrounds.ToList().Find(x => x.scenarioName == _iat.ScenarioName).mat;
                    }
                    else
                    {
                        _background.GetComponent <Renderer>().material = activeBackgroundMaterial;
                    }
                }
                else
                {
                    _background.GetComponent <Renderer>().material = activeBackgroundMaterial;
                }
            });
        }
        AddButton("Back to Scenario Selection Menu", () =>
        {
            _iat = null;
            LoadScenarioMenu();
        });
    }
Example #10
0
        private void CalculateEmotions(object sender, EventArgs e)
        {
            Dictionary <string, Dictionary <string, int> > emotionList = new Dictionary <string, Dictionary <string, int> >();

            IntegratedAuthoringToolAsset loadedIAT = this.LoadedAsset;

            List <RolePlayCharacterAsset> rpcList = new List <RolePlayCharacterAsset>();

            List <WellFormedNames.Name> _eventList = new List <WellFormedNames.Name>();

            foreach (var rpc in loadedIAT.GetAllCharacterSources())
            {
                var actor = RolePlayCharacterAsset.LoadFromFile(rpc.Source);
                ;

                actor.LoadAssociatedAssets();

                loadedIAT.BindToRegistry(actor.DynamicPropertiesRegistry);

                rpcList.Add(actor);
            }

            foreach (var actor in rpcList)
            {
                foreach (var anotherActor in rpcList)
                {
                    if (actor != anotherActor)
                    {
                        var changed = new[]
                        { EventHelper.ActionEnd(anotherActor.CharacterName.ToString(), "Enters", "Room") };
                        actor.Perceive(changed);
                    }
                }

                emotionList.Add(actor.CharacterName.ToString(), new Dictionary <string, int>());
                // actor.SaveToFile("../../../Tests/" + actor.CharacterName + "-output1" + ".rpc");
            }

            string validationMessage = "";

            var rpcActions = new Dictionary <IAction, RolePlayCharacterAsset>();

            var act = rpcList.FirstOrDefault().Decide();

            if (act == null)
            {
                foreach (var r in rpcList)
                {
                    act = r.Decide();
                    if (act != null)
                    {
                        rpcActions.Add(act.FirstOrDefault(), r);
                        break;
                    }
                }
            }

            int timestamp = 0;

            while (rpcActions.Keys != null)
            {
                // Stopping condition kinda shaky
                rpcActions = new Dictionary <ActionLibrary.IAction, RolePlayCharacterAsset>();

                foreach (var rpc in rpcList)
                {
                    act = rpc.Decide();

                    if (act.FirstOrDefault() == null)
                    {
                        continue;
                    }

                    foreach (var action in act)
                    {
                        rpcActions.Add(action, rpc);
                    }
                }

                // COPY the rpc list without linked refereces

                var newList =
                    new List <RolePlayCharacterAsset>(); // mmm is the new list linked to the other? to be tested

                foreach (var action in rpcActions)
                {
                    // COPY the rpc list without linked refereces

                    var newListAux =
                        new List <RolePlayCharacterAsset>(
                            rpcList); // mmm is the new list linked to the other? to be tested

                    foreach (var rpctoPerceive in newListAux)
                    {
                        _eventList = new List <WellFormedNames.Name>();

                        if (rpctoPerceive.CharacterName != action.Value.CharacterName)
                        {
                            if (action.Key.Name.ToString().Contains("Speak") &&
                                action.Key.Target == rpctoPerceive.CharacterName)
                            {
                                _eventList.Add(EventHelper.PropertyChange(
                                                   "DialogueState(" + action.Value.CharacterName.ToString() + ")",
                                                   action.Key.Parameters.ElementAt(1).ToString(),
                                                   action.Value.CharacterName.ToString()));
                            }

                            _eventList.Add(EventHelper.ActionEnd(action.Value.CharacterName.ToString(),
                                                                 action.Key.Name.ToString(), action.Key.Target.ToString()));

                            rpctoPerceive.Perceive(_eventList);

                            newList.Add(rpctoPerceive);
                        }
                    }
                }

                rpcList.Clear();
                rpcList = newList;

                foreach (var rpc in rpcList)
                {
                    foreach (var emot in rpc.GetAllActiveEmotions())
                    {
                        if (!emotionList[rpc.CharacterName.ToString()].Keys.Contains(emot.Type))
                        {
                            emotionList[rpc.CharacterName.ToString()].Add(emot.Type, (timestamp + 1));
                        }
                    }
                }

                timestamp++;
                if (timestamp > 1)
                {
                    break;
                }
            }

            if (emotionList.Count > 0)
            {
                validationMessage = "Simulation result:                " + "\n";

                foreach (var rpc in emotionList.Keys)
                {
                    validationMessage += rpc + " felt: " + "\n";

                    foreach (var emot in emotionList[rpc])
                    {
                        var    lastFor        = timestamp - emot.Value;
                        double timePercentage = ((double)lastFor / (double)timestamp) * 100;
                        validationMessage += "Emotion: " + emot.Key + " ( " + timePercentage +
                                             "% of total scenario time)\n";
                    }
                }
            }
            else
            {
                validationMessage += "No emotions detected";
            }

            MessageBox.Show(validationMessage);
        }