14using System.Collections.Generic;
23 [Tooltip(
"A list of RectTransforms that are floated relative to this GameObject.")]
34 [Tooltip(
"The child UI Element to hover above the canvas")]
37 [Tooltip(
"The height above this (base) element that the Layer will float")]
40 [Tooltip(
"The minimum height that this layer can be compressed to.")]
43 [Tooltip(
"OPTIONAL: If you have a dropshadow image that you would like to opacity fade on compression, add one here")]
46 [Tooltip(
"If the shadow effect is not childed to this layer, but the layer above it (for masking purposes)")]
49 [Tooltip(
"If the event is triggered upon touching this layer (useful for ratcheted sounds)")]
70 [Tooltip(
"The movement speed of this element when the expansion event is triggered; between 0-1")]
73 [Tooltip(
"The movement speed of this element when the compression event is triggered; between 0-1")]
76 [Tooltip(
"Padding below the selection threshold that the element begins depressing")]
81 [Tooltip(
"Triggered when the layers that have 'TriggerLayerEvent' enabled go from 'Expanded' to 'Partially Expanded'")]
84 [Tooltip(
"Triggered when the layers that have 'TriggerLayerEvent' enabled go from 'Expanded' or 'Partially Expanded' to 'Collapsed'")]
87 [Tooltip(
"Triggered when the layers that have 'TriggerLayerEvent' enabled go from 'Collapsed' to 'Partially Expanded' or 'Expanded'")]
92 private float curLerpSpeed = 0.1f;
95 private float HoveringDistance = 0f;
98 private bool currentlyFloating =
false;
100 private float TimeLastHovered = 0f;
104 for (
int i = 0; i <
Layers.Length; i++) {
105 if (
Layers[i].LayerTransform !=
null &&
Layers[i].LayerTransform != transform) {
108 if (
Layers[i].Shadow !=
null) {
113 Debug.LogWarning(
"Ensure that the layers that you have allotted are children of CompressibleUI object and have UI Elements in them!");
121 void OnApplicationQuit() {
122 for (
int i = 0; i <
Layers.Length; i++) {
123 if (
Layers[i].LayerTransform !=
null) {
131 if (Time.time > TimeLastHovered + 0.1f && HoveringDistance != 100f) {
132 HoveringDistance = 100f;
134 for (
int i = 0; i <
Layers.Length; i++) {
136 if (currentlyFloating) {
137 if (
Layers[i].LayerTransform !=
null) {
138 if (HoveringDistance <
Layers[i].MaxFloatDistance && HoveringDistance >
Layers[i].MinFloatDistance) {
140 if (
Layers[i].TriggerLayerEvent && !
Layers[i].touchingFinger) {
144 }
else if (HoveringDistance <
Layers[i].MinFloatDistance) {
145 if (
Layers[i].TriggerLayerEvent) {
146 if (!
Layers[i].touchingFinger) {
149 if (
Layers[i].CurrentFloatingDistance >
Layers[i].MinFloatDistance) {
156 if (
Layers[i].TriggerLayerEvent &&
Layers[i].touchingFinger) {
164 if (
Layers[i].LayerTransform !=
null) {
166 if (
Layers[i].TriggerLayerEvent &&
Layers[i].touchingFinger) {
173 if (
Layers[i].Shadow !=
null) {
174 if (
Layers[i].ShadowOnAboveLayer) {
187 if (
Layers[i].LayerTransform !=
null) {
199 TimeLastHovered = Time.time;
204 currentlyFloating =
true;
211 currentlyFloating =
false;
218 for (
int i = 0; i <
Layers.Length; i++) {
223 for (
int i = 0; i <
Layers.Length; i++) {
231 for (
int i = 0; i <
Layers.Length; i++) {
232 if (
Layers[i].LayerTransform !=
null) {
239 public static class ExtensionMethods {
240 public static float Remap(
this float value,
float from1,
float to1,
float from2,
float to2) {
241 return (value - from1) / (to1 - from1) * (to2 - from2) + from2;