private void OnGUI()
        {
            if (FindObjectOfType <LightingSystem>())
            {
                GUILayout.Label(
                    "WARNING: existing lighting system is found.\nIt is recommended to remove it first, before adding new one.",
                    EditorStyles.boldLabel);
            }

            GUILayout.Label("Select layers you wish to use. You could modify them later in created object.");
            _lightObstaclesLayer = EditorGUILayout.LayerField("Light Obstacles", _lightObstaclesLayer);
            _lightSourcesLayer   = EditorGUILayout.LayerField("Light Sources", _lightSourcesLayer);
            _ambientLightLayer   = EditorGUILayout.LayerField("Ambient Light", _ambientLightLayer);

            if (GUILayout.Button("Create"))
            {
                Camera         mainCamera    = Camera.main;
                LightingSystem lighingSystem = mainCamera.GetComponent <LightingSystem>() ??
                                               mainCamera.gameObject.AddComponent <LightingSystem>();

                GameObject prefab            = Resources.Load <GameObject>("Lighting Camera");
                GameObject lightingSystemObj = Instantiate(prefab);
                lightingSystemObj.name                    = lightingSystemObj.name.Replace("(Clone)", "");
                lightingSystemObj.transform.parent        = mainCamera.transform;
                lightingSystemObj.transform.localPosition = Vector3.zero;
                lightingSystemObj.transform.localScale    = Vector3.one;
                lightingSystemObj.transform.localRotation = Quaternion.identity;

                LightingSystemPrefabConfig config = lightingSystemObj.GetComponent <LightingSystemPrefabConfig>();

                lighingSystem.LightCamera = lightingSystemObj.GetComponent <Camera>();
                lighingSystem.AmbientLightComputeMaterial = config.AmbientLightComputeMaterial;
                lighingSystem.LightOverlayMaterial        = config.LightOverlayMaterial;
                lighingSystem.AmbientLightBlurMaterial    = lighingSystem.LightSourcesBlurMaterial = config.BlurMaterial;

                DestroyImmediate(config);

                lighingSystem.LightCamera.depth = mainCamera.depth - 1;

                lighingSystem.LightCamera.cullingMask = 1 << _lightSourcesLayer;

                lighingSystem.LightSourcesLayer   = _lightSourcesLayer;
                lighingSystem.AmbientLightLayer   = _ambientLightLayer;
                lighingSystem.LightObstaclesLayer = _lightObstaclesLayer;

                mainCamera.cullingMask &=
                    ~((1 << _lightSourcesLayer) | (1 << _ambientLightLayer) | (1 << _lightObstaclesLayer));

                Close();
            }
        }
示例#2
0
    public void SetResolution(int _value)
    {
        float xOffsetCamFollow = 0;

        switch (_value)
        {
        case 0:
            width            = 1024;
            height           = 640;
            xOffsetCamFollow = 1.7f;
            break;

        case 1:
            width            = 1280;
            height           = 720;
            xOffsetCamFollow = 2.5f;
            break;

        case 2:
            //FIXME: Interact problems at this reso
            width  = 1920;
            height = 1080;
            break;
        }
        PlayerPrefs.SetInt("reso", _value);
        Screen.SetResolution(width, height, false);
        if (GameData.IsInGame)
        {
            Camera2DFollow.followControl.listenerObj.transform.localPosition = new Vector3(-xOffsetCamFollow, 1f);             //set listenerObj's position to player's pos
            Camera2DFollow.followControl.xOffset = xOffsetCamFollow;
        }
        if (optionsDropDown.value != _value)
        {
            optionsDropDown.value = _value;
        }
        if (lightingSystem != null)
        {
            lightingSystem._renderTargetTexture = new RenderTexture(width, height, -2, RenderTextureFormat.ARGB32);
        }
        else
        {
            lightingSystem = FindObjectOfType <Light2D.LightingSystem>();
            if (lightingSystem != null)
            {
                mainCamera = lightingSystem.GetComponent <Camera>();
                lightingSystem._renderTargetTexture  = new RenderTexture(width, height, -2, RenderTextureFormat.ARGB32);
                lightingSystem._camera.targetTexture = lightingSystem._renderTargetTexture;
            }
        }
    }
