Documentation

Modifying MPImages

Updated on February 28, 2021

Modifying MPImage Settings #

MPImage image = GetComponent<MPImage>();
image.StrokeWidth = 5f;
image.DrawShape = DrawShape.Circle;
image.OutlineColor = Color.red;

Modifying Shape Properties #

  • MPImage
MPImage image = GetComponent<MPImage>();
Rectangle rectangle = new Rectangle();
rectangle.CornerRadius = new Vector4(20, 20, 40, 40);
image.Rectangle = rectangle;
  • MPImage Basic
MPImageBasic image = GetComponent<MPImageBasic>();
image.RectangleCornerRadius = new Vector4(20, 20, 40, 40);

Modifying Gradient Effect Properties  #

MPImage image = GetComponent<MPImage>();
GradientEffect gradient = new GradientEffect;
gradient.Enabled = true;
gradient.GradientType = GradientType.Corner;
gradient.CornerGradientColors = new Color[]
    {Color.red, Color.red, Color.green, Color.cyan};
image.GradientEffect = gradient;

Changing Material of MPImage Component #

Shared material can be provided from the inspector or set through code. The material must use the MPSprite Shader.

MPImage image = GetComponent<MPImage>();
image.material = m_MyMaterial;

Switching Material Modes #

  • Switching to Dynamic Material from Shared Material
MPImage image = GetComponent<MPImage>();
image.MaterialMode = MaterialMode.Dynamic;

Here, MPImage will create a duplicate instance of the previously using shared material, so all the properties of the shared material will be carried over. As a result, There won’t be any visual changes.

  • Switching to Shared Material from Dynamic Material
MPImage image = GetComponent<MPImage>();
image.MaterialMode = MaterialMode.Shared;

Here, MPImage discards the dynamic material being used and uses the provided shared material. All the settings of the dynamic material will be discarded and settings in the shared material will be prioritized and used. 

If there is no shared material but the settings are changed to shared, MPimage will keep using the dynamic material as long as a shared material is provided. 

Shared material can be provided from the inspector or set through code. The material must use the MPSprite Shader.

What are your feelings