Ejemplo n.º 1
0
 public void Set(TrafLightState state)
 {
     currentState = state;
     foreach (var light in GetComponentsInChildren <TrafficLightVisuals>())
     {
         light.Set(state);
     }
 }
    public void Set(TrafLightState state)
    {
        switch (state)
        {
        case TrafLightState.RED:
            rend.material = red;
            break;

        case TrafLightState.YELLOW:
            rend.material = yellow;
            break;

        case TrafLightState.GREEN:
            rend.material = green;
            break;
        }
    }
Ejemplo n.º 3
0
    public void Set(TrafLightState state)
    {
        switch (state)
        {
        case TrafLightState.RED:
            rend.material = red;
            break;

        case TrafLightState.YELLOW:
            rend.material = yellow;
            break;

        case TrafLightState.GREEN:
            rend.material = green;
            break;
        }

        if (makeLight)
        {
            switch (state)
            {
            case TrafLightState.RED:
                lightGameObject.GetComponent <Light>().color = Color.red;
                lightGameObject.transform.localPosition      = new Vector3(0, 0, 0.0071f);
                break;

            case TrafLightState.YELLOW:
                lightGameObject.GetComponent <Light>().color = Color.yellow;
                lightGameObject.transform.localPosition      = new Vector3(0, 0, 0);
                break;

            case TrafLightState.GREEN:
                lightGameObject.GetComponent <Light>().color = Color.green;
                lightGameObject.transform.localPosition      = new Vector3(0, 0, -0.0086f);
                break;
            }
        }
    }
