//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; } } }
//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); } } }