Elin Decompiled Documentation EA 23.102 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 Start()
51 {
52 }
53
54 private void Update()
55 {
57 }
58
60 {
61 if (renderTexture.width != Screen.width || renderTexture.height != Screen.height)
62 {
63 renderTexture = new RenderTexture(Screen.width, Screen.height, 24);
64 }
65 }
66
67 private IEnumerator EnlargeAreaAroundPointer()
68 {
69 while (true)
70 {
71 yield return new WaitForEndOfFrame();
74 int num = (int)Mathf.Clamp(Input.mousePosition.x, 0f, texture2D.width);
75 int num2 = (int)Mathf.Clamp(Input.mousePosition.y, 0f, texture2D.height);
76 Vector2 vector = new Vector2(num - 8, num2 - 8);
77 Vector2 vector2 = new Vector2(num + 8, num2 + 8);
78 Vector2 vector3 = new Vector2(Mathf.Clamp(vector.x, 0f, texture2D.width - 8), Mathf.Clamp(vector.y, 0f, texture2D.height - 8));
79 Vector2 vector4 = new Vector2(Mathf.Clamp(vector2.x, 8f, texture2D.width), Mathf.Clamp(vector2.y, 8f, texture2D.height));
80 int blockWidth = (int)vector4.x - (int)vector3.x;
81 int blockHeight = (int)vector4.y - (int)vector3.y;
82 Color[] pixels = texture2D.GetPixels((int)vector3.x, (int)vector3.y, blockWidth, blockHeight);
83 float num3 = vector3.x - vector.x;
84 float num4 = vector3.y - vector.y;
85 pixelBlock.SetPixels(0, 0, 16, 16, black16x16);
86 pixelBlock.SetPixels((int)num3, (int)num4, blockWidth, blockHeight, pixels);
88 }
89 }
90
91 private void UpdateTexture()
92 {
93 texture2D.ReadPixels(new Rect(0f, 0f, renderTexture.width, renderTexture.height), 0, 0);
94 texture2D.Apply();
95 }
96
98 {
100 }
101
102 public void PickColors(Action<Color> onColorPicked, Action onDropCanceled)
103 {
104 this.onDropCanceled = onDropCanceled;
105 this.onColorPicked = onColorPicked;
106 palette.ShowDropperMarker(value: true);
107 blocker = UnityEngine.Object.Instantiate(blockerPrefab);
108 blocker.onClick.AddListener(OnBlockerClicked);
109 coroutine = blocker.StartCoroutine(EnlargeAreaAroundPointer());
110 }
111
112 private void OnBlockerClicked()
113 {
114 Stop();
116 }
117
118 public void Stop()
119 {
120 palette.ShowDropperMarker(value: false);
121 StopCoroutine(coroutine);
122 coroutine = null;
123 UnityEngine.Object.Destroy(blocker.gameObject);
124 blocker = null;
125 }
126}
Definition: EInput.cs:8
static Vector3 uiMousePosition
Definition: EInput.cs:369
void ShowEnlargedPixels(Color[] colors)
void PickColors(Action< Color > onColorPicked, Action onDropCanceled)
Definition: Dropper.cs:102
IEnumerator EnlargeAreaAroundPointer()
Definition: Dropper.cs:67
Action< Color > onColorPicked
Definition: Dropper.cs:36
RenderTexture renderTexture
Definition: Dropper.cs:22
void UpdateRenderTextureIfNecessary()
Definition: Dropper.cs:59