Skip to content

Commit 613502e

Browse files
committed
Added dependency checker for the editor
1 parent 385da46 commit 613502e

File tree

8 files changed

+251
-36
lines changed

8 files changed

+251
-36
lines changed

Assets/CoReality/Scripts/AvatarSystem/AvatarModule.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,21 @@ void Awake()
128128

129129
//Check for network module (Ensure this is after NetworkModule in Script Execution Order)
130130
if (!NetworkModule.Instance)
131-
throw new System.Exception("NetworkModule not present in scene? Can't start AvatarModule until it exists.");
131+
throw new System.Exception("NetworkModule not present in scene? Can't start AvatarModule without it.");
132132

133133
//Add HandPose to Photon's known serializable data types
134134
PhotonPeer.RegisterType(typeof(HandPose), 0x68, HandPose.SerializeHandPose, HandPose.DeserializeHandPose);
135135
PhotonNetwork.AddCallbackTarget(this);
136136
}
137137

138-
138+
/// <summary>
139+
/// Spawns either a remote or local avatar
140+
/// </summary>
141+
/// <param name="remote">flag to spawn a remote or local avatar</param>
142+
/// <param name="viewID"> the avatar's view idea, only needed for remote spawning</param>
139143
private void SpawnAvatar(bool remote, int viewID = -1)
140144
{
145+
print("Spawn Avatar Start");
141146
//spawn local avatar
142147
HoloAvatar avatar = Instantiate(_holoAvatarPrefab);
143148
avatar.Initalize(remote);
@@ -154,11 +159,11 @@ private void SpawnAvatar(bool remote, int viewID = -1)
154159
new RaiseEventOptions
155160
{
156161
Receivers = ReceiverGroup.Others,
157-
CachingOption = EventCaching.AddToRoomCache
162+
CachingOption = EventCaching.AddToRoomCache,
158163
},
159164
new SendOptions
160165
{
161-
Reliability = true
166+
DeliveryMode = DeliveryMode.Reliable
162167
}
163168
);
164169
_onAvatarCreated?.Invoke(avatar);
@@ -184,8 +189,12 @@ private void SpawnAvatar(bool remote, int viewID = -1)
184189
_localAvatar.Name = _randomAdjectives[UnityEngine.Random.Range(0, _randomAdjectives.Count)] + " "
185190
+ _randomNouns[UnityEngine.Random.Range(0, _randomNouns.Count)];
186191
_localAvatar.Color = _randomColors[UnityEngine.Random.Range(0, _randomColors.Count)];
192+
193+
print("Spawn Avatar End");
187194
}
188195