Ejemplo n.º 4
0
    void EnvironmentDetect()
    {
        float currentSpeed = gameObject.GetComponent <VehicleController>().CurrentSpeed;
        int   safetyDist   = Mathf.RoundToInt(Mathf.Pow(currentSpeed / 10, 2));

        if (safetyDist < 50)
        {
            safetyDist = 50;
        }
        LayerMask mask = (/*1 << LayerMask.NameToLayer("Traffic")) | (1 << LayerMask.NameToLayer("obstacle")) |*/ 1 << LayerMask.NameToLayer("EnvironmentProp") | 1 << LayerMask.NameToLayer("Signage") | 1 << LayerMask.NameToLayer("Roads")); //restrict OverlapSphere only to the layers of interest

        Collider[]          colls    = Physics.OverlapSphere(gameObject.transform.position, safetyDist, mask);
        HashSet <Transform> curColls = new HashSet <Transform>(); //this is to store the root transform of the colliders returned by OverlapSphere

        Timer -= Time.deltaTime;                                  //thanks to this timer cubes and tags are instantiated only every 0.1 ms
        if (Timer <= 0f)
        {
            foreach (KeyValuePair <GameObject, GameObject> pair in cubesAndTags)
            {
                Destroy(pair.Key);
                Destroy(pair.Value);
                //Debug.Log("destroyed" + g + "update is: " + i);
            }
            cubesAndTags.Clear();

            foreach (Collider c in colls)
            {
                switch (c.gameObject.layer)
                {
                case 16:      //EnvironmentProp
                {
                    Bounds bounds = new Bounds();
                    if (c.transform.name.StartsWith("BasicCar"))
                    {
                        BoxCollider boxCol = c as BoxCollider;
                        bounds.center = Quaternion.Euler(c.transform.localEulerAngles) * boxCol.center;
                        bounds.size   = boxCol.size;
                        Vector3 traslL = Quaternion.Euler(c.transform.localEulerAngles) * bounds.size;         //infoTag trasl
                        traslL = new Vector3(traslL.x * 0.5f + 2.0f, traslL.y * 0.5f, 0);
                        Vector3 traslR = new Vector3(-traslL.x, traslL.y, traslL.z);

                        float dist = CalculateDistance(rayCastPos.position, c.transform.position + bounds.center);
                        if (dist <= 50.0f)
                        {
                            infos[0] = "0" + " KPH";         //speed of EnvironmentProp is null
                            infos[1] = Mathf.RoundToInt(dist).ToString() + " M";
                            infos[2] = "";
                            cubesAndTags.Add(CreateBoundingCube(c.transform, c.transform.position + bounds.center, bounds.size), CreateInfoTag(c.transform.position + bounds.center, traslL, traslR, sprites[28], transform.rotation, infos, Color.white));
                        }
                    }
                    else if (c.transform.tag.Equals("Sign"))
                    {
                        BoxCollider boxCol = c as BoxCollider;
                        bounds.center = boxCol.center;
                        bounds.size   = boxCol.size * 1.25f;
                        float dist = CalculateDistance(rayCastPos.position, c.transform.position + bounds.center);
                        if (dist <= 50.0f)
                        {
                            infos[0] = "0" + " KPH";         //speed of EnvironmentProp is null
                            infos[1] = Mathf.RoundToInt(dist).ToString() + " M";
                            infos[2] = "";
                            cubesAndTags.Add(CreateBoundingCube(c.transform, c.transform.position + bounds.center, bounds.size), new GameObject());         //at the moment i don't need an InfoTag
                        }
                    }
                    switch (c.transform.name)
                    {
                    case "streetlight":
                    {
                        CapsuleCollider capsCol = c as CapsuleCollider;
                        bounds.center = Quaternion.Euler(c.transform.localEulerAngles) * capsCol.center;
                        bounds.size   = new Vector3(capsCol.radius * 4.0f, capsCol.radius * 4.0f, capsCol.height);
                        Vector3 traslL = Quaternion.Euler(c.transform.localEulerAngles) * bounds.size;                 //infoTag trasl
                        traslL = new Vector3(traslL.x * 0.5f + 2.0f, 0, 0);
                        Vector3 traslR = new Vector3(-traslL.x, traslL.y, traslL.z);

                        float dist = CalculateDistance(rayCastPos.position, c.transform.position + bounds.center);
                        if (dist <= 10.0f)
                        {
                            infos[0] = "0" + " KPH";                 //speed of EnvironmentProp is null
                            infos[1] = Mathf.RoundToInt(dist).ToString() + " M";
                            infos[2] = "";
                            RaycastHit hit;
                            Vector3    fwd   = rayCastPos.TransformDirection(Vector3.forward);
                            bool       isHit = Physics.Raycast(rayCastPos.position, fwd, out hit, 10.0f);
                            if (isHit)
                            {
                                //Debug.DrawLine(rayCastPos.position, hit.point, Color.yellow);
                                GameObject boundingCube = CreateBoundingCube(c.transform, c.transform.position + bounds.center, bounds.size);
                                GameObject infotag      = CreateInfoTag(c.transform.position + bounds.center, traslL, traslR, sprites[29], transform.rotation, infos, Color.red);
                                StartCoroutine(HideUnhide(infotag, isHit));
                                cubesAndTags.Add(boundingCube, infotag);
                            }
                            else
                            {
                                //Debug.DrawLine(rayCastPos.position, rayCastPos.position + (fwd * 10.0f), Color.magenta);
                                cubesAndTags.Add(CreateBoundingCube(c.transform, c.transform.position + bounds.center, bounds.size), CreateInfoTag(c.transform.position + bounds.center, traslL, traslR, sprites[28], transform.rotation, infos, Color.white));
                            }
                        }
                    }
                    break;

                    case "tree_dec01":
                    {
                        Transform oldParent = c.transform.parent;
                        c.transform.parent = null;                 //I am forced to unparent since I can't take into account the parent scale in the bounding box computation
                        CapsuleCollider capsCol = c as CapsuleCollider;
                        bounds.center = Quaternion.Euler(c.transform.localEulerAngles) * new Vector3(capsCol.center.x * c.transform.localScale.x, capsCol.center.y * c.transform.localScale.y, capsCol.center.z * c.transform.localScale.z);
                        bounds.size   = new Vector3(capsCol.radius * 2.0f * c.transform.localScale.x, capsCol.radius * 2.0f * c.transform.localScale.y, capsCol.height * c.transform.localScale.z);
                        Vector3 traslL = Quaternion.Euler(c.transform.localEulerAngles) * bounds.size;                 //infoTag trasl
                        traslL = new Vector3(traslL.x * 0.5f + 3.0f, 0, 0);
                        Debug.Log(c.transform.name + ", " + traslL);
                        Vector3 traslR = new Vector3(-traslL.x, traslL.y, traslL.z);

                        c.transform.parent = oldParent;

                        float dist = CalculateDistance(rayCastPos.position, c.transform.position + bounds.center);
                        if (dist <= 10.0f)
                        {
                            infos[0] = "0" + " KPH";                 //speed of EnvironmentProp is null
                            infos[1] = Mathf.RoundToInt(dist).ToString() + " M";
                            infos[2] = "";
                            cubesAndTags.Add(CreateBoundingCube(c.transform, c.transform.position + bounds.center, bounds.size), CreateInfoTag(c.transform.position + bounds.center, traslL, traslR, sprites[28], transform.rotation, infos, Color.white));
                        }
                    }
                    break;

                    case "Dumpster":

                    case "busstop":

                    case "barrier_concrete":

                    case "barrier_metal":

                    case "Lamppost":

                    case "Table_For2":

                    case "Table_For4":
                    {
                        BoxCollider boxCol = c as BoxCollider;
                        bounds.center = Quaternion.Euler(c.transform.localEulerAngles) * new Vector3(boxCol.center.x * c.transform.localScale.x, boxCol.center.y * c.transform.localScale.y, boxCol.center.z * c.transform.localScale.z);
                        bounds.size   = new Vector3(boxCol.size.x * c.transform.localScale.x, boxCol.size.y * c.transform.localScale.y, boxCol.size.z * c.transform.localScale.z);
                        Vector3 traslL = Quaternion.Euler(c.transform.localEulerAngles) * bounds.size;                 //infoTag trasl
                        traslL = new Vector3(traslL.x * 0.5f + 2.0f, traslL.y * 0.5f, 0);
                        Vector3 traslR = new Vector3(-traslL.x, traslL.y, traslL.z);

                        float dist = CalculateDistance(rayCastPos.position, c.transform.position + bounds.center);
                        if (dist <= 10.0f)
                        {
                            infos[0] = "0" + " KPH";                 //speed of EnvironmentProp is null
                            infos[1] = Mathf.RoundToInt(dist).ToString() + " M";
                            infos[2] = "";
                            cubesAndTags.Add(CreateBoundingCube(c.transform, c.transform.position + bounds.center, bounds.size), CreateInfoTag(c.transform.position + bounds.center, traslL, traslR, sprites[28], transform.rotation, infos, Color.white));
                        }
                    }
                    break;
                    }
                }
                break;

                case 17:      //Signage
                {
                    Bounds bounds = new Bounds();
                    if (c.transform.parent.name.Equals("StreetArrows") || c.transform.name.Equals("Post"))
                    {
                        break;
                    }

                    BoxCollider boxCol = c as BoxCollider;
                    bounds.center = boxCol.center;
                    bounds.size   = boxCol.size * 1.25f;
                    float dist = CalculateDistance(rayCastPos.position, c.transform.position + bounds.center);
                    if (dist <= 50.0f)
                    {
                        infos[0] = "0" + " KPH";         //speed of EnvironmentProp is null
                        infos[1] = Mathf.RoundToInt(dist).ToString() + " M";
                        infos[2] = "";
                        cubesAndTags.Add(CreateBoundingCube(c.transform, c.transform.position + bounds.center, bounds.size), new GameObject());
                    }
                }
                break;

                case 12:     //obstacle
                {
                    Bounds bounds = ComputeBounds(c.transform);
                    infos[0] = Mathf.RoundToInt(CalculateObstacleSpeed(c.transform)).ToString() + " KPH";
                    infos[1] = Mathf.RoundToInt(CalculateDistance(rayCastPos.position, bounds.center)).ToString() + " M";
                    infos[2] = "";
                    //cubesAndTags.Add(CreateBoundingCube(c.transform, bounds.center, bounds.size), CreateInfoTag(bounds.center, bounds.size, sprites[28], infos));
                }
                break;

                case 8:
                {         //Traffic
                    if (!curColls.Contains(c.transform.root))
                    {     //this is in order to check if an object has more colliders than one; if so, one is sufficient so simply discard other otherwise the cube instantiated would be equal to the number of colliders
                        Bounds  bounds  = ComputeBounds(c.transform.root);
                        TrafPCH trafPCH = c.transform.root.GetComponent <TrafPCH>();
                        if (trafPCH != null)
                        {
                            float speed = trafPCH.currentSpeed;
                            infos[0] = Mathf.RoundToInt(speed * 3.6f).ToString() + " KPH";
                            infos[1] = Mathf.RoundToInt(CalculateDistance(rayCastPos.position, bounds.center)).ToString() + " M";
                            infos[2] = "";
                            //cubesAndTags.Add(CreateBoundingCube(c.transform.root, bounds.center, bounds.size), CreateInfoTag(bounds.center, bounds.size, sprites[0], infos));
                            curColls.Add(c.transform.root);
                        }
                    }
                }
                break;

                case 18:     //Roads
                {
                    if (c.transform.name.StartsWith("TrafficLight"))
                    {
                        TrafLightState currentState = c.transform.GetComponent <TrafficLightContainer>().State;
                        Dictionary <string, Transform> trafLightChildren = new Dictionary <string, Transform>();
                        List <Bounds> bounds = new List <Bounds>();
                        foreach (Transform t in c.transform)
                        {
                            if (t.name.StartsWith("Light") && t.gameObject.activeInHierarchy)         //there are some trafficLights not active so I have to exclude them
                            {
                                trafLightChildren.Add(t.name, t);
                                bounds.Add(ComputeBounds(t));
                            }
                        }
                        if (trafLightChildren.Count != 0)           //I have to check whether the dictionary is empty or not since there may be some inactive trafficLights which in the next code I will erronously reference
                        {
                            infos[0] = infos[1] = "";
                            if (currentState.Equals(TrafLightState.GREEN))
                            {
                                infos[2] = "GO";
                                cubesAndTags.Add(CreateBoundingCube(trafLightChildren["Light0"], bounds[0].center, bounds[0].size), CreateInfoTag(bounds[0].center, new Vector3(0, 0, -bounds[0].size.x), new Vector3(0, 0, -bounds[0].size.x), sprites[25], Quaternion.Euler(0f, 90f, 0f) * trafLightChildren["Light0"].rotation, infos, Color.white));       //I add another 90 degrees to position the tag orthogonally with respect to the trafficLight
                                cubesAndTags.Add(CreateBoundingCube(trafLightChildren["Light1"], bounds[1].center, bounds[1].size), CreateInfoTag(bounds[1].center, new Vector3(0, 0, -bounds[1].size.x), new Vector3(0, 0, -bounds[1].size.x), sprites[25], Quaternion.Euler(0f, 90f, 0f) * trafLightChildren["Light1"].rotation, infos, Color.white));
                            }
                            else if (currentState.Equals(TrafLightState.YELLOW))
                            {
                                infos[2] = "GO";
                                cubesAndTags.Add(CreateBoundingCube(trafLightChildren["Light0"], bounds[0].center, bounds[0].size), CreateInfoTag(bounds[0].center, new Vector3(0, 0, -bounds[0].size.x), new Vector3(0, 0, -bounds[0].size.x), sprites[27], Quaternion.Euler(0f, 90f, 0f) * trafLightChildren["Light0"].rotation, infos, Color.white));
                                cubesAndTags.Add(CreateBoundingCube(trafLightChildren["Light1"], bounds[1].center, bounds[1].size), CreateInfoTag(bounds[1].center, new Vector3(0, 0, -bounds[1].size.x), new Vector3(0, 0, -bounds[1].size.x), sprites[27], Quaternion.Euler(0f, 90f, 0f) * trafLightChildren["Light1"].rotation, infos, Color.white));
                            }
                            else
                            {
                                infos[2] = "STOP";
                                cubesAndTags.Add(CreateBoundingCube(trafLightChildren["Light0"], bounds[0].center, bounds[0].size), CreateInfoTag(bounds[0].center, new Vector3(0, 0, -bounds[0].size.x), new Vector3(0, 0, -bounds[0].size.x), sprites[26], Quaternion.Euler(0f, 90f, 0f) * trafLightChildren["Light0"].rotation, infos, Color.white));
                                cubesAndTags.Add(CreateBoundingCube(trafLightChildren["Light1"], bounds[1].center, bounds[1].size), CreateInfoTag(bounds[1].center, new Vector3(0, 0, -bounds[1].size.x), new Vector3(0, 0, -bounds[1].size.x), sprites[26], Quaternion.Euler(0f, 90f, 0f) * trafLightChildren["Light1"].rotation, infos, Color.white));
                            }
                        }
                    }
                }
                break;
                }
            }
            Timer = 0.1f;
        }
        //i++;
    }
