public WorldState(PlayerInRange playerInRange, HasObstacle hasObstacle, AtObstacle atObstacle, PlayerDead playerDead)
 {
     this.playerInRange = playerInRange;
     this.hasObstacle   = hasObstacle;
     this.atObstacle    = atObstacle;
     this.playerDead    = playerDead;
 }
 private void OnTriggerStay(Collider other)
 {
     if (!other.CompareTag("Player"))
     {
         return;
     }
     PlayerInRange?.Invoke(transform.position, other.transform.position);
 }
Ejemplo n.º 3
0
    private Task getBTfromGenotype(BTNode subTree)
    {
        string taskName = subTree.taskName;

        if (subTree.isLeafNode())
        {
            // Actions
            if (taskName.Equals("Jump"))
            {
                Jump temp = new Jump();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveLeftForSeconds"))
            {
                MoveLeftForSeconds temp = new MoveLeftForSeconds();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveRightForSeconds"))
            {
                MoveRightForSeconds temp = new MoveRightForSeconds();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveRightForDistance"))
            {
                MoveRightForDistance temp = new MoveRightForDistance();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("ShootBullet"))
            {
                ShootBullet temp = new ShootBullet();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveLeftForDistance"))
            {
                MoveLeftForDistance temp = new MoveLeftForDistance();
                #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            // TO DO add conditionals
            else if (taskName.Equals("AtEdge"))
            {
                AtEdge temp = new AtEdge();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("HittingWall"))
            {
                HittingWall temp = new HittingWall();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("LowLife"))
            {
                LowLife temp = new LowLife();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("PlayerInRange"))
            {
                PlayerInRange temp = new PlayerInRange();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else
            {
                Grounded temp = new Grounded();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
        }
        else
        {
            if (taskName.Equals("Selector"))
            {
                Selector temp = new Selector();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else if (taskName.Equals("Sequence"))
            {
                Sequence temp = new Sequence();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else if (taskName.Equals("RandomSelector"))
            {
                RandomSelector temp = new RandomSelector();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else if (taskName.Equals("RandomSequence"))
            {
                RandomSequence temp = new RandomSequence();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else
            {
                Parallel temp = new Parallel();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
        }
    }