196+
#region PUN Callbacks
197+
189198
public void OnJoinedRoom()
190199
{
191200
//Spawn local avatar
@@ -218,6 +227,7 @@ public void OnPlayerLeftRoom(Player otherPlayer)
218227

219228
public void OnEvent(EventData photonEvent)
220229
{
230+
print("On Event");
221231
if (photonEvent.Code == AVATAR_EVENT)
222232
SpawnAvatar(true, (int)photonEvent.CustomData);
223233
}
@@ -242,6 +252,8 @@ public void OnPlayerPropertiesUpdate(Player targetPlayer, ExitGames.Client.Photo
242252
public void OnMasterClientSwitched(Player newMasterClient)
243253
{ }
244254

255+
#endregion
256+
245257
}
246258

247259
[Serializable]

Assets/CoReality/Scripts/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#if UNITY_EDITOR
2+
3+
using UnityEditor;
4+
using UnityEngine;
5+
using System.IO;
6+
7+
namespace CoReality
8+
{
9+
public class DependencyChecker : EditorWindow
10+
{
11+
12+
13+
static bool _hasMRTK;
14+
static bool _hasVuforia;
15+
static bool _hasPhoton;
16+
17+
[MenuItem("CoReality/DependencyChecker")]
18+
public static void InitPopup()
19+
{
20+
DependencyChecker window = (DependencyChecker)EditorWindow.GetWindow(typeof(DependencyChecker));
21+
window.position = new Rect((Screen.width / 2) - 150, (Screen.height / 2) - 110, 300, 220);
22+
window.ShowPopup();
23+
24+
Refresh();
25+
}
26+
27+
static void Refresh()
28+
{
29+
//Do Check
30+
string mrtkVersion = Application.dataPath + "/MRTK/SDK/Version.txt";
31+
if (File.Exists(mrtkVersion))
32+
{
33+
if (File.ReadAllText(mrtkVersion)
34+
.Contains("Microsoft Mixed Reality Toolkit 2.7.2"))
35+
{
36+
_hasMRTK = true;
37+
}
38+
}
39+
40+
_hasPhoton = Directory.Exists(Application.dataPath + "/Photon");
41+
42+
}
43+
44+
void OnGUI()
45+
{
46+
EditorGUILayout.Separator();
47+
48+
GUIStyle headerStyle = EditorStyles.label;
49+
headerStyle.fontSize = 18;
50+
headerStyle.alignment = TextAnchor.MiddleCenter;
51+
52+
EditorGUILayout.LabelField("CoReality Dependencies", headerStyle);
53+
54+
GUIStyle labelStyle = EditorStyles.label;
55+
labelStyle.fontSize = 14;
56+
headerStyle.alignment = TextAnchor.MiddleLeft;
57+
58+
EditorGUILayout.Separator();
59+
60+
EditorGUILayout.LabelField("Mixed Reality Toolkit 2.7.2", labelStyle);
61+
if (!_hasMRTK)
62+
{
63+
EditorGUILayoutExtensions.LinkLabel("Download there", Color.blue, Vector2.zero, 14, "https://github.com/microsoft/MixedRealityToolkit-Unity/releases/tag/v2.7.2");
64+
}
65+
else
66+
{
67+
EditorGUILayout.LabelField("Installation found ✓", labelStyle);
68+
}
69+
70+
EditorGUILayout.Separator();
71+
72+
EditorGUILayout.LabelField("Vuforia (latest)", labelStyle);
73+
if (!_hasVuforia)
74+
{
75+
EditorGUILayoutExtensions.LinkLabel("Download here", Color.blue, Vector2.zero, 14, "https://developer.vuforia.com/");
76+
}
77+
else
78+
{
79+
EditorGUILayout.LabelField("Installation found ✓", labelStyle);
80+
}
81+
82+
EditorGUILayout.Separator();
83+
84+
EditorGUILayout.LabelField("Photon PUN 2 Unity", labelStyle);
85+
if (!_hasPhoton)
86+
{
87+
EditorGUILayoutExtensions.LinkLabel("Download here", Color.blue, Vector2.zero, 14, "https://assetstore.unity.com/packages/tools/network/pun-2-free-119922");
88+
}
89+
else
90+
{
91+
EditorGUILayout.LabelField("Installation found ✓", labelStyle);
92+
}
93+
94+
EditorGUILayout.Separator();
95+
96+
if (GUILayout.Button("Refresh")) Refresh();
97+
if (GUILayout.Button("Close")) this.Close();
98+
}
99+
}
100+
101+
}
102+
103+
#endif

Assets/CoReality/Scripts/Editor/DependencyChecker.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using UnityEngine;
5+
using UnityEditor;
6+
7+
//Here is a static class to hold my gui stuff.
8+
9+
public static class EditorGUILayoutExtensions
10+
{
11+
12+
//Alternate Method
13+
public static bool LinkLabel(string labelText)
14+
{
15+
return LinkLabel(labelText, Color.black, new Vector2(), 0);
16+
}
17+
18+
//Alternate Method
19+
public static bool LinkLabel(string labelText, Color labelColor)
20+
{
21+
return LinkLabel(labelText, labelColor, new Vector2(), 0);
22+
}
23+
24+
//Alternate Method
25+
public static bool LinkLabel(string labelText, Color labelColor, Vector2 contentOffset)
26+
{
27+
return LinkLabel(labelText, labelColor, contentOffset, 0);
28+
}
29+
30+
//The Main Method
31+
public static bool LinkLabel(string labelText, Color labelColor, Vector2 contentOffset, int fontSize)
32+
{
33+
//Let's use Unity's label style for this
34+
GUIStyle stl = EditorStyles.label;
35+
//Next let's record the settings for Unity's label style because we will have to make sure these settings get returned back to
36+
//normal after we are done changing them and drawing our LinkLabel.
37+
Color col = stl.normal.textColor;
38+
Vector2 os = stl.contentOffset;
39+
int size = stl.fontSize;
40+
//Now we can modify the label's settings via the editor style : EditorStyles.label (stl).
41+
stl.normal.textColor = labelColor;
42+
stl.contentOffset = contentOffset;
43+
stl.fontSize = fontSize;
44+
//We are now ready to draw our Linklabel. I will actually use a GUILayout.Button to do this and our "stl" style will
45+
//make the button appear as a label.
46+
47+
//Note : You may include a web address parameter in this method and open a URL at this point if the button is clicked,
48+
//however, I am going to just return bool based on weather or not the link was clicked. This gives me more control over
49+
//what actually happens when a link label is used. I also will instead include a "URL version" of this method below.
50+
51+
//Since the button already returns bool, I will just return that result straight across like this.
52+
53+
try
54+
{
55+
return GUILayout.Button(labelText, stl);
56+
}
57+
finally
58+
{
59+
//Remember to set the editor style (stl) back to normal here. A try / finally clause will work perfectly for this!!!
60+
61+
stl.normal.textColor = col;
62+
stl.contentOffset = os;
63+
stl.fontSize = size;
64+
}
65+
}
66+
67+
//This is a modified version of link label that opens a URL automatically. Note : this can also return bool if you want.
68+
public static void LinkLabel(string labelText, Color labelColor, Vector2 contentOffset, int fontSize, string webAddress)
69+
{
70+
if (LinkLabel(labelText, labelColor, contentOffset, fontSize))
71+
{
72+
try
73+
{
74+
Application.OpenURL(@webAddress);
75+
//if returning bool, return true here.
76+
}
77+
catch
78+
{
79+
//In most cases, the catch clause would not happen but in the interest of being thorough I will log an
80+
//error and have Unity "beep" if an exception gets thrown for any reason.
81+
Debug.LogError("Could not open URL. Please check your network connection and ensure the web address is correct.");
82+
EditorApplication.Beep();
83+
}
84+
}
85+
//if returning bool, return false here.
86+
}
87+
}
88+

Assets/CoReality/Scripts/Editor/EditorGUILayoutExtensions.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/CoReality/Scripts/NetworkModule.cs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public class NetworkModule : MonoBehaviour, IMatchmakingCallbacks, IConnectionCa
3434
[SerializeField, Tooltip("The OPTIONAL vuforia target. This marker is what is used to align each user's networked space.")]
3535
/// <summary>
3636
/// If no vuforia target is supplied the default position of the origin will be world zero
37-
/// and all users will be aligned around their world zero (the spatial head position the
38-
/// application was launched from).
37+
/// and all users will be aligned around that position
38+
/// On hololens this is the user's inital head position when the launch the application.
3939
/// </summary>
4040
protected DefaultTrackableEventHandler _vuforiaTarget;
4141

@@ -139,43 +139,28 @@ public static void Disconnect()
139139
#region PUN Callbacks
140140

141141
public void OnFriendListUpdate(List<FriendInfo> friendList)
142-
{
143-
144-
}
142+
{}
145143

146144
public void OnCreatedRoom()
147-
{
148-
149-
}
145+
{}
150146

151147
public void OnCreateRoomFailed(short returnCode, string message)
152-
{
153-
154-
}
148+
{}
155149

156150
public void OnJoinedRoom()
157-
{
158-
159-
}
151+
{}
160152

161153
public void OnJoinRoomFailed(short returnCode, string message)
162-
{
163-
164-
}
154+
{}
165155

166156
public void OnJoinRandomFailed(short returnCode, string message)
167-
{
168-
169-
}
157+
{}
170158

171159
public void OnLeftRoom()
172-
{
173-
174-
}
160+
{}
175161

176162
public void OnConnected()
177-
{
178-
}
163+
{}
179164

180165
public void OnConnectedToMaster()
181166
{

ProjectSettings/EditorBuildSettings.asset

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ EditorBuildSettings:
66
serializedVersion: 2
77
m_Scenes:
88
- enabled: 1
9-
path: Assets/CoReality/Examples/3 Desktop Hololens Mode/3.1 Startup.unity
10-
guid: 000844f5b22562846a892f5ac9d8c9fd
9+
path: Assets/CoReality/Examples/1 Networked Object/1 Networked Object.unity
10+
guid: f50610625c8ade24e87bc6de74eca77b
1111
- enabled: 1
12-
path: Assets/CoReality/Examples/3 Desktop Hololens Mode/3.2 Desktop.unity
13-
guid: af1d792426ea7804ca6ecffa736b7ae8
14-
- enabled: 1
15-
path: Assets/CoReality/Examples/3 Desktop Hololens Mode/3.3 Hololens.unity
16-
guid: bcaa3e1a7829cef45832d078dccb5b27
12+
path: Assets/CoReality/Examples/2 Hololens Avatars/2 Hololens Avatars.unity
13+
guid: f0a2ab1031f83e64e84ecdbc62bfe8fb
1714
m_configObjects: {}

0 commit comments

Comments
 (0)