public SamplerElement(SerializedProperty property, Parameter parameter) { m_Property = property; var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>( $"{StaticData.uxmlDir}/Sampler/SamplerElement.uxml"); template.CloneTree(this); m_Parameter = parameter; m_Sampler = GetSamplerFromSerializedObject(); if (m_Sampler == null) { CreateSampler(typeof(UniformSampler)); } var samplerName = this.Q <Label>("sampler-name"); samplerName.text = UppercaseFirstLetter(m_Property.name); m_Properties = this.Q <VisualElement>("fields-container"); m_SamplerTypeDropdown = this.Q <ToolbarMenu>("sampler-type-dropdown"); m_SamplerTypeDropdown.text = SamplerUtility.GetSamplerDisplayName(m_Sampler.GetType());; foreach (var samplerType in StaticData.samplerTypes) { var displayName = SamplerUtility.GetSamplerDisplayName(samplerType);; m_SamplerTypeDropdown.menu.AppendAction( displayName, a => { ReplaceSampler(samplerType); }, a => DropdownMenuAction.Status.Normal); } CreatePropertyFields(); }
void ReplaceSampler(Type samplerType) { CreateSampler(samplerType); m_SamplerTypeDropdown.text = SamplerUtility.GetSamplerDisplayName(samplerType); CreatePropertyFields(); }