Exemple #1
0
        //-------------Draw Functions----------------

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

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

            currentlyDrawing = editorData;
            active           = this;

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

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

            editorData.defaultShader = Shader.Find(defaultShaderName);

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

            currentlyDrawing = editorData;

            //collect shader properties
            CollectAllProperties();

            ShaderOptimizerProperty = editorData.propertyDictionary?["_ShaderOptimizerEnabled"];

            AddResetProperty();

            firstOnGUICall = false;
        }
Exemple #2
0
 public void HanldeDropEvent(MaterialProperty prop, ShaderProperty shaderProperty)
 {
     string[] paths = DragAndDrop.paths;
     if (AssetDatabase.GetMainAssetTypeAtPath(paths[0]) != typeof(Texture2DArray))
     {
         Texture2DArray tex = Converter.PathsToTexture2DArray(paths);
         MaterialHelper.UpdateTargetsValue(prop, tex);
         if (shaderProperty.options.reference_property != null)
         {
             ShaderProperty p;
             if (ShaderEditor.currentlyDrawing.propertyDictionary.TryGetValue(shaderProperty.options.reference_property, out p))
             {
                 MaterialHelper.UpdateFloatValue(p.materialProperty, tex.depth);
             }
         }
         prop.textureValue = tex;
     }
     else
     {
         Texture2DArray tex = AssetDatabase.LoadAssetAtPath <Texture2DArray>(paths[0]);
         prop.textureValue = tex;
         if (shaderProperty.options.reference_property != null)
         {
             ShaderProperty p;
             if (ShaderEditor.currentlyDrawing.propertyDictionary.TryGetValue(shaderProperty.options.reference_property, out p))
             {
                 MaterialHelper.UpdateFloatValue(p.materialProperty, tex.depth);
             }
         }
     }
 }
        private void DrawBoxAndContent(Rect rect, Event e, GUIContent content, PropertyOptions options, GUIStyle style)
        {
            if (options.reference_property != null)
            {
                GUI.Box(rect, "", style);
                DrawIcons(rect, e);
                DrawButton(rect, options, e, style);

                Rect togglePropertyRect = new Rect(rect);
                togglePropertyRect.x -= 11;
                togglePropertyRect.y += 2;
                ShaderProperty prop       = ThryEditor.currentlyDrawing.propertyDictionary[options.reference_property];
                float          labelWidth = EditorGUIUtility.labelWidth;
                float          fieldWidth = EditorGUIUtility.fieldWidth;
                EditorGUIUtility.labelWidth = UnityHelper.CalculateLengthOfText(prop.content.text) + EditorGUI.indentLevel * 15 + 45;
                EditorGUIUtility.fieldWidth = 20;
                prop.Draw(new CRect(togglePropertyRect), content);
                EditorGUIUtility.labelWidth = labelWidth;
                EditorGUIUtility.fieldWidth = fieldWidth;
            }
            else
            {
                GUI.Box(rect, content, style);
                DrawIcons(rect, e);
                DrawButton(rect, options, e, style);
            }
        }
Exemple #4
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;
        }
Exemple #5
0
        public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor)
        {
            ShaderProperty shaderProperty = (ShaderProperty)ShaderEditor.currentlyDrawing.currentProperty;

            GuiHelper.drawConfigTextureProperty(position, prop, label, editor, true, true);

            string n = "";

            if (prop.textureValue != null)
            {
                n = prop.textureValue.name;
            }
            if ((ShaderEditor.input.is_drag_drop_event) && position.Contains(ShaderEditor.input.mouse_position))
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                if (ShaderEditor.input.is_drop_event)
                {
                    DragAndDrop.AcceptDrag();
                    HanldeDropEvent(prop, shaderProperty);
                }
            }
            if (ShaderEditor.currentlyDrawing.firstCall)
            {
                ShaderEditor.currentlyDrawing.textureArrayProperties.Add(shaderProperty);
            }
        }
Exemple #6
0
        private void DrawBoxAndContent(Rect rect, Event e, GUIContent content, PropertyOptions options, GUIStyle style)
        {
            if (options.reference_property != null)
            {
                GUI.Box(rect, new GUIContent("     " + content.text, content.tooltip), style);
                DrawIcons(rect, e);
                DrawButton(rect, options, e, style);

                Rect togglePropertyRect = new Rect(rect);
                togglePropertyRect.x      += 5;
                togglePropertyRect.y      += 2;
                togglePropertyRect.height -= 4;
                togglePropertyRect.width   = GUI.skin.font.fontSize * 3;
                float fieldWidth = EditorGUIUtility.fieldWidth;
                EditorGUIUtility.fieldWidth = 20;
                ShaderProperty prop = ShaderEditor.currentlyDrawing.propertyDictionary[options.reference_property];

                int xOffset = prop.xOffset;
                prop.xOffset = 0;
                prop.Draw(new CRect(togglePropertyRect), new GUIContent(), isInHeader: true);
                prop.xOffset = xOffset;
                EditorGUIUtility.fieldWidth = fieldWidth;
            }
            else
            {
                GUI.Box(rect, content, style);
                DrawIcons(rect, e);
                DrawButton(rect, options, e, style);
            }
        }
        public static void drawSmallTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties)
        {
            Rect thumbnailPos = position;

            thumbnailPos.x += hasFoldoutProperties ? 20 : 0;
            editor.TexturePropertyMiniThumbnail(thumbnailPos, prop, label.text, (hasFoldoutProperties ? "Click here for extra properties" : "") + (label.tooltip != "" ? " | " : "") + label.tooltip);
            if (DrawingData.currentTexProperty.reference_property_exists)
            {
                ShaderProperty property = ThryEditor.currentlyDrawing.propertyDictionary[DrawingData.currentTexProperty.options.reference_property];
                Rect           r        = position;
                r.x     += EditorGUIUtility.labelWidth - CurrentIndentWidth();
                r.width -= EditorGUIUtility.labelWidth - CurrentIndentWidth();
                property.Draw(new CRect(r), new GUIContent());
            }
            if (hasFoldoutProperties && DrawingData.currentTexProperty != null)
            {
                //draw dropdown triangle
                thumbnailPos.x += DrawingData.currentTexProperty.xOffset * 15;
                if (Event.current.type == EventType.Repaint)
                {
                    EditorStyles.foldout.Draw(thumbnailPos, false, false, DrawingData.currentTexProperty.showFoldoutProperties, false);
                }

                if (DrawingData.is_enabled)
                {
                    //test click and draw scale/offset
                    if (DrawingData.currentTexProperty.showFoldoutProperties)
                    {
                        EditorGUI.indentLevel += 2;
                        if (DrawingData.currentTexProperty.hasScaleOffset)
                        {
                            ThryEditor.currentlyDrawing.editor.TextureScaleOffsetProperty(prop);
                        }

                        PropertyOptions options = DrawingData.currentTexProperty.options;
                        if (options.reference_properties != null)
                        {
                            foreach (string r_property in options.reference_properties)
                            {
                                ShaderProperty property = ThryEditor.currentlyDrawing.propertyDictionary[r_property];
                                property.Draw(useEditorIndent: true);
                            }
                        }
                        EditorGUI.indentLevel -= 2;
                    }
                    if (ThryEditor.input.MouseClick && position.Contains(Event.current.mousePosition))
                    {
                        DrawingData.currentTexProperty.showFoldoutProperties = !DrawingData.currentTexProperty.showFoldoutProperties;
                        editor.Repaint();
                    }
                }
            }

            DrawingData.lastGuiObjectHeaderRect = position;
            Rect object_rect = new Rect(position);

            object_rect.height            = GUILayoutUtility.GetLastRect().y - object_rect.y + GUILayoutUtility.GetLastRect().height;
            DrawingData.lastGuiObjectRect = object_rect;
        }
