Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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;
                }
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }