【问题标题】:MaterialPropertyBlock doesn't change colors at runtime?MaterialPropertyBlock 在运行时不会改变颜色?
【发布时间】:2020-09-08 08:20:32
【问题描述】:

我画了很多不同颜色的盒子。为此,我正在使用 MaterialPropertyBlocks

public override void DrawPlot()
{
    for (int posIdx = 0; posIdx < data.Length; posIdx++)
    {
        plotModelInstances[posIdx] = GameObject.Instantiate(plotModel, ...);

        _propBlock = new MaterialPropertyBlock();
        _renderer = plotModelInstances[posIdx].GetComponent<Renderer>();
        _renderer.GetPropertyBlock(_propBlock);
        _propBlock.SetColor("Color", MiscUtils.GetColor(data[posIdx].Value / maxValue, StaticValues.jet));
        _renderer.SetPropertyBlock(_propBlock);
    }
}

此函数是(非单一行为)类的一部分。 问题是,如果我运行程序,所有块都是白色的。 那是因为我在 MonoBehaviour 脚本之外使用 MaterialPropertyBlocks 吗?

【问题讨论】:

    标签: c# unity3d rendering


    【解决方案1】:

    发现问题:该属性名为“_Color”而不是“Color” 这行得通

    _propBlock.SetColor("_Color", MiscUtils.GetColor(data[posIdx].Value / maxValue, StaticValues.jet));
    currentBar.GetComponent<MeshRenderer>().SetPropertyBlock(_propBlock);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 2016-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多