Example #1
0
 public void UpdateRegion(float rectX, float rectZ)
 {
     for (int i = 0; i < agentCnt; i++)
     {
         agents[i].transform.Translate(transform.position - agents[i].transform.position);
         agents[i].transform.Translate(MathDefs.GetRandomNumber(-rectX, rectX), 0, MathDefs.GetRandomNumber(-rectZ, rectZ));
     }
 }
Example #2
0
    private void Start()
    {
        _agentScripts = transform.GetComponentsInChildren <AnimationInfo>();



        _dropDownRectAgents    = new DropDownRect(new Rect(115, 20, 90, 300));
        _dropDownRectAnimNames = new DropDownRect(new Rect(210, 20, 90, 300));

        _dropDownRectNationality = new DropDownRect(new Rect(115, 60, 90, 300));
        _dropDownRectProfession  = new DropDownRect(new Rect(210, 60, 90, 300));

        for (int i = 0; i < 32; i++)
        {
            _driveParams[i] = new DriveParams();
        }



#if !WEBMODE
        for (int i = 0; i < 32; i++)
        {
            _driveParams[i].ReadValuesDrives(i);
        }
#elif WEBMODE
        for (int i = 0; i < 32; i++)
        {
            this.StartCoroutine(_driveParams[i].GetValuesDrives(i, "funda"));
        }
#endif



        _firstRun = true;



        _agentSelInd = 0;



        _persMapper = new PersonalityMapper();



        foreach (AnimationInfo t in _agentScripts)
        {
            Reset(t);
        }

        AgentText = new GUIText[_agentScripts.Length];

        //   FormatData("motionEffortCoefs.txt");

        MathDefs.SetSeed(30);
    }
Example #3
0
 public void ComputePersonality(int ind, float mean, float std)
 {
     personality[ind] = MathDefs.GaussianDist(mean, std);
     if (personality[ind] < -1f)
     {
         personality[ind] = -1f;
     }
     else if (personality[ind] > 1f)
     {
         personality[ind] = 1f;
     }
 }
Example #4
0
    void UpdateAction()
    {
        if (agentComponent.IsFighting())
        {
            agentComponent.CurrAction = "fight";

            if (bannerCarrier)
            {
                banner.SetActiveRecursively(false);
            }
        }
        else if (bannerCarrier)
        {
            banner.SetActiveRecursively(true);
            agentComponent.CurrAction = "protest";
        }
        else
        {
            if (frameCnt % 300 == 0)           //protesting -- update every 300 frames
            {
                int    animId;
                string exp = affectComponent.GetEkmanEmotion();
                if (exp.Equals("angry") || exp.Equals("sad"))
                {
                    animId = MathDefs.GetRandomNumber(3);
                }
                else if (exp.Equals("happy"))
                {
                    animId = 0;
                }
                else
                {
                    animId = -1; //no action
                }
                if (animId == 0)
                {
                    agentComponent.CurrAction = "clap";
                }
                else if (animId == 1)
                {
                    agentComponent.CurrAction = "cheer";
                }
                else if (animId == 2)
                {
                    agentComponent.CurrAction = "throw";
                }
                else
                {
                    agentComponent.CurrAction = "";
                }
            }
        }
    }
Example #5
0
    public void AddDose(float sus)
    {
        if (Status == StatusType.Susceptible || Status == StatusType.Wounded)
        {
            float d;

            d = MathDefs.GaussianDist(DoseMean, DoseVariance);

            dose += d * sus * Time.deltaTime;

            UpdateStatus();
        }
    }
Example #6
0
    public void DecayDose()
    {
        float d;
        float decayCoef = 2f;         //decays in twice the time as it increases

        d = MathDefs.GaussianDist(DoseMean / decayCoef, DoseVariance / decayCoef);

        //take some percentage of the normal dose depending on susceptibility
        dose -= d * susceptibility * Time.deltaTime;

        if (dose < 0f)
        {
            dose = 0f;
        }

        UpdateStatus();
    }
Example #7
0
    private void Start()
    {
        _agentScripts = transform.GetComponentsInChildren <AnimationInfo>();



        _dropDownRectAgents = new DropDownRect(new Rect(115, 20, 90, 300));

        for (int i = 0; i < 32; i++)
        {
            _driveParams[i] = new DriveParams();
        }



        for (int i = 0; i < 32; i++)
        {
            _driveParams[i].ReadValuesDrives(i);
        }



        _firstRun = true;



        _agentSelInd = 0;



        _persMapper = new PersonalityMapper();



        foreach (AnimationInfo t in _agentScripts)
        {
            Reset(t);
        }

        AgentText = new GUIText[_agentScripts.Length];

        //   FormatData("motionEffortCoefs.txt");

        MathDefs.SetSeed(30);
    }
