Beispiel #1
0
    public void MoveAgent()
    {
        Edge_IA     e = CalcMinorPath();
        New_Node_IA n = e.OtherPeerNode(LocalNodePos);

        myBoid.GoTo(n);
    }
Beispiel #2
0
//    */
    #endregion
    public void Check()
    {
        RaycastHit ray;

        //Debug.Log("LoadingConection");
        if (Physics.Raycast(this.transform.position, Vector3.down, out ray, LengthLine))
        {
            if (ray.transform.gameObject.tag == "Node")
            {
                CurrentNode = ray.transform.gameObject.GetComponent <New_Node_IA>();
                if (gridRef == null)
                {
                    return;
                }
                if (lastHilighted != null && lastHilighted != CurrentNode)
                {
                    lastHilighted.GetComponent <MeshRenderer>().material =
                        gridRef.Walk;
                }
                CurrentNode.gameObject.GetComponent <MeshRenderer>().material =
                    this.gameObject.GetComponent <MeshRenderer>().material;
                lastHilighted = CurrentNode;
            }
        }
    }
Beispiel #3
0
    public void GenerateGraph()// principal método gerador do grafo
    {
        GridMatrix = new New_Node_IA[Size, Size];

        RaycastHit ray;

        CreateEdges_Controller(); //cria o gameobject Master dos Edges (Arestas)
        CreateNodes_Controller(); //cria o gameobject Master dos Vertex (Nodes)

        for (int i = 0; i < Size; i++)
        {
            for (int j = 0; j < Size; j++)
            {
                if (Physics.Raycast(this.transform.position + new Vector3(i * Granularidade, 0, j * Granularidade), Vector3.down, out ray, 100.0f))
                {
                    GameObject aux = Instantiate(Node, ray.point, Quaternion.identity);
                    aux.transform.parent = Nodes_Controller.transform;
                    New_Node_IA aux_n = aux.GetComponent <New_Node_IA>();

                    if (ray.collider.tag == "Walk")// nodes que são passáveis
                    {
                        aux.GetComponent <Renderer>().material = Walk;
                        aux_n.imReachable = true;
                    }
                    else if (ray.collider.tag == "Dontwalk")// nodes que não são passáveis
                    {
                        aux.GetComponent <Renderer>().material = Dontwalk;
                        aux_n.imReachable = false;
                    }
                    aux_n.ID = new Vector2(i, j);                                                          // muda o ID cartesiano discreto do node (X,Y)
                    aux_n.gameObject.name = "Node_" + Mathf.Abs(aux_n.ID.x) + "," + Mathf.Abs(aux_n.ID.y); // muda o nome do gameObject pro nome com ID

                    GridMatrix[i, j] = aux_n;
                }
            }
        }
        //inicialização de cada node da matriz
        for (int i = 0; i < Size; i++)
        {
            for (int j = 0; j < Size; j++)
            {
                if (GridMatrix[i, j] != null)
                {
                    GridMatrix[i, j].Init(GridMatrix, i, j, Size, Size, this);
                }
            }
        }
        //geração de edges (após a matrix estar toda inicializada
        for (int i = 0; i < Size; i++)
        {
            for (int j = 0; j < Size; j++)
            {
                if (GridMatrix[i, j] != null)
                {
                    GridMatrix[i, j].GenerateEdges();
                }
            }
        }
    }
Beispiel #4
0
 public void ReplaceNode(New_Node_IA ReceivedNode)//recebe troca de nodes vindas do boid pra ir pro próximo node
 {
     LocalNodePos = ReceivedNode;
     if (LocalNodePos != Target)
     {
         MoveAgent();
     }
 }
Beispiel #5
0
    public void MoveAgent(New_Node_IA myTarget)
    {
        Target = myTarget;
        Edge_IA     e = CalcMinorPath();
        New_Node_IA n = e.OtherPeerNode(LocalNodePos);

        myBoid.GoTo(n);
    }
Beispiel #6
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        New_Node_IA myScript = (New_Node_IA)target;

        if (GUILayout.Button("Ativar/Desativar Node"))
        {
            myScript.SwitchActiveBtn();
        }
    }
Beispiel #7
0
 void FixedUpdate()
 {
     if (StarTargetCatcher.CurrentNode != null)
     {
         Target = StarTargetCatcher.CurrentNode;                                    // seta posição do target pro node apontado pela estrela
     }
     if (LocalCatcher.CurrentNode != null)
     {
         LocalNodePos = LocalCatcher.CurrentNode; // seta o Node atual pro node referente ao componente NodeCatcher
     }
     if (Input.GetKeyDown(KeyCode.Space))         //apenas para teste REMOVER na build FINAL
     {
         MoveAgent();
     }
 }
