Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
CustomImageBase.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3using UnityEngine.UI;
4
5namespace Applibot;
6
7[ExecuteAlways]
8[RequireComponent(typeof(Graphic))]
9public class CustomImageBase : MonoBehaviour, IMaterialModifier
10{
11 [NonSerialized]
12 private Graphic _graphic;
13
14 [NonSerialized]
15 private Image _image;
16
17 protected Material material;
18
19 private CanvasScaler _canvasScaler;
20
21 private int _textureRectId = Shader.PropertyToID("_textureRect");
22
23 protected CanvasScaler canvasScaler
24 {
25 get
26 {
27 if (_canvasScaler == null)
28 {
29 _canvasScaler = graphic.canvas.GetComponent<CanvasScaler>();
30 }
31 return _canvasScaler;
32 }
33 }
34
35 public Graphic graphic
36 {
37 get
38 {
39 if (_graphic == null)
40 {
41 _graphic = GetComponent<Graphic>();
42 }
43 return _graphic;
44 }
45 }
46
48 {
49 if (!base.isActiveAndEnabled || graphic == null)
50 {
51 return baseMaterial;
52 }
53 UpdateMaterial(baseMaterial);
55 return material;
56 }
57
59 {
60 if (base.isActiveAndEnabled && !(graphic == null))
61 {
62 graphic.SetMaterialDirty();
63 }
64 }
65
66 protected virtual void UpdateMaterial(Material baseMaterial)
67 {
68 }
69
70 private void SetAtlasInfo()
71 {
72 if (!(_image == null))
73 {
74 if (!_image.sprite.packed)
75 {
76 material.DisableKeyword("USE_ATLAS");
77 return;
78 }
79 Rect textureRect = _image.sprite.textureRect;
80 Vector4 value = new Vector4(textureRect.x, textureRect.y, textureRect.width, textureRect.height);
81 material.SetVector(_textureRectId, value);
82 material.EnableKeyword("USE_ATLAS");
83 }
84 }
85
86 protected void OnEnable()
87 {
88 if (!(graphic == null))
89 {
90 _image = graphic as Image;
91 graphic.SetMaterialDirty();
92 }
93 }
94
95 protected void OnDisable()
96 {
97 if (material != null)
98 {
100 }
101 if (graphic != null)
102 {
103 graphic.SetMaterialDirty();
104 }
105 }
106
107 protected void OnDestroy()
108 {
109 if (material != null)
110 {
112 }
113 }
114
115 public void DestroyMaterial()
116 {
117 UnityEngine.Object.Destroy(material);
118 material = null;
119 }
120}
virtual void UpdateMaterial(Material baseMaterial)
Material GetModifiedMaterial(Material baseMaterial)