Example #8
0
    public float[] ComputeEventFactor()
    {
        int i;


        for (i = 0; i < eventFactor.Length; i++)
        {
            eventFactor[i] = 0;
        }

        foreach (Goal g in goals)
        {
            if (g.consequenceForSelf)
            {
                if (g.prospectRelevant)
                {
                    if (g.confirmed == AppDef.Unconfirmed)
                    {
                        if (g.pleased)
                        {
                            eventFactor[(int)EType.Hope] += 0.02f * g.weight;                             //(1.7 * sqrt(g.expectation)) + (-0.7*g.weight);
                        }
                        else
                        {
                            eventFactor[(int)EType.Fear] += 0.9f * g.weight;                            //0.4;//2 *g.expectation * g.expectation - g.weight;
                        }
                    }
                    else if (g.confirmed == AppDef.Confirmed)
                    {
                        if (g.pleased)
                        {
                            eventFactor[(int)EType.Satisfaction] += 0.7f * g.weight;
                        }
                        else
                        {
                            eventFactor[(int)EType.FearsConfirmed] += 0.8f * g.weight;
                        }

                        //Confirmed goals are removed later
                    }
                    else                       //disconfirmed

                    {
                        if (g.pleased)
                        {
                            eventFactor[(int)EType.Disappointment] += 0.5f * g.weight;                              //(1.7 * sqrt(g.expectation)) + (-0.7*g.weight) * g.weight;  //hope x weight
                        }
                        else
                        {
                            eventFactor[(int)EType.Relief] += 0.6f * g.weight;                              //(2 * g.expectation *g.expectation -g.weight)*g.weight; //fear x weight
                        }
                        //goals.Remove (g);
                        //g = goals.erase(g);
                    }
                }
                else                   //prospect irrelevant

                {
                    if (g.pleased)
                    {
                        eventFactor[(int)EType.Joy] += 0.4f * g.weight;                                //(1.7 * sqrt(g.expectation)) + (-0.7*g.weight);
                    }
                    else
                    {
                        eventFactor[(int)EType.Distress] += 0.5f * g.weight;                                // (2 * g.expectation * g.expectation) -g.weight;
                    }
                }
            }
            else               //consequences for others

            {
                if (g.desirableForOther)
                {
                    if (g.pleased)
                    {
                        eventFactor[(int)EType.HappyFor] += 0.4f * g.weight;
                    }
                    else
                    {
                        eventFactor[(int)EType.Resentment] += 0.5f * g.weight;
                    }
                }
                else                           //undesirable for other

                {
                    if (g.pleased)
                    {
                        eventFactor[(int)EType.Gloating] += 0.5f * g.weight;
                    }
                    else
                    {
                        eventFactor[(int)EType.Pity] += 0.4f * g.weight;
                    }
                }
            }
        }


        foreach (Standard s in standards)
        {
            if (s.focusingOnSelf)
            {
                if (s.approving)
                {
                    eventFactor[(int)EType.Pride] += 0.2f * s.weight;
                }
                else
                {
                    eventFactor[(int)EType.Shame] += 0.2f * s.weight;
                }
            }
            else               //focusing on others
            {
                if (s.approving)
                {
                    eventFactor[(int)EType.Admiration] += 0.3f * s.weight;
                }
                else
                {
                    eventFactor[(int)EType.Reproach] += 0.5f * s.weight;
                }
            }
        }

        foreach (Attitude a in attitudes)
        {
            if (a.liking)
            {
                eventFactor[(int)EType.Love] += 0.02f * a.weight;
            }
            else
            {
                eventFactor[(int)EType.Hate] += 0.2f * a.weight;
            }
        }



        //compound emotions
        if (eventFactor[(int)EType.Admiration] > 0 && eventFactor[(int)EType.Joy] > 0)
        {
            eventFactor[(int)EType.Gratification] = (eventFactor[(int)EType.Admiration] + eventFactor[(int)EType.Joy]) / 2.0f;
        }

        if (eventFactor[(int)EType.Pride] > 0 && eventFactor[(int)EType.Joy] > 0)
        {
            eventFactor[(int)EType.Gratitude] = (eventFactor[(int)EType.Pride] + eventFactor[(int)EType.Joy]) / 2.0f;
        }

        if (eventFactor[(int)EType.Shame] > 0 && eventFactor[(int)EType.Distress] > 0)
        {
            eventFactor[(int)EType.Remorse] = (eventFactor[(int)EType.Shame] + eventFactor[(int)EType.Distress]) / 2.0f;
        }

        if (eventFactor[(int)EType.Reproach] > 0 && eventFactor[(int)EType.Distress] > 0)
        {
            eventFactor[(int)EType.Anger] = (eventFactor[(int)EType.Reproach] + eventFactor[(int)EType.Distress]) / 2.0f;
        }


        //Normalize eventFactor
        MathDefs.NormalizeElements(eventFactor, 0f, 1f);

        return(eventFactor);
    }
