Esempio n. 1
0
            private void OnEnable()
            {
                string productID = this.GetType().ToString().Replace(@"Editor", string.Empty);

                displayColorControlsKey    = string.Format("{0}.displayColorControls", productID);
                displayAdvancedControlsKey = string.Format("{0}.displayAdvancedControls", productID);

                displayColorControls    = EditorPrefs.GetInt(displayColorControlsKey, 0) == 1;
                displayAdvancedControls = EditorPrefs.GetInt(displayAdvancedControlsKey, 0) == 1;

                baseTarget = this.target as VideoGlitchBase;
            }
Esempio n. 2
0
    private int CustomAttributesCount(VideoGlitchBase imageEffect)
    {
        int count = 0;

        PropertyInfo[] properties = imageEffect.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly);
        for (int i = 0; i < properties.Length; ++i)
        {
            count += properties[i].GetCustomAttributes(typeof(RangeIntAttribute), false).Length;
            count += properties[i].GetCustomAttributes(typeof(RangeFloatAttribute), false).Length;
            count += properties[i].GetCustomAttributes(typeof(RangeVector2Attribute), false).Length;
        }

        return(count);
    }
Esempio n. 3
0
    private void OnEnable()
    {
        timeleft = updateInterval;

        Camera selectedCamera = null;

        Camera[] cameras = GameObject.FindObjectsOfType <Camera>();

        for (int i = 0; i < cameras.Length; ++i)
        {
            if (cameras[i].enabled == true)
            {
                selectedCamera = cameras[i];

                break;
            }
        }

        if (selectedCamera != null)
        {
            VideoGlitchBase[] effects = selectedCamera.gameObject.GetComponents <VideoGlitchBase>();
            if (effects.Length > 0)
            {
                for (int i = 0; i < effects.Length; ++i)
                {
                    if (effects[i].IsSupported() == true)
                    {
                        videoGlitches.Add(effects[i]);
                    }
                    else
                    {
                        effects[i].enabled = false;
                    }
                }
            }
            else
            {
                System.Type[] types = Assembly.GetAssembly(typeof(VideoGlitchBase)).GetTypes();
                for (int i = 0; i < types.Length; ++i)
                {
                    if (types[i].IsClass == true && types[i].IsAbstract == false && types[i].IsSubclassOf(typeof(VideoGlitchBase)) == true)
                    {
                        VideoGlitchBase vintageEffect = selectedCamera.gameObject.AddComponent(types[i]) as VideoGlitchBase;
                        if (vintageEffect.IsSupported() == true)
                        {
                            videoGlitches.Add(vintageEffect);
                        }
                        else
                        {
                            Destroy(vintageEffect);
                        }
                    }
                }
            }

            Debug.Log(string.Format("{0} Video Glitches.", videoGlitches.Count));

            for (int i = 0; i < videoGlitches.Count; ++i)
            {
                videoGlitches[i].enabled    = (i == guiSelection);
                videoGlitches[i].EffectMode = screenMode == ScreenModes.Fullscreen ? EffectModes.Screen : EffectModes.Layer;
                videoGlitches[i].Layer      = 1 << LayerMask.NameToLayer(@"DynamicObjects");
            }

            if (musicClip != null)
            {
                AudioSource audioSource = this.gameObject.AddComponent <AudioSource>();
                audioSource.clip   = musicClip;
                audioSource.volume = 0.25f;
                audioSource.loop   = (slideEffectTime > 0.0f);
                audioSource.PlayDelayed(0.0f);
            }
        }
        else
        {
            Debug.LogWarning("No camera found.");
        }
    }
Esempio n. 4
0
 private void EnableEffect(VideoGlitchBase imageEffect, bool enable)
 {
     imageEffect.enabled    = enable;
     imageEffect.EffectMode = screenMode == ScreenModes.Fullscreen ? EffectModes.Screen : EffectModes.Layer;
 }
