Ejemplo n.º 1
0
        public void Initialize()
        {
            // Create effects from the assetbundle, they should read the required assets by themselves.

            // Wow such exception handling.
            try
            {
                m_menus.Add(MenuType.Bloom, new BloomEffect());
            }
            catch (Exception ex)
            {
                PPFXUtility.log(ex);
            }

            try
            {
                m_menus.Add(MenuType.AntiAliasing, new AntiAliasingEffect());
            }
            catch (Exception ex)
            {
                PPFXUtility.log(ex);
            }

            try
            {
                m_menus.Add(MenuType.AmbientOcclusion, new AmbientOcclusionEffect());
            }
            catch (Exception ex)
            {
                PPFXUtility.log(ex);
            }
        }
Ejemplo n.º 2
0
        private void save()
        {
            // For some reason there can be an exception in the constructor, but the object is still created.
            PPFXUtility.log("PostProcessFX: Saving settings.");

            foreach (KeyValuePair <MenuType, IEffectMenu> keyValue in m_menus)
            {
                keyValue.Value.save();
            }

            ConfigUtility.Serialize <GUIConfig>(configFilename, m_config);
        }
Ejemplo n.º 3
0
        public void OnDisabled()
        {
            ModLoader.removeConfigUI();

            if (loadedBundle)
            {
                loadedBundle.Unload(true);
                AssetBundle.Destroy(loadedBundle);
                PPFXUtility.log("Unloaded existing asset bundle.");
            }

            PPFXUtility.log(ModName + " " + VersionString + " disabled.");
        }
Ejemplo n.º 4
0
        public void OnEnabled()
        {
            PPFXUtility.log(ModName + " " + VersionString + " enabled");

            // Find the current directory of the mod
            string modPath   = PluginManager.instance.FindPluginInfo(Assembly.GetAssembly(typeof(ModDescription))).modPath;
            string assetsUri = "file:///" + modPath.Replace("\\", "/") + "/Resources/";

            // Add platform specific folder to it.
            if (Application.platform == RuntimePlatform.WindowsPlayer)
            {
                assetsUri += "Windows";
            }
            else if (Application.platform == RuntimePlatform.LinuxPlayer)
            {
                assetsUri += "Linux";
            }
            else if (Application.platform == RuntimePlatform.OSXPlayer)
            {
                assetsUri += "Mac";
            }


            // File is always called the same.
            assetsUri += "/postprocessfx";

            WWW www = new WWW(assetsUri);

            // Need to wait until the WWW loading has been done, this blocks the game.

            /*while (!www.isDone)
             * {
             *  System.Threading.Thread.Sleep(1000);
             *  PPFXUtility.log("Waiting for asset bundle to be loaded...");
             * }*/

            loadedBundle = www.assetBundle;
            if (loadedBundle == null)
            {
                PPFXUtility.log("Assetbundle with uri " + assetsUri + " couldn't be loaded.");

                // Don't throw, but just don't do anything.
                return;
            }

            // When we are already in the level we can also trigger it here.
            ModLoader.addConfigUI();
        }
Ejemplo n.º 5
0
        /**
         * Remove the ConfigUI from the camera if it exists.
         */
        public static void removeConfigUI()
        {
            if (Camera.main == null || Camera.main.gameObject == null)
            {
                return;
            }
            GameObject cameraObject = Camera.main.gameObject;

            // Remove any existing config UI that was added by us.
            Component oldUI = cameraObject.GetComponent("ConfigUI");

            if (oldUI != null)
            {
                Component.Destroy(oldUI);
                PPFXUtility.log("Destroyed the old ConfigUI game object.");
            }
        }
Ejemplo n.º 6
0
        /**
         * Add the config UI to the camera object.
         */
        public static void addConfigUI()
        {
            if (Camera.main == null || Camera.main.gameObject == null)
            {
                return;
            }
            GameObject cameraObject = Camera.main.gameObject;

            removeConfigUI();

            // Then try to add the new one again.
            ConfigUI newUI = cameraObject.AddComponent <ConfigUI>();

            if (newUI != null)
            {
                PPFXUtility.log("Added the ConfigUI game object.");
            }

            newUI.Initialize();
        }
