Esempio n. 1
0
    private static GameObject CreateVolumeLight(VLight.LightTypes type)
    {
        VLight[]   otherLights          = GameObject.FindObjectsOfType(typeof(VLight)) as VLight[];
        GameObject volumeLightContainer = new GameObject("V-Light " + otherLights.Length);

        if (SceneView.lastActiveSceneView != null)
        {
            SceneView.lastActiveSceneView.MoveToView(volumeLightContainer.transform);
        }
        VLight light = volumeLightContainer.AddComponent <VLight>();

        volumeLightContainer.camera.enabled = false;

#if UNITY_4_2 || UNITY_4_3 || UNITY_4_4
        volumeLightContainer.camera.fieldOfView   = 45;
        volumeLightContainer.camera.nearClipPlane = 0.1f;
        volumeLightContainer.camera.farClipPlane  = 1;
#else
        volumeLightContainer.camera.fov  = 45;
        volumeLightContainer.camera.near = 0.1f;
        volumeLightContainer.camera.far  = 1;
#endif
        volumeLightContainer.camera.renderingPath    = RenderingPath.VertexLit;
        volumeLightContainer.camera.orthographicSize = 2.5f;

        switch (type)
        {
        case VLight.LightTypes.Spot:
            light.lightType = VLight.LightTypes.Spot;
            break;

        case VLight.LightTypes.Point:
            volumeLightContainer.camera.isOrthoGraphic = true;
#if UNITY_4_2 || UNITY_4_3 || UNITY_4_4
            volumeLightContainer.camera.nearClipPlane    = -volumeLightContainer.camera.farClipPlane;
            volumeLightContainer.camera.orthographicSize = volumeLightContainer.camera.farClipPlane * 2;
#else
            volumeLightContainer.camera.near             = -volumeLightContainer.camera.far;
            volumeLightContainer.camera.orthographicSize = volumeLightContainer.camera.far * 2;
#endif
            light.lightType = VLight.LightTypes.Point;
            break;
        }

        int layer = LayerMask.NameToLayer(VLightManager.VOLUMETRIC_LIGHT_LAYER_NAME);
        if (layer != -1)
        {
            volumeLightContainer.layer = layer;
            volumeLightContainer.camera.cullingMask = ~(1 << layer);
        }

        volumeLightContainer.transform.Rotate(90, 0, 0);
        return(volumeLightContainer);
    }
Esempio n. 2
0
    private static VLight CreateVolumeLight(VLight.LightTypes type)
    {
        var otherLights          = GameObject.FindObjectsOfType(typeof(VLight)) as VLight[];
        var volumeLightContainer = new GameObject("V-Light " + type + " " + otherLights.Length);

        if (SceneView.lastActiveSceneView != null)
        {
            SceneView.lastActiveSceneView.MoveToView(volumeLightContainer.transform);
        }
        var light = volumeLightContainer.AddComponent <VLight>();
        var cam   = volumeLightContainer.GetComponent <Camera>();

        cam.enabled = false;

        cam.fieldOfView      = 45;
        cam.nearClipPlane    = 0.1f;
        cam.farClipPlane     = 1;
        cam.renderingPath    = RenderingPath.VertexLit;
        cam.orthographicSize = 2.5f;

        switch (type)
        {
        case VLight.LightTypes.Spot:
            light.spotRange = 1;
            light.lightType = VLight.LightTypes.Spot;
            break;

        case VLight.LightTypes.Point:
            cam.orthographic       = true;
            cam.nearClipPlane      = -cam.farClipPlane;
            cam.orthographicSize   = cam.farClipPlane * 2;
            light.pointLightRadius = 1;
            light.lightType        = VLight.LightTypes.Point;
            break;

        case VLight.LightTypes.Area:
            cam.orthographic       = true;
            cam.nearClipPlane      = -cam.farClipPlane;
            cam.orthographicSize   = cam.farClipPlane * 2;
            light.pointLightRadius = 1;
            light.lightType        = VLight.LightTypes.Area;
            light.lightMultiplier  = 0.05f;
            light.pointLightRadius = 2.0f;
            break;

        case VLight.LightTypes.Orthographic:
            cam.orthographic  = true;
            cam.nearClipPlane = 0;
            cam.farClipPlane  = 2;
            light.spotRange   = 2;
            light.lightType   = VLight.LightTypes.Orthographic;
            light.orthoSize   = 0.5f;
            break;
        }

        var layer = LayerMask.NameToLayer(VLightManager.VOLUMETRIC_LIGHT_LAYER_NAME);

        if (layer != -1)
        {
            volumeLightContainer.layer = layer;
            cam.cullingMask            = ~(1 << layer);
        }

        volumeLightContainer.transform.Rotate(90, 0, 0);
        return(light);
    }