This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathCardPOIManager.cs
More file actions
157 lines (135 loc) · 4.73 KB
/
CardPOIManager.cs
File metadata and controls
157 lines (135 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using Microsoft.MixedReality.Toolkit.Input;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GalaxyExplorer
{
public class CardPOIManager : MonoBehaviour, IMixedRealityPointerHandler
{
[Header("Galaxy Card POI Fading")]
[Tooltip("The time it takes for all points of interest to completely fade out when a card point of interest is selected.")]
public float POIFadeOutTime = 1.0f;
[Tooltip("How the opacity changes when all points of interest fade out when a card is selected.")]
public AnimationCurve POIOpacityCurve;
private List<PointOfInterest> allPOIs = new List<PointOfInterest>();
private SpiralGalaxy[] spiralGalaxies;
private PoiAnimator poiAnimator;
public void RegisterPOI(PointOfInterest poi)
{
if (!allPOIs.Contains(poi))
{
allPOIs.Add(poi);
}
}
public void UnRegisterPOI(PointOfInterest poi)
{
allPOIs.Remove(poi);
}
// Find if a card POI is activa and its card is on/visible
public bool IsAnyCardActive()
{
foreach (var poi in allPOIs)
{
if (poi.IsCardActive)
{
return true;
}
}
return false;
}
// If a poi card is active then deactivate all poi colliders so user cant activate another one during card presentation
// This needs to happen in every airtap, mouse click, controller click, keyboard tap so any open magic window card will close
public IEnumerator UpdateActivationOfPOIColliders(bool waitForEndOfFrame = true)
{
if (waitForEndOfFrame)
{
yield return new WaitForEndOfFrame();
}
if (GalaxyExplorerManager.Instance.TransitionManager.InTransition)
{
yield break;
}
bool isAnyCardActive = IsAnyCardActive();
if (spiralGalaxies == null || spiralGalaxies.Length < 1)
{
spiralGalaxies = FindObjectsOfType<SpiralGalaxy>();
}
if (poiAnimator == null)
{
poiAnimator = FindObjectOfType<PoiAnimator>();
}
if (isAnyCardActive)
{
foreach (var poi in allPOIs)
{
if (poi.IndicatorCollider)
{
poi.IndicatorCollider.enabled = false;
}
}
if (spiralGalaxies != null)
{
foreach (var spiralGalaxy in spiralGalaxies)
{
spiralGalaxy.IsSpinning = false;
}
if (poiAnimator != null)
{
poiAnimator.animator.speed = 0;
}
}
}
else
{
if (spiralGalaxies != null)
{
foreach (var spiralGalaxy in spiralGalaxies)
{
spiralGalaxy.IsSpinning = true;
}
if (poiAnimator != null)
{
poiAnimator.animator.speed = 1;
}
}
}
}
// Find if a card POI is active and its card is on/visible, close the card and trigger audio
public void CloseAnyOpenCard()
{
bool isCardActive = false;
foreach (var poi in allPOIs)
{
if (poi.IsCardActive)
{
isCardActive = true;
poi.OnPointerDown(null);
break;
}
}
// If any magic window card was active then activate all indicator colliders
if (isCardActive)
{
foreach (var poi in allPOIs)
{
if (poi.IndicatorCollider)
{
poi.IndicatorCollider.enabled = true;
}
}
}
}
public void OnPointerUp(MixedRealityPointerEventData eventData)
{
}
public virtual void OnPointerDown(MixedRealityPointerEventData eventData)
{
StartCoroutine(UpdateActivationOfPOIColliders());
}
public void OnPointerClicked(MixedRealityPointerEventData eventData)
{
}
}
}