예제 #1
0
    // form connections between tiles
    void Start()
    {
        aus         = this.GetComponent <AudioSource>();
        timer       = GameObject.FindGameObjectWithTag("Finish");
        food        = GameObject.FindGameObjectsWithTag("Food");
        score_text  = GameObject.FindGameObjectsWithTag("Score");
        info_text   = GameObject.FindGameObjectWithTag("UIText");
        info_pan    = GameObject.FindGameObjectWithTag("UIPanel");
        player_text = GameObject.FindGameObjectWithTag("HostMsg");
        List <GameObject> wps = (new List <GameObject>(GameObject.FindGameObjectsWithTag("WP")));

        wps.AddRange(new List <GameObject>(GameObject.FindGameObjectsWithTag("GhostPen")));

        MapSetup.disable_food();
        foreach (GameObject wp in wps)
        {
            Collider[] wp_connections = Physics.OverlapSphere(
                wp.transform.position,
                wp_overlap,
                1 << 10 | 1 << 11
                );
            // Toroidal Behaviour
            if (Mathf.Abs(wp.transform.position.z) > (toroidal_north_south - wp_overlap))
            {
                Debug.Log("hitns" + wp.transform.position.z);
                NodeBehaviour wp_head_node = wp.GetComponent <NodeBehaviour>();
                wp_head_node.set_z_warp(true);
                Collider[] opposite_wp = Physics.OverlapSphere(
                    new Vector3(
                        wp.transform.position.x,
                        wp.transform.position.y,
                        -wp.transform.position.z),
                    wp_overlap / 2,
                    1 << 10 | 1 << 11
                    );
                if (wp.transform.position.z < 0)
                {
                    wp_head_node.connections.Add("Down", opposite_wp[0].gameObject);
                    //assign to the next node the node it came from
                    opposite_wp[0].gameObject.GetComponent <NodeBehaviour>().npc_paths_container.Add("Down", new NodeBehaviour.PastPathProperties(1.0f, wp_head_node));
                }
                else
                {
                    wp_head_node.connections.Add("Up", opposite_wp[0].gameObject);
                    //assign to the next node the node it came from
                    opposite_wp[0].gameObject.GetComponent <NodeBehaviour>().npc_paths_container.Add("Up", new NodeBehaviour.PastPathProperties(1.0f, wp_head_node));
                }
            }
            else if (Mathf.Abs(wp.transform.position.x) > (toroidal_east_west - wp_overlap))
            {
                Debug.Log("hitns");
                NodeBehaviour wp_head_node = wp.GetComponent <NodeBehaviour>();
                wp_head_node.set_x_warp(true);
                Collider[] opposite_wp = Physics.OverlapSphere(
                    new Vector3(
                        -wp.transform.position.x,
                        wp.transform.position.y,
                        wp.transform.position.z),
                    wp_overlap / 2,
                    1 << 10 | 1 << 11
                    );
                if (wp.transform.position.x < 0)
                {
                    wp_head_node.connections.Add("Left", opposite_wp[0].gameObject);
                    //assign to the next node the node it came from
                    opposite_wp[0].gameObject.GetComponent <NodeBehaviour>().npc_paths_container.Add("Left", new NodeBehaviour.PastPathProperties(1.0f, wp_head_node));
                }
                else
                {
                    wp_head_node.connections.Add("Right", opposite_wp[0].gameObject);
                    //assign to the next node the node it came from
                    opposite_wp[0].gameObject.GetComponent <NodeBehaviour>().npc_paths_container.Add("Right", new NodeBehaviour.PastPathProperties(1.0f, wp_head_node));
                }
            }
            foreach (Collider wp_connection in wp_connections)
            {
                NodeBehaviour wp_head_node = wp.GetComponent <NodeBehaviour>();
                if (Mathf.Floor(wp_connection.gameObject.transform.position.z / wp_overlap) < Mathf.Floor(wp.gameObject.transform.position.z / wp_overlap))
                {
                    wp_head_node.connections.Add("Down", wp_connection.gameObject);
                    //assign to the next node the node it came from
                    wp_connection.gameObject.GetComponent <NodeBehaviour>().npc_paths_container.Add("Down", new NodeBehaviour.PastPathProperties(1.0f, wp_head_node));
                }
                else if (Mathf.Floor(wp_connection.gameObject.transform.position.z / wp_overlap) > Mathf.Floor(wp.gameObject.transform.position.z / wp_overlap))
                {
                    wp_head_node.connections.Add("Up", wp_connection.gameObject);
                    //assign to the next node the node it came from
                    wp_connection.gameObject.GetComponent <NodeBehaviour>().npc_paths_container.Add("Up", new NodeBehaviour.PastPathProperties(1.0f, wp_head_node));
                }
                else if (Mathf.Floor(wp_connection.gameObject.transform.position.x / wp_overlap) < Mathf.Floor(wp.gameObject.transform.position.x / wp_overlap))
                {
                    wp_head_node.connections.Add("Left", wp_connection.gameObject);
                    //assign to the next node the node it came from
                    wp_connection.gameObject.GetComponent <NodeBehaviour>().npc_paths_container.Add("Left", new NodeBehaviour.PastPathProperties(1.0f, wp_head_node));
                }
                else if (Mathf.Floor(wp_connection.gameObject.transform.position.x / wp_overlap) > Mathf.Floor(wp.gameObject.transform.position.x / wp_overlap))
                {
                    wp_head_node.connections.Add("Right", wp_connection.gameObject);
                    //assign to the next node the node it came from
                    wp_connection.gameObject.GetComponent <NodeBehaviour>().npc_paths_container.Add("Right", new NodeBehaviour.PastPathProperties(1.0f, wp_head_node));
                }
                else if (wp_connection.gameObject != wp)
                {
                    wp_head_node.connections.Add("?", wp_connection.gameObject);
                    //assign to the next node the node it came from
                    wp_connection.gameObject.GetComponent <NodeBehaviour>().npc_paths_container.Add("?", new NodeBehaviour.PastPathProperties(1.0f, wp_head_node));
                }
            }
        }
    }