예제 #1
0
 public void RegisterNode(RPNavNode node)
 {
     noRegistrFor = 0f;
     if (nodes.Contains(node) == false)
     {
         nodes.Add(node);
         //Debug.Log("Node registered. Now amount: " + nodes.Count.ToString());
     }
 }
예제 #2
0
    public List <RPNavNode> GetPathTo(RPNavNode from, RPNavNode goal)
    {
        List <Node <RPNavNode> > path   = graph.Dijkstra(graph.GetNode(from), graph.GetNode(goal));
        List <RPNavNode>         rpPath = new List <RPNavNode>();

        for (int i = 0; i < path.Count; i++)
        {
            rpPath.Add(path[i].ID);
        }
        return(rpPath);
    }
예제 #3
0
    public List <RPNavNode> GetPathTo(string from, string goal)
    {
        RPNavNode fromNode = GetNode(from);
        RPNavNode toNode   = GetNode(goal);

        if (fromNode != null && toNode != null)
        {
            return(GetPathTo(fromNode, toNode));
        }

        return(new List <RPNavNode>());
    }
예제 #4
0
    public void ReachedNode(RPNavNode node)
    {
        if (currentPath.Count <= 1)
        {
            waitForLowVelocity = true;
            currentPath.Remove(node);
        }
        else
        {
            currentPath.Remove(node);

            updateTempGoal();
        }
    }
예제 #5
0
    public RPNavNode GetNode(string stationName)
    {
        RPNavNode node = null;

        for (int i = 0; i < graph.Nodes.Count; i++)
        {
            if (graph.Nodes[i].ID.nodeName == stationName)
            {
                node = graph.Nodes[i].ID;
            }
        }

        return(node);
    }
예제 #6
0
    public void SetGoal(string goal)
    {
        currentGoal = goal;

        currentPath      = graph.GetPathTo(currentStation, currentGoal);
        currentGoalFinal = currentPath[currentPath.Count - 1];

        updateTempGoal();

        rocketController.UseFloatThrusts = true;
        landingAgent.enabled             = false;
        flyAgent.enabled = true;
        rocketController.LandingMoversOut = false;
        allOff = false;
    }
예제 #7
0
    public void SpawnAt(string station)
    {
        rocketProps.Repair();
        rocketProps.Refill();

        currentGoalFinal = graph.GetNode(station);
        currentPath      = new List <RPNavNode>();

        rocketRB.transform.position = currentGoalFinal.transform.position;
        rocketRB.transform.rotation = Quaternion.Euler(0f, 180f, 0f);
        rocketRB.velocity           = Vector3.zero;
        rocketRB.angularVelocity    = Vector3.zero;

        updateTempGoal();
    }
예제 #8
0
    public void BuildVoronoiMeshes()
    {
        if (Application.isPlaying)
        {
            if (nodeName.Length > 0)
            {
                GameObject newGo = Instantiate(prefabCollider);
                newGo.transform.position = transform.position;

                newGo.transform.localScale = new Vector3(1f, 1f, 1f);


                newGo.GetComponent <NodeCollider>().NavNode = this;

                nodeColliders.Add(newGo);
            }
            else
            {
                for (int i = 0; i < nodeColliders.Count; i++)
                {
                    Destroy(nodeColliders[i]);
                }
                nodeColliders.Clear();
                nodeColliders = new List <GameObject>();


                /*BoxCollider[] children = GetComponentsInChildren<BoxCollider>();
                 * for (int i = 0; i < children.Length; i++)
                 * {
                 *  if (children[i] != null && children[i].gameObject != null)
                 *  {
                 *      DestroyImmediate(children[i].gameObject);
                 *  }
                 * }*/

                List <Edge <RPNavNode> > outEdges = navGraph.Graph.GetOutcommingEdges(navGraph.Graph.GetNode(this));

                //Debug.Log("Out Edges: " + outEdges.Count);

                for (int i = 0; i < outEdges.Count; i++)
                {
                    RPNavNode node = outEdges[i].To.ID;

                    float   distance  = Vector3.Distance(transform.position, node.transform.position);
                    Vector3 dirToNode = node.transform.position - transform.position;

                    GameObject newGo = Instantiate(prefabCollider);
                    newGo.transform.position = transform.position + dirToNode * 0.25f;
                    newGo.transform.forward  = dirToNode;
                    //newGo.transform.up = Vector3.Cross(Vector3.Cross(dirToNode, Vector3.up), dirToNode);

                    float angle = Vector3.Angle(new Vector3(0f, 0f, 1f), dirToNode);
                    if (Vector3.Angle(new Vector3(1f, 0f, 0f), dirToNode) > 90f)
                    {
                        angle = 360f - angle;
                    }
                    angle = angle * Mathf.PI / 180f + 90f;

                    float angleY = angle;
                    float angleX = Vector3.Angle(new Vector3(0f, 0f, 1f), dirToNode);
                    if (Vector3.Angle(new Vector3(1f, 0f, 0f), dirToNode) > 90f)
                    {
                        angleX = 360f - angleX;
                    }
                    angleX = angleX * Mathf.PI / 180f;

                    angle = 90f;

                    float width  = 3f;
                    float height = 20f;

                    newGo.transform.localScale = new Vector3(width, height, distance * 0.5f);

                    /*if (Vector3.Angle(dirToNode, newGo.transform.up) < 45f)
                     * {
                     *  newGo.transform.localScale = new Vector3(height * Mathf.Cos(angle) + width * Mathf.Sin(angle), distance * 0.5f, width * Mathf.Cos(angle) + height * Mathf.Sin(angle));
                     * }
                     * else
                     * {
                     *  newGo.transform.localScale = new Vector3(distance * 0.5f * Mathf.Cos(angle) + width * Mathf.Sin(angle), height, width * Mathf.Cos(angle) + distance * 0.5f * Mathf.Sin(angle));
                     * }*/

                    newGo.GetComponent <NodeCollider>().NavNode = this;

                    nodeColliders.Add(newGo);
                }
            }
        }
    }