/// <summary>
 /// Forces the <see cref="BlendModeEffect"/> to apply material properties on next update.
 /// </summary>
 protected void SetBlendMaterialDirty()
 {
     if (BlendModeEffect)
     {
         BlendModeEffect.SetMaterialDirty();
     }
 }
Beispiel #2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (!BlendModeEffect.IsComponentExtensionValid)
            {
                InstallComponentExtensionGUI();
                serializedObject.ApplyModifiedProperties();
                return;
            }

            if (!BlendModeEffect.IsShaderFamilySupported(BlendModeEffect.ShaderFamily))
            {
                ShaderFamilyGUI();
                InstallShaderExtensionGUI();
                serializedObject.ApplyModifiedProperties();
                return;
            }

            BlendModeGUI();
            ShaderFamilyGUI();
            RenderModeGUI();
            MaskingGUI();
            OptimizationsGUI();

            if (shaderPropertiesList != null)
            {
                shaderPropertiesList.DrawList();
            }

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #3
0
        private void OptimizationsGUI()
        {
            if (BlendModeEffect.RenderMode == RenderMode.TextureWithSelf && !ComponentExtension.AllowMaterialSharing())
            {
                if (shareMaterialProperty.boolValue)
                {
                    shareMaterialProperty.boolValue = false;
                    BlendModeEffect.SetShareMaterial(false);
                }
                return;
            }

            var rect = EditorGUILayout.GetControlRect();

            rect       = EditorGUI.PrefixLabel(rect, optimizationsContent);
            rect.width = rect.width / 2;

            if (BlendModeEffect.RenderMode == RenderMode.TextureWithSelf)
            {
                EditorGUI.BeginChangeCheck();
                ToggleLeftGUI(rect, shareMaterialProperty, shareMaterialContent);
                if (EditorGUI.EndChangeCheck())
                {
                    BlendModeEffect.SetShareMaterial(shareMaterialProperty.boolValue);
                }
                return;
            }
            else if (shareMaterialProperty.boolValue)
            {
                shareMaterialProperty.boolValue = false;
                BlendModeEffect.SetShareMaterial(false);
            }

            var supportsUnifiedGrab = ExtensionManager.ShaderResources.FamilyImplementsUnifiedGrab(BlendModeEffect.ShaderFamily);
            var supportsFramebuffer = ExtensionManager.ShaderResources.FamilyImplementsFramebuffer(BlendModeEffect.ShaderFamily);

            if (!supportsUnifiedGrab && !supportsFramebuffer)
            {
                unifiedGrabEnabledProperty.boolValue = false;
                framebufferEnabledProperty.boolValue = false;
                return;
            }
            if (supportsUnifiedGrab)
            {
                ToggleLeftGUI(rect, unifiedGrabEnabledProperty, unifiedGrabEnabledContent);
                rect.x += rect.width;
            }
            else
            {
                unifiedGrabEnabledProperty.boolValue = false;
            }
            if (supportsFramebuffer)
            {
                ToggleLeftGUI(rect, framebufferEnabledProperty, framebufferEnabledContent);
            }
            else
            {
                framebufferEnabledProperty.boolValue = false;
            }
        }
Beispiel #4
0
 private void InstallShaderExtensionGUI()
 {
     if (!ExtensionManager.IsShaderExtensionAvailable(BlendModeEffect.ShaderFamily))
     {
         EditorGUILayout.HelpBox(string.Format("`{0}` shader family is not available.", BlendModeEffect.ShaderFamily), MessageType.Warning);
         EditorGUILayout.HelpBox("You can add your own shader extensions; see `Adding shader extensions` in the docs for more info.", MessageType.Info);
         return;
     }
     EditorGUILayout.HelpBox(string.Format("`{0}` shader extension is available, but not installed.", BlendModeEffect.ShaderFamily), MessageType.Info);
     if (GUILayout.Button("Install shader extension"))
     {
         ExtensionManager.InstallShaderExtension(BlendModeEffect.ShaderFamily);
         BlendModeEffect.InitializeComponentExtension();
     }
 }
