Inheritance: MonoBehaviour
Beispiel #1
0
    private void Start()
    {
        this.owner = this.GetComponentInParent <T>();
        this.agent = this.GetComponentInParent <PathfindingAgent>();

        this.initializeReferences();
    }
        private void Start()
        {
            m_Total = m_Rows * m_Columns;

            m_Generator  = new GeneticAlgorithm <int> (m_PopulationSize, m_Total, GetRandomInt, GetFitness, m_Elitism, m_MutationRate);
            m_Controller = FindObjectOfType <GridController> ();
            m_Agent      = FindObjectOfType <PathfindingAgent> ();
        }
Beispiel #3
0
    public static IEnumerator WaitAndReturn(PathfindingAgent agent, float duration = 1)
    {
        yield return(new WaitForSeconds(duration));

        agent.transform.localScale = Vector3.one;
        agent.anim.SetTrigger("Walking");
        agent.AssignTarget(agent.origin);
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        PathfindingAgent pathFindingAgent = (PathfindingAgent)target;

        if (GUILayout.Button("Go to Target"))
        {
            pathFindingAgent.GoToTarget();
        }
    }
    public override void ConsiderActionWithNoEnemyInSight(CharacterBase self)
    {
        #region Agent Generic Cover Check
        IncreaseActionValuePerWallCoverLevel(self.occupiedTile, (int)Weighting.Light, (int)Weighting.Heavy, (int)Weighting.Feather);
        #endregion

        #region Agent Ally Proximity Check
        int nearbyAllies = PathfindingAgent.BreadthFirstAllySearch(self.occupiedTile);
        actionValue += nearbyAllies > 2 ? -(int)Weighting.Heavy : (int)Weighting.SuperHeavy;
        #endregion
    }
Beispiel #6
0
    public bool fallNodes        = true;         /*true-- Allows the pathfinding agent to use 'fall' nodes*/

    void Awake()
    {
        _controller = GetComponent <CharacterController2D>();
        _box        = GetComponent <BoxCollider2D>();
        _pathAgent  = GetComponent <PathfindingAgent>();
        _ai         = GetComponent <AiController>();
        //_anim = transform.Find("Graphics").GetComponent<Animator>();
        _graphics = transform.Find("Graphics").gameObject;     /*useful for preventing things from flipping when character is facing left*/
        _input    = GetComponent <IInputController>();

        /*allow movement abilities to access character script*/
        jump.SetCharacter(this);
    }
Beispiel #7
0
    private void Awake()
    {
        if (player == null)
        {
            player = GameObject.FindGameObjectWithTag("Player");
        }
        _ray       = GetComponent <CharacterController2D>();
        _pathAgent = GetComponent <PathfindingAgent>();

        if (_pathScript == null)
        {
            _pathScript = GameObject.FindGameObjectWithTag("GameController").GetComponent <Pathfinding>();
        }
    }
    private void Start()
    {
        //Transform vectors to world space
        for (int i = 0; i < patrolPoints.Length; i++)
        {
            patrolPoints[i] += transform.position;
        }

        beganPlay = true;

        pawn  = GetComponent <Enemy>();
        agent = GetComponent <PathfindingAgent>();
        agent.MoveTowards(patrolPoints[currentTargetIndex]);
    }
    private bool jumped      = false;         /*used for detecting if jump key was pressed (also used in ai)*/

    void Awake()
    {
        _controller   = GetComponent <CharacterController2D>();
        _body         = GetComponent <Rigidbody2D>();
        _pathingAgent = GetComponent <PathfindingAgent>();
        _ai           = GetComponent <AiController>();
        _anim         = transform.Find("Graphics").GetComponent <Animator>();
        _graphics     = transform.Find("Graphics").gameObject; /*useful for preventing things from flipping when character is facing left*/

        /*allow movement abilities to access character script*/
        jump.setCharacter(this);

        _body.isKinematic = true;
    }
