Beispiel #1
0
    void UpdateIDsAndGos(GameObject boundingCube, GameObject infoTag, Collider other, Bounds bounds)
    {
        boundingCube.GetComponent <Renderer>().enabled = false;
        infoTag.GetComponent <Canvas>().enabled        = false;
        CubesAndTags cubesAndTags = new CubesAndTags();

        cubesAndTags.AddElements(boundingCube, infoTag, bounds);
        cubesAndTags.other = other; //DARIO
        IDsAndGos.Add(other.gameObject.GetInstanceID(), cubesAndTags);
    }
Beispiel #2
0
    void OnTriggerEnter(Collider other)
    {
        if (((1 << other.gameObject.layer) & mask) != 0) //matched one!
        {
            switch (other.gameObject.layer)
            {
            case 17:
            {         //Signage
                Bounds bounds = new Bounds();
                if (other.transform.parent.parent.name.Equals("StreetSigns"))
                {
                    break;
                }

                BoxCollider boxCol = other as BoxCollider;
                bounds.center = boxCol.center;
                bounds.size   = boxCol.size * 1.25f;
                GameObject boundingCube = CreateBoundingCube(other.transform, other.transform.position + bounds.center, bounds.size);
                GameObject infoTagSign  = CreateInfoTagSign(other.transform.position + bounds.center);
                UpdateIDsAndGos(boundingCube, infoTagSign, other, bounds);
            }
            break;

            case 12:
            {          //obstacle
                Bounds     bounds       = new Bounds();
                GameObject boundingCube = null;
                GameObject infoTag      = null;
                if (other.transform.root.CompareTag("TrafficCar"))
                {
                    if (other.transform.name.Equals("Body1"))
                    {
                        bounds = ComputeBounds(other.transform.root);
                        try
                        {
                            boundingCube = other.transform.Find("Cube").gameObject;
                        }
                        catch (NullReferenceException)
                        {
                            Debug.Log("object incriminated is: ");
                        }

                        infoTag = CreateInfoTag(other.transform.position + bounds.center);
                        UpdateIDsAndGos(boundingCube, infoTag, other, bounds);
                        other.transform.root.gameObject.AddComponent <TrafficCarNavigationLineUrban>();
                    }
                }
                else
                {
                    bounds = ComputeBounds(other.transform);
                    try
                    {
                        boundingCube = other.transform.Find("Cube").gameObject;
                    }
                    catch (NullReferenceException)
                    {
                        Debug.Log("object incriminated is: ");
                    }

                    infoTag = CreateInfoTag(other.transform.position + bounds.center);
                    UpdateIDsAndGos(boundingCube, infoTag, other, bounds);
                }
            }
            break;

            case 8:
            {
                if (other.transform.name.Equals("Body1") && (other.transform.root.CompareTag("TrafficCar") || other.transform.root.CompareTag("TrafficScooter")))
                {
                    Bounds     bounds       = ComputeBounds(other.transform.root);
                    GameObject boundingCube = other.transform.Find("Cube").gameObject;
                    GameObject infoTag      = null;
                    infoTag = CreateInfoTag(other.transform.position + bounds.center);
                    UpdateIDsAndGos(boundingCube, infoTag, other, bounds);
                    TrafficCarNavigationLineUrban trafficCarNavigationLineUrban = other.transform.root.gameObject.AddComponent <TrafficCarNavigationLineUrban>();
                    trafficCarNavigationLineUrban.enabled = false;
                }
            }
            break;

            case 18:     //Roads
            {
                if (other.transform.name.StartsWith("TrafficLight"))
                {
                    CubesAndTags cubesAndTags = new CubesAndTags();

                    foreach (Transform t in other.transform)
                    {
                        if (t.name.StartsWith("Light") && t.gameObject.activeInHierarchy)         //there are some trafficLights not active so I have to exclude them
                        {
                            Bounds     bounds       = ComputeBounds(t);
                            GameObject boundingCube = CreateBoundingCube(t, bounds.center, bounds.size);
                            boundingCube.transform.SetParent(t.GetComponentInChildren <MeshFilter>().gameObject.transform);
                            boundingCube.transform.localPosition = Vector3.zero;
                            boundingCube.transform.localScale   *= 1.25f;
                            GameObject infoTag = CreateInfoTag(bounds.center);
                            boundingCube.GetComponent <Renderer>().enabled = false;
                            infoTag.GetComponent <Canvas>().enabled        = false;
                            cubesAndTags.other = other;         //DARIO
                            cubesAndTags.AddElements(boundingCube, infoTag, bounds);
                        }
                    }

                    Bounds      boundsPost = new Bounds();
                    BoxCollider boxCol     = other as BoxCollider;
                    boundsPost.center = Quaternion.Euler(other.transform.localEulerAngles) * new Vector3(boxCol.center.x * other.transform.localScale.x, boxCol.center.y * other.transform.localScale.y, boxCol.center.z * other.transform.localScale.z);
                    boundsPost.size   = new Vector3(boxCol.size.x * other.transform.localScale.x * 1.25f, boxCol.size.y * other.transform.localScale.y * 1.25f, boxCol.size.z * other.transform.localScale.z);
                    GameObject boundingCubePost = CreateBoundingCube(other.transform, other.transform.position + boundsPost.center, boundsPost.size);
                    GameObject infoTagPost      = null;
                    infoTagPost = CreateInfoTag(other.transform.position + boundsPost.center);
                    boundingCubePost.GetComponent <Renderer>().enabled = false;
                    infoTagPost.GetComponent <Canvas>().enabled        = false;
                    cubesAndTags.AddElements(boundingCubePost, infoTagPost, boundsPost);
                    if (cubesAndTags.boundingCube.Count != 0)         //maybe this is no more requested since at least the Post is added, the trafficLight depends
                    {
                        IDsAndGos.Add(other.gameObject.GetInstanceID(), cubesAndTags);
                    }
                }
            }
            break;
            }
        }
    }