WuhuIslandTesting/Library/PackageCache/com.unity.render-pipelines.universal@8148.0.7-4/Editor/ShaderGUI/UIClasses/MaterialFloatField.cs

56 lines
1.9 KiB
C#
Raw Normal View History

2025-01-07 02:06:59 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace UnityEditor.SLZMaterialUI
{
public class MaterialFloatField : FloatField, BaseMaterialField
{
public int shaderPropertyIdx;
public int GetShaderPropIdx() { return shaderPropertyIdx; }
public MaterialProperty materialProperty;
public void Initialize(MaterialProperty materialProperty, int shaderPropertyIdx)
{
this.materialProperty = materialProperty;
this.shaderPropertyIdx = shaderPropertyIdx;
this.RegisterValueChangedCallback(OnChangedEvent);
this.SetValueWithoutNotify(materialProperty.floatValue);
style.marginRight = 3;
if (materialProperty.hasMixedValue)
{
//this.SetValueWithoutNotify(Color.gray);
this.showMixedValue = true;
}
label = materialProperty.displayName;
SetFullLineStyle();
}
public void SetFullLineStyle()
{
VisualElement label = this.ElementAt(0);
label.AddToClassList("materialGUILeftBox");
label.style.overflow = Overflow.Hidden;
label.style.minWidth = 0;
VisualElement color = this.ElementAt(1);
color.AddToClassList("materialGUIRightBox");
style.justifyContent = Justify.FlexStart;
}
public void OnChangedEvent(ChangeEvent<float> evt)
{
materialProperty.floatValue = evt.newValue;
this.showMixedValue = false;
}
public void UpdateMaterialProperty(MaterialProperty boundProp)
{
materialProperty = boundProp;
if (value != boundProp.floatValue)
{
this.SetValueWithoutNotify(boundProp.floatValue);
}
this.showMixedValue = boundProp.hasMixedValue;
}
}
}