Beispiel #8
0
    public New_Node_IA OtherPeerNode(New_Node_IA originNode)
    {
        //verifica se A ou B são nulos:
        if (A == null || B == null)
        {
            Debug.Log("AouB = NULL"); return(null);
        }

        //retorna A ou B:
        if (A != originNode)
        {
            return(A);
        }
        else
        {
            return(B);
        }
    }
Beispiel #9
0
 //public float PesoAlinhamento   =1;
 public void GoTo(New_Node_IA DestinyNode)
 {
     ImediateTarget = DestinyNode;
     MoveOn         = true;
 }
Beispiel #10
0
 private void Awake()
 {
     myBoid       = GetComponent <Boid>();
     LocalNodePos = CheckForNode();
 }
Beispiel #11
0
 float CalcHeuristic(Vector3 targetPos, New_Node_IA destinyNode)
 {
     return(Vector3.Distance(targetPos, destinyNode.transform.position));
 }
Beispiel #12
0
    public void Init(New_Node_IA[,] matrix, int pos_i, int pos_j, int max_x, int max_y, Grid_Generator grid_Generator_received)
    {
        grid_Generator = grid_Generator_received;

        if (CheckColideableObjectsAround())//checa se tem objetos de colisão por volta do node se tiver invalida o node e não executa o código abaixo
        {
            InvalidateNode();
            return;
        }


        if (NorteNode == null)
        {//norte
            if (pos_j < max_y - 1)
            {
                if (matrix[pos_i, pos_j + 1] != null)//NorteNode
                {
                    NorteNode = matrix[pos_i, pos_j + 1];
                }
            }
        }
        if (SulNode == null)//sul
        {
            if (pos_j < max_y && pos_j != 0)
            {
                if (matrix[pos_i, pos_j - 1] != null)//SulNode
                {
                    SulNode = matrix[pos_i, pos_j - 1];
                }
            }
        }
        if (LesteNode == null)//leste
        {
            if (pos_i < max_x - 1)
            {
                if (matrix[pos_i + 1, pos_j] != null)//LesteNode
                {
                    LesteNode = matrix[pos_i + 1, pos_j];
                }
            }
        }
        if (OesteNode == null)//oeste
        {
            if (pos_i < max_x && pos_i != 0)
            {
                if (matrix[pos_i - 1, pos_j] != null)//OesteNode
                {
                    OesteNode = matrix[pos_i - 1, pos_j];
                }
            }
        }
        if (NO_Node == null)
        {
            if (pos_i < max_x && pos_j < max_y - 1 &&     /* Está no limite da matriz? */
                pos_i > 0 /*&& pos_j > 0*/)               /* Está na coluna inicial da matriz? */
            {
                if (matrix[pos_i - 1, pos_j + 1] != null) //NoroesteNode
                {
                    NO_Node = matrix[pos_i - 1, pos_j + 1];
                }
            }
        }
        if (NE_Node == null)
        {
            if (pos_i < max_x - 1 && pos_j < max_y - 1)
            {
                if (matrix[pos_i + 1, pos_j + 1] != null)//NordesteNode
                {
                    NE_Node = matrix[pos_i + 1, pos_j + 1];
                }
            }
        }
        if (SE_Node == null)                              //editing
        {
            if (pos_i < max_x - 1 && pos_j < max_y &&     /* Está no limite da matriz? */
                /*pos_i != 0 &&*/ pos_j != 0)             /* é o primeiro node? */
            {
                if (matrix[pos_i + 1, pos_j - 1] != null) //SudesteNode
                {
                    SE_Node = matrix[pos_i + 1, pos_j - 1];
                }
            }
        }
        if (SO_Node == null)
        {
            if (pos_i < max_x && pos_j < max_y &&         /* Está no limite da matriz? */
                pos_i != 0 && pos_j != 0)                 /* é o primeiro node? */
            {
                if (matrix[pos_i - 1, pos_j - 1] != null) //SudoesteNode
                {
                    SO_Node = matrix[pos_i - 1, pos_j - 1];
                }
            }
        }
    }
Beispiel #13
0
 public void Init(New_Node_IA a, New_Node_IA b)
 {
     A = a; B = b;
     grid_Generator = A.grid_Generator;
     Active();
 }