Esempio n. 5
0
    private void DrawCustomAttributes(VideoGlitchBase imageEffect)
    {
        PropertyInfo[] properties = imageEffect.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly);
        if (properties.Length > 0)
        {
            for (int i = 0; i < properties.Length; ++i)
            {
                object[] rangeAtts = properties[i].GetCustomAttributes(typeof(EnumAttribute), false);
                if (rangeAtts.Length > 0)
                {
                    EnumAttribute attb = rangeAtts[0] as EnumAttribute;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        int value = (int)properties[i].GetValue(imageEffect, null);
                        for (int j = 0; j < attb.enumNames.Count; ++j)
                        {
                            if (GUILayout.Button(attb.enumNames[j]) == true)
                            {
                                value = j;

                                break;
                            }
                        }

                        properties[i].SetValue(imageEffect, value, null);
                    }
                    GUILayout.EndHorizontal();
                }

                rangeAtts = properties[i].GetCustomAttributes(typeof(RangeIntAttribute), false);
                if (rangeAtts.Length > 0)
                {
                    RangeIntAttribute attb = rangeAtts[0] as RangeIntAttribute;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        int value = (int)GUILayout.HorizontalSlider((int)properties[i].GetValue(imageEffect, null), attb.min, attb.max, GUILayout.ExpandWidth(true));
                        properties[i].SetValue(imageEffect, value, null);
                    }
                    GUILayout.EndHorizontal();
                }

                rangeAtts = properties[i].GetCustomAttributes(typeof(RangeFloatAttribute), false);
                if (rangeAtts.Length > 0)
                {
                    RangeFloatAttribute attb = rangeAtts[0] as RangeFloatAttribute;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        float value = GUILayout.HorizontalSlider((float)properties[i].GetValue(imageEffect, null), attb.min, attb.max, GUILayout.ExpandWidth(true));
                        properties[i].SetValue(imageEffect, value, null);
                    }
                    GUILayout.EndHorizontal();
                }

                rangeAtts = properties[i].GetCustomAttributes(typeof(RangeVector2Attribute), false);
                if (rangeAtts.Length > 0)
                {
                    RangeVector2Attribute attb = rangeAtts[0] as RangeVector2Attribute;

                    Vector2 value = (Vector2)properties[i].GetValue(imageEffect, null);

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        value.x = GUILayout.HorizontalSlider(value.x, attb.min.x, attb.max.x, GUILayout.ExpandWidth(true));
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(string.Empty, GUILayout.Width(125));

                        value.y = GUILayout.HorizontalSlider(value.y, attb.min.y, attb.max.y, GUILayout.ExpandWidth(true));
                    }
                    GUILayout.EndHorizontal();

                    properties[i].SetValue(imageEffect, value, null);
                }

                rangeAtts = properties[i].GetCustomAttributes(typeof(RangeVector3Attribute), false);
                if (rangeAtts.Length > 0)
                {
                    RangeVector3Attribute attb = rangeAtts[0] as RangeVector3Attribute;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        Vector3 value = (Vector3)properties[i].GetValue(imageEffect, null);

                        value.x = GUILayout.HorizontalSlider(value.x, attb.min.x, attb.max.x, GUILayout.ExpandWidth(true));
                        value.y = GUILayout.HorizontalSlider(value.y, attb.min.y, attb.max.y, GUILayout.ExpandWidth(true));
                        value.z = GUILayout.HorizontalSlider(value.z, attb.min.z, attb.max.z, GUILayout.ExpandWidth(true));

                        properties[i].SetValue(imageEffect, value, null);
                    }
                    GUILayout.EndHorizontal();
                }
            }

            if (GUILayout.Button(@"Reset") == true)
            {
                imageEffect.ResetDefaultValues();
            }
        }
    }