Ejemplo n.º 7
0
        public void onGUI(float x, float y)
        {
            if (GUI.Button(new Rect(x, y, 75, 20), "Default"))
            {
                m_activeConfig = AntiAliasingConfig.getDefaultPreset();
            }

            if (GUI.Button(new Rect(x + 75, y, 75, 20), "Load"))
            {
                m_activeConfig = ConfigUtility.Deserialize <AntiAliasingConfig>(configFilename);
                if (m_activeConfig == null)
                {
                    m_activeConfig = AntiAliasingConfig.getDefaultPreset();
                }
            }
            y += 25;

            m_activeConfig.mode = (AntiAliasingMode)PPFXUtility.drawIntSliderWithLabel(x, y, 0, (int)AntiAliasingMode.Maximum - 2, "Mode: ", m_activeConfig.getLabelFromMode(), (int)m_activeConfig.mode);
            y += 25;

            if (m_activeConfig.mode == AntiAliasingMode.FXAA)
            {
                m_activeConfig.fxaaQuality = PPFXUtility.drawIntSliderWithLabel(x, y, 0, 4, m_activeConfig.getLabelFromFxaaQuality(), m_activeConfig.fxaaQuality);
                y += 25;
            }

            if (m_activeConfig.mode == AntiAliasingMode.SMAA)
            {
                m_activeConfig.smaaQuality = (QualityPreset)PPFXUtility.drawIntSliderWithLabel(x, y, 0, (int)QualityPreset.Custom - 1, m_activeConfig.getLabelFromSmaaQuality(), (int)m_activeConfig.smaaQuality);
                y += 25;

                m_activeConfig.smaaTemporal = GUI.Toggle(new Rect(x, y, 200.0f, 20.0f), m_activeConfig.smaaTemporal, "Enable temporal");
                y += 25;

                //m_activeConfig.smaaPredication = GUI.Toggle(new Rect(x, y, 200.0f, 20.0f), m_activeConfig.smaaPredication, "enable predication");
            }

            applyConfig();
        }
Ejemplo n.º 8
0
        private void enable()
        {
            // Find the existing bloom.
            if (m_bloomComponent == null)
            {
                m_bloomComponent = ModDescription.camera.GetComponent <Bloom>();
            }

            if (m_bloomComponent == null)
            {
                m_bloomComponent = ModDescription.camera.AddComponent <Bloom>();
                if (m_bloomComponent == null)
                {
                    throw new Exception("Could not add component Bloom to Camera.");
                }
            }

            m_bloomComponent.lensFlareShader        = PPFXUtility.checkAndLoadAsset <Shader>(ModDescription.loadedBundle, "LensFlareCreate.shader");
            m_bloomComponent.screenBlendShader      = PPFXUtility.checkAndLoadAsset <Shader>(ModDescription.loadedBundle, "BlendForBloom.shader");
            m_bloomComponent.blurAndFlaresShader    = PPFXUtility.checkAndLoadAsset <Shader>(ModDescription.loadedBundle, "BlurAndFlares.shader");
            m_bloomComponent.brightPassFilterShader = PPFXUtility.checkAndLoadAsset <Shader>(ModDescription.loadedBundle, "BrightPassFilter2.shader");
            m_bloomComponent.enabled = true;
        }
Ejemplo n.º 9
0
        public void OnGUI()
        {
            if (!m_config.active)
            {
                return;
            }

            float x = m_config.menuPositionX;
            float y = m_config.menuPositionY;

            GUI.Box(new Rect(x, y, 320, 400), "");

            if (GUI.Button(new Rect(x, y, 300, 20), ModDescription.ModName + " UI " + ModDescription.VersionString))
            {
                m_dragging = true;
            }

            if (GUI.Button(new Rect(x + 300, y, 20, 20), "X"))
            {
                m_config.active = false;
            }

            x += 10;
            y += 25;
            if (GUI.Button(new Rect(x, y, 60, 20), "Global"))
            {
                m_activeMenu = MenuType.Global;
            }

            if (GUI.Button(new Rect(x + 60, y, 60, 20), "Bloom"))
            {
                m_activeMenu = MenuType.Bloom;
            }

            if (GUI.Button(new Rect(x + 120, y, 60, 20), "AA"))
            {
                m_activeMenu = MenuType.AntiAliasing;
            }

            if (GUI.Button(new Rect(x + 180, y, 60, 20), "SSAO"))
            {
                m_activeMenu = MenuType.AmbientOcclusion;
            }

            y += 25;

            // Handle the Global case as it is rendered here.
            if (m_activeMenu == MenuType.Global)
            {
                GUI.Label(new Rect(x, y, 200, 20), "Toggle Key: ");
                m_toggleKeyString = GUI.TextArea(new Rect(x + 150, y, 150, 20), m_toggleKeyString);
                y += 25;

                m_config.ctrlKey  = GUI.Toggle(new Rect(x, y, 50, 20), m_config.ctrlKey, "ctrl");
                m_config.shiftKey = GUI.Toggle(new Rect(x + 60, y, 50, 20), m_config.shiftKey, "shift");
                m_config.altKey   = GUI.Toggle(new Rect(x + 120, y, 50, 20), m_config.altKey, "alt");
                y += 25;

                try
                {
                    m_config.toggleUIKey = (int)Enum.Parse(typeof(KeyCode), m_toggleKeyString);
                }
                catch (Exception)
                {
                    // Silently ignore this exception, because it just means that it cannot be converted to a keycode.
                    m_config.toggleUIKey = (int)KeyCode.F9;
                    m_toggleKeyString    = "F9";
                }

                if (GUI.Button(new Rect(x, y, 50, 20), "Save"))
                {
                    save();
                }
            }
            else
            {
                try
                {
                    m_menus[m_activeMenu].onGUI(x, y);
                }
                catch (Exception ex)
                {
                    PPFXUtility.log(ex);
                    m_activeMenu = MenuType.Global;
                }
            }
        }
