Elin Decompiled Documentation EA 23.299 Nightly
Loading...
Searching...
No Matches
Dropper.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using UnityEngine;
4using UnityEngine.UI;
5
7
8public class Dropper : MonoBehaviour
9{
10 [SerializeField]
12
13 [SerializeField]
15
16 public const int BlockWidth = 16;
17
18 public const int BlockHeight = 16;
19
20 private Button blocker;
21
22 private RenderTexture renderTexture;
23
24 private Texture2D texture2D;
25
26 private Texture2D pixelBlock;
27
28 public Coroutine coroutine;
29
30 private Color color;
31
32 private Color[] black16x16 = new Color[256];
33
34 public Action onDropCanceled;
35
36 private Action<Color> onColorPicked;
37
38 private void Awake()
39 {
40 Camera.main.targetTexture = renderTexture;
41 renderTexture = new RenderTexture(Screen.width, Screen.height, 24);
42 texture2D = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, mipChain: false);
43 pixelBlock = new Texture2D(16, 16, TextureFormat.ARGB32, mipChain: false);
44 for (int i = 0; i < black16x16.Length; i++)
45 {
46 black16x16[i] = Color.black;
47 }
48 }
49
50 private void OnDestroy()
51 {
52 if ((bool)renderTexture)
53 {
54 UnityEngine.Object.Destroy(renderTexture);
55 }
56 if ((bool)texture2D)
57 {
58 UnityEngine.Object.Destroy(texture2D);
59 }
60 if ((bool)pixelBlock)
61 {
62 UnityEngine.Object.Destroy(pixelBlock);
63 }
64 }
65
66 private void Start()
67 {
68 }
69
70 private void Update()
71 {
73 }
74
76 {
77 if (renderTexture.width != Screen.width || renderTexture.height != Screen.height)
78 {
79 UnityEngine.Object.Destroy(renderTexture);
80 renderTexture = new RenderTexture(Screen.width, Screen.height, 24);
81 }
82 }
83
84 private IEnumerator EnlargeAreaAroundPointer()
85 {
86 while (true)
87 {
88 yield return new WaitForEndOfFrame();
91 int num = (int)Mathf.Clamp(Input.mousePosition.x, 0f, texture2D.width);
92 int num2 = (int)Mathf.Clamp(Input.mousePosition.y, 0f, texture2D.height);
93 Vector2 vector = new Vector2(num - 8, num2 - 8);
94 Vector2 vector2 = new Vector2(num + 8, num2 + 8);
95 Vector2 vector3 = new Vector2(Mathf.Clamp(vector.x, 0f, texture2D.width - 8), Mathf.Clamp(vector.y, 0f, texture2D.height - 8));
96 Vector2 vector4 = new Vector2(Mathf.Clamp(vector2.x, 8f, texture2D.width), Mathf.Clamp(vector2.y, 8f, texture2D.height));
97 int blockWidth = (int)vector4.x - (int)vector3.x;
98 int blockHeight = (int)vector4.y - (int)vector3.y;
99 Color[] pixels = texture2D.GetPixels((int)vector3.x, (int)vector3.y, blockWidth, blockHeight);
100 float num3 = vector3.x - vector.x;
101 float num4 = vector3.y - vector.y;
102 pixelBlock.SetPixels(0, 0, 16, 16, black16x16);
103 pixelBlock.SetPixels((int)num3, (int)num4, blockWidth, blockHeight, pixels);
105 }
106 }
107
108 private void UpdateTexture()
109 {
110 texture2D.ReadPixels(new Rect(0f, 0f, renderTexture.width, renderTexture.height), 0, 0);
111 texture2D.Apply();
112 }
113
115 {
116 int num = (int)Mathf.Clamp(Input.mousePosition.x, 0f, texture2D.width);
117 int num2 = (int)Mathf.Clamp(Input.mousePosition.y, 0f, texture2D.height);
118 Vector2 vector = new Vector2(num - 8, num2 - 8);
119 Vector2 vector2 = new Vector2(num + 8, num2 + 8);
120 Vector2 vector3 = new Vector2(Mathf.Clamp(vector.x, 0f, texture2D.width - 8), Mathf.Clamp(vector.y, 0f, texture2D.height - 8));
121 Vector2 vector4 = new Vector2(Mathf.Clamp(vector2.x, 8f, texture2D.width), Mathf.Clamp(vector2.y, 8f, texture2D.height));
122 int num3 = (int)vector4.x - (int)vector3.x;
123 int num4 = (int)vector4.y - (int)vector3.y;
124 color = texture2D.GetPixel((int)vector3.x + num3 / 2, (int)vector3.y + num4 / 2);
125 }
126
127 public void PickColors(Action<Color> onColorPicked, Action onDropCanceled)
128 {
129 this.onDropCanceled = onDropCanceled;
130 this.onColorPicked = onColorPicked;
131 palette.ShowDropperMarker(value: true);
132 blocker = UnityEngine.Object.Instantiate(blockerPrefab);
133 blocker.onClick.AddListener(OnBlockerClicked);
134 coroutine = blocker.StartCoroutine(EnlargeAreaAroundPointer());
135 }
136
137 private void OnBlockerClicked()
138 {
140 Stop();
142 }
143
144 public void Stop()
145 {
146 palette.ShowDropperMarker(value: false);
147 StopCoroutine(coroutine);
148 coroutine = null;
149 UnityEngine.Object.Destroy(blocker.gameObject);
150 blocker = null;
151 }
152}
void ShowEnlargedPixels(Color[] colors)
void PickColors(Action< Color > onColorPicked, Action onDropCanceled)
Definition: Dropper.cs:127
IEnumerator EnlargeAreaAroundPointer()
Definition: Dropper.cs:84
Action< Color > onColorPicked
Definition: Dropper.cs:36
RenderTexture renderTexture
Definition: Dropper.cs:22
void UpdateRenderTextureIfNecessary()
Definition: Dropper.cs:75