Beispiel #5
0
        private void InstallComponentExtensionGUI()
        {
            if (!ExtensionManager.IsObjectContainsSupportedComponent(BlendModeEffect.gameObject))
            {
                EditorGUILayout.HelpBox(string.Format("`{0}` game object doesn't have a supported component.", BlendModeEffect.gameObject.name), MessageType.Warning);
                EditorGUILayout.HelpBox("You can add your own component extensions; see `Adding component extensions` in the docs for more info.", MessageType.Info);
                return;
            }
            var extendedType = ExtensionManager.GetSupportedComponentOnObject(BlendModeEffect.gameObject).GetType().FullName;

            EditorGUILayout.HelpBox(string.Format("Component extension for `{0}` is available, but not installed.", extendedType), MessageType.Info);
            if (GUILayout.Button("Install component extension"))
            {
                ExtensionManager.InstallComponentExtension(extendedType);
                BlendModeEffect.InitializeComponentExtension();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Based on the current requirements of the provided <see cref="BlendModeEffect"/> object
        /// and shader, retrieves a cached or creates new material and adds it to the cache.
        /// </summary>
        public static Material GetSharedFor(Shader shader, BlendModeEffect blendModeEffect, out bool materialCreated)
        {
            materialCreated = false;
            var blendModeKeyword = blendModeEffect.BlendMode.ToShaderKeyword();

            for (int i = 0; i < cachedMaterials.Count; i++)
            {
                var material = cachedMaterials[i];
                if (!material)
                {
                    continue;
                }
                if (material.shader == shader && material.IsKeywordEnabled(blendModeKeyword))
                {
                    return(material);
                }
            }
            materialCreated = true;
            return(CreateCachedMaterial(shader));
        }
Beispiel #7
0
        private void OnEnable()
        {
            shaderFamilyProperty         = serializedObject.FindProperty("shaderFamily");
            blendModeProperty            = serializedObject.FindProperty("blendMode");
            renderModeProperty           = serializedObject.FindProperty("renderMode");
            overlayColorProperty         = serializedObject.FindProperty("overlayColor");
            overlayTextureProperty       = serializedObject.FindProperty("overlayTexture");
            overlayTextureOffsetProperty = serializedObject.FindProperty("overlayTextureOffset");
            overlayTextureScaleProperty  = serializedObject.FindProperty("overlayTextureScale");
            maskModeProperty             = serializedObject.FindProperty("maskMode");
            maskBehaviourProperty        = serializedObject.FindProperty("maskBehaviour");
            framebufferEnabledProperty   = serializedObject.FindProperty("framebufferEnabled");
            unifiedGrabEnabledProperty   = serializedObject.FindProperty("unifiedGrabEnabled");
            shareMaterialProperty        = serializedObject.FindProperty("shareMaterial");
            componentExtensionProperty   = serializedObject.FindProperty("componentExtension");

            componentExtensionEditor = CreateEditor(componentExtensionProperty.objectReferenceValue);

            BlendModeEffect.InitializeComponentExtension();
        }
Beispiel #8
0
        private void OnEnable()
        {
            if (BlendModeEffect)
            {
                BlendModeEffect.InitializeComponentExtension();
                var shaderPropertiesProperty = serializedObject.FindProperty("componentExtensionState").FindPropertyRelative("shaderProperties");
                shaderPropertiesList = new ShaderPropertiesList(serializedObject, shaderPropertiesProperty, BlendModeEffect.GetComponentExtension <ComponentExtension>());
            }

            shaderFamilyProperty         = serializedObject.FindProperty("shaderFamily");
            blendModeProperty            = serializedObject.FindProperty("blendMode");
            renderModeProperty           = serializedObject.FindProperty("renderMode");
            overlayColorProperty         = serializedObject.FindProperty("overlayColor");
            overlayTextureProperty       = serializedObject.FindProperty("overlayTexture");
            overlayTextureOffsetProperty = serializedObject.FindProperty("overlayTextureOffset");
            overlayTextureScaleProperty  = serializedObject.FindProperty("overlayTextureScale");
            maskModeProperty             = serializedObject.FindProperty("maskMode");
            maskBehaviourProperty        = serializedObject.FindProperty("maskBehaviour");
            framebufferEnabledProperty   = serializedObject.FindProperty("framebufferEnabled");
            unifiedGrabEnabledProperty   = serializedObject.FindProperty("unifiedGrabEnabled");
            shareMaterialProperty        = serializedObject.FindProperty("shareMaterial");
        }
Beispiel #9
0
 private void Awake()
 {
     blendModeEffect = GetComponent <BlendModeEffect>();
 }
Beispiel #10
0
 private void Awake()
 {
     blendModeEffect = GetComponent <BlendModeEffect>();
     cameraOverlay   = GetComponent <CameraOverlay>();
 }