Ejemplo n.º 1
0
    /// <summary>
    /// Visualize the light on the mesh by setting the properties of the light shader accorind to the lighting unit.
    /// </summary>
    /// <param name="unit">Current lighting unit.</param>
    private void DisplayLighting(LightingUnit unit)
    {
        LightingUnitConfigurationHandler configurator = unit.bulb.GetComponent <LightingUnitConfigurationHandler>();

        if (configurator == null)
        {
            unit.bulb.transform.GetChild(1).gameObject.GetComponent <Renderer>().material.SetVector("_CenterPoint", unit.position);
            unit.bulb.transform.GetChild(1).gameObject.GetComponent <Renderer>().material.SetFloat("_MaxDistance", unit.maxRange);
            unit.bulb.transform.GetChild(1).gameObject.GetComponent <Renderer>().material.SetFloat("_ChangePoint", unit.lux);
        }
        else
        {
            unit.bulb.transform.GetChild(2).gameObject.GetComponent <Renderer>().material.SetVector("_CenterPoint", unit.position);
            unit.bulb.transform.GetChild(2).gameObject.GetComponent <Renderer>().material.SetFloat("_MaxDistance", unit.maxRange);
            unit.bulb.transform.GetChild(2).gameObject.GetComponent <Renderer>().material.SetFloat("_ChangePoint", unit.lux);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Creates and places a lighting unit at the power outlet position with the largest range.
    /// </summary>
    /// <param name="p">Current power outlet with the largest range.</param>
    /// <param name="type">Lighting unit type which should be created.</param>
    private void PlaceLightingUnit(PowerOutlet p, string type)
    {
        // Creating a lighting unit and set its properties
        GameObject bulb = Instantiate(bulbPrefab, gameObject.transform);

        bulb.transform.position = p.lampPosition;
        LightingUnit unit = new LightingUnit(p.lampPosition, p.surfacePlane.Type, bulb, p.hits.Select(d => d.distance).Max(), 0, type);

        LightingUnitConfigurationHandler confgurator = bulb.GetComponent <LightingUnitConfigurationHandler>();

        if (confgurator != null)
        {
            confgurator.Init(unit, LightBulbs.Count);
        }

        LightBulbs.Add(unit);

        SetupMesh(unit);
        StartCoroutine(CreateSphereRayCasts(unit));
    }