Exemple #8
0
 private void CopyReferencePropertiesToMaterial(Material target)
 {
     if (options.reference_properties != null)
     {
         foreach (string r_property in options.reference_properties)
         {
             ShaderProperty property = ThryEditor.currentlyDrawing.propertyDictionary[r_property];
             MaterialHelper.CopyPropertyValueToMaterial(property.materialProperty, target);
         }
     }
 }
Exemple #9
0
 private void CopyReferencePropertiesFromMaterial(Material source)
 {
     if (options.reference_properties != null)
     {
         foreach (string r_property in options.reference_properties)
         {
             ShaderProperty property = ShaderEditor.currentlyDrawing.propertyDictionary[r_property];
             MaterialHelper.CopyPropertyValueFromMaterial(property.materialProperty, source);
         }
     }
 }
Exemple #10
0
        public void Init()
        {
            if (_isInit)
            {
                return;
            }
            _hasConstantValue = true;
            if (type == DefineableConditionType.NONE)
            {
                _constantValue = true;
            }
            else if (type == DefineableConditionType.TRUE)
            {
                _constantValue = true;
            }
            else if (type == DefineableConditionType.FALSE)
            {
                _constantValue = false;
            }
            else
            {
                var(compareType, compareString) = GetComparetor();
                _compareType = compareType;

                string[] parts = Regex.Split(data, compareString);
                _obj   = parts[0];
                _value = parts[parts.Length - 1];

                _floatValue = Parser.ParseFloat(_value);
                if (ShaderEditor.Active != null && ShaderEditor.Active.PropertyDictionary.ContainsKey(_obj))
                {
                    _propertyObj = ShaderEditor.Active.PropertyDictionary[_obj];
                }

                if (type == DefineableConditionType.EDITOR_VERSION)
                {
                    InitEditorVersion();
                }
                else if (type == DefineableConditionType.VRC_SDK_VERSION)
                {
                    InitVRCSDKVersion();
                }
                else
                {
                    _hasConstantValue = false;
                }
            }

            _isInit = true;
        }
Exemple #11
0
        private void DrawBoxAndContent(Rect rect, Event e, GUIContent content, PropertyOptions options)
        {
            if (options.reference_property != null && ShaderEditor.active.propertyDictionary.ContainsKey(options.reference_property))
            {
                GUI.Box(rect, new GUIContent("     " + content.text, content.tooltip), Styles.dropDownHeader);
                DrawIcons(rect, e);
                DrawButton(rect, options, e);

                Rect togglePropertyRect = new Rect(rect);
                togglePropertyRect.x      += 5;
                togglePropertyRect.y      += 2;
                togglePropertyRect.height -= 4;
                togglePropertyRect.width   = GUI.skin.font.fontSize * 3;
                float fieldWidth = EditorGUIUtility.fieldWidth;
                EditorGUIUtility.fieldWidth = 20;
                ShaderProperty prop = ShaderEditor.active.propertyDictionary[options.reference_property];

                int xOffset = prop.xOffset;
                prop.xOffset = 0;
                prop.Draw(new CRect(togglePropertyRect), new GUIContent(), isInHeader: true);
                prop.xOffset = xOffset;
                EditorGUIUtility.fieldWidth = fieldWidth;
            }
            else if (keyword != null)
            {
                GUI.Box(rect, "     " + content.text, Styles.dropDownHeader);
                DrawIcons(rect, e);
                DrawButton(rect, options, e);

                Rect togglePropertyRect = new Rect(rect);
                togglePropertyRect.x    += 20;
                togglePropertyRect.width = 20;

                EditorGUI.BeginChangeCheck();
                bool keywordOn = EditorGUI.Toggle(togglePropertyRect, "", ShaderEditor.active.materials[0].IsKeywordEnabled(keyword));
                if (EditorGUI.EndChangeCheck())
                {
                    MaterialHelper.ToggleKeyword(ShaderEditor.active.materials, keyword, keywordOn);
                }
            }
            else
            {
                GUI.Box(rect, content, Styles.dropDownHeader);
                DrawIcons(rect, e);
                DrawButton(rect, options, e);
            }
        }
Exemple #12
0
        public void HanldeDropEvent(MaterialProperty prop, ShaderProperty shaderProperty)
        {
            string[]       paths = DragAndDrop.paths;
            Texture2DArray tex;

            if (AssetDatabase.GetMainAssetTypeAtPath(paths[0]) != typeof(Texture2DArray))
            {
                tex = Converter.PathsToTexture2DArray(paths);
                MaterialHelper.UpdateTargetsValue(prop, tex);
            }
            else
            {
                tex = AssetDatabase.LoadAssetAtPath <Texture2DArray>(paths[0]);
            }
            prop.textureValue = tex;
            UpdateFramesProperty(prop, shaderProperty, tex);
        }
Exemple #13
0
        private void TransferReferencePropertiesToMaterial(Material target, ShaderPart p)
        {
            if (p.options.reference_properties == null || this.options.reference_properties == null)
            {
                return;
            }
            for (int i = 0; i < p.options.reference_properties.Length && i < options.reference_properties.Length; i++)
            {
                if (shaderEditor.propertyDictionary.ContainsKey(this.options.reference_properties[i]) == false)
                {
                    continue;
                }

                ShaderProperty targetP = shaderEditor.propertyDictionary[this.options.reference_properties[i]];
                ShaderProperty sourceP = p.shaderEditor.propertyDictionary[p.options.reference_properties[i]];
                MaterialHelper.CopyMaterialValueFromProperty(targetP.materialProperty, sourceP.materialProperty);
            }
        }