Beispiel #10
0
    private void Awake()
    {
        if (player == null)
        {
            player = GameObject.FindGameObjectWithTag("Player");
        }

        _pathAgent = GetComponent <PathfindingAgent>();

        if (_pathScript == null)
        {
            _pathScript = GameObject.FindGameObjectWithTag("GameController").GetComponent <Pathfinding>();
        }

        _behaviourText      = transform.Find("BehaviourText").GetComponent <TextMesh>();
        _behaviourText.text = "";
    }
Beispiel #11
0
 private void spawnUnit()
 {
     for (int i = spawns.Count; i > 0; i--)
     {
         if (spawns[i - 1] == null)
         {
             spawns.Remove(spawns[i - 1]);
         }
     }
     if (spawns.Count < spawnAmount)
     {
         GameObject newGameObject = (GameObject)Instantiate(Resources.Load("pathfindChaseAi"), new Vector3(transform.position.x, transform.position.y, 0.0f), Quaternion.identity) as GameObject;
         spawns.Add(newGameObject);
         PathfindingAgent newCharScript = newGameObject.transform.GetComponent <PathfindingAgent>();
         newCharScript.RequestPath((Vector3)target.transform.position);
     }
 }
    void Start()
    {
        target     = PlayerManager.instance.player;
        controller = GetComponent <EnemyController>();
        pawnAgent  = GetComponent <PathfindingAgent>();

        if (controller != null)
        {
            pawn = controller.pawn;
        }

        /*detectionTrigger = gameObject.AddComponent<CircleCollider2D>();
         * detectionTrigger.isTrigger = true;
         * detectionTrigger.radius = detectionRadius;
         * attackTrigger = gameObject.AddComponent<CircleCollider2D>();
         * attackTrigger.isTrigger = true;
         * attackTrigger.radius = attackRadius;*/
    }
Beispiel #13
0
    private void SetupThief()
    {
        foreach (Thief t in FindObjectsOfType <Thief>())
        {
            PhotonView photonView = t.GetComponent <PhotonView>();
            if (photonView && m_PhotonView.OwnerActorNr == photonView.OwnerActorNr)
            {
                m_Thief                 = t;
                thiefObject             = t.gameObject;
                m_ThiefPathfindingAgent = thiefObject.GetComponent <PathfindingAgent>();
                m_ThiefPathfindingAgent.onReachedDestination.AddListener(OnReachedDestination);
                m_Thief.gameObject.SetActive(false);

                if (!m_ThiefPathfindingAgent)
                {
                    Debug.LogError("No pathfinding agent found in thief object.");
                }
            }
        }
    }
Beispiel #14
0
    private void Update()
    {
        if (!Pause.isPaused() && !PopupWindow.blockingInput() && Main.DEBUG)
        {
            Position pos = CameraController.instance.getMousePos();

            if (Input.GetMouseButtonDown(0))
            {
                if (Input.GetKey(KeyCode.LeftControl))
                {
                    foreach (EntityBase e in this.world.entities.list)
                    {
                        if (e is EntityWorker)
                        {
                            PathfindingAgent agent = ((EntityWorker)e).moveHelper;
                            NavPath          path  = agent.calculatePath(pos);
                            if (path != null)
                            {
                                agent.setPath(path);
                            }
                        }
                    }
                }

                if (Input.GetKey(KeyCode.Delete))
                {
                    world.setCell(pos, null);
                    world.liftFog(pos);
                }

                if (Input.GetKey(KeyCode.F))
                {
                    world.entities.spawn(pos, 10);
                }
            }
        }
    }
Beispiel #15
0
 public static void SelectAgent(PathfindingAgent agent)
 {
     selectedAgent = agent;
 }
Beispiel #16
0
 public static void RegisterAgent(PathfindingAgent agent, bool selectNewAgent)
 {
     Debug.Log($"Registering agent: {agent.gameObject.name}. {(selectNewAgent ? "Selecting new agent" : "Not selecting new agent")}");
     Agents.Add(agent);
     SelectAgent(agent);
 }