예제 #1
0
 void InitializeFeedBackDictionary(Affordances WhichAffordance)
 {
     if (transform.FindChild(WhichAffordance.name.ToString() + "Feedback"))
     {
         DictionaryOfFeedBacks.Add(WhichAffordance.name, transform.FindChild(WhichAffordance.name.ToString() + "Feedback").GetComponent <FeedBackBase>());
     }
 }
예제 #2
0
    //Initializing value of Affordances and show it with Feedback systems.

    void InitializeFeedBack(Affordances WhichAffordance, float value)
    {
        WhichAffordance.value = value;
        if (DictionaryOfFeedBacks.ContainsKey(WhichAffordance.name))
        {
            DictionaryOfFeedBacks[WhichAffordance.name].InitializeFeedBack(this);
        }
    }
예제 #3
0
 public float[] ApplyAffordance(Affordances affordance) //returns desire matrix with affordance applied
 {
     float[] affordances = affordance.getAffordances();
     if (affordances.Length != desires.Length)
     {
         Debug.Log("Uh, something's wrong with desire lengths");
     }
     else
     {
         for (int i = 0; i < affordances.Length; i++)
         {
             postAffordanceDesires[i] = desires[i] + affordances[i];
         }
         NormalizeDesires(ref postAffordanceDesires);
         //affordance.Use(gameObject);
         //Debug.Log(affordance.stock);
     }
     return(postAffordanceDesires);
 }
예제 #4
0
    void RecognizingAffordances()
    {
        string tempString  = "";
        string tempString2 = "";

        for (int i = 0; i < ListOfAffordances.Count; i++)
        {
            ListOfAffordances[i] = new Affordances();
        }

        Affordances newAffordance;

        for (int i = 0; i < Capabilities.Length; i++)
        {
            newAffordance = new Affordances();
            tempString    = Capabilities[i];
            tempString2   = tempString.Substring(tempString.IndexOf(":") + 1, tempString.Length - tempString.IndexOf(":") - 1);

            tempString = tempString.Substring(0, tempString.IndexOf(":"));


            if (tempString2 != Affordances.Types.Media.ToString())
            {
                for (int j = 0; j < Enum.GetNames(typeof(Affordances.Names)).Length; j++)
                {
                    if (tempString == Enum.GetNames(typeof(Affordances.Names))[j])
                    {
                        newAffordance.name = (Affordances.Names)(j);
                        continue;
                    }
                }

                for (int j = 0; j < Enum.GetNames(typeof(Affordances.Types)).Length; j++)
                {
                    if (tempString2 == Enum.GetNames(typeof(Affordances.Types))[j])
                    {
                        newAffordance.Type = (Affordances.Types)(j);
                        continue;
                    }
                }
                newAffordance.value = SetInitialValue(newAffordance.name, newAffordance.Type);
            }
            else
            {
                newAffordance.Type = Affordances.Types.Media;
                newAffordance.name = Affordances.Names.MediaSupport;
                GetMediaFormats(Capabilities[i].Substring(0, Capabilities[i].IndexOf(':')));
            }
            ListOfAffordances.Add(newAffordance);
            DictionaryOfAffordances.Add(newAffordance.name, newAffordance);
            InitializeFeedBackDictionary(newAffordance);
        }

        #region Initializing Each Affordance with a Value of 0. except for Mute and Volume affordances.
        for (int i = 0; i < DictionaryOfAffordances.Count; i++)
        {
            if (ListOfAffordances[i].name != Affordances.Names.MediaSupport)
            {
                switch (ListOfAffordances[i].name)
                {
                case Affordances.Names.Mute:
                {
                    InitializeFeedBack(ListOfAffordances[i], 1);
                    break;
                }

                case Affordances.Names.Volume:
                {
                    InitializeFeedBack(ListOfAffordances[i], 25);
                    break;
                }

                default:
                {
                    InitializeFeedBack(ListOfAffordances[i], 0);
                    break;
                }
                }
            }
        }
        #endregion
    }