Exemple #14
0
 private void UpdateFramesProperty(MaterialProperty prop, ShaderProperty shaderProperty, Texture2DArray tex)
 {
     if (framesProperty != null)
     {
         ShaderProperty p;
         if (ShaderEditor.active.propertyDictionary.TryGetValue(framesProperty, out p))
         {
             MaterialHelper.UpdateFloatValue(p.materialProperty, tex.depth);
         }
     }
     else if (shaderProperty.options.reference_property != null)
     {
         ShaderProperty p;
         if (ShaderEditor.active.propertyDictionary.TryGetValue(shaderProperty.options.reference_property, out p))
         {
             MaterialHelper.UpdateFloatValue(p.materialProperty, tex.depth);
         }
     }
 }
Exemple #15
0
        public bool Test()
        {
            switch (type)
            {
            case DefineableConditionType.NONE:
                return(true);

            case DefineableConditionType.TRUE:
                return(true);

            case DefineableConditionType.FALSE:
                return(false);
            }
            string comparator = GetComparetor();

            string[] parts = Regex.Split(data, comparator);
            string   obj   = parts[0];
            string   value = parts[parts.Length - 1];

            switch (type)
            {
            case DefineableConditionType.PROPERTY_BOOL:
                ShaderProperty prop = ThryEditor.currentlyDrawing.propertyDictionary[obj];
                if (prop == null)
                {
                    return(false);
                }
                if (comparator == "##")
                {
                    return(prop.materialProperty.floatValue == 1);
                }
                if (comparator == "==")
                {
                    return("" + prop.materialProperty.floatValue == parts[1]);
                }
                if (comparator == "!=")
                {
                    return("" + prop.materialProperty.floatValue != parts[1]);
                }
                break;

            case DefineableConditionType.EDITOR_VERSION:
                int c_ev = Helper.compareVersions(Config.Get().verion, value);
                if (comparator == "==")
                {
                    return(c_ev == 0);
                }
                if (comparator == "!=")
                {
                    return(c_ev != 0);
                }
                if (comparator == "<")
                {
                    return(c_ev == 1);
                }
                if (comparator == ">")
                {
                    return(c_ev == -1);
                }
                if (comparator == ">=")
                {
                    return(c_ev == -1 || c_ev == 0);
                }
                if (comparator == "<=")
                {
                    return(c_ev == 1 || c_ev == 0);
                }
                break;

            case DefineableConditionType.VRC_SDK_VERSION:
                int c_vrc = Helper.compareVersions(VRCInterface.Get().installed_sdk_version, value);
                if (comparator == "==")
                {
                    return(c_vrc == 0);
                }
                if (comparator == "!=")
                {
                    return(c_vrc != 0);
                }
                if (comparator == "<")
                {
                    return(c_vrc == 1);
                }
                if (comparator == ">")
                {
                    return(c_vrc == -1);
                }
                if (comparator == ">=")
                {
                    return(c_vrc == -1 || c_vrc == 0);
                }
                if (comparator == "<=")
                {
                    return(c_vrc == 1 || c_vrc == 0);
                }
                break;

            case DefineableConditionType.TEXTURE_SET:
                ShaderProperty shaderProperty = ThryEditor.currentlyDrawing.propertyDictionary[data];
                if (shaderProperty == null)
                {
                    return(false);
                }
                return(shaderProperty.materialProperty.textureValue != null);

            case DefineableConditionType.DROPDOWN:
                ShaderProperty dropdownProperty = ThryEditor.currentlyDrawing.propertyDictionary[obj];
                if (dropdownProperty == null)
                {
                    return(false);
                }
                if (comparator == "##")
                {
                    return(dropdownProperty.materialProperty.floatValue == 1);
                }
                if (comparator == "==")
                {
                    return("" + dropdownProperty.materialProperty.floatValue == parts[1]);
                }
                if (comparator == "!=")
                {
                    return("" + dropdownProperty.materialProperty.floatValue != parts[1]);
                }
                break;

            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);
        }
