56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|