Example #9
0
    private void ComputeMood()
    {
        int         i;
        int         activeEmotionCnt;
        Vector3     emotionCenter = Vector3.zero;
        const float pullPushSpeed = 0.2f;
        const float decaySpeed = 0.01f;
        Vector3     m2ec, ec2m, m2dm, ec2dm;

        activeEmotionCnt = 0;
        for (i = 0; i < pad.Length; i++)
        {
            if (emotion[i] > 0)
            {
                emotionCenter += pad[i] * emotion[i];
                activeEmotionCnt++;
            }
        }

        m2dm = defaultMood - mood;

        if (activeEmotionCnt > 0)
        {
            //emotionCenter = emotionCenter / activeEmotionCnt;
            emotionCenter = emotionCenter / MathDefs.Length(emotion);

            m2ec  = emotionCenter - mood;
            ec2m  = mood - emotionCenter;
            ec2dm = defaultMood - emotionCenter;

            m2ec.Normalize();

            if (Vector3.Dot(m2ec, m2dm) > 0.0f && Vector3.Dot(ec2m, ec2dm) < 0.0f)
            {
                mood = -pullPushSpeed * m2ec;
            }
            else
            {
                mood = pullPushSpeed * m2ec;
            }

            m2dm.Normalize();
        }

        //now decay mood to the default mood
        mood = mood - decaySpeed * m2dm * Time.deltaTime;


        //constrain to region -1 to 1

        if (mood.x > 1)
        {
            mood.x = 1;
        }
        else if (mood.x < -1)
        {
            mood.x = -1;
        }

        if (mood.y > 1)
        {
            mood.y = 1;
        }
        else if (mood.y < -1)
        {
            mood.y = -1;
        }

        if (mood.z > 1)
        {
            mood.z = 1;
        }
        else if (mood.z < -1)
        {
            mood.z = -1;
        }
    }
    void Start()
    {
        for (int i = 0; i < 32; i++)
        {
            _driveParams[i] = new DriveParams();
        }

        _agentLeft  = GameObject.Find("AgentPrefabLeft");
        _agentRight = GameObject.Find("AgentPrefabRight");


        if (!_agentLeft)
        {
            Debug.Log("AgentLeft prefab not found");
            return;
        }
        if (!_agentRight)
        {
            Debug.Log("AgentRight prefab not found");
            return;
        }

        _personality = UserInfo.Personality;


#if WEBMODE
        _animInd = UserInfo.AnimInd;
        _qCnt    = UserInfo.QCnt;
#elif !WEBMODE
        _animInd = 1;
        _qCnt    = 48;
#endif
        _taskQInd            = 0; //initial question's index
        _arePositionsSwapped = new bool[_qCnt * 2];
        _isSubmittedStr      = new string[_qCnt + 2];
        _isSubmitted         = new bool[_qCnt + 2];
        _alreadyPlayed       = new bool[_qCnt];


        //compute effortCombination hashes
        for (int i = 0; i < 32; i++)
        {
            int val = _effortList[i, 3] + _effortList[i, 2] * 3 + _effortList[i, 1] * 9 + _effortList[i, 0] * 27;
            _effortCombination.Add(val, i);
        }

        for (int i = 0; i < _isSubmittedStr.Length; i++)
        {
            _isSubmittedStr[i] = "";//"Answer NOT submitted";
        }
        for (int i = 0; i < _alreadyPlayed.Length; i++)
        {
            _alreadyPlayed[i] = false;
        }

        UpdateCameraBoundaries();


        //    _drivesAchieved = false;
        //Read all drive and shape parameters

#if !WEBMODE
        for (int i = 0; i < 32; i++)
        {
            _driveParams[i].ReadValuesDrives(i);
        }
#elif WEBMODE
        for (int i = 0; i < 32; i++)
        {
            this.StartCoroutine(_driveParams[i].GetValuesDrives(i, "funda"));
        }


        //wait till drives are achieved

        /*
         *  _drivesAchieved = true;
         *  for (int i = 0; i < 32; i++)  //make sure all the drives are achieved
         *      _drivesAchieved = _drivesAchieved && _driveParams[i].DrivesAchieved;
         *
         */
#endif



        //Select if positions are swapped in the beginning
        for (int i = 0; i < _arePositionsSwapped.Length / 2; i++)
        {
            if (MathDefs.GetRandomNumber(2) == 1)
            {
                //50% chance
                _arePositionsSwapped[i] = true;
            }
            else
            {
                _arePositionsSwapped[i] = false;
            }
        }


        Reset();

        _firstQFirstPlay = true;



        _goldQ1Ind = MathDefs.GetRandomNumber(2, 4);
        _goldQ2Ind = MathDefs.GetRandomNumber(4, 6);

        _goldQ1Asked = _goldQ2Asked = false;

        _quality = 0;
    }