Exemple #16
0
        //finds all properties and headers and stores them in correct order
        private void CollectAllProperties()
        {
            //load display names from file if it exists
            MaterialProperty[]          props  = Properties;
            Dictionary <string, string> labels = LoadDisplayNamesFromFile();

            LoadLocales();

            PropertyDictionary = new Dictionary <string, ShaderProperty>();
            ShaderParts        = new List <ShaderPart>();
            MainGroup          = new ShaderGroup(this);                  //init top object that all Shader Objects are childs of
            Stack <ShaderGroup> headerStack = new Stack <ShaderGroup>(); //header stack. used to keep track if editorData header to parent new objects to

            headerStack.Push(MainGroup);                                 //add top object as top object to stack
            headerStack.Push(MainGroup);                                 //add top object a second time, because it get's popped with first actual header item
            _footers = new List <FooterButton>();                        //init footer list
            int headerCount = 0;

            for (int i = 0; i < props.Length; i++)
            {
                string displayName = props[i].displayName;

                //Load from label file
                if (labels.ContainsKey(props[i].name))
                {
                    displayName = labels[props[i].name];
                }

                //Check for locale
                if (Locale != null)
                {
                    if (displayName.StartsWith("locale::", StringComparison.Ordinal))
                    {
                        if (Locale.Constains(displayName))
                        {
                            displayName = Locale.Get(displayName);
                        }
                    }
                }
                //extract json data from display name
                PropertyOptions options = ExtractExtraOptionsFromDisplayName(ref displayName);

                int offset = options.offset + headerCount;

                DrawingData.ResetLastDrawerData();
                Editor.GetPropertyHeight(props[i]);

                ThryPropertyType type = GetPropertyType(props[i], options);
                switch (type)
                {
                case ThryPropertyType.header:
                    headerStack.Pop();
                    break;

                case ThryPropertyType.legacy_header:
                    headerStack.Pop();
                    break;

                case ThryPropertyType.headerWithEnd:
                case ThryPropertyType.legacy_header_start:
                    offset = options.offset + ++headerCount;
                    break;

                case ThryPropertyType.legacy_header_end:
                    headerStack.Pop();
                    headerCount--;
                    break;

                case ThryPropertyType.on_swap_to:
                    _onSwapToActions = options.actions;
                    break;
                }
                ShaderProperty NewProperty = null;
                ShaderPart     newPart     = null;
                switch (type)
                {
                case ThryPropertyType.master_label:
                    _shaderHeader = new ShaderHeaderProperty(this, props[i], displayName, 0, options, false);
                    break;

                case ThryPropertyType.footer:
                    _footers.Add(new FooterButton(Parser.ParseToObject <ButtonData>(displayName)));
                    break;

                case ThryPropertyType.header:
                case ThryPropertyType.headerWithEnd:
                case ThryPropertyType.legacy_header:
                case ThryPropertyType.legacy_header_start:
                    ShaderHeader newHeader = new ShaderHeader(this, props[i], Editor, displayName, offset, options);
                    headerStack.Peek().addPart(newHeader);
                    headerStack.Push(newHeader);
                    newPart = newHeader;
                    break;

                case ThryPropertyType.group_start:
                    ShaderGroup new_group = new ShaderGroup(this, options);
                    headerStack.Peek().addPart(new_group);
                    headerStack.Push(new_group);
                    newPart = new_group;
                    break;

                case ThryPropertyType.group_end:
                    headerStack.Pop();
                    break;

                case ThryPropertyType.none:
                case ThryPropertyType.property:
                    if (props[i].type == MaterialProperty.PropType.Texture)
                    {
                        NewProperty = new TextureProperty(this, props[i], displayName, offset, options, props[i].flags.HasFlag(MaterialProperty.PropFlags.NoScaleOffset) == false, !DrawingData.LastPropertyUsedCustomDrawer, i);
                    }
                    else
                    {
                        NewProperty = new ShaderProperty(this, props[i], displayName, offset, options, false, i);
                    }
                    break;

                case ThryPropertyType.lightmap_flags:
                    NewProperty = new GIProperty(this, props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.dsgi:
                    NewProperty = new DSGIProperty(this, props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.instancing:
                    NewProperty = new InstancingProperty(this, props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.locale:
                    NewProperty = new LocaleProperty(this, props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.shader_version:
                    _shaderVersionRemote = new Version(WebHelper.GetCachedString(options.remote_version_url));
                    _shaderVersionLocal  = new Version(displayName);
                    _isShaderUpToDate    = _shaderVersionLocal >= _shaderVersionRemote;
                    _shaderUpdateUrl     = options.generic_string;
                    _hasShaderUpdateUrl  = _shaderUpdateUrl != null;
                    break;
                }
                if (NewProperty != null)
                {
                    newPart = NewProperty;
                    if (PropertyDictionary.ContainsKey(props[i].name))
                    {
                        continue;
                    }
                    PropertyDictionary.Add(props[i].name, NewProperty);
                    if (type != ThryPropertyType.none)
                    {
                        headerStack.Peek().addPart(NewProperty);
                    }
                }
                //if new header is at end property
                if (headerStack.Peek() is ShaderHeader && (headerStack.Peek() as ShaderHeader).GetEndProperty() == props[i].name)
                {
                    headerStack.Pop();
                    headerCount--;
                }
                if (newPart != null)
                {
                    ShaderParts.Add(newPart);
                }
            }
        }
Exemple #17
0
        public static void drawSmallTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties)
        {
            Rect thumbnailPos     = position;
            Rect foloutClickCheck = position;

            thumbnailPos.x += hasFoldoutProperties ? 20 : 0;
            editor.TexturePropertyMiniThumbnail(thumbnailPos, prop, label.text, label.tooltip);
            if (DrawingData.currentTexProperty.reference_property_exists)
            {
                ShaderProperty property = ShaderEditor.active.propertyDictionary[DrawingData.currentTexProperty.options.reference_property];
                Rect           r        = position;
                r.x     += EditorGUIUtility.labelWidth - CurrentIndentWidth();
                r.width -= EditorGUIUtility.labelWidth - CurrentIndentWidth();
                foloutClickCheck.width -= r.width;
                property.Draw(new CRect(r), new GUIContent());
                property.tooltip.ConditionalDraw(r);
            }
            if (hasFoldoutProperties && DrawingData.currentTexProperty != null)
            {
                //draw dropdown triangle
                thumbnailPos.x += DrawingData.currentTexProperty.xOffset * 15;
                //This is an invisible button with zero functionality. But it needs to be here so that the triangle click reacts fast
                if (GUI.Button(thumbnailPos, "", GUIStyle.none))
                {
                }
                if (Event.current.type == EventType.Repaint)
                {
                    EditorStyles.foldout.Draw(thumbnailPos, false, false, DrawingData.currentTexProperty.showFoldoutProperties, false);
                }

                if (DrawingData.is_enabled)
                {
                    //test click and draw scale/offset
                    if (DrawingData.currentTexProperty.showFoldoutProperties)
                    {
                        EditorGUI.indentLevel += 2;
                        if (DrawingData.currentTexProperty.hasScaleOffset)
                        {
                            ShaderEditor.active.editor.TextureScaleOffsetProperty(prop);
                        }

                        PropertyOptions options = DrawingData.currentTexProperty.options;
                        if (options.reference_properties != null)
                        {
                            foreach (string r_property in options.reference_properties)
                            {
                                ShaderProperty property = ShaderEditor.active.propertyDictionary[r_property];
                                property.Draw(useEditorIndent: true);
                            }
                        }
                        EditorGUI.indentLevel -= 2;
                    }
                    if (ShaderEditor.input.LeftClick_IgnoreUnityUses && foloutClickCheck.Contains(Event.current.mousePosition))
                    {
                        ShaderEditor.input.Use();
                        DrawingData.currentTexProperty.showFoldoutProperties = !DrawingData.currentTexProperty.showFoldoutProperties;
                    }
                }
            }

            Rect object_rect = new Rect(position);

            object_rect.height            = GUILayoutUtility.GetLastRect().y - object_rect.y + GUILayoutUtility.GetLastRect().height;
            DrawingData.lastGuiObjectRect = object_rect;
            DrawingData.tooltipCheckRect  = position;
        }
Exemple #18
0
        public static void drawStylizedBigTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties, bool skip_drag_and_drop_handling = false)
        {
            position.x     += (EditorGUI.indentLevel) * 15;
            position.width -= (EditorGUI.indentLevel) * 15;
            Rect rect = GUILayoutUtility.GetRect(label, Styles.bigTextureStyle);

            rect.x     += (EditorGUI.indentLevel) * 15;
            rect.width -= (EditorGUI.indentLevel) * 15;
            Rect border = new Rect(rect);

            border.position = new Vector2(border.x, border.y - position.height);
            border.height  += position.height;

            if (DrawingData.currentTexProperty.reference_properties_exist)
            {
                border.height += 8;
                foreach (string r_property in DrawingData.currentTexProperty.options.reference_properties)
                {
                    border.height += editor.GetPropertyHeight(ShaderEditor.active.propertyDictionary[r_property].materialProperty);
                }
            }
            if (DrawingData.currentTexProperty.reference_property_exists)
            {
                border.height += 8;
                border.height += editor.GetPropertyHeight(ShaderEditor.active.propertyDictionary[DrawingData.currentTexProperty.options.reference_property].materialProperty);
            }


            //background
            //GUI.DrawTexture(border, Styles.rounded_texture, ScaleMode.StretchToFill, true, 0, Styles.COLOR_BACKGROUND_1, 0, 0);

            Color prevC = GUI.color;

            GUI.color = Styles.COLOR_BACKGROUND_1;

            GUI.DrawTexture(border, Styles.rounded_texture, ScaleMode.StretchToFill, true);
            Rect quad = new Rect(border);

            quad.width = quad.height / 2;
            GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0, 0, 0.5f, 1), true);
            quad.x += border.width - quad.width;
            GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0.5f, 0, 0.5f, 1), true);

            GUI.color = prevC;

            quad.width  = border.height - 4;
            quad.height = quad.width;
            quad.x      = border.x + border.width - quad.width - 1;
            quad.y     += 2;

            Rect preview_rect_border = new Rect(position);

            preview_rect_border.height = rect.height + position.height - 6;
            preview_rect_border.width  = preview_rect_border.height;
            preview_rect_border.y     += 3;
            preview_rect_border.x     += position.width - preview_rect_border.width - 3;
            Rect preview_rect = new Rect(preview_rect_border);

            preview_rect.height -= 6;
            preview_rect.width  -= 6;
            preview_rect.x      += 3;
            preview_rect.y      += 3;
            if (prop.hasMixedValue)
            {
                Rect mixedRect = new Rect(preview_rect);
                mixedRect.y -= 5;
                mixedRect.x += mixedRect.width / 2 - 4;
                GUI.Label(mixedRect, "_");
            }
            else if (prop.textureValue != null)
            {
                GUI.DrawTexture(preview_rect, prop.textureValue);
            }
            GUI.DrawTexture(preview_rect_border, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 0, Color.grey, 3, 5);

            //selection button and pinging
            Rect select_rect = new Rect(preview_rect);

            select_rect.height = 12;
            select_rect.y     += preview_rect.height - 12;
            if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow && texturePickerWindowProperty.name == prop.name)
            {
                prop.textureValue = (Texture)EditorGUIUtility.GetObjectPickerObject();
                ShaderEditor.Repaint();
            }
            if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow)
            {
                texturePickerWindow         = -1;
                texturePickerWindowProperty = null;
            }
            if (GUI.Button(select_rect, "Select", EditorStyles.miniButton))
            {
                EditorGUIUtility.ShowObjectPicker <Texture>(prop.textureValue, false, "", 0);
                texturePickerWindow         = EditorGUIUtility.GetObjectPickerControlID();
                texturePickerWindowProperty = prop;
            }
            else if (Event.current.type == EventType.MouseDown && preview_rect.Contains(Event.current.mousePosition))
            {
                EditorGUIUtility.PingObject(prop.textureValue);
            }

            if (!skip_drag_and_drop_handling)
            {
                if ((ShaderEditor.input.is_drag_drop_event) && preview_rect.Contains(ShaderEditor.input.mouse_position) && DragAndDrop.objectReferences[0] is Texture)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    if (ShaderEditor.input.is_drop_event)
                    {
                        DragAndDrop.AcceptDrag();
                        prop.textureValue = (Texture)DragAndDrop.objectReferences[0];
                    }
                }
            }

            //scale offset rect

            if (hasFoldoutProperties || DrawingData.currentTexProperty.options.reference_property != null)
            {
                EditorGUI.indentLevel += 2;

                if (DrawingData.currentTexProperty.hasScaleOffset)
                {
                    Rect scale_offset_rect = new Rect(position);
                    scale_offset_rect.y     += 37;
                    scale_offset_rect.width -= 2 + preview_rect.width + 10 + 30;
                    scale_offset_rect.x     += 30;
                    editor.TextureScaleOffsetProperty(scale_offset_rect, prop);
                }
                float oldLabelWidth = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 128;

                PropertyOptions options = DrawingData.currentTexProperty.options;
                if (options.reference_property != null)
                {
                    ShaderProperty property = ShaderEditor.active.propertyDictionary[options.reference_property];
                    property.Draw(useEditorIndent: true);
                }
                if (options.reference_properties != null)
                {
                    foreach (string r_property in options.reference_properties)
                    {
                        ShaderProperty property = ShaderEditor.active.propertyDictionary[r_property];
                        property.Draw(useEditorIndent: true);
                    }
                }
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUI.indentLevel      -= 2;
            }

            Rect label_rect = new Rect(position);

            label_rect.x += 2;
            label_rect.y += 2;
            GUI.Label(label_rect, label);

            GUILayoutUtility.GetRect(0, 5);

            DrawingData.lastGuiObjectRect = border;
            DrawingData.tooltipCheckRect  = border;
        }
