Exemple #1
0
    public float Evaluate()
    {
        if (topAction != null)
        {
            previousAction = topAction;
        }

        float topActionScore = 0.0f;

        for (int i = 0; i < linkedActions.Count; i++)
        {
            if (linkedActions[i].actionEnabled == true)
            {
                linkedActions[i].action.EvaluateAction();
                if (linkedActions[i].action.GetActionScore() > topActionScore)
                {
                    topAction            = linkedActions[i].action;
                    topActionScore       = linkedActions[i].action.GetActionScore();
                    topLinkedActionIndex = i;
                }
            }
        }

        if (topAction != previousAction)
        {
            newAction = true;
        }
        else
        {
            StartTimer();
        }

        if (topAction.interruptible)
        {
            secondsSinceLastEvaluation = 0.0f;
        }

        actionHistory.Add(topAction.name);
        if (actionHistory.Count > historyStates)
        {
            actionHistory.RemoveAt(0);
        }

        if (linkedActions [topLinkedActionIndex].cooldown > 0.0f)
        {
            DisableAction(linkedActions [topLinkedActionIndex].action.name);
            StartCoroutine(CooldownAction(topLinkedActionIndex));
        }

        if (consoleLogging)
        {
            Debug.Log(agentName + ". New topAction: " + topAction.name + ". With actionScore: " + topActionScore);
        }

        currentActionScore = topActionScore;
        return(topActionScore);
    }
Exemple #2
0
    public bool EvaluateInteruption()
    {
        int        topActionPriority = topAction.priorityLevel;
        float      topActionScore    = 0.0f;
        UAI_Action topInterruption   = topAction;
        bool       validInterruption = false;

        for (int i = 0; i < linkedActions.Count; i++)
        {
            if (linkedActions[i].actionEnabled == true)
            {
                if (linkedActions[i].action.priorityLevel < topActionPriority)
                {
                    linkedActions[i].action.EvaluateAction();
                    if (linkedActions[i].action.GetActionScore() > currentActionScore &&
                        linkedActions[i].action.GetActionScore() > topActionScore)
                    {
                        topInterruption   = linkedActions[i].action;
                        topActionScore    = linkedActions[i].action.GetActionScore();
                        validInterruption = true;
                    }
                }
            }
        }

        if (validInterruption)
        {
            newAction = true;
            topAction = topInterruption;
            actionHistory.Add("Interruption: " + topAction.name);
            if (actionHistory.Count > historyStates)
            {
                actionHistory.RemoveAt(0);
            }
            currentActionScore = topActionScore;

            if (topAction.interruptible)
            {
                secondsSinceLastEvaluation = 0.0f;
            }

            if (consoleLogging)
            {
                Debug.Log(agentName + ". Interruption: " + topAction.name + ". With actionScore: " + topActionScore);
            }

            return(true);
        }
        return(false);
    }
Exemple #3
0
    public void DisplayActionConsiderations(UAI_Action action, bool selected)
    {
        for (int i = 0; i < actionConsiderationElements.Count; i++)
        {
            Destroy(actionConsiderationElements[i]);
        }
        actionConsiderationElements.Clear();

        if (!selected)
        {
            if (selectedAction != null)
            {
                for (int i = 0; i < actionElements.Count; i++)
                {
                    UAI_Action tempAction = actionElements[i].GetComponent <OverlayUIActionElement>().GetAction();
                    if (selectedAction == tempAction)
                    {
                        actionElements[i].GetComponent <OverlayUIActionElement>().Select();
                        break;
                    }
                }
            }

            for (int i = 0; i < action.considerations.Count; i++)
            {
                GameObject tempCon = Instantiate(considerationElement,
                                                 new Vector3(actionConsiderationContent.transform.position.x,
                                                             actionConsiderationContent.transform.position.y + actionConsiderationElements.Count * -27,
                                                             actionConsiderationContent.transform.position.z), Quaternion.identity) as GameObject;
                tempCon.transform.SetParent(actionConsiderationContent.transform);
                tempCon.GetComponent <OverlayUIConsiderationElement> ().SetConsideration(action.considerations [i], true, action.name);
                actionConsiderationElements.Add(tempCon);
            }
            actionConsiderationContent.GetComponent <RectTransform>().sizeDelta = new Vector2(200, actionConsiderationElements.Count * 27);

            actionConsiderationCurve.SetActive(false);
            displayingActionCurve = false;
            actionConsiderationsPanel.SetActive(true);
            selectedAction = action;
        }
        else
        {
            actionConsiderationCurve.SetActive(false);
            displayingActionCurve = false;
            actionConsiderationsPanel.SetActive(false);
            selectedAction = null;
            selectedActionConsideration = null;
        }
    }
 public void SetAction(UAI_Action p_action)
 {
     action    = p_action;
     text.text = action.name;
 }
