Ejemplo n.º 1
0
    UtilityObject GetMaxScoreUtilityObject(UtilityObject[] utilityObjects)
    {
        UtilityObject maxUtilityObject = null;

        // find goal with the highest utility (need/desire/motive)
        float            maxUtility = 0;
        UtilityAgentGoal maxGoal    = null;

        foreach (var goal in goals)
        {
            if (goal.utility > maxUtility)
            {
                maxUtility = goal.utility;
                maxGoal    = goal;
            }
        }

        // get the utility object with the highest score for the goal
        if (maxUtility > utilityThreshold)
        {
            float maxScore = 0;
            foreach (var utilityObject in utilityObjects)
            {
                float score = utilityObject.GetScore(maxGoal.id);
                if (score > maxScore)
                {
                    maxScore         = score;
                    maxUtilityObject = utilityObject;
                }
            }
        }

        return(maxUtilityObject);
    }
Ejemplo n.º 2
0
 void UpdateUtilityObjectScore(UtilityObject utilityObject)
 {
     foreach (var goal in goals)
     {
         float score = utilityObject.GetScore(goal.id);
         goal.input += score;
     }
 }
Ejemplo n.º 3
0
 public void StartUtilityObject(UtilityObject utilityObject)
 {
     if (state == eState.Idle)
     {
         state = eState.ActionStart;
         this.utilityObject = utilityObject;
     }
 }
Ejemplo n.º 4
0
    IEnumerator ExecuteUtilityObject(UtilityObject utilityObject)
    {
        state = eState.ActionInProgress;

        // walk to utility object
        movement.MoveTowards(utilityObject.location.position);
        while (Vector3.Distance(transform.position, utilityObject.location.position) > 0.1f)
        {
            yield return(null);
        }

        // transform to utility object action
        GetComponent <NavMeshAgent>().enabled = false;
        if (utilityObject.actionLocation != null)
        {
            float     time  = 1;
            float     timer = 0;
            Transform start = transform;

            while (timer < time)
            {
                timer += Time.deltaTime;
                timer  = Mathf.Min(timer, time);
                Utilities.Lerp(start, utilityObject.actionLocation, transform, timer / time);
                yield return(null);
            }
        }

        // perform utility object action
        animator.SetTrigger(utilityObject.animationID);
        if (utilityObject.actionFX != null)
        {
            utilityObject.actionFX.SetActive(true);
        }

        // wait for action duration
        yield return(new WaitForSeconds(utilityObject.duration));

        // return to idle
        GetComponent <NavMeshAgent>().enabled = true;
        animator.SetTrigger("Idle");
        if (utilityObject.actionFX != null)
        {
            utilityObject.actionFX.SetActive(false);
        }

        // add utility score
        UpdateUtilityObjectScore(utilityObject);

        state = eState.ActionComplete;

        yield return(null);
    }
Ejemplo n.º 5
0
        private IEnumerable <ListRelation> GetChildrenLists(SPList parentList)
        {
            IEnumerable <ListRelation> childrenLists = new List <ListRelation>();

            WebSettings settings = WebSettings.GetWebSettings(parentList.ParentWeb); // TODO make sure the right web is chosen
            string      setting  = settings[ListRelation.SettingKey];

            if (!string.IsNullOrWhiteSpace(setting))
            {
                childrenLists = UtilityObject.Deserialize <List <ListRelation> >(setting);
                childrenLists = childrenLists.Where(s => parentList.DefaultViewUrl.Contains(s.ParentListUrl));
            }

            return(childrenLists);
        }
Ejemplo n.º 6
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && agent.state == UtilityAgent.eState.Idle)
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out RaycastHit raycastHit))
         {
             UtilityObject utilityObject = raycastHit.collider.gameObject.GetComponent <UtilityObject>();
             if (utilityObject != null && agent.utilityAI == false)
             {
                 Debug.Log(utilityObject.id);
                 agent.StartUtilityObject(utilityObject);
             }
             else
             {
                 agent.movement.MoveTowards(raycastHit.point);
             }
         }
     }
 }
Ejemplo n.º 7
0
    void Update()
    {
        animator.SetFloat("Speed", movement.Velocity.magnitude);

        switch (state)
        {
        case eState.Idle:
            if (utilityAI)
            {
                UtilityObject[] utilityObjects = FindObjectsOfType <UtilityObject>();
                utilityObject = GetMaxScoreUtilityObject(utilityObjects);
                if (utilityObject != null)
                {
                    StartUtilityObject(utilityObject);
                }
            }
            break;

        case eState.ActionStart:
            StartCoroutine(ExecuteUtilityObject(utilityObject));
            break;

        case eState.ActionInProgress:
            break;

        case eState.ActionComplete:
            StopCoroutine("ExecuteUtilityObject");
            // update agent scores
            utilityObject = null;
            state         = eState.Idle;
            break;

        default:
            break;
        }
    }