示例#3
0
 private void OnEnable()
 {
     _instance = this;
     _camera   = GetComponent <Camera>();
 }
        public override void OnInspectorGUI()
        {
            // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
            serializedObject.Update();

            if (Application.isPlaying)
            {
                GUI.enabled = false;
            }

            LightingSystem lightingSystem = (LightingSystem)target;
            Camera         cam            = lightingSystem.GetComponent <Camera>();
            bool           isMobileTarget = EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS ||
                                            EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android;

            if (cam == null)
            {
                EditorGUILayout.LabelField("WARNING: No attached camera found.");
            }

            EditorGUILayout.PropertyField(_lightPixelSize, new GUIContent("Light Pixel Size"));

            if (cam != null)
            {
                float size;
                if (cam.orthographic)
                {
                    size = (cam.orthographicSize + _lightCameraSizeAdd.floatValue) * 2f;
                }
                else
                {
                    float halfFov = (cam.fieldOfView + _lightCameraFovAdd.floatValue) * Mathf.Deg2Rad / 2f;
                    size = Mathf.Tan(halfFov) * _lightObstaclesDistance.floatValue * 2;
                }
                if (!Application.isPlaying)
                {
                    int lightTextureHeight = Mathf.RoundToInt(size / _lightPixelSize.floatValue);
                    int oldSize            = lightTextureHeight;
                    lightTextureHeight = EditorGUILayout.IntField("Light Texture Height", lightTextureHeight);
                    if (lightTextureHeight % 2 != 0)
                    {
                        lightTextureHeight++;
                    }
                    if (lightTextureHeight < 16)
                    {
                        if (lightTextureHeight < 8)
                        {
                            lightTextureHeight = 8;
                        }
                        EditorGUILayout.LabelField("WARNING: Light Texture Height is too small.");
                        EditorGUILayout.LabelField(" 50-200 (mobile) and 200-1000 (pc) is recommended.");
                    }
                    if (lightTextureHeight > (isMobileTarget ? 200 : 1000))
                    {
                        if (lightTextureHeight > 2048)
                        {
                            lightTextureHeight = 2048;
                        }
                        EditorGUILayout.LabelField("WARNING: Light Texture Height is too big.");
                        EditorGUILayout.LabelField(" 50-200 (mobile) and 200-1000 (pc) is recommended.");
                    }
                    if (oldSize != lightTextureHeight)
                    {
                        _lightPixelSize.floatValue = size / lightTextureHeight;
                    }
                }
            }

            if (cam == null || cam.orthographic)
            {
                EditorGUILayout.PropertyField(_lightCameraSizeAdd, new GUIContent("Light Camera Size Add"));
            }
            else
            {
                EditorGUILayout.PropertyField(_lightCameraFovAdd, new GUIContent("Light Camera Fov Add"));
                EditorGUILayout.PropertyField(_lightObstaclesDistance, new GUIContent("Camera To Light Obstacles Distance"));
            }

            EditorGUILayout.PropertyField(_hdr, new GUIContent("64 Bit Color"));
            EditorGUILayout.PropertyField(_lightObstaclesAntialiasing, new GUIContent("Light Obstacles Antialiasing"));
            EditorGUILayout.PropertyField(_enableNormalMapping, new GUIContent("Normal Mapping"));
            if (_enableNormalMapping.boolValue && isMobileTarget)
            {
                EditorGUILayout.LabelField("WARNING: Normal mapping is not supported on mobiles.");
            }
            _lightTexturesFilterMode.enumValueIndex = (int)(FilterMode)EditorGUILayout.EnumPopup(
                "Texture Filtering", (FilterMode)_lightTexturesFilterMode.enumValueIndex);

            EditorGUILayout.PropertyField(_blurLightSources, new GUIContent("Blur Light Sources"));
            if (_blurLightSources.boolValue && _enableNormalMapping.boolValue)
            {
                EditorGUILayout.LabelField("    Blurring light sources with normal mapping enabled\n");
                EditorGUILayout.LabelField("     could significantly reduce lighting quality.");
            }

            bool normalGuiEnableState = GUI.enabled;

            if (!_blurLightSources.boolValue)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(_lightSourcesBlurMaterial, new GUIContent("   Light Sources Blur Material"));
            GUI.enabled = normalGuiEnableState;

            EditorGUILayout.PropertyField(_enableAmbientLight, new GUIContent("Enable Ambient Light"));
            if (!_enableAmbientLight.boolValue)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(_blurAmbientLight, new GUIContent("   Blur Ambient Light"));
            bool oldEnabled = GUI.enabled;

            if (!_blurAmbientLight.boolValue)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(_ambientLightBlurMaterial, new GUIContent("   Ambient Light Blur Material"));
            GUI.enabled = oldEnabled;
            EditorGUILayout.PropertyField(_ambientLightComputeMaterial, new GUIContent("   Ambient Light Compute Material"));
            GUI.enabled = normalGuiEnableState;

            EditorGUILayout.PropertyField(_lightOverlayMaterial, new GUIContent("Light Overlay Material"));
            EditorGUILayout.PropertyField(_lightCamera, new GUIContent("Lighting Camera"));
            _lightSourcesLayer.intValue =
                EditorGUILayout.LayerField(new GUIContent("Light Sources Layer"), _lightSourcesLayer.intValue);
            _lightObstaclesLayer.intValue =
                EditorGUILayout.LayerField(new GUIContent("Light Obstacles Layer"), _lightObstaclesLayer.intValue);
            _ambientLightLayer.intValue =
                EditorGUILayout.LayerField(new GUIContent("Ambient Light Layer"), _ambientLightLayer.intValue);
            EditorGUILayout.PropertyField(_lightObstaclesReplacementShaderLayer);

            // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
            serializedObject.ApplyModifiedProperties();
        }
示例#5
0
 private void OnEnable()
 {
     _instance = this;
     _camera = GetComponent<Camera>();
 }