Example #11
0
    private void OnGUI()
    {
        GUI.skin = ButtonSkin;


        bool disableBefore = DisableLMA;

        DisableLMA = GUILayout.Toggle(DisableLMA, "Disable LMA");

        if (disableBefore != DisableLMA)      //a change has been made in the toggle
        {
            foreach (AnimationInfo a in _agentScripts)
            {
                a.DisableLMA = DisableLMA;
            }
        }



        GUI.color = Color.white;
        GUILayout.BeginArea(_dropDownRectAgents.DdRect);
        GUILayout.Label("Character");
        _dropDownRectAgents.DdList = _agentScripts.Select(s => s.CharacterName).ToList();
        _agentSelInd = _dropDownRectAgents.ShowDropDownRect();
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(5, 20, 105, Screen.height));


        GUILayout.Label("Personality");
        GUI.color = Color.white;

        GUILayout.Label("");
        for (int i = 0; i < 5; i++)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("" + _persMin);
            GUILayout.Label("" + _personalityName[i]);
            GUILayout.Label("" + _persMax);
            GUILayout.EndHorizontal();

            _personality[i] = _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[i];
            GUI.color       = Color.white;



            GUI.backgroundColor = Color.white;
            _personality[i]     = GUILayout.HorizontalSlider(_personality[i], _persMin, _persMax).Truncate(1);

            //Assign agent personality
            _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[i] = _personality[i];


            string[] ocean = { "O", "C", "E", "A", "N" };
            for (int j = 0; j < 5; j++)
            {
                if (_agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[j] == -1)
                {
                    ocean[j] += "-";
                }
                else if (_agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[j] == 1)
                {
                    ocean[j] += "+";
                }
                else
                {
                    ocean[j] = "";
                }
            }
        }


        GUI.color = Color.white;



        if (_driveParams[31].DrivesAchieved)
        {
            if (GUILayout.Button("Reset scene"))
            {
                Application.LoadLevel(Application.loadedLevel);
            }
            if (GUILayout.Button("Randomize"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = MathDefs.GetRandomNumber(-1f, 1f);
                    }
                }
            }
            if (GUILayout.Button("Reset"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = 0;
                    }
                }
            }
            if (GUILayout.Button("Assign All"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = _personality[i];
                    }
                }
            }
            if (GUILayout.Button("Play"))
            {
                _walkIsOver = 0;
                int agentInd = 0;
                foreach (AnimationInfo t in _agentScripts)
                {
                    t.AnimName = "walking";

                    ResetComponents(t);


                    _persMapper.MapPersonalityToMotion(t.GetComponent <PersonalityComponent>()); //calls initkeypoints, which stops the animation
                    Play(t);

                    GUI.color = Color.white;
                    agentInd++;
                }
            }

            if (GUILayout.Button("Record"))
            {
                _walkIsOver = 0;

                GameObject.Find("Camera").GetComponent <Screenshot>().IsRunning = true;

                Time.timeScale = 0.5f;

                int agentInd = 0;

                foreach (AnimationInfo t in _agentScripts)
                {
                    t.AnimName = "walking";

                    ResetComponents(t);


                    _persMapper.MapPersonalityToMotion(t.GetComponent <PersonalityComponent>()); //calls initkeypoints, which stops the animation
                    Play(t);

                    GUI.color = Color.white;
                    agentInd++;
                }
            }



            //we need to update after play because playanim resets torso parameters for speed etc. when animinfo is reset
        }

        GUI.color = Color.yellow;
        GUILayout.Label("S:" + _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[0] + " W:" + _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[1] + " T:" +
                        _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[2] + " F:" + _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[3]);

        GUILayout.EndArea();
    }
    private void OnGUI()
    {
        GUI.color = Color.white;
        GUILayout.BeginArea(_dropDownRectAgents.DdRect);
        GUILayout.Label("Character");
        _dropDownRectAgents.DdList = _agentScripts.Select(s => s.CharacterName).ToList();
        _agentSelInd = _dropDownRectAgents.ShowDropDownRect();

        GUILayout.EndArea();


        GUILayout.BeginArea(_dropDownRectAnimNames.DdRect);
        GUILayout.Label("Animation");
        _dropDownRectAnimNames.DdList = _agentScripts[_agentSelInd].AnimNames.ToList();
        int ind = _dropDownRectAnimNames.ShowDropDownRect();

        _agentScripts[_agentSelInd].AnimName = _agentScripts[_agentSelInd].AnimNames[ind];
        GUILayout.EndArea();


        GUILayout.BeginArea(new Rect(5, 20, 105, Screen.height));


        GUILayout.Label("Personality");
        GUI.color = Color.white;

        GUILayout.Label("");
        for (int i = 0; i < 5; i++)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("" + _persMin);
            GUILayout.Label("" + _personalityName[i]);
            GUILayout.Label("" + _persMax);
            GUILayout.EndHorizontal();

            _personality[i] = _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[i];
            GUI.color       = Color.white;



            GUI.backgroundColor = Color.white;
            _personality[i]     = GUILayout.HorizontalSlider(_personality[i], _persMin, _persMax).Truncate(1);

            //Assign agent personality
            _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[i] = _personality[i];


            string[] ocean = { "O", "C", "E", "A", "N" };
            for (int j = 0; j < 5; j++)
            {
                if (_agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[j] == -1)
                {
                    ocean[j] += "-";
                }
                else if (_agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[j] == 1)
                {
                    ocean[j] += "+";
                }
                else
                {
                    ocean[j] = "";
                }
            }


            /*
             * _agentSel.AgentText.text = string.Format(ocean[0] + "  " + ocean[1] + "  " + ocean[2] + "  " + ocean[3] + "  " + ocean[4]);
             *
             *
             * _agentSel.AgentText.text += string.Format("\nS: {0:0.00} W: {1:0.00} T: {2:0.00} F: {3:0.00}", _agentSel.Effort[0], _agentSel.Effort[1], _agentSel.Effort[2], _agentSel.Effort[3]);
             */
        }


        GUI.color = Color.white;


        _lockHand = GUILayout.Toggle(_lockHand, "Lock hand");
        foreach (AnimationInfo a in _agentScripts)
        {
            a.GetComponent <IKAnimator>().LockHand = _lockHand;
        }



        if (_driveParams[31].DrivesAchieved)
        {
            if (GUILayout.Button("Reset scene"))
            {
                Application.LoadLevel(Application.loadedLevel);
            }
            if (GUILayout.Button("Randomize"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = MathDefs.GetRandomNumber(-1f, 1f);
                    }
                }
            }
            if (GUILayout.Button("Reset"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = 0;
                    }
                }
            }
            if (GUILayout.Button("Assign All"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = _personality[i];
                    }
                }
            }
            if (GUILayout.Button("Assign All Variation"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = _personality[i] +
                                                                                 MathDefs.GetRandomNumber(-0.2f, 0.2f);
                        if (a.GetComponent <PersonalityComponent>().Personality[i] > 1)
                        {
                            a.GetComponent <PersonalityComponent>().Personality[i] = 1;
                        }
                        else if (a.GetComponent <PersonalityComponent>().Personality[i] < -1)
                        {
                            a.GetComponent <PersonalityComponent>().Personality[i] = -1;
                        }
                    }
                }
            }
            if (GUILayout.Button("Play"))
            {
                PlayAgents();
            }

            if (GUILayout.Button("Record"))
            {
                GameObject.Find("Main Camera").GetComponent <Screenshot>().IsRunning = true;

                Time.timeScale = 0.25f;



                PlayAgents();
            }



            //we need to update after play because playanim resets torso parameters for speed etc. when animinfo is reset
        }

        GUI.color = Color.yellow;
        GUILayout.Label("S:" + _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[0] + " W:" + _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[1] + " T:" +
                        _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[2] + " F:" + _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[3]);

        GUILayout.EndArea();
    }
    void Start()
    {
        UserInfo.Hit = 5;

        _quality = 0;
        for (int i = 0; i < _agentsLeft.Length; i++)
        {
            _agentsLeft[i]  = GameObject.Find("AgentPrefabLeft" + i).GetComponent <AnimationInfo>();
            _agentsRight[i] = GameObject.Find("AgentPrefabRight" + i).GetComponent <AnimationInfo>();


            //Make all invisible so that users can't see the models
            _agentsLeft[i].gameObject.SetActive(false);
            _agentsRight[i].gameObject.SetActive(false);
        }


        //TODO: Hits start from 0!!
        _agentsLeft[(UserInfo.Hit / 3)].gameObject.SetActive(true);
        _agentsRight[(UserInfo.Hit / 3)].gameObject.SetActive(true);

        for (int i = 0; i < 32; i++)
        {
            _driveParams[i] = new DriveParams();
        }

        _qCnt = 5;


#if DEBUGMODE
        UserInfo.Hit = 0;
#endif


        _taskQInd = 4;

        //_taskQInd = 0; //initial question's index
        _arePositionsSwapped = new bool[_qCnt];
        _isSubmittedStr      = new string[_qCnt];
        _isSubmitted         = new bool[_qCnt];
        _alreadyPlayed       = new bool[_qCnt];



        for (int i = 0; i < _isSubmittedStr.Length; i++)
        {
            _isSubmittedStr[i] = "";//"Answer NOT submitted";
        }
        for (int i = 0; i < _alreadyPlayed.Length; i++)
        {
            _alreadyPlayed[i] = false;
        }

        UpdateCameraBoundaries();


        //    _drivesAchieved = false;
        //Read all drive and shape parameters

#if !WEBMODE
        for (int i = 0; i < 32; i++)
        {
            _driveParams[i].ReadValuesDrives(i);
        }
#elif WEBMODE
        for (int i = 0; i < 32; i++)
        {
            this.StartCoroutine(_driveParams[i].GetValuesDrives(i, "funda"));
        }
#endif



        //Select if positions are swapped in the beginning
        for (int i = 0; i < _arePositionsSwapped.Length / 2; i++)
        {
            if (MathDefs.GetRandomNumber(2) == 1)
            {
                //50% chance
                _arePositionsSwapped[i] = true;
            }
            else
            {
                _arePositionsSwapped[i] = false;
            }
        }



        _persMapper      = new PersonalityMapper();
        _firstQFirstPlay = true;

        _agentLeft  = GameObject.Find("AgentPrefabLeft" + (UserInfo.Hit / 3)).GetComponent <AnimationInfo>();
        _agentRight = GameObject.Find("AgentPrefabRight" + (UserInfo.Hit / 3)).GetComponent <AnimationInfo>();
        //  _agentLeft = new Agent("AgentPrefabLeft" + (UserInfo.Hit/3));
        // _agentRight = new Agent("AgentPrefabRight" + (UserInfo.Hit / 3));


        if ((UserInfo.Hit % 3) == 2)   //walking
        {
            _agentLeft.transform.position  -= Vector3.forward * 4;
            _agentRight.transform.position -= Vector3.forward * 4;
        }



        Reset(_agentLeft);
        Reset(_agentRight);
    }
