private string ReplaceVariables(IChalkboard chalkboard, string expandedMessage)
        {
            MatchCollection matches = variableRegex.Matches(expandedMessage);

            for (int i = 0; i < matches.Count; i++)
            {
                string token        = matches[i].Groups[0].Value;
                int    index        = matches[i].Groups[0].Index;
                string variableName = matches[i].Groups[1].Value;
                string stringValue;

                if (variableName == "agent")
                {
                    stringValue = agent.name;
                }
                else
                {
                    UnityEngine.Object unityValue = chalkboard.GetUnity <UnityEngine.Object>(variableName);
                    if (unityValue != null)
                    {
                        stringValue = unityValue.ToString();
                    }
                    else
                    {
                        System.Object systemValue = chalkboard.GetSystem <System.Object>(variableName);
                        if (systemValue != null)
                        {
                            stringValue = systemValue.ToString();
                        }
                        else
                        {
                            stringValue = "[Missing or unrecognized type for variable " + token + "]";
                        }
                    }
                }

                expandedMessage = expandedMessage.Remove(index, token.Length).Insert(index, stringValue);
            }

            return(expandedMessage);
        }
        public override void Tick(IChalkboard chalkboard)
        {
            base.Tick(chalkboard);

            List <Interactable> detectedInteractables = new List <Interactable>();

            Collider[] colliders = Physics.OverlapSphere(transform.position, radius, layerMask);
            for (int i = 0; i < colliders.Length; i++)
            {
                if (colliders[i].gameObject != transform.gameObject)
                {
                    Interactable interactable = colliders[i].GetComponentInParent <Interactable>();
                    if (interactable)
                    {
                        detectedInteractables.Add(interactable);
                    }
                }
            }
            chalkboard.AddOrUpdate(interactablesListName, detectedInteractables);

            if (detectedInteractables.Count == 0)
            {
                if (noInteractablesBehaviour)
                {
                    noInteractablesBehaviour.Tick(chalkboard);
                }
            }
            else
            {
                Vector3 pos = detectedInteractables[0].GetInteractionPosition();
                chalkboard.AddOrUpdate(chosenInteractablePositionName, pos);

                if (interactablesBehaviour)
                {
                    interactablesBehaviour.Tick(chalkboard);
                }
                Debug.Log(transform.name + " detected " + chalkboard.GetSystem <List <Interactable> >(interactablesListName).Count + " Colliders");
            }
        }
Example #3
0
        public override void Tick(IChalkboard chalkboard)
        {
            base.Tick(chalkboard);

            Vector3 position = chalkboard.GetSystem <Vector3>(targetPositionVariable);

            if (position == currentTargetPosition)
            {
                return;
            }

            currentTargetPosition = position;
            NavMeshHit hit;

            if (NavMesh.SamplePosition(position, out hit, 1.0f, NavMesh.AllAreas))
            {
                position = hit.position;
            }

            navMeshAgent.SetDestination(position);
            navMeshAgent.isStopped = false;
        }