Esempio n. 1
0
        /// <summary>
        /// Returns the current priority for this behaviour, based on all attached & enabled considerations.
        /// </summary>
        public float Evaluate()
        {
            // Raise pre-evaluation events
            _preEvaluation.Invoke();

            // Calculate priority
            float totalPriority  = 0.0f;
            int   i              = 0;
            float considerations = 0;

            // Iterate through each consideration to get total priority
            while (i < _considerations.Count)
            {
                uaiConsideration c = _considerations[i];

                if (c._enabled)
                {
                    totalPriority  += c.Evaluate() * c._weight;
                    considerations += c._weight;
                }

                i++;
            }

            if (considerations == 0)
            {
                return(0.0f);
            }

            return((totalPriority / considerations) * _weight);
        }
Esempio n. 2
0
        /// <summary>
        /// Used internally to iterate through each consideration &
        /// link them to the correct properties.
        /// </summary>
        private void LinkConsiderations()
        {
            if (_agent)
            {
                // Iterate through each consideration
                for (int i = 0; i < _considerations.Count; i++)
                {
                    uaiConsideration c = _considerations[i];

                    // Find the correct property attached to the agent
                    uaiProperty property = _agent.FindProperty(c._propertyName);

                    if (property != null)
                    {
                        c.property = property;
                    }
                    else
                    {
                        // No property matching the consideration's name was found
                        Debug.LogWarning("No attached property with name '" + c._propertyName + "' was found. The consideration will be removed.");
                        _considerations.RemoveAt(i);
                        i--;
                    }
                }
            }
        }