コード例 #1
0
        public void HandleKajAnimatable()
        {
            Rect lastRect = GUILayoutUtility.GetLastRect();

            if (ShaderEditor.currentlyDrawing.isLockedMaterial == false && Event.current.isMouse && Event.current.button == 1 && lastRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.control && Config.Singleton.renameAnimatedProps)
                {
                    if (!is_animated)
                    {
                        is_animated = true;
                    }

                    if (is_animated)
                    {
                        is_renaming = !is_renaming;
                    }
                }
                else
                {
                    is_animated = !is_animated;
                }
                ShaderOptimizer.SetAnimatedTag(materialProperty, is_animated ? (is_renaming ? "2" : "1") : "");
                EditorUtility.SetDirty(materialProperty.targets[0]);
            }
            if (is_animated)
            {
                Rect r = new Rect(8, lastRect.y + 2, 16, 16);
                GUI.DrawTexture(r, is_renaming ? Styles.texture_animated_renamed : Styles.texture_animated, ScaleMode.StretchToFill, true);
            }
        }
コード例 #2
0
        //-------------Draw Functions----------------

        public void InitlizeThryUI()
        {
            Config config = Config.Singleton;

            show_eyeIcon_tutorial = !EditorPrefs.GetBool("thry_openeEyeIcon", false);
            active = this;

            //get material targets
            materials = editor.targets.Select(o => o as Material).ToArray();

            shader = materials[0].shader;
            string defaultShaderName = materials[0].shader.name.Split(new string[] { "-queue" }, System.StringSplitOptions.None)[0].Replace(".differentQueues/", "");

            defaultShader = Shader.Find(defaultShaderName);

            animPropertySuffix = new string(materials[0].name.Trim().ToLower().Where(char.IsLetter).ToArray());

            //collect shader properties
            CollectAllProperties();

            if (ShaderOptimizer.IsShaderUsingThryOptimizer(shader))
            {
                ShaderOptimizerProperty = propertyDictionary[ShaderOptimizer.GetOptimizerPropertyName(shader)];
            }

            AddResetProperty();

            firstOnGUICall = false;
        }
コード例 #3
0
        //-------------Draw Functions----------------

        public void InitlizeThryUI()
        {
            Config config = Config.Singleton;

            active = this;

            //get material targets
            materials = editor.targets.Select(o => o as Material).ToArray();

            shader = materials[0].shader;

            animPropertySuffix = ShaderOptimizer.GetAnimPropertySuffix(materials[0]);

            _isPresetEditor = materials.Length == 1 && Presets.ArePreset(materials);

            //collect shader properties
            CollectAllProperties();

            if (ShaderOptimizer.IsShaderUsingThryOptimizer(shader))
            {
                ShaderOptimizerProperty = propertyDictionary[ShaderOptimizer.GetOptimizerPropertyName(shader)];
                if (ShaderOptimizerProperty != null)
                {
                    ShaderOptimizerProperty.exempt_from_locked_disabling = true;
                }
            }

            AddResetProperty();

            firstOnGUICall = false;
        }
コード例 #4
0
        private void OnUpgrade(string oldVersionString)
        {
            Version newVersion = new Version(VERSION);
            Version oldVersion = new Version(oldVersionString);

            //Upgrade locking valuesd from Animated property to tags
            if (newVersion >= "2.11.0" && oldVersion > "2.0" && oldVersion < "2.11.0")
            {
                ShaderOptimizer.UpgradeAnimatedPropertiesToTagsOnAllMaterials();
            }
        }
コード例 #5
0
 public override void CopyToMaterial(Material m)
 {
     MaterialHelper.CopyPropertyValueToMaterial(materialProperty, m);
     if (keyword != null)
     {
         SetKeyword(m, materialProperty.floatValue == 1);
     }
     if (is_animatable)
     {
         ShaderOptimizer.CopyAnimatedTagToMaterials(new Material[] { m }, materialProperty);
     }
 }