Example #14
0
    private void OnGUI()
    {
        GUI.skin = ButtonSkin;


        bool disableBefore = DisableLMA;

        DisableLMA = GUILayout.Toggle(DisableLMA, "Disable LMA");

        if (disableBefore != DisableLMA)      //a change has been made in the toggle
        {
            foreach (AnimationInfo a in _agentScripts)
            {
                a.DisableLMA = DisableLMA;
            }
        }



        GUI.color = Color.white;
        GUILayout.BeginArea(_dropDownRectAgents.DdRect);
        GUILayout.Label("Character");
        _dropDownRectAgents.DdList = _agentScripts.Select(s => s.CharacterName).ToList();
        _agentSelInd = _dropDownRectAgents.ShowDropDownRect();

        GUILayout.EndArea();


        GUILayout.BeginArea(_dropDownRectAnimNames.DdRect);
        GUILayout.Label("Animation");
        _dropDownRectAnimNames.DdList = _agentScripts[_agentSelInd].AnimNames.ToList();
        int ind = _dropDownRectAnimNames.ShowDropDownRect();

        _agentScripts[_agentSelInd].AnimName = _agentScripts[_agentSelInd].AnimNames[ind];
        GUILayout.EndArea();

        GUILayout.BeginArea(_dropDownRectNationality.DdRect);
        GUILayout.Label("Nationality");
        _dropDownRectNationality.DdList = _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().listNationality();
        int ind_nationality = _dropDownRectNationality.ShowDropDownRect();

        nationality_s = _dropDownRectNationality.DdList[ind_nationality];
        _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Culture = nationality_s;
        GUILayout.EndArea();

        GUILayout.BeginArea(_dropDownRectProfession.DdRect);
        GUILayout.Label("Profession");
        _dropDownRectProfession.DdList = _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().listProfession();
        int ind_profession = _dropDownRectProfession.ShowDropDownRect();

        profession_s = _dropDownRectProfession.DdList[ind_profession];
        _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Profession = profession_s;
        GUILayout.EndArea();



        GUILayout.BeginArea(new Rect(5, 20, 105, Screen.height));


        GUILayout.Label("Personality");
        GUI.color = Color.white;

        GUILayout.Label("");
        for (int i = 0; i < 5; i++)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("" + _persMin);
            GUILayout.Label("" + _personalityName[i]);
            GUILayout.Label("" + _persMax);
            GUILayout.EndHorizontal();

            _personality[i] = _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[i];
            GUI.color       = Color.white;



            GUI.backgroundColor = Color.white;
            _personality[i]     = GUILayout.HorizontalSlider(_personality[i], _persMin, _persMax).Truncate(1);

            //Assign agent personality
            _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[i] = _personality[i];


            string[] ocean = { "O", "C", "E", "A", "N" };
            for (int j = 0; j < 5; j++)
            {
                if (_agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[j] == -1)
                {
                    ocean[j] += "-";
                }
                else if (_agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Personality[j] == 1)
                {
                    ocean[j] += "+";
                }
                else
                {
                    ocean[j] = "";
                }
            }


            /*
             * _agentSel.AgentText.text = string.Format(ocean[0] + "  " + ocean[1] + "  " + ocean[2] + "  " + ocean[3] + "  " + ocean[4]);
             *
             *
             * _agentSel.AgentText.text += string.Format("\nS: {0:0.00} W: {1:0.00} T: {2:0.00} F: {3:0.00}", _agentSel.Effort[0], _agentSel.Effort[1], _agentSel.Effort[2], _agentSel.Effort[3]);
             */
        }


        GUI.color = Color.white;


        _lockHand = GUILayout.Toggle(_lockHand, "Lock hand");
        foreach (AnimationInfo a in _agentScripts)
        {
            a.GetComponent <IKAnimator>().LockHand = _lockHand;
        }


        GUILayout.BeginHorizontal();
        GUILayout.Label("" + 0);
        GUILayout.Label("W");
        GUILayout.Label("" + 1);
        GUILayout.EndHorizontal();
        GUI.color           = Color.white;
        GUI.backgroundColor = Color.white;
        n_p_weight          = GUILayout.HorizontalSlider(n_p_weight, 0, 1).Truncate(1);
        if (n_p_weight != prev_n_p_weight)
        {
            prev_n_p_weight = n_p_weight;
            foreach (AnimationInfo a in _agentScripts)
            {
                a.GetComponent <PersonalityComponent>().BlendWeight = n_p_weight;
            }
        }
        if (_driveParams[31].DrivesAchieved)
        {
            if (GUILayout.Button("Reset scene"))
            {
                Application.LoadLevel(Application.loadedLevel);
            }
            if (GUILayout.Button("Randomize"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = MathDefs.GetRandomNumber(-1f, 1f);
                    }
                }
            }
            if (GUILayout.Button("Reset"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = 0;
                    }
                }
            }
            if (GUILayout.Button("Assign All"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = _personality[i];
                    }
                    //will cause small diff in ocean values if I do this, for unknown reasons: so I comment this out
                    //a.GetComponent<PersonalityComponent>().Culture = nationality_s;
                    //a.GetComponent<PersonalityComponent>().Profession = profession_s;
                }
            }
            if (GUILayout.Button("Assign All Variation"))
            {
                foreach (AnimationInfo a in _agentScripts)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        a.GetComponent <PersonalityComponent>().Personality[i] = _personality[i] +
                                                                                 MathDefs.GetRandomNumber(-0.2f, 0.2f);
                        if (a.GetComponent <PersonalityComponent>().Personality[i] > 1)
                        {
                            a.GetComponent <PersonalityComponent>().Personality[i] = 1;
                        }
                        else if (a.GetComponent <PersonalityComponent>().Personality[i] < -1)
                        {
                            a.GetComponent <PersonalityComponent>().Personality[i] = -1;
                        }
                    }
                }
            }
            if (GUILayout.Button("Play"))
            {
                int agentInd = 0;



                foreach (AnimationInfo t in _agentScripts)
                {
                    ResetComponents(t);


                    _persMapper.MapPersonalityToMotion(t.GetComponent <PersonalityComponent>()); //calls initkeypoints, which stops the animation

                    Play(t);

                    GUI.color = Color.white;
                    agentInd++;
                }
                _persMapper.MapAnimSpeeds(_agentScripts, 0.9f, 1.3f); //map them to the range
            }

            if (GUILayout.Button("Record"))
            {
                GameObject.Find("Camera").GetComponent <Screenshot>().IsRunning = true;

                Time.timeScale = 0.25f;

                int agentInd = 0;
                foreach (AnimationInfo t in _agentScripts)
                {
                    ResetComponents(t);


                    _persMapper.MapPersonalityToMotion(t.GetComponent <PersonalityComponent>()); //calls initkeypoints, which stops the animation
                    Play(t);

                    GUI.color = Color.white;
                    agentInd++;
                }


                _persMapper.MapAnimSpeeds(_agentScripts, 0.9f, 1.3f); //map them to the range
            }



            //we need to update after play because playanim resets torso parameters for speed etc. when animinfo is reset
        }

        GUI.color = Color.yellow;
        GUILayout.Label("S:" + _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[0] + " W:" + _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[1] + " T:" +
                        _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[2] + " F:" + _agentScripts[_agentSelInd].GetComponent <PersonalityComponent>().Effort[3]);

        GUILayout.EndArea();
    }
