Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
CircularRadialButton.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5public class CircularRadialButton : MonoBehaviour
6{
8
9 public float MainButtonMinSize = 0.5f;
10
11 public float MainButtonMaxSize = 1f;
12
13 public AnimationCurve MainButtonImageCurve;
14
16
17 [Header("Options Settings")]
18 public List<RectTransform> Options;
19
20 public float OptionsMinRadius = 75f;
21
22 public float OptionsMaxRadius = 120f;
23
24 [Tooltip("the scale size the options will have when the menu is collapsed.")]
25 public float OptionsMinSize = 0.1f;
26
27 [Tooltip("the scale size the options will have when the menu is expanded")]
28 public float OptionsMaxSize = 1f;
29
30 [Tooltip("this defines the options’ angle separation when the menu is collapsed.")]
32
33 [Tooltip("this defines the options’ angle separation when the menu is expanded.")]
35
36 [Tooltip("defines the start angle for the previous options (counterclockwise)")]
37 public float StartAngleOffset;
38
39 [Tooltip("sets whether the menu options are shown one by one or all at once.")]
41
42 [Tooltip("defines the time is takes from the collapsed menu to be expanded.")]
43 public float OpenTransitionTime = 0.5f;
44
45 [Tooltip("defines the time is takes from the expanded menu to be collapsed.")]
46 public float CloseTransitionTime = 0.5f;
47
48 private float TransitionTime = 0.5f;
49
50 [Tooltip("is used to define the options’ scale size over Open Transition time.")]
51 public AnimationCurve OpenCurve;
52
53 [Tooltip("is used to define the options’ scale size over Close Transition time.")]
54 public AnimationCurve CloseCurve;
55
56 private AnimationCurve CurrentCurve;
57
58 private bool Open;
59
60 private float T;
61
62 public void Init()
63 {
64 moldButton.SetActive(enable: false);
69 StartAngleOffset = 90f;
70 if (Options.Count == 10)
71 {
72 StartAngleOffset = 108f;
73 }
74 Animate();
75 Toggle();
76 int num = 4;
77 for (int i = 0; i < Options.Count; i++)
78 {
79 num++;
80 if (num >= Options.Count)
81 {
82 num = 0;
83 }
84 Options[num].transform.SetAsFirstSibling();
85 }
86 }
87
88 public void Toggle()
89 {
90 if (T < TransitionTime)
91 {
92 return;
93 }
94 Open = !Open;
97 T = 0f;
99 {
100 CircularRadialButton[] componentsInChildren = GetComponentsInChildren<CircularRadialButton>();
101 for (int i = 0; i < componentsInChildren.Length; i++)
102 {
103 componentsInChildren[i].CloseIfOpen();
104 }
105 }
106 }
107
108 public void CloseIfOpen()
109 {
110 if (Open)
111 {
112 Toggle();
113 }
114 }
115
116 private void Update()
117 {
118 if (!(T >= TransitionTime))
119 {
120 T += Time.deltaTime;
121 if (T > TransitionTime)
122 {
124 }
125 Animate();
126 }
127 }
128
129 private void Animate()
130 {
131 int count = Options.Count;
132 float num = TransitionTime / (float)count;
133 float time = T * 2f / TransitionTime;
135 float num3 = num2 * (float)(count - 1) / 2f + StartAngleOffset;
136 for (int i = 0; i < count; i++)
137 {
138 if (!(Options[i] == null))
139 {
140 float time2 = (T - num * (float)i) / num;
141 if (T >= num * (float)i && T < num * (float)(i + 1))
142 {
143 time2 = (T - num * (float)i) / num;
144 float num4 = OptionsMinSize + (OptionsMaxSize - OptionsMinSize) * CurrentCurve.Evaluate(time2);
145 Options[i].transform.localScale = new Vector3(num4, num4, num4);
146 }
147 if (ShowAllOptionsAtOnce || T >= num * (float)(i + 1))
148 {
149 time2 = T / num;
150 float num5 = OptionsMinSize + (OptionsMaxSize - OptionsMinSize) * CurrentCurve.Evaluate(time2);
151 Options[i].transform.localScale = new Vector3(num5, num5, num5);
152 }
153 float num6 = OptionsMinRadius + (OptionsMaxRadius - OptionsMinRadius) * CurrentCurve.Evaluate(time2);
154 float x = num6 * Mathf.Cos(MathF.PI / 180f * num3);
155 float y = num6 * Mathf.Sin(MathF.PI / 180f * num3);
156 Options[i].GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
157 num3 -= num2;
158 }
159 }
160 }
161
162 public UIButton AddOption(Sprite sprite, Action action = null)
163 {
164 UIButton uIButton = Util.Instantiate(moldButton, base.transform);
165 uIButton.SetActive(enable: true);
166 uIButton.icon.sprite = sprite;
167 RectTransform rectTransform = uIButton.Rect();
168 if (Options == null)
169 {
170 Options = new List<RectTransform>();
171 }
172 Options.Add(rectTransform);
173 _ = Options.Count;
174 uIButton.onClick.SetListener(action);
175 rectTransform.localPosition = new Vector3(0f, 0f, 0f);
176 return uIButton;
177 }
178}
List< RectTransform > Options
AnimationCurve MainButtonImageCurve
UIButton AddOption(Sprite sprite, Action action=null)