Ejemplo n.º 5
0
    void EnvironmentDetect()
    {
        List <CubesAndTags> objectsList = new List <CubesAndTags>(IDsAndGos.Values);

        for (int i = 0; i < objectsList.Count; i++)
        {
            if (objectsList[i].other != null)
            {
                float dist = CalculateDistance(rayCastPos.position, objectsList[i].other.transform.position); //this distance does not include bounds since it cannot always be precomputed, for example, this is the case of moving objects

                switch (objectsList[i].other.gameObject.layer)
                {
                case 17:     //Signage
                {
                    float    dotProduct = Vector3.Dot(gameObject.transform.TransformDirection(Vector3.forward), objectsList[i].other.transform.TransformDirection(Vector3.up));
                    Animator anim       = objectsList[i].infoTag[0].GetComponent <Animator>();
                    if (dotProduct >= -1 && dotProduct <= -0.707f)
                    {
                        if ((objectsList[i].other.transform.name.Equals("StopSign") || objectsList[i].other.transform.name.Equals("RoadWork") || objectsList[i].other.transform.name.Equals("Speed_Limit_40") || objectsList[i].other.transform.name.Equals("Speed_Limit_50") || objectsList[i].other.transform.name.Equals("End_Limit_40") || objectsList[i].other.transform.name.Equals("Speed_Limit_60")) && dist <= 40)
                        {
                            Bounds bounds      = objectsList[i].bounds[0];
                            int    spriteIndex = CSVSignDictionary[objectsList[i].other.name];
                            objectsList[i].boundingCube[0].GetComponent <Renderer>().enabled = true;
                            objectsList[i].infoTag[0].GetComponent <Canvas>().enabled        = true;
                            RiskAssessmentSelective.UpdateInfoTag(objectsList[i], bounds, "", ResourceHandler.instance.sprites[spriteIndex], dist, Vector3.zero, 0);
                            anim.SetBool("Blink", true);
                            float dotproduct2 = Vector3.Dot(gameObject.transform.TransformDirection(Vector3.forward), objectsList[i].other.transform.position - transform.position);         //play audio only if sign is in front of me
                            if (dotproduct2 > 0)
                            {
                                objectsList[i].infoTag[0].GetComponent <PlaySignSignal>().PlayAudio();        //DARIO
                            }
                        }
                        else
                        {
                            objectsList[i].boundingCube[0].GetComponent <Renderer>().enabled = false;
                            objectsList[i].infoTag[0].GetComponent <Canvas>().enabled        = false;
                            anim.SetBool("Blink", false);
                        }
                    }
                    else
                    {
                        if (objectsList[i].other.transform.name.Equals("StopSign") || objectsList[i].other.transform.name.Equals("RoadWork") || objectsList[i].other.transform.name.Equals("Speed_Limit_40") || objectsList[i].other.transform.name.Equals("Speed_Limit_50") || objectsList[i].other.transform.name.Equals("End_Limit_40") || objectsList[i].other.transform.name.Equals("Speed_Limit_60"))
                        {
                            anim.SetBool("Blink", false);
                        }
                    }
                }
                break;

                case 12:
                {
                    Bounds bounds = objectsList[i].bounds[0];
                    Sprite sprite = objectsList[i].other.GetComponent <Image>().sprite;
                    if (objectsList[i].other.CompareTag("Obstacle"))
                    {
                        RiskAssessmentSelective.BoundingCubeLerperObstacleDefSF(objectsList[i], bounds, CalculateObstacleSpeed(objectsList[i]), 0, sprite, Vector3.zero, 0);
                    }
                    else if (objectsList[i].other.CompareTag("Stop"))
                    {
                        RiskAssessmentSelective.BoundingCubeLerperManSF(objectsList[i], bounds, CalculateObstacleSpeed(objectsList[i]), 0, sprite, Vector3.zero, 0);
                    }
                }
                break;

                case 8:
                {
                    Debug.DrawLine(objectsList[i].other.transform.position, rayCastPos.position, Color.green);
                    Bounds      bounds      = objectsList[i].bounds[0];
                    TrafAIMotor trafAIMotor = objectsList[i].other.transform.root.GetComponent <TrafAIMotor>();
                    if (trafAIMotor != null)
                    {
                        float  speed        = trafAIMotor.currentSpeed;
                        float  acceleration = trafAIMotor.accelerazione;
                        Sprite sprite       = objectsList[i].other.GetComponent <Image>().sprite;
                        if (objectsList[i].other.transform.root.CompareTag("TrafficCar"))
                        {
                            RiskAssessmentSelective.BoundingCubeLerperSF(objectsList[i], bounds, speed, acceleration, sprite, Vector3.zero, 0);
                        }
                        else
                        {
                            RiskAssessmentSelective.BoundingCubeLerperScooterSF(objectsList[i], bounds, speed, sprite, Vector3.zero, 0);
                        }
                    }
                }
                break;

                case 18:     //Roads
                {
                    if (objectsList[i].bounds.Count == 3)
                    {
                        float dotProduct = Vector3.Dot(gameObject.transform.TransformDirection(Vector3.forward), objectsList[i].other.transform.TransformDirection(Vector3.right));
                        if (dotProduct >= -1 && dotProduct <= -0.707f)
                        {
                            TrafAIMotor trafAIMotor = transform.root.GetComponent <TrafAIMotor>();
                            if (trafAIMotor != null)         //Among the various potential trafficLights which can be traced by OnTriggerEnter I am sure by this test that I Am considering the next one and not the others
                            {
                                if (trafAIMotor.nextEntry50 != null)
                                {
                                    trafLight = trafAIMotor.nextEntry50.light;
                                }
                                if (trafLight != null && trafLight.gameObject.GetInstanceID().Equals(objectsList[i].other.gameObject.GetInstanceID()))
                                {
                                    Transform Panel = objectsList[i].infoTag[0].transform.GetChild(0);
                                    Panel.transform.GetChild(2).GetComponent <TextMeshProUGUI>().fontSize = 110;

                                    TrafLightState currentState = trafLight.State;
                                    Animator       anim         = objectsList[i].infoTag[0].GetComponent <Animator>();
                                    if (currentState.Equals(TrafLightState.GREEN))
                                    {
                                        Panel.transform.GetChild(3).GetComponent <Image>().sprite          = ResourceHandler.instance.sprites[30];
                                        Panel.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text  = "GO";
                                        Panel.transform.GetChild(2).GetComponent <TextMeshProUGUI>().color = new Color32(0x3B, 0xAA, 0x34, 0xFF);

                                        anim.SetInteger("trafLightState", (int)TrafLightState.GREEN);
                                    }
                                    else if (currentState.Equals(TrafLightState.YELLOW))
                                    {
                                        Panel.transform.GetChild(3).GetComponent <Image>().sprite = ResourceHandler.instance.sprites[31];
                                        Vector3 offset = trafLight.transform.position - rayCastPos.position;
                                        float   mag    = offset.sqrMagnitude;
                                        if (mag >= 1600 || trafAIMotor.hasStopTarget)         //40m
                                        {
                                            Panel.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text = "STOP";
                                        }
                                        //else if ()
                                        //{
                                        //    Panel.transform.GetChild(2).GetComponent<TextMeshProUGUI>().text = "STOP";
                                        //}
                                        else
                                        {
                                            Panel.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text = "GO";
                                        }
                                        Panel.transform.GetChild(2).GetComponent <TextMeshProUGUI>().color = new Color32(0xFE, 0xED, 0x01, 0xFF);
                                        anim.SetInteger("trafLightState", (int)TrafLightState.YELLOW);
                                    }
                                    else
                                    {
                                        Panel.transform.GetChild(3).GetComponent <Image>().sprite          = ResourceHandler.instance.sprites[32];
                                        Panel.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text  = "STOP";
                                        Panel.transform.GetChild(2).GetComponent <TextMeshProUGUI>().color = new Color32(0xE3, 0x07, 0x13, 0xFF);

                                        anim.SetInteger("trafLightState", (int)TrafLightState.RED);
                                    }


                                    //IDsAndGos[other.gameObject.GetInstanceID()].infoTag[i].transform.rotation = Quaternion.Euler(0f, 90f, 0f) * IDsAndGos[other.gameObject.GetInstanceID()].boundingCube[0].transform.rotation;
                                    float infoTagOffset = Vector3.Distance(objectsList[i].boundingCube[0].transform.position, objectsList[i].boundingCube[1].transform.position);
                                    objectsList[i].infoTag[0].transform.position = objectsList[i].boundingCube[0].transform.position + objectsList[i].infoTag[0].transform.TransformDirection(-Vector3.right.x * (infoTagOffset / 2), -Vector3.up.y * 1.5f, -Vector3.forward.z);

                                    float distMax  = 150f;
                                    float distMin  = 5.5f;
                                    float scaleMax = (infoTagStartScale.x * distMax) / distMin;
                                    float offset2  = Vector3.Distance(objectsList[i].infoTag[0].transform.position, driverCam.transform.position);
                                    float newScale = infoTagResize.Evaluate(offset2 / distMax) * scaleMax;
                                    objectsList[i].infoTag[0].transform.localScale = new Vector3(newScale, newScale, newScale);
                                    objectsList[i].infoTag[0].transform.LookAt((2 * objectsList[i].infoTag[0].transform.position - driverCam.transform.position));

                                    objectsList[i].boundingCube[0].GetComponent <Renderer>().enabled = objectsList[i].boundingCube[1].GetComponent <Renderer>().enabled = true;
                                    objectsList[i].infoTag[0].GetComponent <Canvas>().enabled        = true;
                                }
                                else
                                {
                                    objectsList[i].boundingCube[0].GetComponent <Renderer>().enabled = false;
                                    objectsList[i].infoTag[0].GetComponent <Canvas>().enabled        = false;
                                    objectsList[i].boundingCube[1].GetComponent <Renderer>().enabled = false;
                                    objectsList[i].infoTag[1].GetComponent <Canvas>().enabled        = false;
                                }
                            }
                            else
                            {
                                objectsList[i].boundingCube[0].GetComponent <Renderer>().enabled = false;
                                objectsList[i].infoTag[0].GetComponent <Canvas>().enabled        = false;
                                objectsList[i].boundingCube[1].GetComponent <Renderer>().enabled = false;
                                objectsList[i].infoTag[1].GetComponent <Canvas>().enabled        = false;
                            }
                        }
                        else
                        {
                            objectsList[i].boundingCube[0].GetComponent <Renderer>().enabled = false;
                            objectsList[i].infoTag[0].GetComponent <Canvas>().enabled        = false;
                            objectsList[i].boundingCube[1].GetComponent <Renderer>().enabled = false;
                            objectsList[i].infoTag[1].GetComponent <Canvas>().enabled        = false;
                        }
                        Bounds boundsPost = objectsList[i].bounds[2];
                        Sprite sprite     = objectsList[i].other.GetComponent <Image>().sprite;
                        RiskAssessmentSelective.BoundingCubeLerperSF(objectsList[i], boundsPost, sprite, ReturnTrasl(boundsPost, objectsList[i].other), 2);
                    }
                    else
                    {
                        Bounds boundsPost = objectsList[i].bounds[0];
                        Sprite sprite     = objectsList[i].other.GetComponent <Image>().sprite;
                        RiskAssessmentSelective.BoundingCubeLerperSF(objectsList[i], boundsPost, sprite, ReturnTrasl(boundsPost, objectsList[i].other), 0);
                    }
                }
                break;
                }
            }
        }
    }
Ejemplo n.º 6
0
 void Awake()
 {
     currentState = TrafLightState.RED;
 }