Example #15
0
    void Start()
    {
        for (int i = 0; i < 32; i++)
        {
            _arm[i] = new Vector3[2];
        }

        _agentLeft  = GameObject.Find("AgentPrefabLeft");
        _agentRight = GameObject.Find("AgentPrefabRight");


        if (!_agentLeft)
        {
            Debug.Log("AgentLeft prefab not found");
            return;
        }
        if (!_agentRight)
        {
            Debug.Log("AgentRight prefab not found");
            return;
        }



        _qInd = 0;
        //compute effortCombination hashes
        for (int i = 0; i < 32; i++)
        {
            int val = _effortList[i, 3] + _effortList[i, 2] * 3 + _effortList[i, 1] * 9 + _effortList[i, 0] * 27;
            _effortCombination.Add(val, i);
        }



        for (int i = 0; i < _isSubmittedStr.Length; i++)
        {
            _isSubmittedStr[i] = "Answer NOT submitted";
        }

        UpdateCameraBoundaries();

        for (int i = 0; i < 18; i++)
        {
            _shapeParams[i] = new float[6];
        }

        //Read all drive and shape parameters

#if !WEBMODE
        for (int i = 0; i < 32; i++)
        {
            ReadValuesDrives(i);
        }

        for (int i = 5; i >= 0; i--)
        {
            ReadValuesShapes(i);
        }
#elif WEBMODE
        for (int i = 0; i < 32; i++)
        {
            this.StartCoroutine(GetValuesDrives(i));
        }

        for (int i = 5; i >= 0; i--)
        {
            this.StartCoroutine(GetValuesShapes(i));
        }

        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 48; j++)
            {
                this.StartCoroutine(GetValuesSubmitted(j, i));
            }
        }
#endif
        //Read all shape parameters


        //Select if positions are swapped in the beginning
        for (int i = 0; i < _arePositionsSwapped.Length; i++)
        {
            if (MathDefs.GetRandomNumber(2) == 1) //50% chance
            {
                _arePositionsSwapped[i] = true;
            }
            else
            {
                _arePositionsSwapped[i] = false;
            }
        }


        Reset();

        _leftPos  = _agentLeft.transform.position;
        _rightPos = _agentRight.transform.position;
    }