Пример #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  = 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 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:
                    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)
                    {
                        NewProperty = new TextureProperty(this, props[i], displayName, offset, options, props[i].flags.HasFlag(MaterialProperty.PropFlags.NoScaleOffset) == false, !DrawingData.lastPropertyUsedCustomDrawer);
                    }
                    else
                    {
                        NewProperty = new ShaderProperty(this, props[i], displayName, offset, options, forceOneLine);
                    }
                    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);
                    //Debug.Log(NewProperty.materialProperty.name + ":" + headerStack.Count);
                    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);

                    DrawingData.lastInitiatedPart = newPart;
                    editor.GetPropertyHeight(props[i]);
                    DrawingData.lastInitiatedPart = null;
                }
            }
        }