コード例 #6
0
 public override void CopyFromMaterial(Material m)
 {
     MaterialHelper.CopyPropertyValueFromMaterial(materialProperty, m);
     if (keyword != null)
     {
         SetKeyword(shaderEditor.materials, m.GetFloat(materialProperty.name) == 1);
     }
     if (is_animatable)
     {
         ShaderOptimizer.CopyAnimatedTagFromMaterial(m, materialProperty);
     }
     this.is_animated = is_animatable && ShaderOptimizer.GetAnimatedTag(materialProperty) != "";
     this.is_renaming = is_animatable && ShaderOptimizer.GetAnimatedTag(materialProperty) == "2";
 }
コード例 #7
0
 public virtual void HandleRightClickToggles(bool isInHeader)
 {
     if (ShaderEditor.input.RightClick && DrawingData.tooltipCheckRect.Contains(Event.current.mousePosition))
     {
         //Preset toggle
         if (Event.current.shift)
         {
             if (shaderEditor._isPresetEditor && isInHeader == false)
             {
                 is_preset = !is_preset;
                 Presets.SetProperty(shaderEditor.materials[0], materialProperty, is_preset);
                 ShaderEditor.Repaint();
                 ShaderEditor.input.Use();
             }
         }
         //Animated toggle
         else
         {
             if (is_animatable && isInHeader == false && this is ShaderHeader == false)
             {
                 if (Event.current.control && Config.Singleton.renameAnimatedProps)
                 {
                     if (!is_animated)
                     {
                         is_animated = true;
                         is_renaming = true;
                     }
                     else if (!is_renaming)
                     {
                         is_renaming = true;
                     }
                     else
                     {
                         is_animated = false;
                         is_renaming = false;
                     }
                 }
                 else
                 {
                     is_animated = !is_animated;
                     is_renaming = false;
                 }
                 ShaderOptimizer.SetAnimatedTag(materialProperty, is_animated ? (is_renaming ? "2" : "1") : "");
                 ShaderEditor.Repaint();
                 ShaderEditor.input.Use();
             }
         }
     }
 }
コード例 #8
0
 public override void TransferFromMaterialAndGroup(Material m, ShaderPart p)
 {
     if (materialProperty.type != p.materialProperty.type)
     {
         return;
     }
     MaterialHelper.CopyMaterialValueFromProperty(materialProperty, p.materialProperty);
     if (keyword != null)
     {
         SetKeyword(shaderEditor.materials, m.GetFloat(p.materialProperty.name) == 1);
     }
     if (is_animatable && p.is_animatable)
     {
         ShaderOptimizer.CopyAnimatedTagFromProperty(p.materialProperty, materialProperty);
     }
     this.is_animated = is_animatable && ShaderOptimizer.GetAnimatedTag(materialProperty) != "";
     this.is_renaming = is_animatable && ShaderOptimizer.GetAnimatedTag(materialProperty) == "2";
 }
コード例 #9
0
        public bool has_not_searchedFor = false; //used for property search

        public ShaderPart(ShaderEditor shaderEditor, MaterialProperty prop, int xOffset, string displayName, PropertyOptions options)
        {
            this.shaderEditor               = shaderEditor;
            this.materialProperty           = prop;
            this.xOffset                    = xOffset;
            this.options                    = options;
            this.content                    = new GUIContent(displayName);
            this.tooltip                    = new BetterTooltips.Tooltip(options.tooltip);
            this.reference_properties_exist = options.reference_properties != null && options.reference_properties.Length > 0;
            this.reference_property_exists  = options.reference_property != null;
            this.is_preset                  = shaderEditor._isPresetEditor && Presets.IsPreset(shaderEditor.materials[0], prop);

            if (prop == null)
            {
                return;
            }
            bool   propHasDuplicate = shaderEditor.GetMaterialProperty(prop.name + "_" + shaderEditor.animPropertySuffix) != null;
            string tag = null;

            //If prop is og, but is duplicated (locked) dont have it animateable
            if (propHasDuplicate)
            {
                this.is_animatable = false;
            }
            else
            {
                //if prop is a duplicated or renamed get og property to check for animted status
                if (prop.name.Contains(shaderEditor.animPropertySuffix))
                {
                    string ogName = prop.name.Substring(0, prop.name.Length - shaderEditor.animPropertySuffix.Length - 1);
                    tag = ShaderOptimizer.GetAnimatedTag(materialProperty.targets[0] as Material, ogName);
                }
                else
                {
                    tag = ShaderOptimizer.GetAnimatedTag(materialProperty);
                }
                this.is_animatable = true;
            }


            this.is_animated = is_animatable && tag != "";
            this.is_renaming = is_animatable && tag == "2";
        }