Exemple #19
0
        public static void SmallTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties, Action extraFoldoutGUI = null)
        {
            Rect thumbnailPos     = position;
            Rect foloutClickCheck = position;
            Rect tooltipRect      = position;

            thumbnailPos.x += hasFoldoutProperties ? 20 : 0;
            editor.TexturePropertyMiniThumbnail(thumbnailPos, prop, label.text, label.tooltip);
            if (DrawingData.CurrentTextureProperty.DoesReferencePropertyExist)
            {
                ShaderProperty property = ShaderEditor.Active.PropertyDictionary[DrawingData.CurrentTextureProperty.Options.reference_property];
                Rect           r        = position;
                r.x     += EditorGUIUtility.labelWidth - CurrentIndentWidth();
                r.width -= EditorGUIUtility.labelWidth - CurrentIndentWidth();
                foloutClickCheck.width -= r.width;
                property.Draw(new CRect(r), new GUIContent());
                property.tooltip.ConditionalDraw(r);
            }
            if (hasFoldoutProperties && DrawingData.CurrentTextureProperty != null)
            {
                //draw dropdown triangle
                thumbnailPos.x += DrawingData.CurrentTextureProperty.XOffset * 15;
                //This is an invisible button with zero functionality. But it needs to be here so that the triangle click reacts fast
                if (GUI.Button(thumbnailPos, "", GUIStyle.none))
                {
                }
                if (Event.current.type == EventType.Repaint)
                {
                    EditorStyles.foldout.Draw(thumbnailPos, false, false, DrawingData.CurrentTextureProperty.showFoldoutProperties, false);
                }

                if (DrawingData.IsEnabled)
                {
                    //sub properties
                    if (DrawingData.CurrentTextureProperty.showFoldoutProperties)
                    {
                        EditorGUI.indentLevel += 2;
                        extraFoldoutGUI?.Invoke();
                        if (DrawingData.CurrentTextureProperty.hasScaleOffset)
                        {
                            ShaderEditor.Active.Editor.TextureScaleOffsetProperty(prop);
                            tooltipRect.height += GUILayoutUtility.GetLastRect().height;
                        }
                        //In case of locked material end disabled group here to allow editing of sub properties
                        if (ShaderEditor.Active.IsLockedMaterial)
                        {
                            EditorGUI.EndDisabledGroup();
                        }

                        PropertyOptions options = DrawingData.CurrentTextureProperty.Options;
                        if (options.reference_properties != null)
                        {
                            foreach (string r_property in options.reference_properties)
                            {
                                ShaderProperty property = ShaderEditor.Active.PropertyDictionary[r_property];
                                property.Draw(useEditorIndent: true);
                            }
                        }

                        //readd disabled group
                        if (ShaderEditor.Active.IsLockedMaterial)
                        {
                            EditorGUI.BeginDisabledGroup(false);
                        }

                        EditorGUI.indentLevel -= 2;
                    }
                    if (ShaderEditor.Input.LeftClick_IgnoreLockedAndUnityUses && foloutClickCheck.Contains(Event.current.mousePosition))
                    {
                        ShaderEditor.Input.Use();
                        DrawingData.CurrentTextureProperty.showFoldoutProperties = !DrawingData.CurrentTextureProperty.showFoldoutProperties;
                    }
                }
            }

            Rect object_rect = new Rect(position);

            object_rect.height            = GUILayoutUtility.GetLastRect().y - object_rect.y + GUILayoutUtility.GetLastRect().height;
            DrawingData.LastGuiObjectRect = object_rect;
            DrawingData.TooltipCheckRect  = tooltipRect;
        }