Exemple #5
0
    public void DisplayAgent(UAI_Agent agent, bool selected)
    {
        for (int i = 0; i < actionElements.Count; i++)
        {
            Destroy(actionElements[i]);
        }
        for (int i = 0; i < considerationElements.Count; i++)
        {
            Destroy(considerationElements[i]);
        }
        for (int i = 0; i < propertyElements.Count; i++)
        {
            Destroy(propertyElements[i]);
        }
        actionElements.Clear();
        considerationElements.Clear();
        agentProperties.Clear();
        propertyElements.Clear();

        propertyConsiderationsPanel.SetActive(false);
        actionConsiderationsPanel.SetActive(false);
        selectedAction                = null;
        selectedProperty              = null;
        selectedActionConsideration   = null;
        selectedPropertyConsideration = null;

        //deselect other agents
        if (!selected)
        {
            if (displayedAgent != null)
            {
                for (int i = 0; i < agentElements.Count; i++)
                {
                    if (agentElements [i].GetComponent <OverlayUIAgentElement> ().GetAgent() == displayedAgent)
                    {
                        agentElements [i].GetComponent <OverlayUIAgentElement> ().Select();
                        break;
                    }
                }
            }

            displayedAgent  = agent;
            displayingAgent = true;

            for (int i = 0; i < agent.GetComponentsInChildren <UAI_Property>().Length; i++)
            {
                agentProperties.Add(agent.GetComponentsInChildren <UAI_Property> () [i]);
            }

            for (int i = 0; i < agentProperties.Count; i++)
            {
                GameObject tempProp;
                if (agentProperties [i].modifiable)
                {
                    tempProp = Instantiate(ModifiablePropertyElement,
                                           new Vector3(propertyContent.transform.position.x,
                                                       considerationContent.transform.position.y + propertyElements.Count * -27,
                                                       considerationContent.transform.position.z), Quaternion.identity) as GameObject;
                }
                else
                {
                    tempProp = Instantiate(PropertyElement,
                                           new Vector3(propertyContent.transform.position.x,
                                                       considerationContent.transform.position.y + propertyElements.Count * -27,
                                                       considerationContent.transform.position.z), Quaternion.identity) as GameObject;
                }
                tempProp.transform.SetParent(propertyContent.transform);
                tempProp.GetComponent <OverlayUIPropertyElement> ().SetProperty(agentProperties [i]);
                propertyElements.Add(tempProp);
            }
            propertyContent.GetComponent <RectTransform>().sizeDelta = new Vector2(200, propertyElements.Count * 27);


            for (int i = 0; i < agent.linkedActions.Count; i++)
            {
                //populate UI actions
                GameObject tempAct = Instantiate(actionElement,
                                                 new Vector3(actionContent.transform.position.x + 100,
                                                             actionContent.transform.position.y + actionElements.Count * -27,
                                                             actionContent.transform.position.z), Quaternion.identity) as GameObject;
                tempAct.transform.SetParent(actionContent.transform);
                tempAct.GetComponent <OverlayUIActionElement> ().SetAction(agent.linkedActions[i].action);
                actionElements.Add(tempAct);
            }
            actionContent.GetComponent <RectTransform>().sizeDelta = new Vector2(200, actionElements.Count * 27);
        }
        else
        {
            displayingAgent = false;
            displayedAgent  = null;
        }
    }