コード例 #10
0
        static void FixKeywords()
        {
            IEnumerable <Material> materials = AssetDatabase.FindAssets("t:material").Select(g => AssetDatabase.GUIDToAssetPath(g)).Where(p => string.IsNullOrEmpty(p) == false)
                                               .Select(p => AssetDatabase.LoadAssetAtPath <Material>(p)).Where(m => m != null && m.shader != null)
                                               .Where(m => ShaderOptimizer.IsMaterialLocked(m) == false && ShaderHelper.IsShaderUsingThryShaderEditor(m.shader));
            float f     = 0;
            int   count = materials.Count();

            foreach (Material m in materials)
            {
                for (int i = 0; i < m.shader.GetPropertyCount(); i++)
                {
                    if (m.shader.GetPropertyType(i) == UnityEngine.Rendering.ShaderPropertyType.Float)
                    {
                        ShaderHelper.EnableDisableKeywordsBasedOnTheirFloatValue(new Material[] { m }, m.shader, m.shader.GetPropertyName(i));
                    }
                }
                EditorUtility.DisplayProgressBar("Fixing Keywords", m.name, f++ / count);
            }
            EditorUtility.ClearProgressBar();
        }
コード例 #11
0
        //-------------Draw Functions----------------

        public void InitlizeThryUI()
        {
            Config config = Config.Singleton;

            Active = this;
            Helper.RegisterEditorUse();

            //get material targets
            Materials = Editor.targets.Select(o => o as Material).ToArray();

            Shader = Materials[0].shader;

            RenamedPropertySuffix = ShaderOptimizer.GetRenamedPropertySuffix(Materials[0]);

            IsPresetEditor = Materials.Length == 1 && Presets.ArePreset(Materials);

            //collect shader properties
            CollectAllProperties();

            if (ShaderOptimizer.IsShaderUsingThryOptimizer(Shader))
            {
                ShaderOptimizerProperty = PropertyDictionary[ShaderOptimizer.GetOptimizerPropertyName(Shader)];
                if (ShaderOptimizerProperty != null)
                {
                    ShaderOptimizerProperty.ExemptFromLockedDisabling = true;
                }
            }

            _renderQueueProperty = new RenderQueueProperty(this);
            _vRCFallbackProperty = new VRCFallbackProperty(this);
            ShaderParts.Add(_renderQueueProperty);
            ShaderParts.Add(_vRCFallbackProperty);

            AddResetProperty();

            _isFirstOnGUICall = false;
        }
コード例 #12
0
ファイル: Drawers.cs プロジェクト: MaxFerney/462-vr-game
 public override void OnGUI(Rect position, MaterialProperty shaderOptimizer, string label, MaterialEditor materialEditor)
 {
     // Theoretically this shouldn't ever happen since locked in materials have different shaders.
     // But in a case where the material property says its locked in but the material really isn't, this
     // will display and allow users to fix the property/lock in
     ShaderEditor.currentlyDrawing.isLockedMaterial = shaderOptimizer.floatValue == 1;
     if (shaderOptimizer.hasMixedValue)
     {
         EditorGUI.BeginChangeCheck();
         GUILayout.Button("Lock in Optimized Shaders (" + materialEditor.targets.Length + " materials)");
         if (EditorGUI.EndChangeCheck())
         {
             foreach (Material m in materialEditor.targets)
             {
                 m.SetFloat(shaderOptimizer.name, 1);
                 MaterialProperty[] props = MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { m });
                 if (!ShaderOptimizer.Lock(m, props)) // Error locking shader, revert property
                 {
                     m.SetFloat(shaderOptimizer.name, 0);
                 }
             }
         }
     }
     else
     {
         EditorGUI.BeginChangeCheck();
         if (shaderOptimizer.floatValue == 0)
         {
             if (materialEditor.targets.Length == 1)
             {
                 GUILayout.Button("Lock In Optimized Shader");
             }
             else
             {
                 GUILayout.Button("Lock in Optimized Shaders (" + materialEditor.targets.Length + " materials)");
             }
         }
         else
         {
             GUILayout.Button("Unlock Shader");
         }
         if (EditorGUI.EndChangeCheck())
         {
             shaderOptimizer.floatValue = shaderOptimizer.floatValue == 1 ? 0 : 1;
             if (shaderOptimizer.floatValue == 1)
             {
                 foreach (Material m in materialEditor.targets)
                 {
                     MaterialProperty[] props = MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { m });
                     if (!ShaderOptimizer.Lock(m, props))
                     {
                         m.SetFloat(shaderOptimizer.name, 0);
                     }
                 }
             }
             else
             {
                 foreach (Material m in materialEditor.targets)
                 {
                     if (!ShaderOptimizer.Unlock(m))
                     {
                         m.SetFloat(shaderOptimizer.name, 1);
                     }
                 }
             }
         }
     }
     if (ShaderEditor.input.MouseClick)
     {
         if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
         {
             foreach (Material m in materialEditor.targets)
             {
                 ShaderOptimizer.Unlock(m);
                 m.SetFloat(shaderOptimizer.name, 0);
             }
         }
     }
 }