Exemple #20
0
        //finds all properties and headers and stores them in correct order
        private void CollectAllProperties()
        {
            //load display names from file if it exists
            MaterialProperty[]          props  = properties;
            Dictionary <string, string> labels = LoadDisplayNamesFromFile();

            LoadLocales();

            propertyDictionary = new Dictionary <string, ShaderProperty>();
            shaderParts        = new List <ShaderPart>();
            mainHeader         = new ShaderHeader(this);                 //init top object that all Shader Objects are childs of
            Stack <ShaderGroup> headerStack = new Stack <ShaderGroup>(); //header stack. used to keep track if editorData header to parent new objects to

            headerStack.Push(mainHeader);                                //add top object as top object to stack
            headerStack.Push(mainHeader);                                //add top object a second time, because it get's popped with first actual header item
            footers = new List <FooterButton>();                         //init footer list
            int headerCount = 0;

            for (int i = 0; i < props.Length; i++)
            {
                DrawingData.ResetLastDrawerData();
                editor.GetPropertyHeight(props[i]);

                string displayName = props[i].displayName;

                //Load from label file
                if (labels.ContainsKey(props[i].name))
                {
                    displayName = labels[props[i].name];
                }

                //Check for locale
                if (locale != null)
                {
                    if (displayName.Contains("locale::"))
                    {
                        Match m = Regex.Match(displayName, @"locale::(\d\w)+d");
                        if (m.Success)
                        {
                            string key = m.Value.Substring(8, m.Value.Length - 8);
                            if (locale.Constains(key))
                            {
                                displayName = displayName.Replace("locale::" + locale.Get(key), "");
                            }
                        }
                    }
                }
                displayName = displayName.Replace("''", "\"");

                //extract json data from display name
                PropertyOptions options = ExtractExtraOptionsFromDisplayName(ref displayName);

                int offset = options.offset + headerCount;

                ThryPropertyType type = GetPropertyType(props[i], options);
                switch (type)
                {
                case ThryPropertyType.header:
                    headerStack.Pop();
                    break;

                case ThryPropertyType.legacy_header:
                    headerStack.Pop();
                    break;

                case ThryPropertyType.headerWithEnd:
                case ThryPropertyType.legacy_header_start:
                    offset = options.offset + ++headerCount;
                    break;

                case ThryPropertyType.legacy_header_end:
                    headerStack.Pop();
                    headerCount--;
                    break;

                case ThryPropertyType.on_swap_to:
                    on_swap_to_actions = options.actions;
                    break;
                }
                ShaderProperty newPorperty = null;
                ShaderPart     newPart     = null;
                switch (type)
                {
                case ThryPropertyType.master_label:
                    shaderHeader = new ShaderHeaderProperty(this, props[i], displayName, 0, options, false);
                    break;

                case ThryPropertyType.footer:
                    footers.Add(new FooterButton(Parser.ParseToObject <ButtonData>(displayName)));
                    break;

                case ThryPropertyType.header:
                case ThryPropertyType.headerWithEnd:
                case ThryPropertyType.legacy_header:
                case ThryPropertyType.legacy_header_start:
                    if (options.is_hideable)
                    {
                        show_HeaderHider = true;
                    }
                    ShaderHeader newHeader = new ShaderHeader(this, props[i], editor, displayName, offset, options);
                    headerStack.Peek().addPart(newHeader);
                    headerStack.Push(newHeader);
                    HeaderHider.InitHidden(newHeader);
                    newPart = newHeader;
                    break;

                case ThryPropertyType.group_start:
                    ShaderGroup new_group = new ShaderGroup(this, options);
                    headerStack.Peek().addPart(new_group);
                    headerStack.Push(new_group);
                    newPart = new_group;
                    break;

                case ThryPropertyType.group_end:
                    headerStack.Pop();
                    break;

                case ThryPropertyType.none:
                case ThryPropertyType.property:

                    bool forceOneLine = props[i].type == MaterialProperty.PropType.Vector && !DrawingData.lastPropertyUsedCustomDrawer;
                    if (props[i].type == MaterialProperty.PropType.Texture)
                    {
                        newPorperty = new TextureProperty(this, props[i], displayName, offset, options, props[i].flags.HasFlag(MaterialProperty.PropFlags.NoScaleOffset) == false, !DrawingData.lastPropertyUsedCustomDrawer);
                    }
                    else
                    {
                        newPorperty = new ShaderProperty(this, props[i], displayName, offset, options, forceOneLine);
                    }
                    break;

                case ThryPropertyType.lightmap_flags:
                    newPorperty = new GIProperty(this, props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.dsgi:
                    newPorperty = new DSGIProperty(this, props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.instancing:
                    newPorperty = new InstancingProperty(this, props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.locale:
                    newPorperty = new LocaleProperty(this, props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.shader_optimizer:
                    use_ShaderOptimizer = true;
                    newPorperty         = new ShaderProperty(this, props[i], displayName, offset, options, false);
                    break;
                }
                if (newPorperty != null)
                {
                    newPart = newPorperty;
                    if (propertyDictionary.ContainsKey(props[i].name))
                    {
                        continue;
                    }
                    propertyDictionary.Add(props[i].name, newPorperty);
                    //Debug.Log(newPorperty.materialProperty.name + ":" + headerStack.Count);
                    if (type != ThryPropertyType.none && type != ThryPropertyType.shader_optimizer)
                    {
                        headerStack.Peek().addPart(newPorperty);
                    }
                }
                //if new header is at end property
                if (headerStack.Peek() is ShaderHeader && (headerStack.Peek() as ShaderHeader).GetEndProperty() == props[i].name)
                {
                    headerStack.Pop();
                    headerCount--;
                }
                if (newPart != null)
                {
                    shaderParts.Add(newPart);

                    DrawingData.lastInitiatedPart = newPart;
                    editor.GetPropertyHeight(props[i]);
                    DrawingData.lastInitiatedPart = null;
                }
            }
        }
Exemple #21
0
        //finds all properties and headers and stores them in correct order
        private void CollectAllProperties()
        {
            //load display names from file if it exists
            MaterialProperty[]          props  = editorData.properties;
            Dictionary <string, string> labels = LoadDisplayNamesFromFile();

            LoadLocales();

            editorData.propertyDictionary = new Dictionary <string, ShaderProperty>();
            editorData.shaderParts        = new List <ShaderPart>();
            shaderparts = new ShaderHeader();                            //init top object that all Shader Objects are childs of
            Stack <ShaderGroup> headerStack = new Stack <ShaderGroup>(); //header stack. used to keep track if editorData header to parent new objects to

            headerStack.Push(shaderparts);                               //add top object as top object to stack
            headerStack.Push(shaderparts);                               //add top object a second time, because it get's popped with first actual header item
            footer = new List <ButtonData>();                            //init footer list
            int headerCount = 0;

            Type         materialPropertyDrawerType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.MaterialPropertyHandler");
            MethodInfo   getPropertyHandlerMethod   = materialPropertyDrawerType.GetMethod("GetShaderPropertyHandler", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
            PropertyInfo drawerProperty             = materialPropertyDrawerType.GetProperty("propertyDrawer");

            Type      materialToggleDrawerType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.MaterialToggleDrawer");
            FieldInfo keyWordField             = materialToggleDrawerType.GetField("keyword", BindingFlags.Instance | BindingFlags.NonPublic);

            for (int i = 0; i < props.Length; i++)
            {
                string displayName = props[i].displayName;
                if (locale != null)
                {
                    foreach (string key in locale.GetAllKeys())
                    {
                        if (displayName.Contains("locale::" + key))
                        {
                            displayName = displayName.Replace("locale::" + key, locale.Get(key));
                        }
                    }
                }
                displayName = Regex.Replace(displayName, @"''", "\"");

                if (labels.ContainsKey(props[i].name))
                {
                    displayName = labels[props[i].name];
                }
                PropertyOptions options = ExtractExtraOptionsFromDisplayName(ref displayName);

                int offset = options.offset + headerCount;

                //Handle keywords
                object propertyHandler = getPropertyHandlerMethod.Invoke(null, new object[] { editorData.shader, props[i].name });
                //if has custom drawer
                if (propertyHandler != null)
                {
                    object propertyDrawer = drawerProperty.GetValue(propertyHandler, null);
                    //if custom drawer exists
                    if (propertyDrawer != null)
                    {
                        if (propertyDrawer.GetType().ToString() == "UnityEditor.MaterialToggleDrawer")
                        {
                            object keyword = keyWordField.GetValue(propertyDrawer);
                            if (keyword != null)
                            {
                                foreach (Material m in editorData.materials)
                                {
                                    if (m.GetFloat(props[i].name) == 1)
                                    {
                                        m.EnableKeyword((string)keyword);
                                    }
                                    else
                                    {
                                        m.DisableKeyword((string)keyword);
                                    }
                                }
                            }
                        }
                    }
                }


                ThryPropertyType type = GetPropertyType(props[i], options);
                switch (type)
                {
                case ThryPropertyType.header:
                    headerStack.Pop();
                    break;

                case ThryPropertyType.header_start:
                    offset = options.offset + ++headerCount;
                    break;

                case ThryPropertyType.header_end:
                    headerStack.Pop();
                    headerCount--;
                    break;

                case ThryPropertyType.on_swap_to:
                    on_swap_to_actions = options.actions;
                    break;
                }
                ShaderProperty newPorperty = null;
                ShaderPart     newPart     = null;
                switch (type)
                {
                case ThryPropertyType.master_label:
                    masterLabelText = displayName;
                    break;

                case ThryPropertyType.footer:
                    footer.Add(Parser.ParseToObject <ButtonData>(displayName));
                    break;

                case ThryPropertyType.header:
                case ThryPropertyType.header_start:
                    if (options.is_hideable)
                    {
                        editorData.show_HeaderHider = true;
                    }
                    ShaderHeader newHeader = new ShaderHeader(props[i], editorData.editor, displayName, offset, options);
                    headerStack.Peek().addPart(newHeader);
                    headerStack.Push(newHeader);
                    HeaderHider.InitHidden(newHeader);
                    newPart = newHeader;
                    break;

                case ThryPropertyType.group_start:
                    ShaderGroup new_group = new ShaderGroup(options);
                    headerStack.Peek().addPart(new_group);
                    headerStack.Push(new_group);
                    newPart = new_group;
                    break;

                case ThryPropertyType.group_end:
                    headerStack.Pop();
                    break;

                case ThryPropertyType.none:
                case ThryPropertyType.property:
                    DrawingData.lastPropertyUsedCustomDrawer = false;
                    editorData.editor.GetPropertyHeight(props[i]);
                    bool forceOneLine = props[i].type == MaterialProperty.PropType.Vector && !DrawingData.lastPropertyUsedCustomDrawer;
                    if (props[i].type == MaterialProperty.PropType.Texture)
                    {
                        newPorperty = new TextureProperty(props[i], displayName, offset, options, props[i].flags.HasFlag(MaterialProperty.PropFlags.NoScaleOffset) == false, !DrawingData.lastPropertyUsedCustomDrawer);
                    }
                    else
                    {
                        newPorperty = new ShaderProperty(props[i], displayName, offset, options, forceOneLine);
                    }
                    break;

                case ThryPropertyType.lightmap_flags:
                    newPorperty = new GIProperty(props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.dsgi:
                    newPorperty = new DSGIProperty(props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.instancing:
                    newPorperty = new InstancingProperty(props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.locale:
                    newPorperty = new LocaleProperty(props[i], displayName, offset, options, false);
                    break;

                case ThryPropertyType.shader_optimizer:
                    editorData.use_ShaderOptimizer = true;
                    newPorperty = new ShaderProperty(props[i], displayName, offset, options, false);
                    break;
                }
                if (newPorperty != null)
                {
                    newPart = newPorperty;
                    if (editorData.propertyDictionary.ContainsKey(props[i].name))
                    {
                        continue;
                    }
                    editorData.propertyDictionary.Add(props[i].name, newPorperty);
                    if (type != ThryPropertyType.none && type != ThryPropertyType.shader_optimizer)
                    {
                        headerStack.Peek().addPart(newPorperty);
                    }
                }
                if (newPart != null)
                {
                    editorData.shaderParts.Add(newPart);
                }
            }
        }
Exemple #22
0
        public bool Test()
        {
            if (cachedTest != null)
            {
                return((bool)cachedTest);
            }

            switch (type)
            {
            case DefineableConditionType.NONE:
                return((bool)(cachedTest = true));

            case DefineableConditionType.TRUE:
                return((bool)(cachedTest = true));

            case DefineableConditionType.FALSE:
                return((bool)(cachedTest = false));
            }
            string comparator = GetComparetor();

            string[] parts = Regex.Split(data, comparator);
            string   obj   = parts[0];
            string   value = parts[parts.Length - 1];

            switch (type)
            {
            case DefineableConditionType.PROPERTY_BOOL:
                ShaderProperty prop = ShaderEditor.currentlyDrawing.propertyDictionary[obj];
                if (prop == null)
                {
                    return((bool)(cachedTest = false));
                }

                if (comparator == "##")
                {
                    return((bool)(cachedTest = prop.materialProperty.floatValue == 1));
                }
                float f = Parser.ParseFloat(parts[1]);
                if (comparator == "==")
                {
                    return((bool)(cachedTest = prop.materialProperty.floatValue == f));
                }
                if (comparator == "!=")
                {
                    return((bool)(cachedTest = prop.materialProperty.floatValue != f));
                }
                if (comparator == "<")
                {
                    return((bool)(cachedTest = prop.materialProperty.floatValue < f));
                }
                if (comparator == ">")
                {
                    return((bool)(cachedTest = prop.materialProperty.floatValue > f));
                }
                if (comparator == ">=")
                {
                    return((bool)(cachedTest = prop.materialProperty.floatValue >= f));
                }
                if (comparator == "<=")
                {
                    return((bool)(cachedTest = prop.materialProperty.floatValue <= f));
                }
                break;

            case DefineableConditionType.EDITOR_VERSION:
                int c_ev = Helper.compareVersions(Config.Get().verion, value);
                if (comparator == "==")
                {
                    return((bool)(cachedTest = c_ev == 0));
                }
                if (comparator == "!=")
                {
                    return((bool)(cachedTest = c_ev != 0));
                }
                if (comparator == "<")
                {
                    return((bool)(cachedTest = c_ev == 1));
                }
                if (comparator == ">")
                {
                    return((bool)(cachedTest = c_ev == -1));
                }
                if (comparator == ">=")
                {
                    return((bool)(cachedTest = c_ev == -1 || c_ev == 0));
                }
                if (comparator == "<=")
                {
                    return((bool)(cachedTest = c_ev == 1 || c_ev == 0));
                }
                break;

            case DefineableConditionType.VRC_SDK_VERSION:
                if (VRCInterface.Get().sdk_information.type == VRCInterface.VRC_SDK_Type.NONE)
                {
                    return((bool)(cachedTest = false));
                }
                int c_vrc = Helper.compareVersions(VRCInterface.Get().sdk_information.installed_version, value);
                if (comparator == "==")
                {
                    return((bool)(cachedTest = c_vrc == 0));
                }
                if (comparator == "!=")
                {
                    return((bool)(cachedTest = c_vrc != 0));
                }
                if (comparator == "<")
                {
                    return((bool)(cachedTest = c_vrc == 1));
                }
                if (comparator == ">")
                {
                    return((bool)(cachedTest = c_vrc == -1));
                }
                if (comparator == ">=")
                {
                    return((bool)(cachedTest = c_vrc == -1 || c_vrc == 0));
                }
                if (comparator == "<=")
                {
                    return((bool)(cachedTest = c_vrc == 1 || c_vrc == 0));
                }
                break;

            case DefineableConditionType.TEXTURE_SET:
                ShaderProperty shaderProperty = ShaderEditor.currentlyDrawing.propertyDictionary[data];
                if (shaderProperty == null)
                {
                    return((bool)(cachedTest = false));
                }
                return((bool)(cachedTest = shaderProperty.materialProperty.textureValue != null));

            case DefineableConditionType.DROPDOWN:
                ShaderProperty dropdownProperty = ShaderEditor.currentlyDrawing.propertyDictionary[obj];
                if (dropdownProperty == null)
                {
                    return((bool)(cachedTest = false));
                }
                if (comparator == "##")
                {
                    return((bool)(cachedTest = dropdownProperty.materialProperty.floatValue == 1));
                }
                if (comparator == "==")
                {
                    return((bool)(cachedTest = "" + dropdownProperty.materialProperty.floatValue == parts[1]));
                }
                if (comparator == "!=")
                {
                    return((bool)(cachedTest = "" + dropdownProperty.materialProperty.floatValue != parts[1]));
                }
                break;

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

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

            return((bool)(cachedTest = true));
        }