Esempio n. 6
0
    private void OnGUI()
    {
        if (videoGlitches.Count == 0)
        {
            return;
        }

        if (effectNameStyle == null)
        {
            effectNameStyle           = new GUIStyle(GUI.skin.textArea);
            effectNameStyle.alignment = TextAnchor.MiddleCenter;
            effectNameStyle.fontSize  = 22;
        }

        if (boxStyle == null)
        {
            boxStyle = new GUIStyle(GUI.skin.box);
            boxStyle.normal.background = MakeTex(2, 2, new Color(0.5f, 0.5f, 0.5f, 0.5f));
            boxStyle.focused.textColor = Color.red;
        }

        if (menuStyle == null)
        {
            menuStyle           = new GUIStyle(GUI.skin.textArea);
            menuStyle.alignment = TextAnchor.MiddleCenter;
            menuStyle.fontSize  = 22;
        }

        if (showEffectName == true && guiShow == false)
        {
            string effectName = EffectName(videoGlitches[guiSelection].GetType().ToString());

            GUILayout.BeginArea(new Rect(Screen.width * 0.5f - 150.0f, 20.0f, 300.0f, 30.0f), effectName.ToUpper(), effectNameStyle);
            GUILayout.EndArea();
        }

        if (guiShow == false)
        {
            return;
        }

        GUILayout.BeginHorizontal(boxStyle, GUILayout.Width(Screen.width));
        {
            GUILayout.Space(guiMargen);

            if (GUILayout.Button("MENU", menuStyle, GUILayout.Width(80.0f)) == true)
            {
                menuOpen = !menuOpen;
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("<<<", menuStyle) == true)
            {
                showCustomProperties = false;

                slideEffectTime = 0.0f;

                if (guiSelection > 0)
                {
                    guiSelection--;
                }
                else
                {
                    guiSelection = videoGlitches.Count - 1;
                }

                Event.current.Use();
            }

            GUI.contentColor = Color.white;

            string effectName = EffectName(videoGlitches[guiSelection].GetType().ToString());

            GUILayout.Label(effectName.ToUpper(), menuStyle, GUILayout.Width(325.0f));

            if (GUILayout.Button(">>>", menuStyle) == true)
            {
                showCustomProperties = false;

                slideEffectTime = 0.0f;

                if (guiSelection < videoGlitches.Count - 1)
                {
                    guiSelection++;
                }
                else
                {
                    guiSelection = 0;
                }
            }

            GUILayout.FlexibleSpace();

            if (musicClip != null && GUILayout.Button(@"MUTE", menuStyle) == true)
            {
                AudioListener.volume = 1.0f - AudioListener.volume;
            }

            if (fps < 24.0f)
            {
                GUI.contentColor = Color.yellow;
            }
            else if (fps < 15.0f)
            {
                GUI.contentColor = Color.red;
            }
            else
            {
                GUI.contentColor = Color.green;
            }

            GUILayout.Label(fps.ToString("000"), menuStyle, GUILayout.Width(50.0f));

            GUI.contentColor = Color.white;

            GUILayout.Space(guiMargen);
        }
        GUILayout.EndHorizontal();

        // Update
        for (int i = 0; i < videoGlitches.Count; ++i)
        {
            VideoGlitchBase imageEffect = videoGlitches[i];

            if (guiSelection == i && imageEffect.enabled == false)
            {
                showCustomProperties = false;

                EnableEffect(imageEffect, true);
            }

            if (imageEffect.enabled == true && guiSelection != i)
            {
                imageEffect.enabled = false;
            }
        }

        if (menuOpen == true)
        {
            GUILayout.BeginVertical(boxStyle, GUILayout.Height(Screen.height), GUILayout.Width(guiWidth));
            {
                GUILayout.Space(guiMargen);

                int newScreenMode = GUILayout.Toolbar((int)screenMode, new string[] { @"Full screen", @"Layers" });
                if (newScreenMode != (int)screenMode)
                {
                    screenMode = (ScreenModes)newScreenMode;

                    videoGlitches[guiSelection].EffectMode = screenMode == ScreenModes.Fullscreen ? EffectModes.Screen : EffectModes.Layer;
                }

                GUILayout.Space(guiMargen);

                // Video Glitches.
                if (videoGlitches.Count > 0)
                {
                    scrollPosition = GUILayout.BeginScrollView(scrollPosition, "box");
                    {
                        int effectChanged = -1;

                        // Draw.
                        for (int i = 0; i < videoGlitches.Count; ++i)
                        {
                            VideoGlitchBase imageEffect = videoGlitches[i];

                            GUILayout.BeginVertical(imageEffect.enabled == true ? @"box" : string.Empty);
                            {
                                GUILayout.BeginHorizontal();
                                {
                                    bool enableChanged = GUILayout.Toggle(imageEffect.enabled, guiTab + EffectName(imageEffect.GetType().ToString()));
                                    if (enableChanged != imageEffect.enabled)
                                    {
                                        showCustomProperties = false;

                                        slideEffectTime = 0.0f;

                                        effectChanged = i;
                                    }

                                    if (CustomAttributesCount(imageEffect) > 0)
                                    {
                                        GUILayout.FlexibleSpace();

                                        if (imageEffect.enabled == true && GUILayout.Button(showCustomProperties == true ? @"-" : @"+") == true)
                                        {
                                            slideEffectTime = 0.0f;

                                            showCustomProperties = !showCustomProperties;
                                        }
                                    }
                                }
                                GUILayout.EndHorizontal();

                                if (imageEffect.enabled == true && showCustomProperties == true)
                                {
                                    DrawCustomAttributes(imageEffect);
                                }
                            }
                            GUILayout.EndVertical();

                            GUILayout.Space(guiMargen * 0.5f);
                        }

                        // Update
                        for (int i = 0; i < videoGlitches.Count; ++i)
                        {
                            VideoGlitchBase imageEffect = videoGlitches[i];

                            if (effectChanged == i)
                            {
                                EnableEffect(imageEffect, !imageEffect.enabled);

                                if (imageEffect.enabled == true)
                                {
                                    guiSelection = i;
                                }
                            }

                            if (imageEffect.enabled == true && guiSelection != i)
                            {
                                imageEffect.enabled = false;
                            }
                        }
                    }
                    GUILayout.EndScrollView();
                }
                else
                {
                    GUILayout.Label("No 'Video Glitches' found.");
                }

                GUILayout.FlexibleSpace();

                GUILayout.BeginVertical("box");
                {
                    GUILayout.Label("TAB - Hide/Show gui.");
                    GUILayout.Label("PageUp/Down - Change effects.");
                }
                GUILayout.EndVertical();

                GUILayout.Space(guiMargen);

                if (GUILayout.Button(@"Open Web") == true)
                {
                    Application.OpenURL(@"http://www.ibuprogames.com/2015/07/02/video-glitches/‎");
                }

                GUILayout.Space(guiMargen);
            }
            GUILayout.EndVertical();
        }
    }