Tanoda
UIImageCrop.cs
Go to the documentation of this file.
1
3
4
6{
7 [AddComponentMenu("UI/Effects/Extensions/UIImageCrop")]
8 [ExecuteInEditMode]
9 [RequireComponent(typeof(RectTransform))]
10 public class UIImageCrop : MonoBehaviour
11 {
12 MaskableGraphic mGraphic;
13 Material mat;
14 int XCropProperty, YCropProperty;
15 public float XCrop = 0f;
16 public float YCrop = 0f;
17
18
19 // Use this for initialization
20 void Start()
21 {
23 }
24
25 public void SetMaterial()
26 {
27 mGraphic = this.GetComponent<MaskableGraphic>();
28 XCropProperty = Shader.PropertyToID("_XCrop");
29 YCropProperty = Shader.PropertyToID("_YCrop");
30 if (mGraphic != null)
31 {
32 if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
33 {
34 //Applying default material with UI Image Crop shader
35 mGraphic.material = new Material(Shader.Find("UI Extensions/UI Image Crop"));
36 }
37 mat = mGraphic.material;
38 }
39 else
40 {
41 Debug.LogError("Please attach component to a Graphical UI component");
42 }
43 }
44 public void OnValidate()
45 {
49 }
54 public void SetXCrop(float xcrop)
55 {
56 XCrop = Mathf.Clamp01(xcrop);
57 mat.SetFloat(XCropProperty, XCrop);
58 }
59
64 public void SetYCrop(float ycrop)
65 {
66 YCrop = Mathf.Clamp01(ycrop);
67 mat.SetFloat(YCropProperty, YCrop);
68 }
69 }
70}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void SetXCrop(float xcrop)
Set the x crop factor, with x being a normalized value 0-1f.
Definition: UIImageCrop.cs:54
void SetYCrop(float ycrop)
Set the y crop factor, with y being a normalized value 0-1f.
Definition: UIImageCrop.cs:64
Credit Erdener Gonenc - @PixelEnvision.