7 [AddComponentMenu(
"UI/Effects/Extensions/UIImageCrop")]
9 [RequireComponent(typeof(RectTransform))]
12 MaskableGraphic mGraphic;
14 int XCropProperty, YCropProperty;
27 mGraphic = this.GetComponent<MaskableGraphic>();
28 XCropProperty = Shader.PropertyToID(
"_XCrop");
29 YCropProperty = Shader.PropertyToID(
"_YCrop");
32 if (mGraphic.material ==
null || mGraphic.material.name ==
"Default UI Material")
35 mGraphic.material =
new Material(Shader.Find(
"UI Extensions/UI Image Crop"));
37 mat = mGraphic.material;
41 Debug.LogError(
"Please attach component to a Graphical UI component");
56 XCrop = Mathf.Clamp01(xcrop);
57 mat.SetFloat(XCropProperty,
XCrop);
66 YCrop = Mathf.Clamp01(ycrop);
67 mat.SetFloat(YCropProperty,
YCrop);
void SetXCrop(float xcrop)
Set the x crop factor, with x being a normalized value 0-1f.
void SetYCrop(float ycrop)
Set the y crop factor, with y being a normalized value 0-1f.
Credit Erdener Gonenc - @PixelEnvision.