예제 #5
0
    IEnumerator DecideAffordance(float time)
    {
        NavMeshAgent mNavMeshAgent = GetComponent <NavMeshAgent>();


        WaitForSeconds waitForSeconds     = new WaitForSeconds(time);
        WaitForSeconds waitForIdleSeconds = new WaitForSeconds(10 * time * attention_Span);

        for (; ;)
        {
            while (happiness > 50 && idlePosition != null && !inTask) //content, no need to decide on anything
            {
                if (Random.value * 100 < 100 - happiness)
                {
                    break;
                }
                agent.SetDestination(idlePosition.transform.position);
                yield return(waitForIdleSeconds);
            }


            inTask = true;
            NormalizeDesires(ref desires);
            maxweight = 0;

            maxweightindex = -1;
            movement.Set(0, 0, 0);
            allAffordances = FindObjectsOfType <Affordances>();                                      //find all gameobjects that contain affordances
            weightmatrix   = new float[allAffordances.Length];
            for (int i = 0; i < allAffordances.Length; i++)                                          //logic goes here for calculating affordance weight
            {
                weightmatrix[i] = currWeight - FindDesireWeight(ApplyAffordance(allAffordances[i])); //see weight after applying affordance

                if (weightmatrix[i] > 0)
                {
                    movement = transform.position - allAffordances[i].transform.position;

                    if (allAffordances[i].duration > 35) //if too long, apply a penalty
                    {
                        weightmatrix[i] /= 1.3f;
                    }

                    //energy
                    if (movement.magnitude > farThreshold) //if too far, apply a penalty, to be slightly complicated further in future
                    {
                        if (CompareTag("Adult"))
                        {
                            weightmatrix[i] /= 2;
                        }
                        else if (CompareTag("Elder"))
                        {
                            weightmatrix[i] /= 4;
                        }
                    }
                    // weightmatrix[i] *= energy/50;
                    if (allAffordances[i] == lastAffordanceUsed) //if last affordance used, apply a penalty, to be a buffer of N affordances in the future
                    {
                        weightmatrix[i] /= 4;
                    }



                    //extraversion
                    if (Physics.OverlapSphere(allAffordances[i].transform.position, 7).Length > 10) //consider a popular area
                    {
                        if (CompareTag("Adult"))
                        {
                            weightmatrix[i] /= 4;
                        }
                        else if (CompareTag("Elder"))
                        {
                            weightmatrix[i] /= 6;
                        }

                        /*if (extraversion>50)
                         * {
                         *  weightmatrix[i] *= (extraversion - 50) / 25;
                         * }
                         * else if (extraversion<50)
                         * {
                         *  weightmatrix[i] /= (50 - extraversion) / 25;
                         * }*/
                    }


                    if (maxweight < weightmatrix[i])
                    {
                        maxweight      = weightmatrix[i];
                        maxweightindex = i;
                        //desireAffordance
                    }
                }
            }
            //Debug.Log(maxweight + " " + currWeight);
            if (maxweightindex > -1) //if there is a affordance desired, work towards it
            {
                //Debug.Log(maxweight);
                //Debug.Log(weightmatrix[0]);
                desire = allAffordances[maxweightindex].gameObject;

                movement = transform.position - desire.transform.position;

                //afterwards, check if need to apply affordance, at the moment just sees if its a specific distance away

                /*Debug.Log(mNavMeshAgent.remainingDistance);
                 * if (mNavMeshAgent.remainingDistance<1.5)
                 * {
                 *
                 *  postAffordanceDesires = ApplyAffordance(desire.GetComponent<Affordances>());
                 *  Debug.Log("Used " + desire.name);
                 *
                 *  for (int i = 0; i < desires.Length; i++)
                 *  {
                 *      desires[i] = postAffordanceDesires[i];
                 *  }
                 *  flag = true;
                 *  desire.GetComponent<Affordances>().Use(gameObject);
                 *  inTask = true;
                 *  lastAffordanceUsed = desire.GetComponent<Affordances>();
                 *  yield return new WaitForSeconds(desire.GetComponent<Affordances>().duration * clock.timeSpeed);
                 * }
                 * else
                 *  agent.SetDestination(desire.transform.position); */


                if (movement.magnitude < 2.2)
                {
                    postAffordanceDesires = ApplyAffordance(desire.GetComponent <Affordances>());
                    Debug.Log("Used " + desire.name);

                    for (int i = 0; i < desires.Length; i++)
                    {
                        desires[i] = postAffordanceDesires[i];
                    }
                    flag = true;
                    desire.GetComponent <Affordances>().Use(gameObject);
                    inTask             = true;
                    lastAffordanceUsed = desire.GetComponent <Affordances>();
                    inTask             = false;
                    yield return(new WaitForSeconds(desire.GetComponent <Affordances>().duration *clock.timeSpeed));

                    // postAffordanceDesires[0] = 151;

                    //NormalizeDesires(ref desires);
                    //Debug.Log(desires[0] + " " + desires[1] + " " + desires[2] + " " + desires[3]);
                }
                else
                {
                    agent.SetDestination(desire.transform.position);
                }
                //Debug.Log(gameObject.name);
                //Debug.Log(agent.destination);
            }
            yield return(waitForSeconds);
        }
    }