コード例 #13
0
ファイル: Drawers.cs プロジェクト: rygo6/GTPoiyomiToonShader
        public override void OnGUI(Rect position, MaterialProperty shaderOptimizer, string label, MaterialEditor materialEditor)
        {
            bool isLocked = (shaderOptimizer.targets[0] as Material).shader.name.StartsWith("Hidden/") && (shaderOptimizer.targets[0] as Material).GetTag("OriginalShader", false, "") != "";

            //this will make sure the button is unlocked if you manually swap to an unlocked shader
            //shaders that have the ability to be locked shouldnt really be hidden themself. at least it wouldnt make too much sense
            if (shaderOptimizer.hasMixedValue == false && shaderOptimizer.floatValue == 1 && isLocked == false)
            {
                shaderOptimizer.floatValue = 0;
            }
            else if (shaderOptimizer.hasMixedValue == false && shaderOptimizer.floatValue == 0 && isLocked)
            {
                shaderOptimizer.floatValue = 1;
            }

            // Theoretically this shouldn't ever happen since locked in materials have different shaders.
            // But in a case where the material property says its locked in but the material really isn't, this
            // will display and allow users to fix the property/lock in
            ShaderEditor.active.isLockedMaterial = shaderOptimizer.floatValue == 1;
            if (shaderOptimizer.hasMixedValue)
            {
                EditorGUI.BeginChangeCheck();
                GUILayout.Button("Lock in Optimized Shaders (" + materialEditor.targets.Length + " materials)");
                if (EditorGUI.EndChangeCheck())
                {
                    SaveChangeStack();
                    Material[] materials = new Material[shaderOptimizer.targets.Length];
                    for (int i = 0; i < materials.Length; i++)
                    {
                        materials[i] = shaderOptimizer.targets[i] as Material;
                    }
                    ShaderOptimizer.SetLockedForAllMaterials(materials, shaderOptimizer.floatValue == 1 ? 0 : 1, true, false, true, shaderOptimizer);
                    RestoreChangeStack();
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                if (shaderOptimizer.floatValue == 0)
                {
                    if (materialEditor.targets.Length == 1)
                    {
                        GUILayout.Button("Lock In Optimized Shader");
                    }
                    else
                    {
                        GUILayout.Button("Lock in Optimized Shaders (" + materialEditor.targets.Length + " materials)");
                    }
                }
                else
                {
                    GUILayout.Button("Unlock Shader");
                }
                if (EditorGUI.EndChangeCheck())
                {
                    SaveChangeStack();
                    Material[] materials = new Material[shaderOptimizer.targets.Length];
                    for (int i = 0; i < materials.Length; i++)
                    {
                        materials[i] = shaderOptimizer.targets[i] as Material;
                    }
                    ShaderOptimizer.SetLockedForAllMaterials(materials, shaderOptimizer.floatValue == 1 ? 0 : 1, true, false, true, shaderOptimizer);
                    RestoreChangeStack();
                }
            }
        }
コード例 #14
0
 static void MenuUpgradeAnimatedPropertiesToTagsOnAllMaterials()
 {
     ShaderOptimizer.UpgradeAnimatedPropertiesToTagsOnAllMaterials();
 }
コード例 #15
0
 private void HandleReset()
 {
     MaterialLinker.UnlinkAll(Materials[0]);
     ShaderOptimizer.DeleteTags(Materials);
 }
コード例 #16
0
        public bool Test()
        {
            Init();
            if (_hasConstantValue)
            {
                return(_constantValue);
            }

            MaterialProperty materialProperty = null;

            switch (type)
            {
            case DefineableConditionType.PROPERTY_BOOL:
                materialProperty = GetMaterialProperty();
                if (materialProperty == null)
                {
                    return(false);
                }
                if (_compareType == CompareType.NONE)
                {
                    return(materialProperty.floatValue == 1);
                }
                if (_compareType == CompareType.EQUAL)
                {
                    return(materialProperty.floatValue == _floatValue);
                }
                if (_compareType == CompareType.NOT_EQUAL)
                {
                    return(materialProperty.floatValue != _floatValue);
                }
                if (_compareType == CompareType.SMALLER)
                {
                    return(materialProperty.floatValue < _floatValue);
                }
                if (_compareType == CompareType.BIGGER)
                {
                    return(materialProperty.floatValue > _floatValue);
                }
                if (_compareType == CompareType.BIGGER_EQ)
                {
                    return(materialProperty.floatValue >= _floatValue);
                }
                if (_compareType == CompareType.SMALLER_EQ)
                {
                    return(materialProperty.floatValue <= _floatValue);
                }
                break;

            case DefineableConditionType.TEXTURE_SET:
                materialProperty = GetMaterialProperty();
                if (materialProperty == null)
                {
                    return(false);
                }
                return(materialProperty.textureValue != null);

            case DefineableConditionType.DROPDOWN:
                materialProperty = GetMaterialProperty();
                if (materialProperty == null)
                {
                    return(false);
                }
                if (_compareType == CompareType.NONE)
                {
                    return(materialProperty.floatValue == 1);
                }
                if (_compareType == CompareType.EQUAL)
                {
                    return("" + materialProperty.floatValue == _value);
                }
                if (_compareType == CompareType.NOT_EQUAL)
                {
                    return("" + materialProperty.floatValue != _value);
                }
                break;

            case DefineableConditionType.PROPERTY_IS_ANIMATED:
                return(ShaderOptimizer.IsAnimated(_materialInsteadOfEditor, _obj));

            case DefineableConditionType.PROPERTY_IS_NOT_ANIMATED:
                return(!ShaderOptimizer.IsAnimated(_materialInsteadOfEditor, _obj));

            case DefineableConditionType.AND:
                if (condition1 != null && condition2 != null)
                {
                    return(condition1.Test() && condition2.Test());
                }
                break;

            case DefineableConditionType.OR:
                if (condition1 != null && condition2 != null)
                {
                    return(condition1.Test() || condition2.Test());
                }
                break;
            }

            return(true);
        }