Ejemplo n.º 10
0
        public void onGUI(float x, float y)
        {
            if (GUI.Button(new Rect(x, y, 75, 20), "Default"))
            {
                m_activeConfig = new BloomConfig();
            }

            if (GUI.Button(new Rect(x + 75, y, 75, 20), "Medium"))
            {
                m_activeConfig = BloomConfig.getMediumPreset();
            }

            if (GUI.Button(new Rect(x + 150, y, 75, 20), "High"))
            {
                m_activeConfig = BloomConfig.getHighPreset();
            }

            if (GUI.Button(new Rect(x + 225, y, 75, 20), "Load"))
            {
                load();
            }

            y += 25;
            m_activeConfig.bloomEnabled = GUI.Toggle(new Rect(x, y, 200.0f, 20.0f), m_activeConfig.bloomEnabled, "Enable bloom");
            y += 25;

            m_activeConfig.intensity = PPFXUtility.drawSliderWithLabel(x, y, 0.0f, 2.0f, "Intensity", m_activeConfig.intensity);
            y += 25;

            m_activeConfig.threshhold = PPFXUtility.drawSliderWithLabel(x, y, 0.0f, 1.0f, "Threshold", m_activeConfig.threshhold);
            y += 25;

            m_activeConfig.blurSpread = PPFXUtility.drawSliderWithLabel(x, y, 0.0f, 2.0f, "Spread", m_activeConfig.blurSpread);
            y += 25;

            m_activeConfig.blurIterations = PPFXUtility.drawIntSliderWithLabel(x, y, 1, 5, "Spread", m_activeConfig.blurIterations);
            y += 25;

            m_activeConfig.lensflareEnabled = GUI.Toggle(new Rect(x, y, 200.0f, 20.0f), m_activeConfig.lensflareEnabled, "Enable lensflare.");
            y += 25;

            m_activeConfig.lensflareIntensity = PPFXUtility.drawSliderWithLabel(x, y, 0.0f, 2.0f, "Intensity", m_activeConfig.lensflareIntensity);
            y += 25;

            m_activeConfig.lensflareThreshold = PPFXUtility.drawSliderWithLabel(x, y, 0.0f, 1.0f, "Threshold", m_activeConfig.lensflareThreshold);
            y += 25;

            m_activeConfig.lensflareSaturation = PPFXUtility.drawSliderWithLabel(x, y, 0.0f, 1.0f, "Saturation", m_activeConfig.lensflareSaturation);
            y += 25;

            m_activeConfig.lensflareRotation = PPFXUtility.drawSliderWithLabel(x, y, 0.0f, 3.14f, "Rotation", m_activeConfig.lensflareRotation);
            y += 25;

            m_activeConfig.lensflareStretchWidth = PPFXUtility.drawSliderWithLabel(x, y, 0.0f, 5.0f, "Width", m_activeConfig.lensflareStretchWidth);
            y += 25;

            m_activeConfig.lensflareBlurIterations = PPFXUtility.drawIntSliderWithLabel(x, y, 1, 5, "Blur Iterations", m_activeConfig.lensflareBlurIterations);
            y += 25;

            m_activeConfig.lensFlareStyle = (LensFlareStyle)PPFXUtility.drawIntSliderWithLabel(x, y, 0, 2, "Style", m_activeConfig.getLensFlareStyleLabel(), (int)m_activeConfig.lensFlareStyle);
            y += 25;

            //m_activeConfig.lensflareSun = GUI.Toggle(new Rect(x, y, 200.0f, 20.0f), m_activeConfig.lensflareSun, "Enable sun lensflare.");
            //y += 25;

            applyConfig();
        }
Ejemplo n.º 11
0
 public LensflareEffect()
 {
     m_sunflare = PPFXUtility.checkAndLoadAsset <Flare>(ModDescription.loadedBundle, "50mmZoom.flare");
 }