public override void OnInspectorGUI()
    {
        FadeObjectOptions fadeOption = target as FadeObjectOptions;

        EditorGUILayout.BeginHorizontal();
        fadeOption.OverrideFinalAlpha = EditorGUILayout.Toggle(
            new GUIContent("Override Alpha", "Override the final alpha this object fades to, value should be between 0 and 1"),
            fadeOption.OverrideFinalAlpha);
        if (fadeOption.OverrideFinalAlpha)
        {
            fadeOption.FinalAlpha = EditorGUILayout.FloatField(fadeOption.FinalAlpha);
            if (fadeOption.FinalAlpha < 0)
            {
                fadeOption.FinalAlpha = 0;
            }
            if (fadeOption.FinalAlpha > 1)
            {
                fadeOption.FinalAlpha = 1;
            }
        }
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.BeginHorizontal();
        fadeOption.OverrideFadeOutSeconds = EditorGUILayout.Toggle(
            new GUIContent("Fade Out Seconds", "Override the number of seconds this object takes to fade to it's final alpha"),
            fadeOption.OverrideFadeOutSeconds);
        if (fadeOption.OverrideFadeOutSeconds)
        {
            fadeOption.FadeOutSeconds = EditorGUILayout.FloatField(fadeOption.FadeOutSeconds);
            if (fadeOption.FadeOutSeconds < 0)
            {
                fadeOption.FadeOutSeconds = 0;
            }
        }
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.BeginHorizontal();
        fadeOption.OverrideFadeInSeconds = EditorGUILayout.Toggle(
            new GUIContent("Fade In Seconds", "Override the number of seconds this object takes to fade to it's final alpha"),
            fadeOption.OverrideFadeInSeconds);
        if (fadeOption.OverrideFadeInSeconds)
        {
            fadeOption.FadeInSeconds = EditorGUILayout.FloatField(fadeOption.FadeInSeconds);
            if (fadeOption.FadeInSeconds < 0)
            {
                fadeOption.FadeInSeconds = 0;
            }
        }
        EditorGUILayout.EndHorizontal();
    }
    private void FadeObstructions(List <GameObject> objectsInWay)
    {
        foreach (GameObject go in objectsInWay)
        {
            // If the object is already hidden
            FadeObject hiddenObject = HiddenObjects.FirstOrDefault(x => x.GameObject == go);
            if (hiddenObject == null)
            {
                // Get the object fade options
                FadeObjectOptions fadeObjectOptions = go.GetComponent <FadeObjectOptions>();

                // If the maximum fade is set to 1 then this object won't be hidden, so skip it
                if (fadeObjectOptions != null && fadeObjectOptions.OverrideFinalAlpha && fadeObjectOptions.FinalAlpha == 1)
                {
                    continue;
                }

                hiddenObject = new FadeObject {
                    GameObject = go, TransparencyLevel = 1.0f
                };

                //
                hiddenObject.Options = fadeObjectOptions;

                // Add to hidden objects
                HiddenObjects.Add(hiddenObject);
                go.AddComponent <NotifyFadeSystem>();
            }
        }

        // Unhide the objects that are not hidden anymore
        HiddenObjects.RemoveAll(x =>
        {
            float fadeOutSeconds = x.Options != null && x.Options.OverrideFadeOutSeconds ? x.Options.FadeOutSeconds : FadeOutSeconds;
            float fadeInSeconds  = x.Options != null && x.Options.OverrideFadeInSeconds ? x.Options.FadeInSeconds : FadeInSeconds;

            foreach (GameObject go in objectsInWay)
            {
                if (go == x.GameObject)
                {
                    // Change the transparency of already hidden items
                    float maximumFade = x.Options != null && x.Options.OverrideFinalAlpha ? x.Options.FinalAlpha : FinalAlpha;
                    if (x.TransparencyLevel > maximumFade)
                    {
                        x.TransparencyLevel -= Time.deltaTime * (1.0f / fadeOutSeconds);

                        if (x.TransparencyLevel <= maximumFade)
                        {
                            x.TransparencyLevel = maximumFade;
                        }

                        foreach (Material m in x.GameObject.GetComponent <Renderer>().materials)
                        {
                            m.color = new Color(m.color.r, m.color.g, m.color.b, x.TransparencyLevel);
                        }

                        // Reached the intended level of fade, disable the renderer if the alpha is 0
                        if (x.TransparencyLevel == maximumFade && x.TransparencyLevel == 0)
                        {
                            x.GameObject.GetComponent <Renderer>().enabled = false;
                        }
                    }

                    return(false);
                }
            }

            // Bring the object up to full transparency before removing it from the fade list
            if (x.TransparencyLevel < 1.0f)
            {
                // Renable the renderer if the transparency level was 0
                if (x.TransparencyLevel == 0)
                {
                    x.GameObject.GetComponent <Renderer>().enabled = true;
                }

                x.TransparencyLevel += Time.deltaTime * (1.0f / fadeInSeconds);
                if (x.TransparencyLevel > 1)
                {
                    x.TransparencyLevel = 1;
                }

                foreach (Material m in x.GameObject.GetComponent <Renderer>().materials)
                {
                    m.color = new Color(m.color.r, m.color.g, m.color.b, x.TransparencyLevel);
                }

                return(false);
            }

            // Remove the FadedObject monobehaviour
            Destroy(x.GameObject.GetComponent <NotifyFadeSystem>());

            return(true);
        });
    }