diff --git a/Assets/HoloToolkit/Sharing/Prefabs/Sharing.prefab b/Assets/HoloToolkit/Sharing/Prefabs/Sharing.prefab index d0b73087354..6abbf86e3e3 100644 --- a/Assets/HoloToolkit/Sharing/Prefabs/Sharing.prefab +++ b/Assets/HoloToolkit/Sharing/Prefabs/Sharing.prefab @@ -5,12 +5,12 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 475158} - - 114: {fileID: 114000012667812730} - - 114: {fileID: 114000011012997360} - - 114: {fileID: 114000013602799446} + - component: {fileID: 475158} + - component: {fileID: 114000012667812730} + - component: {fileID: 114000013602799446} + - component: {fileID: 114332427252237600} m_Layer: 0 m_Name: Sharing m_TagString: Untagged @@ -42,7 +42,7 @@ Prefab: m_ParentPrefab: {fileID: 0} m_RootGameObject: {fileID: 163528} m_IsPrefabParent: 1 ---- !u!114 &114000011012997360 +--- !u!114 &114000012667812730 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} @@ -50,10 +50,17 @@ MonoBehaviour: m_GameObject: {fileID: 163528} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9b9c87aaa636d31488ddd2b3e3fe29e3, type: 3} + m_Script: {fileID: 11500000, guid: 9af4ac91e9017f34c971bbf5e12948d3, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &114000012667812730 + ClientRole: 0 + ServerAddress: localhost + ServerPort: 20602 + connectOnAwake: 1 + AutoDiscoverServer: 0 + PingIntervalSec: 2 + IsAudioEndpoint: 1 +--- !u!114 &114000013602799446 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} @@ -61,14 +68,11 @@ MonoBehaviour: m_GameObject: {fileID: 163528} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9af4ac91e9017f34c971bbf5e12948d3, type: 3} + m_Script: {fileID: 11500000, guid: 8fa5da1314a4aa745a5be3f0f6ab6bd6, type: 3} m_Name: m_EditorClassIdentifier: - ClientRole: 0 - ServerAddress: localhost - ServerPort: 20602 - IsAudioEndpoint: 0 ---- !u!114 &114000013602799446 + SessionName: Default +--- !u!114 &114332427252237600 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} @@ -76,7 +80,6 @@ MonoBehaviour: m_GameObject: {fileID: 163528} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 8fa5da1314a4aa745a5be3f0f6ab6bd6, type: 3} + m_Script: {fileID: 11500000, guid: c7a63ef1b98adec49bdb80fe1f187893, type: 3} m_Name: m_EditorClassIdentifier: - SessionName: Default diff --git a/Assets/HoloToolkit/Sharing/Editor.meta b/Assets/HoloToolkit/Sharing/Scripts/Editor.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Editor.meta rename to Assets/HoloToolkit/Sharing/Scripts/Editor.meta diff --git a/Assets/HoloToolkit/Sharing/Editor/SharingMenu.cs b/Assets/HoloToolkit/Sharing/Scripts/Editor/SharingMenu.cs similarity index 90% rename from Assets/HoloToolkit/Sharing/Editor/SharingMenu.cs rename to Assets/HoloToolkit/Sharing/Scripts/Editor/SharingMenu.cs index 98dc411ad6f..e6419a3d74b 100644 --- a/Assets/HoloToolkit/Sharing/Editor/SharingMenu.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Editor/SharingMenu.cs @@ -4,6 +4,7 @@ using UnityEditor; using UnityEngine; using System.IO; +using HoloToolkit.Utilities; namespace HoloToolkit.Sharing { @@ -21,7 +22,7 @@ public static void LaunchSessionServer() return; } - Utilities.ExternalProcess.FindAndLaunch(filePathName, @"-local"); + ExternalProcess.FindAndLaunch(filePathName, @"-local"); } [MenuItem("HoloToolkit/Sharing Service/Launch Session Manager", false, 101)] @@ -36,7 +37,7 @@ public static void LaunchSessionUI() return; } - Utilities.ExternalProcess.FindAndLaunch(filePathName); + ExternalProcess.FindAndLaunch(filePathName); } [MenuItem("HoloToolkit/Sharing Service/Launch Profiler", false, 103)] @@ -51,7 +52,7 @@ public static void LaunchProfilerX() return; } - Utilities.ExternalProcess.FindAndLaunch(filePathName); + ExternalProcess.FindAndLaunch(filePathName); } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Editor/SharingMenu.cs.meta b/Assets/HoloToolkit/Sharing/Scripts/Editor/SharingMenu.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Editor/SharingMenu.cs.meta rename to Assets/HoloToolkit/Sharing/Scripts/Editor/SharingMenu.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Editor/SharingStageEditor.cs b/Assets/HoloToolkit/Sharing/Scripts/Editor/SharingStageEditor.cs similarity index 69% rename from Assets/HoloToolkit/Sharing/Editor/SharingStageEditor.cs rename to Assets/HoloToolkit/Sharing/Scripts/Editor/SharingStageEditor.cs index 0a4b56377cd..3ad819d0775 100644 --- a/Assets/HoloToolkit/Sharing/Editor/SharingStageEditor.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Editor/SharingStageEditor.cs @@ -10,7 +10,7 @@ namespace HoloToolkit.Sharing { - [CustomEditor(typeof (SharingStage))] + [CustomEditor(typeof(SharingStage))] public class SharingStageEditor : Editor { private Dictionary foldoutGUIMap = new Dictionary(); @@ -21,7 +21,7 @@ public override void OnInspectorGUI() if (Application.isPlaying) { - SharingStage networkManager = target as SharingStage; + SharingStage networkManager = (SharingStage)target; SyncRoot root = networkManager.Root; @@ -44,34 +44,34 @@ public override void OnInspectorGUI() private void DrawDataModelGUI(SyncPrimitive syncPrimitive, string parentPath) { - string name = syncPrimitive.FieldName; - object value = syncPrimitive.RawValue; + string fieldName = syncPrimitive.FieldName; + object rawValue = syncPrimitive.RawValue; - SyncObject SyncObject = syncPrimitive as SyncObject; + SyncObject syncObject = syncPrimitive as SyncObject; - if (SyncObject != null) + if (syncObject != null) { bool foldout = false; - if (foldoutGUIMap.ContainsKey(SyncObject)) + if (foldoutGUIMap.ContainsKey(syncObject)) { - foldout = foldoutGUIMap[SyncObject]; + foldout = foldoutGUIMap[syncObject]; } - int ownerId = SyncObject.OwnerId; + int ownerId = syncObject.OwnerId; string owner = ownerId == int.MaxValue ? string.Empty : ownerId.ToString(); - string objectType = SyncObject.ObjectType; + string objectType = syncObject.ObjectType; - foldout = EditorGUILayout.Foldout(foldout, string.Format("{0} (Owner:{1} Type:{2})", name, owner, objectType)); - foldoutGUIMap[SyncObject] = foldout; + foldout = EditorGUILayout.Foldout(foldout, string.Format("{0} (Owner:{1} Type:{2})", fieldName, owner, objectType)); + foldoutGUIMap[syncObject] = foldout; if (foldout) { EditorGUI.indentLevel++; - SyncPrimitive[] children = SyncObject.GetChildren(); + SyncPrimitive[] children = syncObject.GetChildren(); for (int i = 0; i < children.Length; i++) { - DrawDataModelGUI(children[i], parentPath + "/" + name); + DrawDataModelGUI(children[i], parentPath + "/" + fieldName); } EditorGUI.indentLevel--; @@ -80,13 +80,12 @@ private void DrawDataModelGUI(SyncPrimitive syncPrimitive, string parentPath) else { EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField(name, GUILayout.MaxWidth(125)); - EditorGUILayout.LabelField(value != null ? value.ToString() : "null", GUILayout.MaxWidth(200)); - EditorGUILayout.LabelField(syncPrimitive.NetworkElement != null ? "live" : "local", - GUILayout.MaxWidth(50)); + EditorGUILayout.LabelField(fieldName, GUILayout.MaxWidth(125)); + EditorGUILayout.LabelField(rawValue != null ? rawValue.ToString() : "null", GUILayout.MaxWidth(200)); + EditorGUILayout.LabelField(syncPrimitive.NetworkElement != null ? "live" : "local", GUILayout.MaxWidth(50)); if (syncPrimitive.NetworkElement != null) { - EditorGUILayout.LabelField(parentPath + "/" + name, GUILayout.MaxWidth(500)); + EditorGUILayout.LabelField(parentPath + "/" + fieldName, GUILayout.MaxWidth(500)); } EditorGUILayout.EndHorizontal(); diff --git a/Assets/HoloToolkit/Sharing/Editor/SharingStageEditor.cs.meta b/Assets/HoloToolkit/Sharing/Scripts/Editor/SharingStageEditor.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Editor/SharingStageEditor.cs.meta rename to Assets/HoloToolkit/Sharing/Scripts/Editor/SharingStageEditor.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Scripts/SDK/DiscoveryClientAdapter.cs b/Assets/HoloToolkit/Sharing/Scripts/SDK/DiscoveryClientAdapter.cs index e4c0d0a6c23..4830ebe897e 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SDK/DiscoveryClientAdapter.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SDK/DiscoveryClientAdapter.cs @@ -2,9 +2,6 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace HoloToolkit.Sharing { diff --git a/Assets/HoloToolkit/Sharing/Scripts/ServerSessionsTracker.cs b/Assets/HoloToolkit/Sharing/Scripts/ServerSessionsTracker.cs index 78d9bd26b9a..139b372f250 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/ServerSessionsTracker.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/ServerSessionsTracker.cs @@ -15,7 +15,7 @@ namespace HoloToolkit.Sharing /// public class ServerSessionsTracker : IDisposable { - private bool disposed = false; + private bool disposed; private SessionManager sessionManager; private SessionManagerAdapter sessionManagerAdapter; @@ -31,7 +31,7 @@ public class ServerSessionsTracker : IDisposable public event Action ServerConnected; public event Action ServerDisconnected; - + /// /// List of sessions on the server. /// @@ -49,17 +49,17 @@ public ServerSessionsTracker(SessionManager sessionMgr) if (sessionManager != null) { - this.sessionManagerAdapter = new SessionManagerAdapter(); - sessionManager.AddListener(this.sessionManagerAdapter); - this.sessionManagerAdapter.ServerConnectedEvent += OnServerConnected; - this.sessionManagerAdapter.ServerDisconnectedEvent += OnServerDisconnected; - this.sessionManagerAdapter.SessionClosedEvent += OnSessionClosed; - this.sessionManagerAdapter.SessionAddedEvent += OnSessionAdded; - this.sessionManagerAdapter.CreateSucceededEvent += OnSessionCreatedSuccess; - this.sessionManagerAdapter.CreateFailedEvent += OnSessionCreatedFail; - this.sessionManagerAdapter.UserChangedEvent += OnUserChanged; - this.sessionManagerAdapter.UserJoinedSessionEvent += OnUserJoined; - this.sessionManagerAdapter.UserLeftSessionEvent += OnUserLeft; + sessionManagerAdapter = new SessionManagerAdapter(); + sessionManager.AddListener(sessionManagerAdapter); + sessionManagerAdapter.ServerConnectedEvent += OnServerConnected; + sessionManagerAdapter.ServerDisconnectedEvent += OnServerDisconnected; + sessionManagerAdapter.SessionClosedEvent += OnSessionClosed; + sessionManagerAdapter.SessionAddedEvent += OnSessionAdded; + sessionManagerAdapter.CreateSucceededEvent += OnSessionCreatedSuccess; + sessionManagerAdapter.CreateFailedEvent += OnSessionCreatedFail; + sessionManagerAdapter.UserChangedEvent += OnUserChanged; + sessionManagerAdapter.UserJoinedSessionEvent += OnUserJoined; + sessionManagerAdapter.UserLeftSessionEvent += OnUserLeft; } } @@ -214,19 +214,19 @@ protected virtual void Dispose(bool disposing) { OnServerDisconnected(); - if (this.sessionManagerAdapter != null) + if (sessionManagerAdapter != null) { - this.sessionManagerAdapter.ServerConnectedEvent -= OnServerConnected; - this.sessionManagerAdapter.ServerDisconnectedEvent -= OnServerDisconnected; - this.sessionManagerAdapter.SessionClosedEvent -= OnSessionClosed; - this.sessionManagerAdapter.SessionAddedEvent -= OnSessionAdded; - this.sessionManagerAdapter.CreateSucceededEvent -= OnSessionCreatedSuccess; - this.sessionManagerAdapter.CreateFailedEvent -= OnSessionCreatedFail; - this.sessionManagerAdapter.UserChangedEvent -= OnUserChanged; - this.sessionManagerAdapter.UserJoinedSessionEvent -= OnUserJoined; - this.sessionManagerAdapter.UserLeftSessionEvent -= OnUserLeft; - this.sessionManagerAdapter.Dispose(); - this.sessionManagerAdapter = null; + sessionManagerAdapter.ServerConnectedEvent -= OnServerConnected; + sessionManagerAdapter.ServerDisconnectedEvent -= OnServerDisconnected; + sessionManagerAdapter.SessionClosedEvent -= OnSessionClosed; + sessionManagerAdapter.SessionAddedEvent -= OnSessionAdded; + sessionManagerAdapter.CreateSucceededEvent -= OnSessionCreatedSuccess; + sessionManagerAdapter.CreateFailedEvent -= OnSessionCreatedFail; + sessionManagerAdapter.UserChangedEvent -= OnUserChanged; + sessionManagerAdapter.UserJoinedSessionEvent -= OnUserJoined; + sessionManagerAdapter.UserLeftSessionEvent -= OnUserLeft; + sessionManagerAdapter.Dispose(); + sessionManagerAdapter = null; } if (sessionManager != null) diff --git a/Assets/HoloToolkit/Sharing/Scripts/SessionUsersTracker.cs b/Assets/HoloToolkit/Sharing/Scripts/SessionUsersTracker.cs index 5018ec3de0f..8b9dd242858 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SessionUsersTracker.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SessionUsersTracker.cs @@ -26,7 +26,7 @@ public class SessionUsersTracker : IDisposable /// Local cached pointer to the sessions tracker.. /// private readonly ServerSessionsTracker serverSessionsTracker; - + /// /// List of users that are in the current session. /// @@ -36,33 +36,35 @@ public SessionUsersTracker(ServerSessionsTracker sessionsTracker) { CurrentUsers = new List(); - this.serverSessionsTracker = sessionsTracker; - this.serverSessionsTracker.CurrentUserJoined += OnCurrentUserJoinedSession; - this.serverSessionsTracker.CurrentUserLeft += OnCurrentUserLeftSession; - - this.serverSessionsTracker.UserJoined += OnUserJoinedSession; - this.serverSessionsTracker.UserLeft += OnUserLeftSession; - } - - /// - /// Finds and returns an object representing a user who has the supplied id number. Returns null if the user is not found. - /// - /// The numerical id of the session User to find - /// The User with the specified id or null (if not found) - public User GetUserById(int userId) - { - for (int u = 0; u < CurrentUsers.Count; u++) - { - var user = CurrentUsers[u]; - if (user.GetID() == userId) - return user; - } - return null; - } - - #region IDisposable - - public void Dispose() + serverSessionsTracker = sessionsTracker; + serverSessionsTracker.CurrentUserJoined += OnCurrentUserJoinedSession; + serverSessionsTracker.CurrentUserLeft += OnCurrentUserLeftSession; + + serverSessionsTracker.UserJoined += OnUserJoinedSession; + serverSessionsTracker.UserLeft += OnUserLeftSession; + } + + /// + /// Finds and returns an object representing a user who has the supplied id number. Returns null if the user is not found. + /// + /// The numerical id of the session User to find + /// The User with the specified id or null (if not found) + public User GetUserById(int userId) + { + for (int u = 0; u < CurrentUsers.Count; u++) + { + User user = CurrentUsers[u]; + if (user.GetID() == userId) + { + return user; + } + } + return null; + } + + #region IDisposable + + public void Dispose() { Dispose(true); GC.SuppressFinalize(this); @@ -72,11 +74,11 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - this.serverSessionsTracker.CurrentUserJoined -= OnCurrentUserJoinedSession; - this.serverSessionsTracker.CurrentUserLeft -= OnCurrentUserLeftSession; + serverSessionsTracker.CurrentUserJoined -= OnCurrentUserJoinedSession; + serverSessionsTracker.CurrentUserLeft -= OnCurrentUserLeftSession; - this.serverSessionsTracker.UserJoined -= OnUserJoinedSession; - this.serverSessionsTracker.UserLeft -= OnUserLeftSession; + serverSessionsTracker.UserJoined -= OnUserJoinedSession; + serverSessionsTracker.UserLeft -= OnUserLeftSession; } } @@ -94,7 +96,8 @@ private void OnCurrentUserJoinedSession(Session joinedSession) { User user = joinedSession.GetUser(i); CurrentUsers.Add(user); - UserJoined.RaiseEvent(user);; + UserJoined.RaiseEvent(user); + ; } } @@ -115,9 +118,18 @@ private void OnUserJoinedSession(Session session, User user) if (!CurrentUsers.Contains(user)) { - //Debug.LogFormat("User {0} joined current session.", user.GetName()); - CurrentUsers.RemoveAll(x => x.GetID() == user.GetID()); // in case there was an old user with the same ID - CurrentUsers.Add(user); + //Debug.LogFormat("User {0} joined current session.", user.GetName()); + + // Remove any old users with the same ID + for (int i = 0; i < CurrentUsers.Count; i++) + { + if (CurrentUsers[i].GetID() == user.GetID()) + { + CurrentUsers.Remove(user); + } + } + + CurrentUsers.Add(user); UserJoined.RaiseEvent(user); } } @@ -129,19 +141,22 @@ private void OnUserLeftSession(Session session, User user) return; } - if (CurrentUsers.RemoveAll(x => x.GetID() == user.GetID()) > 0) + for (int i = 0; i < CurrentUsers.Count; i++) { - //Debug.LogFormat("User {0} left current session.", user.GetName()); - UserLeft.RaiseEvent(user); + if (CurrentUsers[i].GetID() == user.GetID()) + { + //Debug.LogFormat("User {0} left current session.", user.GetName()); + UserLeft.RaiseEvent(user); + } } - } - - /// - /// Clears the current session, removing any users being tracked. - /// This should be called whenever the current session changes, to reset this class - /// and handle a new curren session. - /// - private void ClearCurrentSession() + } + + /// + /// Clears the current session, removing any users being tracked. + /// This should be called whenever the current session changes, to reset this class + /// and handle a new curren session. + /// + private void ClearCurrentSession() { for (int i = 0; i < CurrentUsers.Count; i++) { diff --git a/Assets/HoloToolkit/Sharing/Scripts/SharingStage.cs b/Assets/HoloToolkit/Sharing/Scripts/SharingStage.cs index b6b100a3bdd..dc0e9f304ea 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SharingStage.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SharingStage.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using System; +using HoloToolkit.Sharing.Utilities; using HoloToolkit.Unity; using UnityEngine; @@ -15,7 +16,7 @@ public class SharingStage : Singleton /// /// SharingManagerConnected event notifies when the sharing manager is created and connected. /// - public event EventHandler SharingManagerConnected; + public event EventHandler SharingManagerConnected; /// /// Default username to use when joining a session. @@ -52,7 +53,7 @@ public class SharingStage : Singleton public SharingManager Manager { get { return sharingMgr; } } private SharingManager sharingMgr; - public bool AutoDiscoverServer = false; + public bool AutoDiscoverServer; [Tooltip("Determines how often the discovery service should ping the network in search of a server.")] public float PingIntervalSec = 2; @@ -108,8 +109,8 @@ public class SharingStage : Singleton /// private DiscoveryClientAdapter discoveryClientAdapter; - private float pingIntervalCurrent = 0; - private bool isTryingToFindServer = false; + private float pingIntervalCurrent; + private bool isTryingToFindServer; public string UserName { @@ -169,9 +170,9 @@ protected override void OnDestroy() { base.OnDestroy(); - if (this.discoveryClient != null) + if (discoveryClient != null) { - discoveryClient.RemoveListener(this.discoveryClientAdapter); + discoveryClient.RemoveListener(discoveryClientAdapter); discoveryClient.Dispose(); discoveryClient = null; @@ -190,16 +191,16 @@ protected override void OnDestroy() } // Release the Sharing resources - if (this.SessionUsersTracker != null) + if (SessionUsersTracker != null) { - this.SessionUsersTracker.Dispose(); - this.SessionUsersTracker = null; + SessionUsersTracker.Dispose(); + SessionUsersTracker = null; } - if (this.SessionsTracker != null) + if (SessionsTracker != null) { - this.SessionsTracker.Dispose(); - this.SessionsTracker = null; + SessionsTracker.Dispose(); + SessionsTracker = null; } if (networkConnection != null) @@ -227,7 +228,7 @@ protected override void OnDestroy() private void LateUpdate() { - if (this.isTryingToFindServer) + if (isTryingToFindServer) { AutoDiscoverUpdate(); } @@ -265,8 +266,8 @@ private void Connect() Root = new SyncRoot(sharingMgr.GetRootSyncObject()); - this.SessionsTracker = new ServerSessionsTracker(sharingMgr.GetSessionManager()); - this.SessionUsersTracker = new SessionUsersTracker(this.SessionsTracker); + SessionsTracker = new ServerSessionsTracker(sharingMgr.GetSessionManager()); + SessionUsersTracker = new SessionUsersTracker(SessionsTracker); using (XString userName = new XString(DefaultUserName)) { @@ -280,58 +281,58 @@ private void NetworkConnectionAdapter_ConnectedCallback(NetworkConnection obj) } private void SendConnectedNotification() - { - if (Manager.GetServerConnection().IsConnected()) - { + { + if (Manager.GetServerConnection().IsConnected()) + { //Send notification that we're connected - EventHandler connectedEvent = SharingManagerConnected; - if (connectedEvent != null) - { - connectedEvent(this, EventArgs.Empty); - } - } - else - { - Log.Error(string.Format("Cannot connect to server {0}:{1}", ServerAddress, ServerPort)); - } - } - + EventHandler connectedEvent = SharingManagerConnected; + if (connectedEvent != null) + { + connectedEvent(this, EventArgs.Empty); + } + } + else + { + Log.Error(string.Format("Cannot connect to server {0}:{1}", ServerAddress, ServerPort.ToString())); + } + } + private void AutoDiscoverInit() { discoveryClientAdapter = new DiscoveryClientAdapter(); - discoveryClientAdapter.DiscoveredEvent += OnSystemDiscovered; - - discoveryClient = DiscoveryClient.Create(); - discoveryClient.AddListener(discoveryClientAdapter); - + discoveryClientAdapter.DiscoveredEvent += OnSystemDiscovered; + + discoveryClient = DiscoveryClient.Create(); + discoveryClient.AddListener(discoveryClientAdapter); + //Start Finding Server - isTryingToFindServer = true; - } - + isTryingToFindServer = true; + } + private void AutoDiscoverUpdate() - { + { //Searching Enabled-> Update DiscoveryClient to check results, Wait Interval then Ping network. - pingIntervalCurrent += Time.deltaTime; - if (pingIntervalCurrent > PingIntervalSec) - { - pingIntervalCurrent = 0; - discoveryClient.Ping(); - } - discoveryClient.Update(); - } - + pingIntervalCurrent += Time.deltaTime; + if (pingIntervalCurrent > PingIntervalSec) + { + pingIntervalCurrent = 0; + discoveryClient.Ping(); + } + discoveryClient.Update(); + } + private void OnSystemDiscovered(DiscoveredSystem obj) - { - if (obj.GetRole() == SystemRole.SessionDiscoveryServerRole) - { + { + if (obj.GetRole() == SystemRole.SessionDiscoveryServerRole) + { //Found a server. Stop pinging the network and connect - isTryingToFindServer = false; - this.ServerAddress = obj.GetAddress(); - Debug.Log("System Discovered at: " + this.ServerAddress); - Connect(); - Debug.Log(string.Format("Connected to: {0}:{1}", this.ServerAddress, this.ServerPort)); - } - } + isTryingToFindServer = false; + ServerAddress = obj.GetAddress(); + Debug.Log("System Discovered at: " + ServerAddress); + Connect(); + Debug.LogFormat("Connected to: {0}:{1}", ServerAddress, ServerPort.ToString()); + } + } public void ConnectToServer(string serverAddress, int port) { diff --git a/Assets/HoloToolkit/Sharing/Scripts/Spawning/PrefabSpawnManager.cs b/Assets/HoloToolkit/Sharing/Scripts/Spawning/PrefabSpawnManager.cs index 8392bdccd8d..5471cceef0a 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Spawning/PrefabSpawnManager.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Spawning/PrefabSpawnManager.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; -using HoloToolkit.Unity; using UnityEngine; +using HoloToolkit.Unity; namespace HoloToolkit.Sharing.Spawning { @@ -32,7 +32,7 @@ public class PrefabSpawnManager : SpawnManager /// /// It is assumed that this list is the same on all connected applications. [SerializeField] - private List spawnablePrefabs = null; + private List spawnablePrefabs; private Dictionary typeToPrefab; @@ -49,10 +49,10 @@ private void Awake() private void InitializePrefabs() { - typeToPrefab = new Dictionary(this.spawnablePrefabs.Count); - for (int i = 0; i < this.spawnablePrefabs.Count; i++) + typeToPrefab = new Dictionary(spawnablePrefabs.Count); + for (int i = 0; i < spawnablePrefabs.Count; i++) { - typeToPrefab.Add(this.spawnablePrefabs[i].DataModelClassName, this.spawnablePrefabs[i].Prefab); + typeToPrefab.Add(spawnablePrefabs[i].DataModelClassName, spawnablePrefabs[i].Prefab); } } @@ -71,13 +71,12 @@ protected override void InstantiateFromNetwork(SyncSpawnedObject spawnedObject) parent = GameObject.Find(spawnedObject.ParentPath.Value); if (parent == null) { - Debug.LogErrorFormat("Parent object '{0}' could not be found to instantiate object.", - spawnedObject.ParentPath); + Debug.LogErrorFormat("Parent object '{0}' could not be found to instantiate object.", spawnedObject.ParentPath); return; } } - this.CreatePrefabInstance(spawnedObject, prefab, parent, spawnedObject.Name.Value); + CreatePrefabInstance(spawnedObject, prefab, parent, spawnedObject.Name.Value); } protected override void RemoveFromNetwork(SyncSpawnedObject removedObject) @@ -91,8 +90,8 @@ protected override void RemoveFromNetwork(SyncSpawnedObject removedObject) protected virtual string CreateInstanceName(string baseName) { - string instanceName = string.Format("{0}{1}_{2}", baseName, this.objectCreationCounter, NetworkManager.AppInstanceUniqueId); - this.objectCreationCounter++; + string instanceName = string.Format("{0}{1}_{2}", baseName, objectCreationCounter.ToString(), NetworkManager.AppInstanceUniqueId); + objectCreationCounter++; return instanceName; } @@ -107,8 +106,7 @@ protected virtual GameObject GetPrefab(SyncSpawnedObject dataModel, string baseN string dataModelTypeName = GetPrefabLookupKey(dataModel, baseName); if (dataModelTypeName == null || !typeToPrefab.TryGetValue(dataModelTypeName, out prefabToSpawn)) { - Debug.LogErrorFormat("Trying to instantiate an object from unregistered data model {0}.", - dataModelTypeName); + Debug.LogErrorFormat("Trying to instantiate an object from unregistered data model {0}.", dataModelTypeName); return null; } return prefabToSpawn; @@ -128,10 +126,9 @@ protected virtual GameObject GetPrefab(SyncSpawnedObject dataModel, string baseN /// An object that is locally owned will be removed from the sync system when its owner leaves the session. /// /// True if spawning succeeded, false if not. - public bool Spawn(SyncSpawnedObject dataModel, Vector3 localPosition, Quaternion localRotation, Vector3? localScale, - GameObject parent, string baseName, bool isOwnedLocally) + public bool Spawn(SyncSpawnedObject dataModel, Vector3 localPosition, Quaternion localRotation, Vector3? localScale, GameObject parent, string baseName, bool isOwnedLocally) { - if (this.SyncSource == null) + if (SyncSource == null) { Debug.LogError("Can't spawn an object: PrefabSpawnManager is not initialized."); return false; @@ -145,7 +142,7 @@ protected virtual GameObject GetPrefab(SyncSpawnedObject dataModel, string baseN if (parent == null) { - parent = this.gameObject; + parent = gameObject; } // Validate that the prefab is valid @@ -177,7 +174,7 @@ protected virtual GameObject GetPrefab(SyncSpawnedObject dataModel, string baseN owner = SharingStage.Instance.Manager.GetLocalUser(); } - this.SyncSource.AddObject(dataModel, owner); + SyncSource.AddObject(dataModel, owner); return true; } @@ -196,17 +193,17 @@ protected virtual GameObject GetPrefab(SyncSpawnedObject dataModel, string baseN /// True if the function succeeded, false if not. public bool Spawn(SyncSpawnedObject dataModel, Vector3 localPosition, Quaternion localRotation, GameObject parent, string baseName, bool isOwnedLocally) { - return this.Spawn(dataModel, localPosition, localRotation, null, parent, baseName, isOwnedLocally); + return Spawn(dataModel, localPosition, localRotation, null, parent, baseName, isOwnedLocally); } protected override void SetDataModelSource() { - this.SyncSource = NetworkManager.Root.InstantiatedPrefabs; + SyncSource = NetworkManager.Root.InstantiatedPrefabs; } public override void Delete(SyncSpawnedObject objectToDelete) { - this.SyncSource.RemoveObject(objectToDelete); + SyncSource.RemoveObject(objectToDelete); } /// @@ -219,7 +216,7 @@ public override void Delete(SyncSpawnedObject objectToDelete) /// protected virtual GameObject CreatePrefabInstance(SyncSpawnedObject dataModel, GameObject prefabToInstantiate, GameObject parentObject, string objectName) { - GameObject instance = (GameObject)Instantiate(prefabToInstantiate, dataModel.Transform.Position.Value, dataModel.Transform.Rotation.Value); + GameObject instance = Instantiate(prefabToInstantiate, dataModel.Transform.Position.Value, dataModel.Transform.Rotation.Value); instance.transform.localScale = dataModel.Transform.Scale.Value; instance.transform.SetParent(parentObject.transform, false); instance.gameObject.name = objectName; diff --git a/Assets/HoloToolkit/Sharing/Scripts/Spawning/SpawnManager.cs b/Assets/HoloToolkit/Sharing/Scripts/Spawning/SpawnManager.cs index df26e2ab28e..1971d68cf07 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Spawning/SpawnManager.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Spawning/SpawnManager.cs @@ -3,8 +3,8 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. // -using HoloToolkit.Sharing.SyncModel; using UnityEngine; +using HoloToolkit.Sharing.SyncModel; namespace HoloToolkit.Sharing.Spawning { @@ -37,8 +37,8 @@ protected virtual void Start() /// private void RegisterToDataModel() { - this.SyncSource.ObjectAdded += OnObjectAdded; - this.SyncSource.ObjectRemoved += OnObjectRemoved; + SyncSource.ObjectAdded += OnObjectAdded; + SyncSource.ObjectRemoved += OnObjectRemoved; } private void OnObjectAdded(T addedObject) diff --git a/Assets/HoloToolkit/Sharing/Scripts/Spawning/SyncSpawnArray.cs b/Assets/HoloToolkit/Sharing/Scripts/Spawning/SyncSpawnArray.cs index cc3130123c5..fa969d3e56b 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Spawning/SyncSpawnArray.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Spawning/SyncSpawnArray.cs @@ -4,8 +4,8 @@ // using System; -using HoloToolkit.Sharing.SyncModel; using UnityEngine; +using HoloToolkit.Sharing.SyncModel; namespace HoloToolkit.Sharing.Spawning { @@ -16,15 +16,9 @@ namespace HoloToolkit.Sharing.Spawning /// Type of object that the array contains public class SyncSpawnArray : SyncArray where T : SyncSpawnedObject, new() { - public SyncSpawnArray(string field) - : base(field) - { - } + public SyncSpawnArray(string field) : base(field) { } - public SyncSpawnArray() - : base(string.Empty) - { - } + public SyncSpawnArray() : base(string.Empty) { } protected override T CreateObject(ObjectElement objectElement) { @@ -33,16 +27,17 @@ protected override T CreateObject(ObjectElement objectElement) Type typeToInstantiate = Type.GetType(objectType); if (typeToInstantiate == null) { - Debug.LogErrorFormat("Could not find the SyncModel type to instantiate."); + Debug.LogError("Could not find the SyncModel type to instantiate."); return null; } - System.Object createdObject = Activator.CreateInstance(typeToInstantiate); + object createdObject = Activator.CreateInstance(typeToInstantiate); - T spawnedDataModel = createdObject as T; + T spawnedDataModel = (T)createdObject; spawnedDataModel.Element = objectElement; spawnedDataModel.FieldName = objectElement.GetName(); - spawnedDataModel.Owner = this.Owner; // TODO: this should really come from objectElement.GetOwnerID(). It not safe to assume that this class and its child have the same owner + // TODO: this should not query SharingStage, but instead query the underlying session layer + spawnedDataModel.Owner = SharingStage.Instance.SessionUsersTracker.GetUserById(objectElement.GetOwnerID()); return spawnedDataModel; } diff --git a/Assets/HoloToolkit/Sharing/Scripts/Spawning/SyncSpawnedObject.cs b/Assets/HoloToolkit/Sharing/Scripts/Spawning/SyncSpawnedObject.cs index bde7c6f35e2..f0610cb3ec9 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Spawning/SyncSpawnedObject.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Spawning/SyncSpawnedObject.cs @@ -3,8 +3,8 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. // -using HoloToolkit.Sharing.SyncModel; using UnityEngine; +using HoloToolkit.Sharing.SyncModel; namespace HoloToolkit.Sharing.Spawning { @@ -40,16 +40,16 @@ public class SyncSpawnedObject : SyncObject public virtual void Initialize(string name, string parentPath) { - this.Name.Value = name; - this.ParentPath.Value = parentPath; + Name.Value = name; + ParentPath.Value = parentPath; - this.ObjectPath.Value = string.Empty; - if (!string.IsNullOrEmpty(this.ParentPath.Value)) + ObjectPath.Value = string.Empty; + if (!string.IsNullOrEmpty(ParentPath.Value)) { - this.ObjectPath.Value = this.ParentPath.Value + "/"; + ObjectPath.Value = ParentPath.Value + "/"; } - this.ObjectPath.Value += this.Name.Value; + ObjectPath.Value += Name.Value; } } } diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncArray.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncArray.cs index a94689e032b..e4a30bacee5 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncArray.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncArray.cs @@ -4,8 +4,8 @@ // using System; -using System.Collections.Generic; using System.Collections; +using System.Collections.Generic; using UnityEngine; namespace HoloToolkit.Sharing.SyncModel @@ -37,19 +37,16 @@ public class SyncArray : SyncObject, IEnumerable where T : SyncObject, new /// Type of objects in the array. /// This is cached so that we don't have to call typeof(T) more than once. /// - protected Type arrayType; + protected Type ArrayType; public SyncArray(string field) : base(field) { - this.dataArray = new Dictionary(); - this.arrayType = typeof(T); + dataArray = new Dictionary(); + ArrayType = typeof(T); } - public SyncArray() - : this(string.Empty) - { - } + public SyncArray() : this(string.Empty) { } /// /// Creates the object in the array, based on its underlying object element that came from the sync system. @@ -59,22 +56,19 @@ public SyncArray() protected virtual T CreateObject(ObjectElement objectElement) { Type objectType = SyncSettings.Instance.GetDataModelType(objectElement.GetObjectType()).AsType(); - if (!objectType.IsSubclassOf(arrayType) && objectType != arrayType) + if (!objectType.IsSubclassOf(ArrayType) && objectType != ArrayType) { throw new InvalidCastException(string.Format("Object of incorrect type added to SyncArray: Expected {0}, got {1} ", objectType, objectElement.GetObjectType().GetString())); } - System.Object createdObject = Activator.CreateInstance(objectType); - T spawnedDataModel = createdObject as T; + object createdObject = Activator.CreateInstance(objectType); - if (spawnedDataModel != null) - { - spawnedDataModel.Element = objectElement; - spawnedDataModel.FieldName = objectElement.GetName(); + T spawnedDataModel = (T)createdObject; + spawnedDataModel.Element = objectElement; + spawnedDataModel.FieldName = objectElement.GetName(); - // TODO: this should not query SharingStage, but instead query the underlying session layer - spawnedDataModel.Owner = SharingStage.Instance.SessionUsersTracker.GetUserById(objectElement.GetOwnerID()); - } + // TODO: this should not query SharingStage, but instead query the underlying session layer + spawnedDataModel.Owner = SharingStage.Instance.SessionUsersTracker.GetUserById(objectElement.GetOwnerID()); return spawnedDataModel; } @@ -87,12 +81,10 @@ protected virtual T CreateObject(ObjectElement objectElement) /// Object that was added, with its networking elements setup. public T AddObject(T newSyncObject, User owner = null) { - string id = null; - // Create our object element for our target - id = System.Guid.NewGuid().ToString(); + string id = System.Guid.NewGuid().ToString(); string dataModelName = SyncSettings.Instance.GetDataModelName(newSyncObject.GetType()); - ObjectElement existingElement = this.Element.CreateObjectElement(new XString(id), dataModelName, owner); + ObjectElement existingElement = Element.CreateObjectElement(new XString(id), dataModelName, owner); // Create a new object and assign the element newSyncObject.Element = existingElement; @@ -103,7 +95,7 @@ public T AddObject(T newSyncObject, User owner = null) AddChild(newSyncObject); // Update internal map - this.dataArray[id] = newSyncObject; + dataArray[id] = newSyncObject; // Initialize it so it can be used immediately. newSyncObject.InitializeLocal(Element); @@ -128,7 +120,7 @@ public bool RemoveObject(T existingObject) if (existingObject != null) { string uniqueName = existingObject.Element.GetName(); - if (this.dataArray.Remove(uniqueName)) + if (dataArray.Remove(uniqueName)) { RemoveChild(existingObject); @@ -147,8 +139,8 @@ public bool RemoveObject(T existingObject) // Returns a full list of the objects public T[] GetDataArray() { - List childrenList = new List(this.dataArray.Count); - foreach (KeyValuePair pair in this.dataArray) + var childrenList = new List(dataArray.Count); + foreach (KeyValuePair pair in dataArray) { childrenList.Add(pair.Value); } @@ -158,12 +150,12 @@ public T[] GetDataArray() IEnumerator IEnumerable.GetEnumerator() { - return this.dataArray.Values.GetEnumerator(); + return dataArray.Values.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { - return this.dataArray.Values.GetEnumerator(); + return dataArray.Values.GetEnumerator(); } public void Clear() @@ -197,9 +189,9 @@ protected override void OnElementDeleted(Element element) base.OnElementDeleted(element); string uniqueName = element.GetName(); - if (this.dataArray.ContainsKey(uniqueName)) + if (dataArray.ContainsKey(uniqueName)) { - T obj = this.dataArray[uniqueName]; + T obj = dataArray[uniqueName]; RemoveObject(obj); } } @@ -220,7 +212,7 @@ private void OnInitializationComplete(SyncObject obj) /// private T AddObject(ObjectElement existingElement) { - bool isLocal = false; + //bool isLocal = false; string id = existingElement.GetName(); // Create a new object and assign the element @@ -230,13 +222,13 @@ private T AddObject(ObjectElement existingElement) AddChild(newObject); // Update internal map - this.dataArray[id] = newObject; + dataArray[id] = newObject; // If it's local, make sure to initialize it so it can be used immediately. - if (isLocal) - { - newObject.InitializeLocal(this.Element); - } + //if (isLocal) + //{ + // newObject.InitializeLocal(Element); + //} return newObject; } diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncBool.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncBool.cs index 3544eacc11c..52b2e0de7b4 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncBool.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncBool.cs @@ -14,14 +14,15 @@ public class SyncBool : SyncPrimitive private BoolElement element; private bool value; +#if UNITY_EDITOR public override object RawValue { - get { return this.value; } + get { return value; } } - +#endif public bool Value { - get { return this.value; } + get { return value; } set { @@ -31,43 +32,39 @@ public bool Value // Change the value this.value = value; - if (this.element != null) + if (element != null) { // Notify network that the value has changed - this.element.SetValue(value); + element.SetValue(value); } } } } - public SyncBool(string field) - : base(field) - { - } + public SyncBool(string field) : base(field) { } public override void InitializeLocal(ObjectElement parentElement) { - this.element = parentElement.CreateBoolElement(XStringFieldName, this.value); - this.NetworkElement = element; + element = parentElement.CreateBoolElement(XStringFieldName, value); + NetworkElement = element; } - public void AddFromLocal(ObjectElement parentElement, bool value) + public void AddFromLocal(ObjectElement parentElement, bool localValue) { InitializeLocal(parentElement); - this.Value = value; + Value = localValue; } - public override void AddFromRemote(Element element) + public override void AddFromRemote(Element remoteElement) { - this.NetworkElement = element; - this.element = BoolElement.Cast(element); - this.value = this.element.GetValue(); + NetworkElement = remoteElement; + element = BoolElement.Cast(remoteElement); + value = element.GetValue(); } - public override void UpdateFromRemote(bool value) + public override void UpdateFromRemote(bool remoteValue) { - // Change the value - this.value = value; + value = remoteValue; } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncDouble.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncDouble.cs index df1c1f2c0f2..9a0c5549421 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncDouble.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncDouble.cs @@ -14,14 +14,16 @@ public class SyncDouble : SyncPrimitive private DoubleElement element; private double value; +#if UNITY_EDITOR public override object RawValue { - get { return this.value; } + get { return value; } } +#endif public double Value { - get { return this.value; } + get { return value; } set { @@ -31,43 +33,39 @@ public double Value // Change the value this.value = value; - if (this.element != null) + if (element != null) { // Notify network that the value has changed - this.element.SetValue(value); + element.SetValue(value); } } } } - public SyncDouble(string field) - : base(field) - { - } + public SyncDouble(string field) : base(field) { } public override void InitializeLocal(ObjectElement parentElement) { - this.element = parentElement.CreateDoubleElement(XStringFieldName, this.value); - this.NetworkElement = element; + element = parentElement.CreateDoubleElement(XStringFieldName, value); + NetworkElement = element; } - public void AddFromLocal(ObjectElement parentElement, double value) + public void AddFromLocal(ObjectElement parentElement, double localValue) { InitializeLocal(parentElement); - this.Value = value; + Value = localValue; } - public override void AddFromRemote(Element element) + public override void AddFromRemote(Element remoteElement) { - this.NetworkElement = element; - this.element = DoubleElement.Cast(element); - this.value = this.element.GetValue(); + NetworkElement = remoteElement; + element = DoubleElement.Cast(remoteElement); + value = element.GetValue(); } - public override void UpdateFromRemote(double value) + public override void UpdateFromRemote(double remoteValue) { - // Change the value - this.value = value; + value = remoteValue; } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncFloat.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncFloat.cs index ff1743de276..9a8f782e180 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncFloat.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncFloat.cs @@ -14,59 +14,59 @@ public class SyncFloat : SyncPrimitive private FloatElement element; private float value; +#if UNITY_EDITOR public override object RawValue { - get { return this.value; } + get { return value; } } +#endif public float Value { - get { return this.value; } + get { return value; } set { + // Has the value actually changed? if (this.value != value) { // Change the value this.value = value; - if (this.element != null) + if (element != null) { // Notify network that the value has changed - this.element.SetValue(value); + element.SetValue(value); } } } } - public SyncFloat(string field) - : base(field) - { - } + public SyncFloat(string field) : base(field) { } public override void InitializeLocal(ObjectElement parentElement) { - this.element = parentElement.CreateFloatElement(XStringFieldName, this.value); - this.NetworkElement = element; + element = parentElement.CreateFloatElement(XStringFieldName, value); + NetworkElement = element; } - public void AddFromLocal(ObjectElement parentElement, float value) + public void AddFromLocal(ObjectElement parentElement, float localValue) { InitializeLocal(parentElement); - this.Value = value; + Value = localValue; } - public override void AddFromRemote(Element element) + public override void AddFromRemote(Element remoteElement) { - this.NetworkElement = element; - this.element = FloatElement.Cast(element); - this.value = this.element.GetValue(); + NetworkElement = remoteElement; + element = FloatElement.Cast(remoteElement); + value = element.GetValue(); } - public override void UpdateFromRemote(float value) + public override void UpdateFromRemote(float remoteValue) { // Change the value - this.value = value; + value = remoteValue; } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncInteger.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncInteger.cs index 6b83acca49c..b4b91ce5253 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncInteger.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncInteger.cs @@ -14,26 +14,29 @@ public class SyncInteger : SyncPrimitive private IntElement element; private int value; +#if UNITY_EDITOR public override object RawValue { - get { return this.value; } + get { return value; } } +#endif public int Value { - get { return this.value; } + get { return value; } set { + // Has the value actually changed? if (this.value != value) { // Change the value this.value = value; - if (this.element != null) + if (element != null) { // Notify network that the value has changed - this.element.SetValue(value); + element.SetValue(value); } } } @@ -46,27 +49,26 @@ public SyncInteger(string field) public override void InitializeLocal(ObjectElement parentElement) { - this.element = parentElement.CreateIntElement(XStringFieldName, this.value); - this.NetworkElement = element; + element = parentElement.CreateIntElement(XStringFieldName, value); + NetworkElement = element; } - public void AddFromLocal(ObjectElement parentElement, int value) + public void AddFromLocal(ObjectElement parentElement, int localValue) { InitializeLocal(parentElement); - this.Value = value; + Value = localValue; } - public override void AddFromRemote(Element element) + public override void AddFromRemote(Element remoteElement) { - this.NetworkElement = element; - this.element = IntElement.Cast(element); - this.value = this.element.GetValue(); + NetworkElement = remoteElement; + element = IntElement.Cast(remoteElement); + value = element.GetValue(); } - public override void UpdateFromRemote(int value) + public override void UpdateFromRemote(int remoteValue) { - // Change the value - this.value = value; + value = remoteValue; } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncLong.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncLong.cs index 15b506e5f41..b5769cdbdc9 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncLong.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncLong.cs @@ -14,14 +14,16 @@ public class SyncLong : SyncPrimitive private LongElement element; private long value; +#if UNITY_EDITOR public override object RawValue { - get { return this.value; } + get { return value; } } +#endif public long Value { - get { return this.value; } + get { return value; } set { @@ -31,10 +33,10 @@ public long Value // Change the value this.value = value; - if (this.element != null) + if (element != null) { // Notify network that the value has changed - this.element.SetValue(value); + element.SetValue(value); } } } @@ -47,27 +49,26 @@ public SyncLong(string field) public override void InitializeLocal(ObjectElement parentElement) { - this.element = parentElement.CreateLongElement(XStringFieldName, this.value); - this.NetworkElement = element; + element = parentElement.CreateLongElement(XStringFieldName, value); + NetworkElement = element; } - public void AddFromLocal(ObjectElement parentElement, long value) + public void AddFromLocal(ObjectElement parentElement, long localValue) { InitializeLocal(parentElement); - this.Value = value; + Value = localValue; } - public override void AddFromRemote(Element element) + public override void AddFromRemote(Element remoteElement) { - this.NetworkElement = element; - this.element = LongElement.Cast(element); - this.value = this.element.GetValue(); + NetworkElement = remoteElement; + element = LongElement.Cast(remoteElement); + value = element.GetValue(); } - public override void UpdateFromRemote(long value) + public override void UpdateFromRemote(long remoteValue) { - // Change the value - this.value = value; + value = remoteValue; } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncObject.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncObject.cs index d154837004f..cd207a8770f 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncObject.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncObject.cs @@ -7,12 +7,13 @@ #define USE_WINRT #endif -using System.Collections.Generic; using System; +using System.Collections.Generic; +using System.Globalization; using System.Reflection; -using HoloToolkit.Unity; using UnityEngine; using UnityEngine.Assertions; +using HoloToolkit.Unity; namespace HoloToolkit.Sharing.SyncModel { @@ -32,37 +33,39 @@ public class SyncObject : SyncPrimitive private ObjectElement internalObjectElement; public ObjectElement Element { - get { return this.internalObjectElement; } + get { return internalObjectElement; } internal set { - if (this.internalObjectElement == null) + if (internalObjectElement == null) { - this.internalObjectElement = value; - this.NetworkElement = value; + internalObjectElement = value; + NetworkElement = value; - if (this.internalObjectElement != null) + if (internalObjectElement != null) { - CreateSyncListener(this.internalObjectElement); + CreateSyncListener(internalObjectElement); } } } } +#if UNITY_EDITOR public override object RawValue { get { return null; } } +#endif - // Optional user that owns this object. - private HoloToolkit.Sharing.User owner; - public HoloToolkit.Sharing.User Owner + // Optional user that owns this object. + private User owner; + public User Owner { get { return owner; } set { - if (this.owner == null) + if (owner == null) { - this.owner = value; + owner = value; } } } @@ -71,17 +74,14 @@ public string ObjectType { get { - if (this.internalObjectElement != null) - return this.internalObjectElement.GetObjectType().GetString(); - else - return null; + return internalObjectElement != null ? internalObjectElement.GetObjectType().GetString() : null; } } // Returns the object element registered owner id public int OwnerId { - get { return this.internalObjectElement != null ? this.internalObjectElement.GetOwnerID() : int.MaxValue; } + get { return internalObjectElement != null ? internalObjectElement.GetOwnerID() : int.MaxValue; } } public SyncObject(string field) @@ -104,11 +104,11 @@ public SyncPrimitive[] GetChildren() private void InitializePrimitives() { - this.primitiveMap = new Dictionary(); - this.primitives = new List(); + primitiveMap = new Dictionary(); + primitives = new List(); // Scan the type of object this is a look for the SyncDataAttribute - System.Type baseType = this.GetType(); + Type baseType = GetType(); #if USE_WINRT var typeFields = baseType.GetRuntimeFields(); @@ -132,7 +132,7 @@ private void InitializePrimitives() if (attribute != null) { - System.Type fieldType = typeField.FieldType; + Type fieldType = typeField.FieldType; string memberName = typeField.Name; // Override the member name if provided @@ -152,10 +152,10 @@ private void InitializePrimitives() // that takes the "memberName" property or use the default (parameter less constructor). // First check if there is a constructor that takes the member name and if so call it - bool hasConstructor = fieldType.GetConstructor(new Type[] { typeof(string) }) != null; + bool hasConstructor = fieldType.GetConstructor(new[] { typeof(string) }) != null; if (hasConstructor) { - dataPrimitive = (SyncPrimitive)Activator.CreateInstance(fieldType, new object[] { memberName }); + dataPrimitive = (SyncPrimitive)Activator.CreateInstance(fieldType, memberName); } else { @@ -188,12 +188,12 @@ protected void AddChild(SyncPrimitive data) { long guid = data.Guid; Assert.AreNotEqual(SharingClient.kInvalidXGuid, guid, "A primitive GUID should never be invalid if it is networked."); - this.primitiveMap.Add(guid, data); + primitiveMap.Add(guid, data); } - if (!this.primitives.Contains(data)) + if (!primitives.Contains(data)) { - this.primitives.Add(data); + primitives.Add(data); } } @@ -201,9 +201,9 @@ protected void AddChild(SyncPrimitive data) protected void RemoveChild(SyncPrimitive data) { // Manually remove from maps - if (this.primitives.Remove(data) && data.HasNetworkElement) + if (primitives.Remove(data) && data.HasNetworkElement) { - this.primitiveMap.Remove(data.NetworkElement.GetGUID()); + primitiveMap.Remove(data.NetworkElement.GetGUID()); // Object has been removed internally, notify network ObjectElement parentElement = ObjectElement.Cast(data.NetworkElement.GetParent()); @@ -219,16 +219,16 @@ protected virtual void OnElementAdded(Element element) { // Find the existing element. bool primitiveDataChanged = false; - for (int i = 0; i < this.primitives.Count; i++) + for (int i = 0; i < primitives.Count; i++) { - if (this.primitives[i].XStringFieldName.IsEqual(element.GetName())) + if (primitives[i].XStringFieldName.IsEqual(element.GetName())) { // Found it, register the element so it knows where to pull data from - this.primitives[i].AddFromRemote(element); + primitives[i].AddFromRemote(element); // Update the internal map long guid = element.GetGUID(); - this.primitiveMap[guid] = this.primitives[i]; + primitiveMap[guid] = primitives[i]; primitiveDataChanged = true; break; } @@ -237,11 +237,11 @@ protected virtual void OnElementAdded(Element element) if (primitiveDataChanged) { // If there are no more primitives waiting to be added, finish the initialization - if (this.primitiveMap.Count == this.primitives.Count) + if (primitiveMap.Count == primitives.Count) { - if (this.InitializationComplete != null) + if (InitializationComplete != null) { - this.InitializationComplete(this); + InitializationComplete(this); } } } @@ -252,18 +252,18 @@ protected virtual void OnElementDeleted(Element element) { // If the child exists, then remove it. long guid = element.GetGUID(); - if (this.primitiveMap.ContainsKey(guid)) + if (primitiveMap.ContainsKey(guid)) { - RemoveChild(this.primitiveMap[guid]); + RemoveChild(primitiveMap[guid]); } } // Handler for if a child bool changes protected virtual void OnBoolElementChanged(long elementID, bool newValue) { - if (this.primitiveMap.ContainsKey(elementID)) + if (primitiveMap.ContainsKey(elementID)) { - SyncPrimitive primitive = this.primitiveMap[elementID]; + SyncPrimitive primitive = primitiveMap[elementID]; primitive.UpdateFromRemote(newValue); NotifyPrimitiveChanged(primitive); } @@ -276,9 +276,9 @@ protected virtual void OnBoolElementChanged(long elementID, bool newValue) // Handler for if a child int changes protected virtual void OnIntElementChanged(long elementID, int newValue) { - if (this.primitiveMap.ContainsKey(elementID)) + if (primitiveMap.ContainsKey(elementID)) { - SyncPrimitive primitive = this.primitiveMap[elementID]; + SyncPrimitive primitive = primitiveMap[elementID]; primitive.UpdateFromRemote(newValue); NotifyPrimitiveChanged(primitive); } @@ -291,9 +291,9 @@ protected virtual void OnIntElementChanged(long elementID, int newValue) // Handler for if a child long changes protected virtual void OnLongElementChanged(long elementID, long newValue) { - if (this.primitiveMap.ContainsKey(elementID)) + if (primitiveMap.ContainsKey(elementID)) { - SyncPrimitive primitive = this.primitiveMap[elementID]; + SyncPrimitive primitive = primitiveMap[elementID]; primitive.UpdateFromRemote(newValue); NotifyPrimitiveChanged(primitive); } @@ -306,39 +306,39 @@ protected virtual void OnLongElementChanged(long elementID, long newValue) // Handler for if a child float changes protected virtual void OnFloatElementChanged(long elementID, float newValue) { - if (this.primitiveMap.ContainsKey(elementID)) + if (primitiveMap.ContainsKey(elementID)) { - SyncPrimitive primitive = this.primitiveMap[elementID]; + SyncPrimitive primitive = primitiveMap[elementID]; primitive.UpdateFromRemote(newValue); NotifyPrimitiveChanged(primitive); } else { - LogUnknownElement(elementID.ToString(), newValue.ToString(), typeof(float)); + LogUnknownElement(elementID.ToString(), newValue.ToString(CultureInfo.InvariantCulture), typeof(float)); } } // Handler for if a child double changes protected virtual void OnDoubleElementChanged(long elementID, double newValue) { - if (this.primitiveMap.ContainsKey(elementID)) + if (primitiveMap.ContainsKey(elementID)) { - SyncPrimitive primitive = this.primitiveMap[elementID]; + SyncPrimitive primitive = primitiveMap[elementID]; primitive.UpdateFromRemote(newValue); NotifyPrimitiveChanged(primitive); } else { - LogUnknownElement(elementID.ToString(), newValue.ToString(), typeof(double)); + LogUnknownElement(elementID.ToString(), newValue.ToString(CultureInfo.InvariantCulture), typeof(double)); } } // Handler for if a child string changes protected virtual void OnStringElementChanged(long elementID, XString newValue) { - if (this.primitiveMap.ContainsKey(elementID)) + if (primitiveMap.ContainsKey(elementID)) { - SyncPrimitive primitive = this.primitiveMap[elementID]; + SyncPrimitive primitive = primitiveMap[elementID]; primitive.UpdateFromRemote(newValue); NotifyPrimitiveChanged(primitive); } @@ -361,16 +361,16 @@ protected virtual void NotifyPrimitiveChanged(SyncPrimitive primitive) private void CreateSyncListener(ObjectElement element) { // Create a listener for this - this.syncListener = new ObjectElementAdapter(); - this.syncListener.ElementAddedEvent += OnElementAdded; - this.syncListener.ElementDeletedEvent += OnElementDeleted; - this.syncListener.BoolChangedEvent += OnBoolElementChanged; - this.syncListener.IntChangedEvent += OnIntElementChanged; - this.syncListener.LongChangedEvent += OnLongElementChanged; - this.syncListener.FloatChangedEvent += OnFloatElementChanged; - this.syncListener.DoubleChangedEvent += OnDoubleElementChanged; - this.syncListener.StringChangedEvent += OnStringElementChanged; - element.AddListener(this.syncListener); + syncListener = new ObjectElementAdapter(); + syncListener.ElementAddedEvent += OnElementAdded; + syncListener.ElementDeletedEvent += OnElementDeleted; + syncListener.BoolChangedEvent += OnBoolElementChanged; + syncListener.IntChangedEvent += OnIntElementChanged; + syncListener.LongChangedEvent += OnLongElementChanged; + syncListener.FloatChangedEvent += OnFloatElementChanged; + syncListener.DoubleChangedEvent += OnDoubleElementChanged; + syncListener.StringChangedEvent += OnStringElementChanged; + element.AddListener(syncListener); } // From SyncPrimitive @@ -382,31 +382,31 @@ private void CreateSyncListener(ObjectElement element) public override void InitializeLocal(ObjectElement parentElement) { // Auto create element if needed - if (this.Element == null) + if (Element == null) { - this.Element = parentElement.CreateObjectElement(XStringFieldName, GetType().FullName, this.Owner); - this.NetworkElement = this.Element; + Element = parentElement.CreateObjectElement(XStringFieldName, GetType().FullName, Owner); + NetworkElement = Element; } // Initialize all primitives - for (int i = 0; i < this.primitives.Count; i++) + for (int i = 0; i < primitives.Count; i++) { - SyncPrimitive data = this.primitives[i]; + SyncPrimitive data = primitives[i]; data.InitializeLocal(Element); - this.primitiveMap[data.Guid] = data; + primitiveMap[data.Guid] = data; } // Complete the initialization - if (this.InitializationComplete != null) + if (InitializationComplete != null) { - this.InitializationComplete(this); + InitializationComplete(this); } } - public override void AddFromRemote(Element element) + public override void AddFromRemote(Element remoteElement) { - this.Element = ObjectElement.Cast(element); - this.NetworkElement = element; + Element = ObjectElement.Cast(remoteElement); + NetworkElement = remoteElement; } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncPrimitive.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncPrimitive.cs index de569cb84e5..f3e9650ad39 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncPrimitive.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncPrimitive.cs @@ -9,25 +9,20 @@ namespace HoloToolkit.Sharing.SyncModel /// Base primitive used to define an element within the data model. /// The primitive is defined by a field and a value. /// - abstract public class SyncPrimitive + public abstract class SyncPrimitive { - protected string fieldName = null; - private XString xStringFieldName = null; - protected Element internalElement = null; + protected string fieldName; + private XString xStringFieldName; + protected Element internalElement; - // Unique identifier for primitive. Returns kInvalidXGuid if uninitialized. + /// + /// Unique identifier for primitive. Returns kInvalidXGuid if uninitialized. + /// public long Guid { get { - if (this.internalElement != null) - { - return this.internalElement.GetGUID(); - } - else - { - return SharingClient.kInvalidXGuid; - } + return internalElement != null ? internalElement.GetGUID() : SharingClient.kInvalidXGuid; } } @@ -37,35 +32,47 @@ public virtual Element NetworkElement protected set { internalElement = value; } } - // Indicates if the primitive has a network element. The primitive can only be modified if this returns true. + /// + /// Indicates if the primitive has a network element. + /// The primitive can only be modified if this returns true. + /// public bool HasNetworkElement { - get { return (this.internalElement != null); } + get { return internalElement != null; } } - // The field name of the primitive + /// + /// The field name of the primitive + /// public XString XStringFieldName { - get { return this.xStringFieldName; } + get { return xStringFieldName; } } - // The field name of the primitive + /// + /// The field name of the primitive + /// public string FieldName { get { return fieldName; } set { - this.fieldName = value; - this.xStringFieldName = new XString(value); + fieldName = value; + xStringFieldName = new XString(value); } } - // Returns the raw boxed object this primitive holds +#if UNITY_EDITOR + /// + /// Returns the raw boxed object this primitive holds. + /// Used by SharingStageEditor.cs + /// public abstract object RawValue { get; } +#endif public SyncPrimitive(string field) { @@ -73,17 +80,17 @@ public SyncPrimitive(string field) } // Initializes this object for local use. Doesn't wait for network initialization. - abstract public void InitializeLocal(ObjectElement parentElement); + public abstract void InitializeLocal(ObjectElement parentElement); // Called when being remotely initialized - abstract public void AddFromRemote(Element element); + public abstract void AddFromRemote(Element remoteElement); // Called when the primitive value has changed from a remote action - virtual public void UpdateFromRemote(XString value) { } - virtual public void UpdateFromRemote(float value) { } - virtual public void UpdateFromRemote(double value) { } - virtual public void UpdateFromRemote(int value) { } - virtual public void UpdateFromRemote(long value) { } - virtual public void UpdateFromRemote(bool value) { } + public virtual void UpdateFromRemote(XString remoteValue) { } + public virtual void UpdateFromRemote(float remoteValue) { } + public virtual void UpdateFromRemote(double remoteValue) { } + public virtual void UpdateFromRemote(int remoteValue) { } + public virtual void UpdateFromRemote(long remoteValue) { } + public virtual void UpdateFromRemote(bool remoteValue) { } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncQuaternion.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncQuaternion.cs index bfe9995e582..6de5b6b62ad 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncQuaternion.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncQuaternion.cs @@ -18,26 +18,25 @@ public class SyncQuaternion : SyncObject [SyncData] private SyncFloat z = null; [SyncData] private SyncFloat w = null; +#if UNITY_EDITOR public override object RawValue { - get { return new Quaternion(this.x.Value, this.y.Value, this.z.Value, this.w.Value); } + get { return new Quaternion(x.Value, y.Value, z.Value, w.Value); } } +#endif public Quaternion Value { - get { return new Quaternion(this.x.Value, this.y.Value, this.z.Value, this.w.Value); } + get { return new Quaternion(x.Value, y.Value, z.Value, w.Value); } set { - this.x.Value = value.x; - this.y.Value = value.y; - this.z.Value = value.z; - this.w.Value = value.w; + x.Value = value.x; + y.Value = value.y; + z.Value = value.z; + w.Value = value.w; } } - public SyncQuaternion(string field) - : base(field) - { - } + public SyncQuaternion(string field) : base(field) { } } } diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncString.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncString.cs index f206276318c..2f3596d6ffd 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncString.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncString.cs @@ -14,14 +14,16 @@ public class SyncString : SyncPrimitive private StringElement element; private string value = ""; +#if UNITY_EDITOR public override object RawValue { - get { return this.value; } + get { return value; } } +#endif public string Value { - get { return this.value; } + get { return value; } set { @@ -31,43 +33,39 @@ public string Value // Change the value this.value = value; - if (this.element != null) + if (element != null) { // Notify network that the value has changed - this.element.SetValue(new XString(value)); + element.SetValue(new XString(value)); } } } } - public SyncString(string field) - : base(field) - { - } + public SyncString(string field) : base(field) { } public override void InitializeLocal(ObjectElement parentElement) { - this.element = parentElement.CreateStringElement(XStringFieldName, new XString(this.value)); - this.NetworkElement = element; + element = parentElement.CreateStringElement(XStringFieldName, new XString(value)); + NetworkElement = element; } - public void AddFromLocal(ObjectElement parentElement, string value) + public void AddFromLocal(ObjectElement parentElement, string localValue) { InitializeLocal(parentElement); - Value = value; + Value = localValue; } - override public void AddFromRemote(Element element) + public override void AddFromRemote(Element remoteElement) { - this.NetworkElement = element; - this.element = StringElement.Cast(element); - this.value = this.element.GetValue().GetString(); + NetworkElement = remoteElement; + element = StringElement.Cast(remoteElement); + value = element.GetValue().GetString(); } - override public void UpdateFromRemote(XString value) + public override void UpdateFromRemote(XString remoteValue) { - // Change the value - this.value = value.GetString(); + value = remoteValue.GetString(); } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncVector3.cs b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncVector3.cs index 163e38fd32e..fbe441e9ce2 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncVector3.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/SyncModel/SyncVector3.cs @@ -17,25 +17,24 @@ public class SyncVector3 : SyncObject [SyncData] private SyncFloat y = null; [SyncData] private SyncFloat z = null; +#if UNITY_EDITOR public override object RawValue { - get { return new Vector3(this.x.Value, this.y.Value, this.z.Value); } + get { return new Vector3(x.Value, y.Value, z.Value); } } +#endif public Vector3 Value { - get { return new Vector3(this.x.Value, this.y.Value, this.z.Value); } + get { return new Vector3(x.Value, y.Value, z.Value); } set { - this.x.Value = value.x; - this.y.Value = value.y; - this.z.Value = value.z; + x.Value = value.x; + y.Value = value.y; + z.Value = value.z; } } - public SyncVector3(string field) - : base(field) - { - } + public SyncVector3(string field) : base(field) { } } } diff --git a/Assets/HoloToolkit/Sharing/Scripts/Unity/DefaultSyncModelAccessor.cs b/Assets/HoloToolkit/Sharing/Scripts/Unity/DefaultSyncModelAccessor.cs index c0b8b3435a0..534a2292b47 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Unity/DefaultSyncModelAccessor.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Unity/DefaultSyncModelAccessor.cs @@ -6,16 +6,19 @@ using UnityEngine; using HoloToolkit.Sharing.SyncModel; -/// -/// Default implementation of a behaviour that allows other components of a game object access the shared data model -/// as a raw SyncObject instance. -/// -public class DefaultSyncModelAccessor : MonoBehaviour, ISyncModelAccessor +namespace HoloToolkit.Sharing { - public SyncObject SyncModel { get; private set; } - - public void SetSyncModel(SyncObject syncObject) + /// + /// Default implementation of a behaviour that allows other components of a game object access the shared data model + /// as a raw SyncObject instance. + /// + public class DefaultSyncModelAccessor : MonoBehaviour, ISyncModelAccessor { - SyncModel = syncObject; + public SyncObject SyncModel { get; private set; } + + public void SetSyncModel(SyncObject syncObject) + { + SyncModel = syncObject; + } } } diff --git a/Assets/HoloToolkit/Sharing/Scripts/Unity/ISyncModelAccessor.cs b/Assets/HoloToolkit/Sharing/Scripts/Unity/ISyncModelAccessor.cs index 78af6bbefdf..e9f7cf929b8 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Unity/ISyncModelAccessor.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Unity/ISyncModelAccessor.cs @@ -5,14 +5,17 @@ using HoloToolkit.Sharing.SyncModel; -/// -/// Interface that allows a components of a game object access the shared data model set by a SpawnManager. -/// -public interface ISyncModelAccessor +namespace HoloToolkit.Sharing { /// - /// Sets the synchronized data model to use for this object. + /// Interface that allows a components of a game object access the shared data model set by a SpawnManager. /// - /// Sync object to set as the model. - void SetSyncModel(SyncObject syncObject); + public interface ISyncModelAccessor + { + /// + /// Sets the synchronized data model to use for this object. + /// + /// Sync object to set as the model. + void SetSyncModel(SyncObject syncObject); + } } diff --git a/Assets/HoloToolkit/Sharing/Scripts/Unity/QuaternionInterpolated.cs b/Assets/HoloToolkit/Sharing/Scripts/Unity/QuaternionInterpolated.cs index 1e2543c5e1f..c1055cd4a30 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Unity/QuaternionInterpolated.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Unity/QuaternionInterpolated.cs @@ -5,83 +5,86 @@ using UnityEngine; -/// -/// Class to encapsulate an interpolating Quaternion property. -/// -[System.Serializable] -public class QuaternionInterpolated +namespace HoloToolkit.Sharing { /// - /// Speed of change in magnitude. + /// Class to encapsulate an interpolating Quaternion property. /// - public float DeltaSpeed = 360f; + [System.Serializable] + public class QuaternionInterpolated + { + /// + /// Speed of change in magnitude. + /// + public float DeltaSpeed = 360f; - /// - /// Current value of the property. - /// - public Quaternion Value { get; private set; } - /// - /// Target value of the property. - /// - public Quaternion TargetValue { get; private set; } - public Quaternion StartValue { get; private set; } - public float Duration { get; private set; } - public float Counter { get; private set; } + /// + /// Current value of the property. + /// + public Quaternion Value { get; private set; } + /// + /// Target value of the property. + /// + public Quaternion TargetValue { get; private set; } + public Quaternion StartValue { get; private set; } + public float Duration { get; private set; } + public float Counter { get; private set; } - public QuaternionInterpolated() - { - Reset(Quaternion.identity); - } + public QuaternionInterpolated() + { + Reset(Quaternion.identity); + } - public QuaternionInterpolated(Quaternion initialValue) - { - Reset(initialValue); - } + public QuaternionInterpolated(Quaternion initialValue) + { + Reset(initialValue); + } - /// - /// Resets property to zero interpolation and set value. - /// - /// Desired value to reset - public void Reset(Quaternion value) - { - Value = value; - TargetValue = value; - StartValue = value; - Duration = 0f; - Counter = 0f; - } + /// + /// Resets property to zero interpolation and set value. + /// + /// Desired value to reset + public void Reset(Quaternion value) + { + Value = value; + TargetValue = value; + StartValue = value; + Duration = 0f; + Counter = 0f; + } - /// - /// Set a target for property to interpolate to. - /// - /// Targeted value. - public void SetTarget(Quaternion targetValue) - { - TargetValue = targetValue; - StartValue = Value; - Duration = Quaternion.Angle(StartValue, TargetValue) / DeltaSpeed; - Counter = 0f; - } + /// + /// Set a target for property to interpolate to. + /// + /// Targeted value. + public void SetTarget(Quaternion targetValue) + { + TargetValue = targetValue; + StartValue = Value; + Duration = Quaternion.Angle(StartValue, TargetValue) / DeltaSpeed; + Counter = 0f; + } - /// - /// Returns whether there are further updates required to get the target value. - /// - /// True if updates are required. False otherwise. - public bool HasUpdate() - { - return Quaternion.Angle(TargetValue, Value) > 0.05f; - } + /// + /// Returns whether there are further updates required to get the target value. + /// + /// True if updates are required. False otherwise. + public bool HasUpdate() + { + return Quaternion.Angle(TargetValue, Value) > 0.05f; + } - /// - /// Performs and fets the updated value. - /// - /// Tick delta. - /// Updated value. - public Quaternion GetUpdate(float deltaTime) - { - Counter += deltaTime; - Value = Quaternion.Slerp(StartValue, TargetValue, Counter / Duration); + /// + /// Performs and fets the updated value. + /// + /// Tick delta. + /// Updated value. + public Quaternion GetUpdate(float deltaTime) + { + Counter += deltaTime; + Value = Quaternion.Slerp(StartValue, TargetValue, Counter / Duration); - return Value; + return Value; + } } } diff --git a/Assets/HoloToolkit/Sharing/Scripts/Unity/Vector3Interpolated.cs b/Assets/HoloToolkit/Sharing/Scripts/Unity/Vector3Interpolated.cs index 5daef778e68..ffa3ec10283 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Unity/Vector3Interpolated.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Unity/Vector3Interpolated.cs @@ -6,83 +6,86 @@ using HoloToolkit.Unity; using UnityEngine; -/// -/// Class to encapsulate an interpolating Vector3 property. -/// -public class Vector3Interpolated +namespace HoloToolkit.Sharing { /// - /// Half-life used to control how fast values are interpolated. + /// Class to encapsulate an interpolating Vector3 property. /// - public float HalfLife = 0.08f; - - /// - /// Current value of the property. - /// - public Vector3 Value { get; private set; } - /// - /// Target value of the property. - /// - public Vector3 TargetValue { get; private set; } - - public Vector3Interpolated() - { - Reset(Vector3.zero); - } - - public Vector3Interpolated(Vector3 initialValue) + public class Vector3Interpolated { - Reset(initialValue); - } + /// + /// Half-life used to control how fast values are interpolated. + /// + public float HalfLife = 0.08f; - /// - /// Resets property to zero interpolation and set value. - /// - /// Desired value to reset - public void Reset(Vector3 value) - { - Value = value; - TargetValue = value; - } + /// + /// Current value of the property. + /// + public Vector3 Value { get; private set; } + /// + /// Target value of the property. + /// + public Vector3 TargetValue { get; private set; } - /// - /// Set a target for property to interpolate to. - /// - /// Targeted value. - public void SetTarget(Vector3 targetValue) - { - TargetValue = targetValue; - } + public Vector3Interpolated() + { + Reset(Vector3.zero); + } - /// - /// Returns whether there are further updates required to get the target value. - /// - /// True if updates are required. False otherwise. - public bool HasUpdate() - { - return TargetValue != Value; - } + public Vector3Interpolated(Vector3 initialValue) + { + Reset(initialValue); + } - /// - /// Performs and gets the updated value. - /// - /// Tick delta. - /// Updated value. - public Vector3 GetUpdate(float deltaTime) - { - Vector3 distance = (TargetValue - Value); + /// + /// Resets property to zero interpolation and set value. + /// + /// Desired value to reset + public void Reset(Vector3 value) + { + Value = value; + TargetValue = value; + } - if (distance.sqrMagnitude <= Mathf.Epsilon) + /// + /// Set a target for property to interpolate to. + /// + /// Targeted value. + public void SetTarget(Vector3 targetValue) { - // When close enough, jump to the target - Value = TargetValue; + TargetValue = targetValue; } - else + + /// + /// Returns whether there are further updates required to get the target value. + /// + /// True if updates are required. False otherwise. + public bool HasUpdate() { - Value = InterpolationUtilities.ExpDecay(Value, TargetValue, HalfLife, deltaTime); + return TargetValue != Value; } + /// + /// Performs and gets the updated value. + /// + /// Tick delta. + /// Updated value. + public Vector3 GetUpdate(float deltaTime) + { + Vector3 distance = (TargetValue - Value); + + if (distance.sqrMagnitude <= Mathf.Epsilon) + { + // When close enough, jump to the target + Value = TargetValue; + } + else + { + Value = InterpolationUtilities.ExpDecay(Value, TargetValue, HalfLife, deltaTime); + } - return Value; + + return Value; + } } } diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/AutoJoinSession.cs b/Assets/HoloToolkit/Sharing/Scripts/Utilities/AutoJoinSession.cs index 4d887464fc2..49c95fa9be0 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Utilities/AutoJoinSession.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Utilities/AutoJoinSession.cs @@ -3,7 +3,7 @@ using UnityEngine; -namespace HoloToolkit.Sharing +namespace HoloToolkit.Sharing.Utilities { public class AutoJoinSession : MonoBehaviour { @@ -17,20 +17,20 @@ public class AutoJoinSession : MonoBehaviour /// private ServerSessionsTracker sessionsTracker; - private bool sessionCreationRequested = false; + private bool sessionCreationRequested; private string previousSessionName; - void Start() + private void Start() { // Get the ServerSessionsTracker to use later. Note that if this processes takes the role of a secondary client, // then the sessionsTracker will always be null if (SharingStage.Instance != null && SharingStage.Instance.Manager != null) { - this.sessionsTracker = SharingStage.Instance.SessionsTracker; + sessionsTracker = SharingStage.Instance.SessionsTracker; } } - void Update() + private void Update() { if (previousSessionName != SessionName) { @@ -39,40 +39,41 @@ void Update() } // If we are a Primary Client and can join sessions... - if (this.sessionsTracker != null && this.sessionsTracker.Sessions.Count > 0) + if (sessionsTracker != null && sessionsTracker.Sessions.Count > 0) { // Check to see if we aren't already in the desired session - Session currentSession = this.sessionsTracker.GetCurrentSession(); + Session currentSession = sessionsTracker.GetCurrentSession(); - if (currentSession == null || // We aren't in any session - currentSession.GetName().GetString() != this.SessionName || // We're in the wrong session - currentSession.GetMachineSessionState() == MachineSessionState.DISCONNECTED) // We aren't joined or joining the right session + if (currentSession == null || // We aren't in any session + currentSession.GetName().GetString() != SessionName || // We're in the wrong session + currentSession.GetMachineSessionState() == MachineSessionState.DISCONNECTED) // We aren't joined or joining the right session { - Debug.Log("Session conn " + this.sessionsTracker.IsServerConnected + " sessions: " + this.sessionsTracker.Sessions.Count); + Debug.LogFormat("Session conn {0} Sessions: {1}.", sessionsTracker.IsServerConnected.ToString(), sessionsTracker.Sessions.Count.ToString()); Debug.Log("Looking for " + SessionName); bool sessionFound = false; - for (int i = 0; i < this.sessionsTracker.Sessions.Count; ++i) + for (int i = 0; i < sessionsTracker.Sessions.Count; ++i) { - Session session = this.sessionsTracker.Sessions[i]; + Session session = sessionsTracker.Sessions[i]; - if (session.GetName().GetString() == this.SessionName) + if (session.GetName().GetString() == SessionName) { - this.sessionsTracker.JoinSession(session); + sessionsTracker.JoinSession(session); sessionFound = true; break; } } - if (this.sessionsTracker.IsServerConnected && !sessionFound && !sessionCreationRequested) + + if (sessionsTracker.IsServerConnected && !sessionFound && !sessionCreationRequested) { Debug.Log("Didn't find session, making a new one"); - if (this.sessionsTracker.CreateSession(new XString(SessionName))) + if (sessionsTracker.CreateSession(new XString(SessionName))) { sessionCreationRequested = true; } } } - } + } } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/ConsoleLogWriter.cs b/Assets/HoloToolkit/Sharing/Scripts/Utilities/ConsoleLogWriter.cs index 0f2fc45b1b2..a1d19447d9e 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Utilities/ConsoleLogWriter.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Utilities/ConsoleLogWriter.cs @@ -3,7 +3,7 @@ using UnityEngine; -namespace HoloToolkit.Sharing +namespace HoloToolkit.Sharing.Utilities { public class ConsoleLogWriter : LogWriter { diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/DirectPairing.cs b/Assets/HoloToolkit/Sharing/Scripts/Utilities/DirectPairing.cs index 03450caa1e3..a75138de975 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Utilities/DirectPairing.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/Utilities/DirectPairing.cs @@ -3,7 +3,7 @@ using UnityEngine; -namespace HoloToolkit.Sharing +namespace HoloToolkit.Sharing.Utilities { /// /// Component to pair with a remote client directly. @@ -16,7 +16,7 @@ public enum Role { Connector, Receiver - }; + } public Role PairingRole = Role.Connector; public string RemoteAddress = "localhost"; @@ -29,93 +29,87 @@ public enum Role private PairingAdapter pairingAdapter; private NetworkConnectionAdapter connectionAdapter; - - void Start() + private void Start() { - if (this.PairingRole == Role.Connector) + if (PairingRole == Role.Connector) { - this.pairMaker = new DirectPairConnector(this.RemoteAddress, this.RemotePort); + pairMaker = new DirectPairConnector(RemoteAddress, RemotePort); } else { - this.pairMaker = new DirectPairReceiver(this.LocalPort); + pairMaker = new DirectPairReceiver(LocalPort); } - this.pairingAdapter = new PairingAdapter(); - this.pairingAdapter.SuccessEvent += OnPairingConnectionSucceeded; - this.pairingAdapter.FailureEvent += OnPairingConnectionFailed; + pairingAdapter = new PairingAdapter(); + pairingAdapter.SuccessEvent += OnPairingConnectionSucceeded; + pairingAdapter.FailureEvent += OnPairingConnectionFailed; // Register to listen for disconnections, so we can reconnect automatically if (SharingStage.Instance != null) { - this.sharingMgr = SharingStage.Instance.Manager; + sharingMgr = SharingStage.Instance.Manager; - if (this.sharingMgr != null) + if (sharingMgr != null) { - this.connectionAdapter = new NetworkConnectionAdapter(); - this.connectionAdapter.DisconnectedCallback += OnDisconnected; + connectionAdapter = new NetworkConnectionAdapter(); + connectionAdapter.DisconnectedCallback += OnDisconnected; - NetworkConnection pairedConnection = this.sharingMgr.GetPairedConnection(); - pairedConnection.AddListener((byte)MessageID.StatusOnly, this.connectionAdapter); + NetworkConnection pairedConnection = sharingMgr.GetPairedConnection(); + pairedConnection.AddListener((byte)MessageID.StatusOnly, connectionAdapter); } } StartPairing(); } - - void OnDestroy() + private void OnDestroy() { // SharingStage's OnDestroy() might execute first in the script order. Therefore we should check if // SharingStage.Instance still exists. Without the instance check, the execution of GetPairingManager // on a disposed sharing manager will crash the Unity Editor and application. - if (SharingStage.Instance != null && this.sharingMgr != null) + if (SharingStage.Instance != null && sharingMgr != null) { PairingManager pairingMgr = sharingMgr.GetPairingManager(); - pairingMgr.CancelPairing(); // Safe to call, even if no pairing is in progress. Will not cause a disconnect + pairingMgr.CancelPairing(); // Safe to call, even if no pairing is in progress. Will not cause a disconnect // Remove our listener from the paired connection NetworkConnection pairedConnection = sharingMgr.GetPairedConnection(); - pairedConnection.RemoveListener((byte)MessageID.StatusOnly, this.connectionAdapter); + pairedConnection.RemoveListener((byte)MessageID.StatusOnly, connectionAdapter); } } - - void OnPairingConnectionSucceeded() + private void OnPairingConnectionSucceeded() { Debug.Log("Direct Pairing Succeeded"); } - - void OnPairingConnectionFailed(PairingResult result) + private void OnPairingConnectionFailed(PairingResult result) { - Debug.LogWarning("Direct pairing failed: " + result.ToString()); + Debug.LogWarning("Direct pairing failed: " + result); - if (this.AutoReconnect) + if (AutoReconnect) { StartPairing(); } } - - void OnDisconnected(NetworkConnection connection) + private void OnDisconnected(NetworkConnection connection) { Debug.LogWarning("Remote client disconnected"); - if (this.AutoReconnect) + if (AutoReconnect) { StartPairing(); } } - - void StartPairing() + private void StartPairing() { - if (this.sharingMgr != null) + if (sharingMgr != null) { - PairingManager pairingMgr = this.sharingMgr.GetPairingManager(); + PairingManager pairingMgr = sharingMgr.GetPairingManager(); - PairingResult result = pairingMgr.BeginPairing(this.pairMaker, this.pairingAdapter); + PairingResult result = pairingMgr.BeginPairing(pairMaker, pairingAdapter); if (result != PairingResult.Ok) { Debug.LogError("Failed to start pairing"); diff --git a/Assets/HoloToolkit/Sharing/Scripts/VoiceChat/MicrophoneReceiver.cs b/Assets/HoloToolkit/Sharing/Scripts/VoiceChat/MicrophoneReceiver.cs index cf985d35ef5..510e5b12215 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/VoiceChat/MicrophoneReceiver.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/VoiceChat/MicrophoneReceiver.cs @@ -1,13 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using UnityEngine; using System; -using System.Collections; using System.Threading; -using HoloToolkit.Sharing; using HoloToolkit.Unity; -using HoloToolkit.Sharing.Utilities; +using HoloToolkit.Utilities; +using UnityEngine; namespace HoloToolkit.Sharing { @@ -17,26 +15,23 @@ namespace HoloToolkit.Sharing [RequireComponent(typeof(AudioSource))] public class MicrophoneReceiver : MonoBehaviour { - private const byte speakerPlaybackMessageID = (byte)MessageID.AudioSamples; - - private BitManipulator versionExtractor = new BitManipulator(0x7, 0); // 3 bits, 0 shift - private BitManipulator audioStreamCountExtractor = new BitManipulator(0x38, 3); // 3 bits, 3 shift - private BitManipulator channelCountExtractor = new BitManipulator(0x1c0, 6); // 3 bits, 6 shift - private BitManipulator sampleRateExtractor = new BitManipulator(0x600, 9); // 2 bits, 9 shift - private BitManipulator sampleTypeExtractor = new BitManipulator(0x1800, 11); // 2 bits, 11 shift - private BitManipulator sampleCountExtractor = new BitManipulator(0x7fe000, 13); // 10 bits, 13 shift - private BitManipulator codecTypeExtractor = new BitManipulator(0x1800000, 23); // 2 bits, 23 shift - private BitManipulator sequenceNumberExtractor = new BitManipulator((int)0x7C000000, 26); // 6 bits, 26 shift + private readonly BitManipulator versionExtractor = new BitManipulator(0x7, 0); // 3 bits, 0 shift + private readonly BitManipulator audioStreamCountExtractor = new BitManipulator(0x38, 3); // 3 bits, 3 shift + private readonly BitManipulator channelCountExtractor = new BitManipulator(0x1c0, 6); // 3 bits, 6 shift + private readonly BitManipulator sampleRateExtractor = new BitManipulator(0x600, 9); // 2 bits, 9 shift + private readonly BitManipulator sampleTypeExtractor = new BitManipulator(0x1800, 11); // 2 bits, 11 shift + private readonly BitManipulator sampleCountExtractor = new BitManipulator(0x7fe000, 13); // 10 bits, 13 shift + private readonly BitManipulator codecTypeExtractor = new BitManipulator(0x1800000, 23); // 2 bits, 23 shift + private readonly BitManipulator sequenceNumberExtractor = new BitManipulator(0x7C000000, 26); // 6 bits, 26 shift public Transform GlobalAnchorTransform; public class ProminentSpeakerInfo { - public UInt32 sourceID; - public float averageAmplitude; - public Vector3 hrtfPosition; - - }; + public UInt32 SourceId; + public float AverageAmplitude; + public Vector3 HrtfPosition; + } /// /// Maximum number of prominent speakers we should ever encounter @@ -46,7 +41,7 @@ public class ProminentSpeakerInfo /// /// The information for current prominent speakers /// - private int prominentSpeakerCount = 0; + private int prominentSpeakerCount; /// /// The information for current prominent speakers. NOTE: preallocated to avoid any runtime allocations. @@ -55,10 +50,10 @@ public class ProminentSpeakerInfo private NetworkConnectionAdapter listener; - private Mutex audioDataMutex = new Mutex(); + private readonly Mutex audioDataMutex = new Mutex(); - private const float kDropOffMaximum = 5f; - private const float kPanMaximum = 5f; + private const float KDropOffMaximum = 5f; + private const float KPanMaximum = 5f; public float DropOffMaximumMetres = 5.0f; public float PanMaximumMetres = 5.0f; @@ -69,9 +64,9 @@ public class ProminentSpeakerInfo private CircularBuffer circularBuffer; #region DebugVariables - private CircularBuffer testCircularBuffer = new CircularBuffer(48000 * 2 * 4 * 3, true); + private readonly CircularBuffer testCircularBuffer = new CircularBuffer(48000 * 2 * 4 * 3, true); private AudioSource testSource; - public AudioClip testClip; + public AudioClip TestClip; public bool SaveTestClip; #endregion @@ -93,10 +88,10 @@ private void TryConnect() { if (listener == null) { - var sharingStage = SharingStage.Instance; + SharingStage sharingStage = SharingStage.Instance; if (sharingStage && sharingStage.Manager != null) { - var connection = SharingStage.Instance.Manager.GetServerConnection(); + NetworkConnection connection = SharingStage.Instance.Manager.GetServerConnection(); listener = new NetworkConnectionAdapter(); listener.ConnectedCallback += OnConnected; @@ -106,13 +101,13 @@ private void TryConnect() connection.AddListener((byte)MessageID.AudioSamples, listener); - UnityEngine.Debug.Log("SpeakerController Start called"); + Debug.Log("SpeakerController Start called"); } } } catch (Exception ex) { - UnityEngine.Debug.Log("Exception: " + ex.ToString()); + Debug.Log("Exception: " + ex); } } @@ -130,30 +125,30 @@ private void OnDestroy() private void OnConnected(NetworkConnection connection) { Profile.BeginRange("SpeakerController.OnConnected"); - internalStartSpeaker(); - UnityEngine.Debug.Log("SpeakerController: Connection to session server succeeded!"); + InternalStartSpeaker(); + Debug.Log("SpeakerController: Connection to session server succeeded!"); Profile.EndRange(); } private void OnDisconnected(NetworkConnection connection) { - internalStopSpeaker(); + InternalStopSpeaker(); prominentSpeakerCount = 0; - UnityEngine.Debug.Log("SpeakerController: Session server disconnected!"); + Debug.Log("SpeakerController: Session server disconnected!"); } private void OnConnectedFailed(NetworkConnection connection) { - internalStopSpeaker(); - UnityEngine.Debug.Log("SpeakerController: Connection to session server failed!"); + InternalStopSpeaker(); + Debug.Log("SpeakerController: Connection to session server failed!"); } /// /// Starts playing the audio stream out to the speaker. /// - private void internalStartSpeaker() + private void InternalStartSpeaker() { GetComponent().Play(); } @@ -161,7 +156,7 @@ private void internalStartSpeaker() /// /// Stops playing the audio stream out to the speaker. /// - private void internalStopSpeaker() + private void InternalStopSpeaker() { GetComponent().Stop(); } @@ -170,8 +165,8 @@ private void Update() { TryConnect(); - var audioSource = GetComponent(); - var remoteHead = GameObject.Find("mixamorig:Head"); + AudioSource audioSource = GetComponent(); + GameObject remoteHead = GameObject.Find("mixamorig:Head"); if (remoteHead) { transform.parent = remoteHead.transform; @@ -193,15 +188,15 @@ private void Update() float[] testBuffer = new float[testCircularBuffer.UsedCapacity / 4]; testCircularBuffer.Read(testBuffer, 0, testBuffer.Length * 4); testCircularBuffer.Reset(); - testClip = AudioClip.Create("testclip", testBuffer.Length / 2, 2, 48000, false); - testClip.SetData(testBuffer, 0); + TestClip = AudioClip.Create("testclip", testBuffer.Length / 2, 2, 48000, false); + TestClip.SetData(testBuffer, 0); if (!testSource) { GameObject testObj = new GameObject("testclip"); testObj.transform.parent = transform; testSource = testObj.AddComponent(); } - testSource.PlayClip(testClip, true); + testSource.PlayClip(TestClip, true); SaveTestClip = false; } #endregion @@ -254,16 +249,16 @@ public void OnMessageReceived(NetworkConnection connection, NetworkInMessage mes float averageAmplitude = message.ReadFloat(); UInt32 hrtfSourceID = (UInt32)message.ReadInt32(); Vector3 hrtfPosition = new Vector3(); - Vector3 hrtfDirection = new Vector3(); + //Vector3 hrtfDirection = new Vector3(); if (hrtfSourceID != 0) { hrtfPosition.x = message.ReadFloat(); hrtfPosition.y = message.ReadFloat(); hrtfPosition.z = message.ReadFloat(); - hrtfDirection.x = message.ReadFloat(); - hrtfDirection.y = message.ReadFloat(); - hrtfDirection.z = message.ReadFloat(); + //hrtfDirection.x = message.ReadFloat(); + //hrtfDirection.y = message.ReadFloat(); + //hrtfDirection.z = message.ReadFloat(); Vector3 cameraPosRelativeToGlobalAnchor = Vector3.zero; Vector3 cameraDirectionRelativeToGlobalAnchor = Vector3.zero; @@ -288,19 +283,19 @@ public void OnMessageReceived(NetworkConnection connection, NetworkInMessage mes soundVector.Normalize(); // x is forward - float fltx = (kDropOffMaximum / DropOffMaximumMetres) * Vector3.Dot(soundVector, cameraDirectionRelativeToGlobalAnchor); + float fltx = (KDropOffMaximum / DropOffMaximumMetres) * Vector3.Dot(soundVector, cameraDirectionRelativeToGlobalAnchor); // y is right Vector3 myRight = Quaternion.Euler(0, 90, 0) * cameraDirectionRelativeToGlobalAnchor; - float flty = -(kPanMaximum / PanMaximumMetres) * Vector3.Dot(soundVector, myRight); + float flty = -(KPanMaximum / PanMaximumMetres) * Vector3.Dot(soundVector, myRight); // z is up Vector3 myUp = Quaternion.Euler(90, 0, 0) * cameraDirectionRelativeToGlobalAnchor; - float fltz = (kPanMaximum / PanMaximumMetres) * Vector3.Dot(soundVector, myUp); + float fltz = (KPanMaximum / PanMaximumMetres) * Vector3.Dot(soundVector, myUp); // Hacky distance check so we don't get too close to source. Vector3 flt = new Vector3(fltx, flty, fltz); - if (flt.magnitude < (MinimumDistance * kDropOffMaximum)) + if (flt.magnitude < (MinimumDistance * KDropOffMaximum)) { - flt = flt.normalized * MinimumDistance * kDropOffMaximum; + flt = flt.normalized * MinimumDistance * KDropOffMaximum; fltx = flt.x; flty = flt.y; fltz = flt.z; @@ -380,11 +375,11 @@ private void AddProminentSpeaker(UInt32 sourceID, float averageAmplitude, float if (prominentSpeakerCount < MaximumProminentSpeakers) { ProminentSpeakerInfo prominentSpeakerInfo = prominentSpeakerList[prominentSpeakerCount++]; - prominentSpeakerInfo.sourceID = sourceID; - prominentSpeakerInfo.averageAmplitude = averageAmplitude; - prominentSpeakerInfo.hrtfPosition.x = posX; - prominentSpeakerInfo.hrtfPosition.y = posY; - prominentSpeakerInfo.hrtfPosition.z = posZ; + prominentSpeakerInfo.SourceId = sourceID; + prominentSpeakerInfo.AverageAmplitude = averageAmplitude; + prominentSpeakerInfo.HrtfPosition.x = posX; + prominentSpeakerInfo.HrtfPosition.y = posY; + prominentSpeakerInfo.HrtfPosition.z = posZ; } } @@ -399,10 +394,7 @@ public ProminentSpeakerInfo GetProminentSpeaker(int index) { return prominentSpeakerList[index]; } - else - { - return null; - } + return null; } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Scripts/VoiceChat/MicrophoneTransmitter.cs b/Assets/HoloToolkit/Sharing/Scripts/VoiceChat/MicrophoneTransmitter.cs index 33e60fca9b6..0c6e04eaf48 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/VoiceChat/MicrophoneTransmitter.cs +++ b/Assets/HoloToolkit/Sharing/Scripts/VoiceChat/MicrophoneTransmitter.cs @@ -1,330 +1,324 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using UnityEngine; using System; -using System.Collections; +using System.Globalization; using System.Threading; using HoloToolkit.Unity; -using HoloToolkit.Sharing; -using HoloToolkit.Sharing.Utilities; using HoloToolkit.Unity.InputModule; +using HoloToolkit.Utilities; +using UnityEngine; namespace HoloToolkit.Sharing { - /// - /// Transmits data from your microphone to other clients connected to a SessionServer. Requires any receiving client to be running the MicrophoneReceiver script. - /// - [RequireComponent(typeof(AudioSource))] - public class MicrophoneTransmitter : MonoBehaviour - { - /// - /// Which type of microphone/quality to access - /// - public MicStream.StreamCategory streamtype = MicStream.StreamCategory.HIGH_QUALITY_VOICE; - - /// - /// You can boost volume here as desired. 1 is default but probably too quiet. You can change during operation. - /// - public float InputGain = 2; - - /// - /// Whether or not to send the microphone data across the network - /// - public bool ShouldTransmitAudio = true; - - /// - /// Whether other users should be able to hear the transmitted audio - /// - public bool Mute = false; - - public Transform GlobalAnchorTransform; - - public bool ShowInterPacketTime = false; - - private DateTime timeOfLastPacketSend; - private float worstTimeBetweenPackets; - - private int sequenceNumber = 0; - - //#if !UNITY_METRO || UNITY_EDITOR - private int sampleRateType = 3; // 48000Hz - //#else - // private int sampleRateType = 1; // 16000Hz - //#endif - - private AudioSource audioSource; - - private bool hasServerConnection; - private bool micStarted; - private int dataChannelCount; - - public const int AudioPacketSize = 960; - private CircularBuffer micBuffer = new CircularBuffer(AudioPacketSize * 10 * 2 * 4, true); - private byte[] packetSamples = new byte[AudioPacketSize * 4]; - - // bit packers - private BitManipulator versionPacker = new BitManipulator(0x7, 0); // 3 bits, 0 shift - private BitManipulator audioStreamCountPacker = new BitManipulator(0x38, 3); // 3 bits, 3 shift - private BitManipulator channelCountPacker = new BitManipulator(0x1c0, 6); // 3 bits, 6 shift - private BitManipulator sampleRatePacker = new BitManipulator(0x600, 9); // 2 bits, 9 shift - private BitManipulator sampleTypePacker = new BitManipulator(0x1800, 11); // 2 bits, 11 shift - private BitManipulator sampleCountPacker = new BitManipulator(0x7fe000, 13); // 10 bits, 13 shift - private BitManipulator codecTypePacker = new BitManipulator(0x1800000, 23); // 2 bits, 23 shift - private BitManipulator mutePacker = new BitManipulator((int)0x2000000, 25); // 1 bits, 25 shift - private BitManipulator sequenceNumberPacker = new BitManipulator((int)0x7C000000, 26); // 6 bits, 26 shift - - private Mutex audioDataMutex = new Mutex(); - - #region DebugVariables - public bool HearSelf = false; - - private CircularBuffer testCircularBuffer = new CircularBuffer(48000 * 2 * 4 * 3, true); - private AudioSource testSource; - public AudioClip testClip; - public bool SaveTestClip; - #endregion - - private NetworkConnection GetActiveConnection() - { - NetworkConnection connection = null; - var stage = SharingStage.Instance; - if (stage && stage.Manager != null) - { - connection = stage.Manager.GetServerConnection(); - } - if (connection == null || !connection.IsConnected()) - { - return null; - } - return connection; - } - - private void Awake() - { - audioSource = GetComponent(); - - int errorCode = MicStream.MicInitializeCustomRate((int)streamtype, AudioSettings.outputSampleRate); - CheckForErrorOnCall(errorCode); - if (errorCode == 0 || errorCode == (int)MicStream.ErrorCodes.ALREADY_RUNNING) - { - if (CheckForErrorOnCall(MicStream.MicSetGain(InputGain))) - { - audioSource.volume = HearSelf ? 1.0f : 0.0f; - micStarted = CheckForErrorOnCall(MicStream.MicStartStream(false, false)); - } - } - } - - private void OnAudioFilterRead(float[] buffer, int numChannels) - { - try - { - audioDataMutex.WaitOne(); - - if (micStarted && hasServerConnection) - { - if (CheckForErrorOnCall(MicStream.MicGetFrame(buffer, buffer.Length, numChannels))) - { - int dataSize = buffer.Length * 4; - if (micBuffer.Write(buffer, 0, dataSize) != dataSize) - { - Debug.LogError("Send buffer filled up. Some audio will be lost."); - } - - dataChannelCount = numChannels; - } - } - } - catch (Exception e) - { - Debug.LogError(e.Message); - } - finally - { - audioDataMutex.ReleaseMutex(); - } - } - - private void Update() - { - CheckForErrorOnCall(MicStream.MicSetGain(InputGain)); - audioSource.volume = HearSelf ? 1.0f : 0.0f; - - try - { - audioDataMutex.WaitOne(); - - var connection = GetActiveConnection(); - hasServerConnection = (connection != null); - if (hasServerConnection) - { - while (micBuffer.UsedCapacity >= 4 * AudioPacketSize) - { - TransmitAudio(connection, dataChannelCount); - } - } - } - catch (Exception e) - { - Debug.LogError(e.Message); - } - finally - { - audioDataMutex.ReleaseMutex(); - } - - #region debuginfo - if (SaveTestClip && testCircularBuffer.UsedCapacity == testCircularBuffer.TotalCapacity) - { - float[] testBuffer = new float[testCircularBuffer.UsedCapacity / 4]; - testCircularBuffer.Read(testBuffer, 0, testBuffer.Length * 4); - testCircularBuffer.Reset(); - testClip = AudioClip.Create("testclip", testBuffer.Length / 2, 2, 48000, false); - testClip.SetData(testBuffer, 0); - if (!testSource) - { - GameObject testObj = new GameObject("testclip"); - testObj.transform.parent = transform; - testSource = testObj.AddComponent(); - } - testSource.PlayClip(testClip, false); - SaveTestClip = false; - } - #endregion - } - - private void TransmitAudio(NetworkConnection connection, int numChannels) - { - micBuffer.Read(packetSamples, 0, 4 * AudioPacketSize); - SendFixedSizedChunk(connection, packetSamples, packetSamples.Length); - - if (SaveTestClip) - { - testCircularBuffer.Write(packetSamples, 0, packetSamples.Length); - } - } - - private void SendFixedSizedChunk(NetworkConnection connection, byte[] data, int dataSize) - { - System.DateTime currentTime = System.DateTime.Now; - float seconds = (float)(currentTime - timeOfLastPacketSend).TotalSeconds; - timeOfLastPacketSend = currentTime; - if (seconds < 10.0) - { - if (worstTimeBetweenPackets < seconds) - { - worstTimeBetweenPackets = seconds; - } - - if (ShowInterPacketTime) - { - UnityEngine.Debug.Log("Microphone: Millisecs since last sent: " + seconds * 1000.0 + " Worst: " + worstTimeBetweenPackets * 1000.0); - } - } - - int clientId = SharingStage.Instance.Manager.GetLocalUser().GetID(); - - // pack the header - NetworkOutMessage msg = connection.CreateMessage((byte)MessageID.AudioSamples); - - int dataCountFloats = dataSize / 4; - - msg.Write((byte)5); // 8 byte header size - - Int32 pack = 0; - versionPacker.SetBits(ref pack, 1); // version - audioStreamCountPacker.SetBits(ref pack, 1); // AudioStreamCount - channelCountPacker.SetBits(ref pack, 1); // ChannelCount - sampleRatePacker.SetBits(ref pack, sampleRateType); // SampleRate: 1 = 16000, 3 = 48000 - sampleTypePacker.SetBits(ref pack, 0); // SampleType - sampleCountPacker.SetBits(ref pack, dataCountFloats); // SampleCount (data count is in bytes and the actual data is in floats, so div by 4) - codecTypePacker.SetBits(ref pack, 0); // CodecType - mutePacker.SetBits(ref pack, Mute ? 1 : 0); - sequenceNumberPacker.SetBits(ref pack, sequenceNumber++); - sequenceNumber %= 32; - - msg.Write((int)pack); // the packed bits - - // This is where stream data starts. Write all data for one stream - - msg.Write((float)0.0f); // average amplitude. Not needed in direction from client to server. - msg.Write((int)clientId); // non-zero client ID for this client. - - // HRTF position bits - - Vector3 cameraPosRelativeToGlobalAnchor = Vector3.zero; - Vector3 cameraDirectionRelativeToGlobalAnchor = Vector3.zero; - - if (GlobalAnchorTransform != null) - { - cameraPosRelativeToGlobalAnchor = MathUtils.TransformPointFromTo( - null, - GlobalAnchorTransform, - Camera.main.transform.position); - - cameraDirectionRelativeToGlobalAnchor = MathUtils.TransformDirectionFromTo( - null, - GlobalAnchorTransform, - Camera.main.transform.position); - } - - cameraPosRelativeToGlobalAnchor.Normalize(); - cameraDirectionRelativeToGlobalAnchor.Normalize(); - - // Camera position - msg.Write(cameraPosRelativeToGlobalAnchor.x); - msg.Write(cameraPosRelativeToGlobalAnchor.y); - msg.Write(cameraPosRelativeToGlobalAnchor.z); - - // HRTF direction bits - msg.Write(cameraDirectionRelativeToGlobalAnchor.x); - msg.Write(cameraDirectionRelativeToGlobalAnchor.y); - msg.Write(cameraDirectionRelativeToGlobalAnchor.z); - - msg.WriteArray(data, (uint)dataCountFloats * 4); - - connection.Send(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Audio, true); - } - - private void OnDestroy() - { - CheckForErrorOnCall(MicStream.MicDestroy()); - } - - private bool CheckForErrorOnCall(int returnCode) - { - return MicStream.CheckForErrorOnCall(returnCode); - } + /// + /// Transmits data from your microphone to other clients connected to a SessionServer. Requires any receiving client to be running the MicrophoneReceiver script. + /// + [RequireComponent(typeof(AudioSource))] + public class MicrophoneTransmitter : MonoBehaviour + { + /// + /// Which type of microphone/quality to access + /// + public MicStream.StreamCategory Streamtype = MicStream.StreamCategory.HIGH_QUALITY_VOICE; + + /// + /// You can boost volume here as desired. 1 is default but probably too quiet. You can change during operation. + /// + public float InputGain = 2; + + /// + /// Whether or not to send the microphone data across the network + /// + public bool ShouldTransmitAudio = true; + + /// + /// Whether other users should be able to hear the transmitted audio + /// + public bool Mute; + + public Transform GlobalAnchorTransform; + + public bool ShowInterPacketTime; + + private DateTime timeOfLastPacketSend; + private float worstTimeBetweenPackets; + + private int sequenceNumber; + + private int sampleRateType = 3; // 48000Hz + + private AudioSource audioSource; + + private bool hasServerConnection; + private bool micStarted; + + public const int AudioPacketSize = 960; + private CircularBuffer micBuffer = new CircularBuffer(AudioPacketSize * 10 * 2 * 4, true); + private byte[] packetSamples = new byte[AudioPacketSize * 4]; + + // bit packers + private readonly BitManipulator versionPacker = new BitManipulator(0x7, 0); // 3 bits, 0 shift + private readonly BitManipulator audioStreamCountPacker = new BitManipulator(0x38, 3); // 3 bits, 3 shift + private readonly BitManipulator channelCountPacker = new BitManipulator(0x1c0, 6); // 3 bits, 6 shift + private readonly BitManipulator sampleRatePacker = new BitManipulator(0x600, 9); // 2 bits, 9 shift + private readonly BitManipulator sampleTypePacker = new BitManipulator(0x1800, 11); // 2 bits, 11 shift + private readonly BitManipulator sampleCountPacker = new BitManipulator(0x7fe000, 13); // 10 bits, 13 shift + private readonly BitManipulator codecTypePacker = new BitManipulator(0x1800000, 23); // 2 bits, 23 shift + private readonly BitManipulator mutePacker = new BitManipulator(0x2000000, 25); // 1 bits, 25 shift + private readonly BitManipulator sequenceNumberPacker = new BitManipulator(0x7C000000, 26); // 6 bits, 26 shift + + private readonly Mutex audioDataMutex = new Mutex(); + + #region DebugVariables + public bool HearSelf; + + private readonly CircularBuffer testCircularBuffer = new CircularBuffer(48000 * 2 * 4 * 3, true); + private AudioSource testSource; + public AudioClip TestClip; + public bool SaveTestClip; + #endregion + + private NetworkConnection GetActiveConnection() + { + NetworkConnection connection = null; + var stage = SharingStage.Instance; + if (stage && stage.Manager != null) + { + connection = stage.Manager.GetServerConnection(); + } + if (connection == null || !connection.IsConnected()) + { + return null; + } + return connection; + } + + private void Awake() + { + audioSource = GetComponent(); + + int errorCode = MicStream.MicInitializeCustomRate((int)Streamtype, AudioSettings.outputSampleRate); + CheckForErrorOnCall(errorCode); + if (errorCode == 0 || errorCode == (int)MicStream.ErrorCodes.ALREADY_RUNNING) + { + if (CheckForErrorOnCall(MicStream.MicSetGain(InputGain))) + { + audioSource.volume = HearSelf ? 1.0f : 0.0f; + micStarted = CheckForErrorOnCall(MicStream.MicStartStream(false, false)); + } + } + } + + private void OnAudioFilterRead(float[] buffer, int numChannels) + { + try + { + audioDataMutex.WaitOne(); + + if (micStarted && hasServerConnection) + { + if (CheckForErrorOnCall(MicStream.MicGetFrame(buffer, buffer.Length, numChannels))) + { + int dataSize = buffer.Length * 4; + if (micBuffer.Write(buffer, 0, dataSize) != dataSize) + { + Debug.LogError("Send buffer filled up. Some audio will be lost."); + } + } + } + } + catch (Exception e) + { + Debug.LogError(e.Message); + } + finally + { + audioDataMutex.ReleaseMutex(); + } + } + + private void Update() + { + CheckForErrorOnCall(MicStream.MicSetGain(InputGain)); + audioSource.volume = HearSelf ? 1.0f : 0.0f; + + try + { + audioDataMutex.WaitOne(); + + var connection = GetActiveConnection(); + hasServerConnection = (connection != null); + if (hasServerConnection) + { + while (micBuffer.UsedCapacity >= 4 * AudioPacketSize) + { + TransmitAudio(connection); + } + } + } + catch (Exception e) + { + Debug.LogError(e.Message); + } + finally + { + audioDataMutex.ReleaseMutex(); + } + + #region debuginfo + if (SaveTestClip && testCircularBuffer.UsedCapacity == testCircularBuffer.TotalCapacity) + { + float[] testBuffer = new float[testCircularBuffer.UsedCapacity / 4]; + testCircularBuffer.Read(testBuffer, 0, testBuffer.Length * 4); + testCircularBuffer.Reset(); + TestClip = AudioClip.Create("testclip", testBuffer.Length / 2, 2, 48000, false); + TestClip.SetData(testBuffer, 0); + if (!testSource) + { + GameObject testObj = new GameObject("testclip"); + testObj.transform.parent = transform; + testSource = testObj.AddComponent(); + } + testSource.PlayClip(TestClip); + SaveTestClip = false; + } + #endregion + } + + private void TransmitAudio(NetworkConnection connection) + { + micBuffer.Read(packetSamples, 0, 4 * AudioPacketSize); + SendFixedSizedChunk(connection, packetSamples, packetSamples.Length); + + if (SaveTestClip) + { + testCircularBuffer.Write(packetSamples, 0, packetSamples.Length); + } + } + + private void SendFixedSizedChunk(NetworkConnection connection, byte[] data, int dataSize) + { + DateTime currentTime = DateTime.Now; + float seconds = (float)(currentTime - timeOfLastPacketSend).TotalSeconds; + timeOfLastPacketSend = currentTime; + if (seconds < 10.0) + { + if (worstTimeBetweenPackets < seconds) + { + worstTimeBetweenPackets = seconds; + } + + if (ShowInterPacketTime) + { + Debug.LogFormat("Microphone: Millisecs since last sent: {0}, Worst: {1}", + (seconds * 1000.0).ToString(CultureInfo.InvariantCulture), + (worstTimeBetweenPackets * 1000.0).ToString(CultureInfo.InvariantCulture)); + } + } + + int clientId = SharingStage.Instance.Manager.GetLocalUser().GetID(); + + // pack the header + NetworkOutMessage msg = connection.CreateMessage((byte)MessageID.AudioSamples); + + int dataCountFloats = dataSize / 4; + + msg.Write((byte)5); // 8 byte header size + + Int32 pack = 0; + versionPacker.SetBits(ref pack, 1); // version + audioStreamCountPacker.SetBits(ref pack, 1); // AudioStreamCount + channelCountPacker.SetBits(ref pack, 1); // ChannelCount + sampleRatePacker.SetBits(ref pack, sampleRateType); // SampleRate: 1 = 16000, 3 = 48000 + sampleTypePacker.SetBits(ref pack, 0); // SampleType + sampleCountPacker.SetBits(ref pack, dataCountFloats); // SampleCount (data count is in bytes and the actual data is in floats, so div by 4) + codecTypePacker.SetBits(ref pack, 0); // CodecType + mutePacker.SetBits(ref pack, Mute ? 1 : 0); + sequenceNumberPacker.SetBits(ref pack, sequenceNumber++); + sequenceNumber %= 32; + + msg.Write(pack); // the packed bits + + // This is where stream data starts. Write all data for one stream + + msg.Write(0.0f); // average amplitude. Not needed in direction from client to server. + msg.Write(clientId); // non-zero client ID for this client. + + // HRTF position bits + + Vector3 cameraPosRelativeToGlobalAnchor = Vector3.zero; + Vector3 cameraDirectionRelativeToGlobalAnchor = Vector3.zero; + + if (GlobalAnchorTransform != null) + { + cameraPosRelativeToGlobalAnchor = MathUtils.TransformPointFromTo( + null, + GlobalAnchorTransform, + Camera.main.transform.position); + + cameraDirectionRelativeToGlobalAnchor = MathUtils.TransformDirectionFromTo( + null, + GlobalAnchorTransform, + Camera.main.transform.position); + } + + cameraPosRelativeToGlobalAnchor.Normalize(); + cameraDirectionRelativeToGlobalAnchor.Normalize(); + + // Camera position + msg.Write(cameraPosRelativeToGlobalAnchor.x); + msg.Write(cameraPosRelativeToGlobalAnchor.y); + msg.Write(cameraPosRelativeToGlobalAnchor.z); + + // HRTF direction bits + msg.Write(cameraDirectionRelativeToGlobalAnchor.x); + msg.Write(cameraDirectionRelativeToGlobalAnchor.y); + msg.Write(cameraDirectionRelativeToGlobalAnchor.z); + + msg.WriteArray(data, (uint)dataCountFloats * 4); + + connection.Send(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Audio, true); + } + + private void OnDestroy() + { + CheckForErrorOnCall(MicStream.MicDestroy()); + } + + private bool CheckForErrorOnCall(int returnCode) + { + return MicStream.CheckForErrorOnCall(returnCode); + } #if DOTNET_FX - // on device, deal with all the ways that we could suspend our program in as few lines as possible - private void OnApplicationPause(bool pause) - { - if (pause) - { - CheckForErrorOnCall(MicStream.MicPause()); - } - else - { - CheckForErrorOnCall(MicStream.MicResume()); - } - } - - private void OnApplicationFocus(bool focused) - { - this.OnApplicationPause(!focused); - } - - private void OnDisable() - { - this.OnApplicationPause(true); - } - - private void OnEnable() - { - this.OnApplicationPause(false); - } + // on device, deal with all the ways that we could suspend our program in as few lines as possible + private void OnApplicationPause(bool pause) + { + if (pause) + { + CheckForErrorOnCall(MicStream.MicPause()); + } + else + { + CheckForErrorOnCall(MicStream.MicResume()); + } + } + + private void OnApplicationFocus(bool focused) + { + OnApplicationPause(!focused); + } + + private void OnDisable() + { + OnApplicationPause(true); + } + + private void OnEnable() + { + OnApplicationPause(false); + } #endif - } + } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest.meta b/Assets/HoloToolkit/Sharing/Tests/Prefabs.meta similarity index 67% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest.meta rename to Assets/HoloToolkit/Sharing/Tests/Prefabs.meta index af196e3f196..c4b93316fdc 100644 --- a/Assets/HoloToolkit/Sharing/Tests/SpawnTest.meta +++ b/Assets/HoloToolkit/Sharing/Tests/Prefabs.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: e43387d4226005742bf1c9a34bac2b7d +guid: 143b74b04f99d3340bdf848c01fe8701 folderAsset: yes -timeCreated: 1463074475 +timeCreated: 1485717681 licenseType: Pro DefaultImporter: userData: diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestCube.prefab b/Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestCube.prefab similarity index 88% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestCube.prefab rename to Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestCube.prefab index bede8626b97..b94bd64c31a 100644 --- a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestCube.prefab +++ b/Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestCube.prefab @@ -16,13 +16,13 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 4000011005901650} - - 33: {fileID: 33000013234338350} - - 65: {fileID: 65000013357994320} - - 23: {fileID: 23000012968995202} - - 114: {fileID: 114000011879003738} + - component: {fileID: 4000011005901650} + - component: {fileID: 33000013234338350} + - component: {fileID: 65000013357994320} + - component: {fileID: 23000012968995202} + - component: {fileID: 114000011879003738} m_Layer: 0 m_Name: SpawnTestCube m_TagString: Untagged @@ -52,11 +52,14 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_Materials: - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_SubsetIndices: + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 m_StaticBatchRoot: {fileID: 0} m_ProbeAnchor: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0} @@ -64,6 +67,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestCube.prefab.meta b/Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestCube.prefab.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestCube.prefab.meta rename to Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestCube.prefab.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestSphere.prefab b/Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestSphere.prefab similarity index 88% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestSphere.prefab rename to Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestSphere.prefab index 34bf8891352..a253ce40975 100644 --- a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestSphere.prefab +++ b/Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestSphere.prefab @@ -16,12 +16,12 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 4000011704771958} - - 33: {fileID: 33000010938939848} - - 135: {fileID: 135000014220753548} - - 23: {fileID: 23000011579165200} + - component: {fileID: 4000011704771958} + - component: {fileID: 33000010938939848} + - component: {fileID: 135000014220753548} + - component: {fileID: 23000011579165200} m_Layer: 0 m_Name: SpawnTestSphere m_TagString: Untagged @@ -51,11 +51,14 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_Materials: - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_SubsetIndices: + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 m_StaticBatchRoot: {fileID: 0} m_ProbeAnchor: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0} @@ -63,6 +66,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestSphere.prefab.meta b/Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestSphere.prefab.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestSphere.prefab.meta rename to Assets/HoloToolkit/Sharing/Tests/Prefabs/SpawnTestSphere.prefab.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomTest.cs b/Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomTest.cs deleted file mode 100644 index 924aa863279..00000000000 --- a/Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomTest.cs +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using UnityEngine; -using HoloToolkit.Sharing; - -public class RoomTest : MonoBehaviour -{ - private RoomManagerAdapter listener; - private RoomManager roomMgr; - - private string roomName = "New Room"; - private Vector2 scrollViewVector = Vector2.zero; - private int Padding = 4; - private int AreaWidth = 400; - private int AreaHeight = 300; - private int ButtonWidth = 80; - private int LineHeight = 20; - - private Vector2 anchorScrollVector = Vector2.zero; - private string anchorName = "New Anchor"; - private byte[] anchorTestData = new byte[5 * 1024 * 1024]; // 5 meg test buffer - - void Start () - { - for (int i = 0; i < anchorTestData.Length; ++i) - { - anchorTestData[i] = (byte)(i % 256); - } - - SharingStage stage = SharingStage.Instance; - if (stage != null) - { - SharingManager sharingMgr = stage.Manager; - if (sharingMgr != null) - { - this.roomMgr = sharingMgr.GetRoomManager(); - - this.listener = new RoomManagerAdapter(); - this.listener.RoomAddedEvent += OnRoomAdded; - this.listener.RoomClosedEvent += OnRoomClosed; - this.listener.UserJoinedRoomEvent += OnUserJoinedRoom; - this.listener.UserLeftRoomEvent += OnUserLeftRoom; - this.listener.AnchorsChangedEvent += OnAnchorsChanged; - this.listener.AnchorsDownloadedEvent += OnAnchorsDownloaded; - this.listener.AnchorUploadedEvent += OnAnchorUploadComplete; - - this.roomMgr.AddListener(this.listener); - } - } - } - - private void OnDestroy() - { - this.roomMgr.RemoveListener(this.listener); - this.listener.Dispose(); - } - - - void OnGUI() - { - // Make a background box - this.scrollViewVector = GUI.BeginScrollView(new Rect(25, 25, this.AreaWidth, this.AreaHeight), scrollViewVector, new Rect(0, 0, this.AreaWidth, this.AreaHeight)); - - if (this.roomMgr != null) - { - SessionManager sessionMgr = SharingStage.Instance.Manager.GetSessionManager(); - if (sessionMgr != null) - { - this.roomName = GUI.TextField(new Rect(this.ButtonWidth + this.Padding, 0, this.AreaWidth - (this.ButtonWidth + this.Padding), this.LineHeight), this.roomName); - - if (GUI.Button(new Rect(0, 0, this.ButtonWidth, this.LineHeight), "Create")) - { - System.Random rnd = new System.Random(); - - Room newRoom = roomMgr.CreateRoom(this.roomName, rnd.Next(), false); - if (newRoom == null) - { - Debug.LogWarning("Cannot create room"); - } - } - - Room currentRoom = roomMgr.GetCurrentRoom(); - - for (int i = 0; i < roomMgr.GetRoomCount(); ++i) - { - Room r = roomMgr.GetRoom(i); - - int vOffset = (this.Padding + this.LineHeight) * (i + 1); - int hOffset = 0; - - bool keepOpen = GUI.Toggle(new Rect(hOffset, vOffset, this.LineHeight, this.LineHeight), r.GetKeepOpen(), ""); - r.SetKeepOpen(keepOpen); - - hOffset += this.LineHeight + this.Padding; - - if (currentRoom != null && r.GetID() == currentRoom.GetID()) - { - if (GUI.Button(new Rect(hOffset, vOffset, this.ButtonWidth, this.LineHeight), "Leave")) - { - roomMgr.LeaveRoom(); - } - } - else - { - if (GUI.Button(new Rect(hOffset, vOffset, this.ButtonWidth, this.LineHeight), "Join")) - { - if (!roomMgr.JoinRoom(r)) - { - Debug.LogWarning("Cannot join room"); - } - } - } - - hOffset += this.ButtonWidth + this.Padding; - - GUI.Label(new Rect(hOffset, vOffset, this.AreaWidth - (this.ButtonWidth + this.Padding), this.LineHeight), r.GetName().GetString()); - - } - } - } - - // End the ScrollView - GUI.EndScrollView(); - - { - Room currentRoom = roomMgr.GetCurrentRoom(); - - if (currentRoom != null) - { - // Display option to upload anchor - this.anchorScrollVector = GUI.BeginScrollView(new Rect(this.AreaWidth + 50, 25, this.AreaWidth, this.AreaHeight), anchorScrollVector, new Rect(0, 0, this.AreaWidth, this.AreaHeight)); - - this.anchorName = GUI.TextField(new Rect(this.ButtonWidth + this.Padding, 0, this.AreaWidth - (this.ButtonWidth + this.Padding), this.LineHeight), this.anchorName); - - if (GUI.Button(new Rect(0, 0, this.ButtonWidth, this.LineHeight), "Create")) - { - if (!this.roomMgr.UploadAnchor(currentRoom, this.anchorName, anchorTestData, anchorTestData.Length)) - { - Debug.LogError("Failed to start anchor upload"); - } - } - - for (int i = 0; i < currentRoom.GetAnchorCount(); ++i) - { - int vOffset = (this.Padding + this.LineHeight) * (i + 1); - - XString name = currentRoom.GetAnchorName(i); - - GUI.Label(new Rect(this.ButtonWidth + this.Padding, vOffset, this.AreaWidth - (this.ButtonWidth + this.Padding), this.LineHeight), name); - - if (GUI.Button(new Rect(0, vOffset, this.ButtonWidth, this.LineHeight), "Download")) - { - if (!roomMgr.DownloadAnchor(currentRoom, name)) - { - Debug.LogWarning("Failed to start anchor download"); - } - } - } - - GUI.EndScrollView(); - } - } - } - - private void OnRoomAdded(Room newRoom) - { - Debug.Log(string.Format("Room {0} added", newRoom.GetName().GetString())); - } - - private void OnRoomClosed(Room room) - { - Debug.Log(string.Format("Room {0} closed", room.GetName().GetString())); - } - - private void OnUserJoinedRoom(Room room, int user) - { - Debug.Log(string.Format("User {0} joined Room {1}", user, room.GetName().GetString())); - } - - private void OnUserLeftRoom(Room room, int user) - { - Debug.Log(string.Format("User {0} left Room {1}", user, room.GetName().GetString())); - } - - private void OnAnchorsChanged(Room room) - { - Debug.Log(string.Format("Anchors changed for Room {0}", room.GetName().GetString())); - } - - private void OnAnchorsDownloaded(bool successful, AnchorDownloadRequest request, XString failureReason) - { - if (successful) - { - Debug.Log(string.Format("Anchors download succeeded for Room {0}", request.GetRoom().GetName().GetString())); - } - else - { - Debug.Log(string.Format("Anchors download failed: {0}", failureReason.GetString())); - } - } - - private void OnAnchorUploadComplete(bool successful, XString failureReason) - { - if (successful) - { - Debug.Log("Anchors upload succeeded"); - } - else - { - Debug.Log(string.Format("Anchors upload failed: {0}", failureReason.GetString())); - } - } -} diff --git a/Assets/HoloToolkit/Sharing/Tests/RoomTest.meta b/Assets/HoloToolkit/Sharing/Tests/Scenes.meta similarity index 67% rename from Assets/HoloToolkit/Sharing/Tests/RoomTest.meta rename to Assets/HoloToolkit/Sharing/Tests/Scenes.meta index 95b611b5269..c17a17cafdc 100644 --- a/Assets/HoloToolkit/Sharing/Tests/RoomTest.meta +++ b/Assets/HoloToolkit/Sharing/Tests/Scenes.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 025459aaf1029a7458859bc68868b1a1 +guid: 0fe5964f4928ad241a3afee16557798a folderAsset: yes -timeCreated: 1465491456 +timeCreated: 1485717652 licenseType: Pro DefaultImporter: userData: diff --git a/Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomAndAnchorTest.unity b/Assets/HoloToolkit/Sharing/Tests/Scenes/RoomAndAnchorTest.unity similarity index 69% rename from Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomAndAnchorTest.unity rename to Assets/HoloToolkit/Sharing/Tests/Scenes/RoomAndAnchorTest.unity index 958aa57be10..a8e314cc162 100644 --- a/Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomAndAnchorTest.unity +++ b/Assets/HoloToolkit/Sharing/Tests/Scenes/RoomAndAnchorTest.unity @@ -1,15 +1,15 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: --- !u!29 &1 -SceneSettings: +OcclusionCullingSettings: m_ObjectHideFlags: 0 - m_PVSData: - m_PVSObjectsArray: [] - m_PVSPortalsArray: [] + serializedVersion: 2 m_OcclusionBakeSettings: smallestOccluder: 5 smallestHole: 0.25 backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} --- !u!104 &2 RenderSettings: m_ObjectHideFlags: 0 @@ -37,7 +37,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44692546, g: 0.4967876, b: 0.57508576, a: 1} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 @@ -79,28 +79,71 @@ NavMeshSettings: m_ObjectHideFlags: 0 m_BuildSettings: serializedVersion: 2 + agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 agentSlope: 45 agentClimb: 0.4 ledgeDropHeight: 0 maxJumpAcrossDistance: 0 - accuratePlacement: 0 minRegionArea: 2 - cellSize: 0.16666667 manualCellSize: 0 + cellSize: 0.16666667 + accuratePlacement: 0 m_NavMeshData: {fileID: 0} +--- !u!1001 &426960207 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + m_IsPrefabParent: 0 --- !u!1 &430568305 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 430568308} - - 114: {fileID: 430568309} - - 114: {fileID: 430568307} - - 114: {fileID: 430568306} + - component: {fileID: 430568308} + - component: {fileID: 430568309} + - component: {fileID: 430568307} + - component: {fileID: 430568306} m_Layer: 0 m_Name: Stage m_TagString: Untagged @@ -142,7 +185,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &430568309 MonoBehaviour: @@ -159,103 +202,18 @@ MonoBehaviour: ServerAddress: localhost ServerPort: 20602 connectOnAwake: 1 + AutoDiscoverServer: 0 + PingIntervalSec: 2 IsAudioEndpoint: 1 ---- !u!1 &525051509 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 525051514} - - 20: {fileID: 525051513} - - 92: {fileID: 525051512} - - 124: {fileID: 525051511} - - 81: {fileID: 525051510} - m_Layer: 0 - m_Name: Main Camera - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!81 &525051510 -AudioListener: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 525051509} - m_Enabled: 1 ---- !u!124 &525051511 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 525051509} - m_Enabled: 1 ---- !u!92 &525051512 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 525051509} - m_Enabled: 1 ---- !u!20 &525051513 -Camera: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 525051509} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 - m_StereoMirrorMode: 0 ---- !u!4 &525051514 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 525051509} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -10} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1059641718 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 1059641720} - - 108: {fileID: 1059641719} + - component: {fileID: 1059641720} + - component: {fileID: 1059641719} m_Layer: 0 m_Name: Directional Light m_TagString: Untagged @@ -280,6 +238,7 @@ Light: m_Shadows: m_Type: 2 m_Resolution: -1 + m_CustomResolution: -1 m_Strength: 1 m_Bias: 0.05 m_NormalBias: 0.4 @@ -307,5 +266,5 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomAndAnchorTest.unity.meta b/Assets/HoloToolkit/Sharing/Tests/Scenes/RoomAndAnchorTest.unity.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomAndAnchorTest.unity.meta rename to Assets/HoloToolkit/Sharing/Tests/Scenes/RoomAndAnchorTest.unity.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SharingSpawnTest.unity b/Assets/HoloToolkit/Sharing/Tests/Scenes/SharingSpawnTest.unity similarity index 67% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest/SharingSpawnTest.unity rename to Assets/HoloToolkit/Sharing/Tests/Scenes/SharingSpawnTest.unity index 6af73af6e26..013fef25b56 100644 --- a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SharingSpawnTest.unity +++ b/Assets/HoloToolkit/Sharing/Tests/Scenes/SharingSpawnTest.unity @@ -1,404 +1,346 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!29 &1 -SceneSettings: - m_ObjectHideFlags: 0 - m_PVSData: - m_PVSObjectsArray: [] - m_PVSPortalsArray: [] - m_OcclusionBakeSettings: - smallestOccluder: 5 - smallestHole: 0.25 - backfaceThreshold: 100 ---- !u!104 &2 -RenderSettings: - m_ObjectHideFlags: 0 - serializedVersion: 7 - m_Fog: 0 - m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} - m_FogMode: 3 - m_FogDensity: 0.01 - m_LinearFogStart: 0 - m_LinearFogEnd: 300 - m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} - m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} - m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} - m_AmbientIntensity: 1 - m_AmbientMode: 0 - m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} - m_HaloStrength: 0.5 - m_FlareStrength: 1 - m_FlareFadeSpeed: 3 - m_HaloTexture: {fileID: 0} - m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} - m_DefaultReflectionMode: 0 - m_DefaultReflectionResolution: 128 - m_ReflectionBounces: 1 - m_ReflectionIntensity: 1 - m_CustomReflection: {fileID: 0} - m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} ---- !u!157 &3 -LightmapSettings: - m_ObjectHideFlags: 0 - serializedVersion: 7 - m_GIWorkflowMode: 1 - m_GISettings: - serializedVersion: 2 - m_BounceScale: 1 - m_IndirectOutputScale: 1 - m_AlbedoBoost: 1 - m_TemporalCoherenceThreshold: 1 - m_EnvironmentLightingMode: 0 - m_EnableBakedLightmaps: 1 - m_EnableRealtimeLightmaps: 1 - m_LightmapEditorSettings: - serializedVersion: 4 - m_Resolution: 2 - m_BakeResolution: 40 - m_TextureWidth: 1024 - m_TextureHeight: 1024 - m_AO: 0 - m_AOMaxDistance: 1 - m_CompAOExponent: 1 - m_CompAOExponentDirect: 0 - m_Padding: 2 - m_LightmapParameters: {fileID: 0} - m_LightmapsBakeMode: 1 - m_TextureCompression: 1 - m_DirectLightInLightProbes: 1 - m_FinalGather: 0 - m_FinalGatherFiltering: 1 - m_FinalGatherRayCount: 256 - m_ReflectionCompression: 2 - m_LightingDataAsset: {fileID: 0} - m_RuntimeCPUUsage: 25 ---- !u!196 &4 -NavMeshSettings: - serializedVersion: 2 - m_ObjectHideFlags: 0 - m_BuildSettings: - serializedVersion: 2 - agentRadius: 0.5 - agentHeight: 2 - agentSlope: 45 - agentClimb: 0.4 - ledgeDropHeight: 0 - maxJumpAcrossDistance: 0 - accuratePlacement: 0 - minRegionArea: 2 - cellSize: 0.16666667 - manualCellSize: 0 - m_NavMeshData: {fileID: 0} ---- !u!1 &93446617 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 93446622} - - 20: {fileID: 93446621} - - 92: {fileID: 93446620} - - 124: {fileID: 93446619} - - 81: {fileID: 93446618} - - 114: {fileID: 93446623} - m_Layer: 0 - m_Name: Main Camera - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!81 &93446618 -AudioListener: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 93446617} - m_Enabled: 1 ---- !u!124 &93446619 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 93446617} - m_Enabled: 1 ---- !u!92 &93446620 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 93446617} - m_Enabled: 1 ---- !u!20 &93446621 -Camera: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 93446617} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 2 - m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0} - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 - m_StereoMirrorMode: 0 ---- !u!4 &93446622 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 93446617} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &93446623 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 93446617} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c7da09fa7ee0c234ba7cf22ab717f17a, type: 3} - m_Name: - m_EditorClassIdentifier: - ExtraMouseSensitivityScale: 3 - DefaultMouseSensitivity: 0.1 - MouseLookButton: 3 - IsControllerLookInverted: 1 - keyboardRotationSensitivity: 100 ---- !u!1 &483826393 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 483826395} - - 108: {fileID: 483826394} - m_Layer: 0 - m_Name: Directional Light - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!108 &483826394 -Light: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 483826393} - m_Enabled: 1 - serializedVersion: 7 - m_Type: 1 - m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} - m_Intensity: 1 - m_Range: 10 - m_SpotAngle: 30 - m_CookieSize: 10 - m_Shadows: - m_Type: 2 - m_Resolution: -1 - m_Strength: 1 - m_Bias: 0.05 - m_NormalBias: 0.4 - m_NearPlane: 0.2 - m_Cookie: {fileID: 0} - m_DrawHalo: 0 - m_Flare: {fileID: 0} - m_RenderMode: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_Lightmapping: 4 - m_AreaSize: {x: 1, y: 1} - m_BounceIntensity: 1 - m_ShadowRadius: 0 - m_ShadowAngle: 0 ---- !u!4 &483826395 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 483826393} - m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} - m_LocalPosition: {x: 0, y: 3, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} ---- !u!1 &915832921 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 915832922} - m_Layer: 0 - m_Name: SpawnParent - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &915832922 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 915832921} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -0.5, z: 2} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 4 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1430003394 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 1430003398} - - 114: {fileID: 1430003397} - - 114: {fileID: 1430003396} - - 114: {fileID: 1430003395} - m_Layer: 0 - m_Name: Sharing - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1430003395 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1430003394} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 50ea9b56756ce4549ac9331b03af784f, type: 3} - m_Name: - m_EditorClassIdentifier: - spawnablePrefabs: - - DataModelClassName: SyncSpawnedObject - Prefab: {fileID: 1000011931115288, guid: 59101abe6f9a51149a4c07b3ea154698, type: 2} - - DataModelClassName: SyncSpawnTestSphere - Prefab: {fileID: 1000010858728632, guid: 68e704edde712c343a99b7c9c0ec7ba5, type: 2} ---- !u!114 &1430003396 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1430003394} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 8fa5da1314a4aa745a5be3f0f6ab6bd6, type: 3} - m_Name: - m_EditorClassIdentifier: - SessionName: Default ---- !u!114 &1430003397 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1430003394} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9af4ac91e9017f34c971bbf5e12948d3, type: 3} - m_Name: - m_EditorClassIdentifier: - ClientRole: 0 - ServerAddress: localhost - ServerPort: 20602 - connectOnAwake: 1 - IsAudioEndpoint: 0 ---- !u!4 &1430003398 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1430003394} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -0.5, z: 2} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1935067747 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 1935067749} - - 114: {fileID: 1935067748} - m_Layer: 0 - m_Name: ObjectSpawner - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1935067748 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1935067747} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 2922f398f96d5a841bf093ce0e760227, type: 3} - m_Name: - m_EditorClassIdentifier: - SpawnParent: {fileID: 915832921} - Prefab: {fileID: 1000011931115288, guid: 59101abe6f9a51149a4c07b3ea154698, type: 2} - SpawnManager: {fileID: 1430003395} ---- !u!4 &1935067749 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1935067747} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 3 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 7 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 7 + m_GIWorkflowMode: 1 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_TemporalCoherenceThreshold: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 1 + m_LightmapEditorSettings: + serializedVersion: 4 + m_Resolution: 2 + m_BakeResolution: 40 + m_TextureWidth: 1024 + m_TextureHeight: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_DirectLightInLightProbes: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_LightingDataAsset: {fileID: 0} + m_RuntimeCPUUsage: 25 +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + accuratePlacement: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &783891814 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 783891816} + - component: {fileID: 783891815} + m_Layer: 0 + m_Name: Directional light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &783891815 +Light: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 783891814} + m_Enabled: 1 + serializedVersion: 7 + m_Type: 1 + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_CookieSize: 10 + m_Shadows: + m_Type: 0 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_Lightmapping: 4 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &783891816 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 783891814} + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &915832921 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 915832922} + m_Layer: 0 + m_Name: SpawnParent + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &915832922 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 915832921} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: -0.5, z: 2} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1008446172 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + propertyPath: m_RootOrder + value: 3 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2} + m_IsPrefabParent: 0 +--- !u!1 &1430003394 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1430003398} + - component: {fileID: 1430003397} + - component: {fileID: 1430003396} + - component: {fileID: 1430003395} + m_Layer: 0 + m_Name: Sharing + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1430003395 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1430003394} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 50ea9b56756ce4549ac9331b03af784f, type: 3} + m_Name: + m_EditorClassIdentifier: + spawnablePrefabs: + - DataModelClassName: SyncSpawnedObject + Prefab: {fileID: 1000011931115288, guid: 59101abe6f9a51149a4c07b3ea154698, type: 2} + - DataModelClassName: SyncSpawnTestSphere + Prefab: {fileID: 1000010858728632, guid: 68e704edde712c343a99b7c9c0ec7ba5, type: 2} +--- !u!114 &1430003396 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1430003394} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8fa5da1314a4aa745a5be3f0f6ab6bd6, type: 3} + m_Name: + m_EditorClassIdentifier: + SessionName: Default +--- !u!114 &1430003397 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1430003394} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9af4ac91e9017f34c971bbf5e12948d3, type: 3} + m_Name: + m_EditorClassIdentifier: + ClientRole: 0 + ServerAddress: localhost + ServerPort: 20602 + connectOnAwake: 1 + AutoDiscoverServer: 0 + PingIntervalSec: 2 + IsAudioEndpoint: 0 +--- !u!4 &1430003398 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1430003394} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: -0.5, z: 2} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1935067747 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1935067749} + - component: {fileID: 1935067748} + m_Layer: 0 + m_Name: ObjectSpawner + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1935067748 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1935067747} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2922f398f96d5a841bf093ce0e760227, type: 3} + m_Name: + m_EditorClassIdentifier: + SpawnParent: {fileID: 915832921} + Prefab: {fileID: 1000011931115288, guid: 59101abe6f9a51149a4c07b3ea154698, type: 2} + SpawnManager: {fileID: 1430003395} +--- !u!4 &1935067749 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1935067747} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SharingSpawnTest.unity.meta b/Assets/HoloToolkit/Sharing/Tests/Scenes/SharingSpawnTest.unity.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest/SharingSpawnTest.unity.meta rename to Assets/HoloToolkit/Sharing/Tests/Scenes/SharingSpawnTest.unity.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/Sharing.unity b/Assets/HoloToolkit/Sharing/Tests/Scenes/SharingTest.unity similarity index 87% rename from Assets/HoloToolkit/Sharing/Tests/Sharing.unity rename to Assets/HoloToolkit/Sharing/Tests/Scenes/SharingTest.unity index a4e6daac861..5d18b28bab8 100644 --- a/Assets/HoloToolkit/Sharing/Tests/Sharing.unity +++ b/Assets/HoloToolkit/Sharing/Tests/Scenes/SharingTest.unity @@ -1,15 +1,15 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: --- !u!29 &1 -SceneSettings: +OcclusionCullingSettings: m_ObjectHideFlags: 0 - m_PVSData: - m_PVSObjectsArray: [] - m_PVSPortalsArray: [] + serializedVersion: 2 m_OcclusionBakeSettings: smallestOccluder: 5 smallestHole: 0.25 backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} --- !u!104 &2 RenderSettings: m_ObjectHideFlags: 0 @@ -79,16 +79,17 @@ NavMeshSettings: m_ObjectHideFlags: 0 m_BuildSettings: serializedVersion: 2 + agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 agentSlope: 45 agentClimb: 0.4 ledgeDropHeight: 0 maxJumpAcrossDistance: 0 - accuratePlacement: 0 minRegionArea: 2 - cellSize: 0.16666667 manualCellSize: 0 + cellSize: 0.16666667 + accuratePlacement: 0 m_NavMeshData: {fileID: 0} --- !u!1001 &64118911 Prefab: @@ -137,10 +138,10 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 543313555} - - 108: {fileID: 543313554} + - component: {fileID: 543313555} + - component: {fileID: 543313554} m_Layer: 0 m_Name: Directional Light m_TagString: Untagged @@ -191,21 +192,21 @@ Transform: m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} m_LocalPosition: {x: 0, y: 3, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &685058484 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 685058485} - - 33: {fileID: 685058488} - - 135: {fileID: 685058487} - - 23: {fileID: 685058486} + - component: {fileID: 685058485} + - component: {fileID: 685058488} + - component: {fileID: 685058487} + - component: {fileID: 685058486} m_Layer: 0 m_Name: Sphere m_TagString: Untagged @@ -222,10 +223,10 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.2, y: 0.2, z: 0.2} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 942915100} m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!23 &685058486 MeshRenderer: m_ObjectHideFlags: 0 @@ -240,7 +241,9 @@ MeshRenderer: m_ReflectionProbeUsage: 1 m_Materials: - {fileID: 2100000, guid: 474f0e0481d4aa14e92a5ada98042f3a, type: 2} - m_SubsetIndices: + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 m_StaticBatchRoot: {fileID: 0} m_ProbeAnchor: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0} @@ -248,7 +251,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 - m_SelectedWireframeHidden: 0 + m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 @@ -279,11 +282,11 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 942915100} - - 114: {fileID: 942915102} - - 114: {fileID: 942915101} + - component: {fileID: 942915100} + - component: {fileID: 942915102} + - component: {fileID: 942915101} m_Layer: 0 m_Name: HologramCollection m_TagString: Untagged @@ -300,11 +303,11 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 2} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: - {fileID: 685058485} m_Father: {fileID: 0} m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &942915101 MonoBehaviour: m_ObjectHideFlags: 0 @@ -368,32 +371,6 @@ Prefab: propertyPath: m_RootOrder value: 1 objectReference: {fileID: 0} - - target: {fileID: 114000012667812730, guid: 8aaf37823b26ee449bb3b3d7775965c3, - type: 2} - propertyPath: ServerAddress - value: 10.124.150.60 - objectReference: {fileID: 0} - - target: {fileID: 114000012667812730, guid: 8aaf37823b26ee449bb3b3d7775965c3, - type: 2} - propertyPath: IsAudioEndpoint - value: 1 - objectReference: {fileID: 0} - m_RemovedComponents: - - {fileID: 114000011012997360, guid: 8aaf37823b26ee449bb3b3d7775965c3, type: 2} + m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 8aaf37823b26ee449bb3b3d7775965c3, type: 2} m_IsPrefabParent: 0 ---- !u!1 &1703234100 stripped -GameObject: - m_PrefabParentObject: {fileID: 163528, guid: 8aaf37823b26ee449bb3b3d7775965c3, type: 2} - m_PrefabInternal: {fileID: 1703234099} ---- !u!114 &1703234101 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1703234100} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c7a63ef1b98adec49bdb80fe1f187893, type: 3} - m_Name: - m_EditorClassIdentifier: diff --git a/Assets/HoloToolkit/Sharing/Tests/Sharing.unity.meta b/Assets/HoloToolkit/Sharing/Tests/Scenes/SharingTest.unity.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/Sharing.unity.meta rename to Assets/HoloToolkit/Sharing/Tests/Scenes/SharingTest.unity.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/Scripts.meta b/Assets/HoloToolkit/Sharing/Tests/Scripts.meta new file mode 100644 index 00000000000..4650d4a6bdc --- /dev/null +++ b/Assets/HoloToolkit/Sharing/Tests/Scripts.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: d16726a004b48074a958826a15c729a7 +folderAsset: yes +timeCreated: 1485717664 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HoloToolkit/Sharing/Tests/CustomMessages.cs b/Assets/HoloToolkit/Sharing/Tests/Scripts/CustomMessages.cs similarity index 80% rename from Assets/HoloToolkit/Sharing/Tests/CustomMessages.cs rename to Assets/HoloToolkit/Sharing/Tests/Scripts/CustomMessages.cs index 187f3714a35..bf308916e2a 100644 --- a/Assets/HoloToolkit/Sharing/Tests/CustomMessages.cs +++ b/Assets/HoloToolkit/Sharing/Tests/Scripts/CustomMessages.cs @@ -3,11 +3,10 @@ using System; using System.Collections.Generic; -using HoloToolkit.Sharing; using HoloToolkit.Unity; using UnityEngine; -namespace HoloToolkit.Sharing +namespace HoloToolkit.Sharing.Tests { public class CustomMessages : Singleton { @@ -24,24 +23,24 @@ public enum TestMessageID : byte public enum UserMessageChannels { - Anchors = MessageChannel.UserMessageChannelStart, + Anchors = MessageChannel.UserMessageChannelStart } /// /// Cache the local user's ID to use when sending messages /// - public long localUserID + public long LocalUserID { get; set; } public delegate void MessageCallback(NetworkInMessage msg); - private Dictionary _MessageHandlers = new Dictionary(); + private Dictionary messageHandlers = new Dictionary(); public Dictionary MessageHandlers { get { - return _MessageHandlers; + return messageHandlers; } } @@ -49,14 +48,14 @@ public long localUserID /// Helper object that we use to route incoming message callbacks to the member /// functions of this class /// - NetworkConnectionAdapter connectionAdapter; + private NetworkConnectionAdapter connectionAdapter; /// /// Cache the connection object for the sharing service /// - NetworkConnection serverConnection; + private NetworkConnection serverConnection; - void Start() + private void Start() { SharingStage.Instance.SharingManagerConnected += SharingManagerConnected; } @@ -66,7 +65,7 @@ private void SharingManagerConnected(object sender, EventArgs e) InitializeMessageHandlers(); } - void InitializeMessageHandlers() + private void InitializeMessageHandlers() { SharingStage sharingStage = SharingStage.Instance; @@ -87,7 +86,7 @@ void InitializeMessageHandlers() connectionAdapter.MessageReceivedCallback += OnMessageReceived; // Cache the local user ID - this.localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID(); + LocalUserID = SharingStage.Instance.Manager.GetLocalUser().GetID(); for (byte index = (byte)TestMessageID.HeadTransform; index < (byte)TestMessageID.Max; index++) { @@ -105,14 +104,14 @@ private NetworkOutMessage CreateMessage(byte messageType) NetworkOutMessage msg = serverConnection.CreateMessage(messageType); msg.Write(messageType); // Add the local userID so that the remote clients know whose message they are receiving - msg.Write(localUserID); + msg.Write(LocalUserID); return msg; } public void SendHeadTransform(Vector3 position, Quaternion rotation) { // If we are connected to a session, broadcast our head info - if (this.serverConnection != null && this.serverConnection.IsConnected()) + if (serverConnection != null && serverConnection.IsConnected()) { // Create an outgoing network message to contain all the info we want to send NetworkOutMessage msg = CreateMessage((byte)TestMessageID.HeadTransform); @@ -120,7 +119,7 @@ public void SendHeadTransform(Vector3 position, Quaternion rotation) AppendTransform(msg, position, rotation); // Send the message as a broadcast, which will cause the server to forward it to all other users in the session. - this.serverConnection.Broadcast( + serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, @@ -132,17 +131,17 @@ protected override void OnDestroy() { base.OnDestroy(); - if (this.serverConnection != null) + if (serverConnection != null) { for (byte index = (byte)TestMessageID.HeadTransform; index < (byte)TestMessageID.Max; index++) { - this.serverConnection.RemoveListener(index, this.connectionAdapter); + serverConnection.RemoveListener(index, connectionAdapter); } - this.connectionAdapter.MessageReceivedCallback -= OnMessageReceived; + connectionAdapter.MessageReceivedCallback -= OnMessageReceived; } } - void OnMessageReceived(NetworkConnection connection, NetworkInMessage msg) + private void OnMessageReceived(NetworkConnection connection, NetworkInMessage msg) { byte messageType = msg.ReadByte(); MessageCallback messageHandler = MessageHandlers[(TestMessageID)messageType]; @@ -154,20 +153,20 @@ void OnMessageReceived(NetworkConnection connection, NetworkInMessage msg) #region HelperFunctionsForWriting - void AppendTransform(NetworkOutMessage msg, Vector3 position, Quaternion rotation) + private void AppendTransform(NetworkOutMessage msg, Vector3 position, Quaternion rotation) { AppendVector3(msg, position); AppendQuaternion(msg, rotation); } - void AppendVector3(NetworkOutMessage msg, Vector3 vector) + private void AppendVector3(NetworkOutMessage msg, Vector3 vector) { msg.Write(vector.x); msg.Write(vector.y); msg.Write(vector.z); } - void AppendQuaternion(NetworkOutMessage msg, Quaternion rotation) + private void AppendQuaternion(NetworkOutMessage msg, Quaternion rotation) { msg.Write(rotation.x); msg.Write(rotation.y); diff --git a/Assets/HoloToolkit/Sharing/Tests/CustomMessages.cs.meta b/Assets/HoloToolkit/Sharing/Tests/Scripts/CustomMessages.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/CustomMessages.cs.meta rename to Assets/HoloToolkit/Sharing/Tests/Scripts/CustomMessages.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/ImportExportAnchorManager.cs b/Assets/HoloToolkit/Sharing/Tests/Scripts/ImportExportAnchorManager.cs similarity index 97% rename from Assets/HoloToolkit/Sharing/Tests/ImportExportAnchorManager.cs rename to Assets/HoloToolkit/Sharing/Tests/Scripts/ImportExportAnchorManager.cs index fa1e77c084d..cc09a8362f5 100644 --- a/Assets/HoloToolkit/Sharing/Tests/ImportExportAnchorManager.cs +++ b/Assets/HoloToolkit/Sharing/Tests/Scripts/ImportExportAnchorManager.cs @@ -1,16 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using HoloToolkit.Sharing; -using HoloToolkit.Unity; using System; using System.Collections.Generic; +using HoloToolkit.Unity; using UnityEngine; using UnityEngine.VR.WSA; using UnityEngine.VR.WSA.Persistence; using UnityEngine.VR.WSA.Sharing; -namespace HoloToolkit.Sharing +namespace HoloToolkit.Sharing.Tests { /// /// Manages creating anchors and sharing the anchors with other clients. @@ -88,7 +87,7 @@ public long RoomID /// /// Indicates if the room should kept around even after all users leave /// - public bool KeepRoomAlive = false; + public bool KeepRoomAlive; /// /// Cached point to the sharing stage. @@ -108,17 +107,17 @@ public long RoomID /// /// Keeps track of stored anchor data blob. /// - private byte[] rawAnchorData = null; + private byte[] rawAnchorData; /// /// Keeps track of locally stored anchors. /// - private WorldAnchorStore anchorStore = null; + private WorldAnchorStore anchorStore; /// /// Keeps track of the name of the anchor we are exporting. /// - private string exportingAnchorName { get; set; } + private string exportingAnchorName; /// /// The datablob of the anchor. @@ -130,7 +129,7 @@ public long RoomID /// We need the sharing service to be ready so we can /// upload and download data for sharing anchors. /// - private bool sharingServiceReady = false; + private bool sharingServiceReady; /// /// The room manager API for the sharing service. @@ -147,7 +146,7 @@ public long RoomID /// Sometimes we'll see a really small anchor blob get generated. /// These tend to not work, so we have a minimum trustable size. /// - private const uint minTrustworthySerializedAnchorDataSize = 100000; + private const uint MinTrustworthySerializedAnchorDataSize = 100000; /// /// Some room ID for indicating which room we are in. @@ -246,7 +245,7 @@ private void RoomManagerCallbacks_AnchorsDownloaded(bool successful, AnchorDownl if (successful) { int datasize = request.GetDataSize(); - Debug.Log(datasize + " bytes "); + Debug.Log(datasize.ToString() + " bytes "); rawAnchorData = new byte[datasize]; request.GetData(rawAnchorData, datasize); @@ -411,7 +410,7 @@ private void StartAnchorProcess() // First, are there any anchors in this room? int anchorCount = currentRoom.GetAnchorCount(); - Debug.Log(anchorCount + " anchors"); + Debug.Log(anchorCount.ToString() + " anchors"); // If there are anchors, we should attach to the first one. if (anchorCount > 0) @@ -555,7 +554,7 @@ private bool AttachToCachedAnchor(string anchorName) /// private void ImportExportAnchorManager_OnTrackingChanged_Attaching(WorldAnchor self, bool located) { - Debug.Log("anchor " + located); + Debug.Log("anchor " + located.ToString()); if (located) { AnchorLoadComplete(); @@ -652,7 +651,7 @@ public void WriteBuffer(byte[] data) /// public void ExportComplete(SerializationCompletionReason status) { - if (status == SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > minTrustworthySerializedAnchorDataSize) + if (status == SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > MinTrustworthySerializedAnchorDataSize) { Debug.Log("Uploading anchor: " + exportingAnchorName); roomManager.UploadAnchor( diff --git a/Assets/HoloToolkit/Sharing/Tests/ImportExportAnchorManager.cs.meta b/Assets/HoloToolkit/Sharing/Tests/Scripts/ImportExportAnchorManager.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/ImportExportAnchorManager.cs.meta rename to Assets/HoloToolkit/Sharing/Tests/Scripts/ImportExportAnchorManager.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/RemoteHeadManager.cs b/Assets/HoloToolkit/Sharing/Tests/Scripts/RemoteHeadManager.cs similarity index 82% rename from Assets/HoloToolkit/Sharing/Tests/RemoteHeadManager.cs rename to Assets/HoloToolkit/Sharing/Tests/Scripts/RemoteHeadManager.cs index e028453f888..6e575debed4 100644 --- a/Assets/HoloToolkit/Sharing/Tests/RemoteHeadManager.cs +++ b/Assets/HoloToolkit/Sharing/Tests/Scripts/RemoteHeadManager.cs @@ -1,12 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using HoloToolkit.Unity; -using HoloToolkit.Sharing; using System.Collections.Generic; using UnityEngine; +using HoloToolkit.Unity; -namespace HoloToolkit.Sharing +namespace HoloToolkit.Sharing.Tests { /// /// Broadcasts the head transform of the local user to other users in the session, @@ -25,11 +24,11 @@ public class RemoteHeadInfo /// /// Keep a list of the remote heads, indexed by XTools userID /// - Dictionary remoteHeads = new Dictionary(); + private Dictionary remoteHeads = new Dictionary(); private void Start() { - CustomMessages.Instance.MessageHandlers[CustomMessages.TestMessageID.HeadTransform] = this.UpdateHeadTransform; + CustomMessages.Instance.MessageHandlers[CustomMessages.TestMessageID.HeadTransform] = UpdateHeadTransform; SharingStage.Instance.SessionUsersTracker.UserJoined += UserJoinedSession; SharingStage.Instance.SessionUsersTracker.UserLeft += UserLeftSession; @@ -41,8 +40,8 @@ private void Update() Transform headTransform = Camera.main.transform; // Transform the head position and rotation from world space into local space - Vector3 headPosition = this.transform.InverseTransformPoint(headTransform.position); - Quaternion headRotation = Quaternion.Inverse(this.transform.rotation) * headTransform.rotation; + Vector3 headPosition = transform.InverseTransformPoint(headTransform.position); + Quaternion headRotation = Quaternion.Inverse(transform.rotation) * headTransform.rotation; CustomMessages.Instance.SendHeadTransform(headPosition, headRotation); } @@ -56,8 +55,8 @@ private void UserLeftSession(User user) int userId = user.GetID(); if (userId != SharingStage.Instance.Manager.GetLocalUser().GetID()) { - RemoveRemoteHead(this.remoteHeads[userId].HeadObject); - this.remoteHeads.Remove(userId); + RemoveRemoteHead(remoteHeads[userId].HeadObject); + remoteHeads.Remove(userId); } } @@ -83,13 +82,13 @@ public RemoteHeadInfo GetRemoteHeadInfo(long userId) RemoteHeadInfo headInfo; // Get the head info if its already in the list, otherwise add it - if (!this.remoteHeads.TryGetValue(userId, out headInfo)) + if (!remoteHeads.TryGetValue(userId, out headInfo)) { headInfo = new RemoteHeadInfo(); headInfo.UserID = userId; headInfo.HeadObject = CreateRemoteHead(); - this.remoteHeads.Add(userId, headInfo); + remoteHeads.Add(userId, headInfo); } return headInfo; @@ -99,7 +98,7 @@ public RemoteHeadInfo GetRemoteHeadInfo(long userId) /// Called when a remote user sends a head transform. /// /// - void UpdateHeadTransform(NetworkInMessage msg) + private void UpdateHeadTransform(NetworkInMessage msg) { // Parse the message long userID = msg.ReadInt64(); @@ -117,10 +116,10 @@ void UpdateHeadTransform(NetworkInMessage msg) /// Creates a new game object to represent the user's head. /// /// - GameObject CreateRemoteHead() + private GameObject CreateRemoteHead() { GameObject newHeadObj = GameObject.CreatePrimitive(PrimitiveType.Cube); - newHeadObj.transform.parent = this.gameObject.transform; + newHeadObj.transform.parent = gameObject.transform; newHeadObj.transform.localScale = Vector3.one * 0.2f; return newHeadObj; } @@ -130,7 +129,7 @@ GameObject CreateRemoteHead() /// head data. /// /// - void RemoveRemoteHead(GameObject remoteHeadObject) + private void RemoveRemoteHead(GameObject remoteHeadObject) { DestroyImmediate(remoteHeadObject); } diff --git a/Assets/HoloToolkit/Sharing/Tests/RemoteHeadManager.cs.meta b/Assets/HoloToolkit/Sharing/Tests/Scripts/RemoteHeadManager.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/RemoteHeadManager.cs.meta rename to Assets/HoloToolkit/Sharing/Tests/Scripts/RemoteHeadManager.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/Scripts/RoomTest.cs b/Assets/HoloToolkit/Sharing/Tests/Scripts/RoomTest.cs new file mode 100644 index 00000000000..2bd32c9cbed --- /dev/null +++ b/Assets/HoloToolkit/Sharing/Tests/Scripts/RoomTest.cs @@ -0,0 +1,237 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; +using Random = System.Random; + +namespace HoloToolkit.Sharing.Tests +{ + public class RoomTest : MonoBehaviour + { + private RoomManagerAdapter listener; + private RoomManager roomMgr; + + private string roomName = "New Room"; + private Vector2 scrollViewVector = Vector2.zero; + private int padding = 4; + private int areaWidth = 400; + private int areaHeight = 300; + private int buttonWidth = 80; + private int lineHeight = 20; + + private Vector2 anchorScrollVector = Vector2.zero; + private string anchorName = "New Anchor"; + private readonly byte[] anchorTestData = new byte[5 * 1024 * 1024]; // 5 meg test buffer + + private void Start() + { + for (int i = 0; i < anchorTestData.Length; ++i) + { + anchorTestData[i] = (byte)(i % 256); + } + + SharingStage stage = SharingStage.Instance; + if (stage != null) + { + SharingManager sharingMgr = stage.Manager; + if (sharingMgr != null) + { + roomMgr = sharingMgr.GetRoomManager(); + + listener = new RoomManagerAdapter(); + listener.RoomAddedEvent += OnRoomAdded; + listener.RoomClosedEvent += OnRoomClosed; + listener.UserJoinedRoomEvent += OnUserJoinedRoom; + listener.UserLeftRoomEvent += OnUserLeftRoom; + listener.AnchorsChangedEvent += OnAnchorsChanged; + listener.AnchorsDownloadedEvent += OnAnchorsDownloaded; + listener.AnchorUploadedEvent += OnAnchorUploadComplete; + + roomMgr.AddListener(listener); + } + } + } + + private void OnDestroy() + { + roomMgr.RemoveListener(listener); + listener.Dispose(); + } + + private void OnGUI() + { + // Make a background box + scrollViewVector = GUI.BeginScrollView(new Rect(25, 25, areaWidth, areaHeight), scrollViewVector, + new Rect(0, 0, areaWidth, areaHeight)); + + if (roomMgr != null) + { + SessionManager sessionMgr = SharingStage.Instance.Manager.GetSessionManager(); + if (sessionMgr != null) + { + roomName = + GUI.TextField( + new Rect(buttonWidth + padding, 0, areaWidth - (buttonWidth + padding), lineHeight), + roomName); + + if (GUI.Button(new Rect(0, 0, buttonWidth, lineHeight), "Create")) + { + Random rnd = new Random(); + + Room newRoom = roomMgr.CreateRoom(roomName, rnd.Next(), false); + if (newRoom == null) + { + Debug.LogWarning("Cannot create room"); + } + } + + Room currentRoom = roomMgr.GetCurrentRoom(); + + for (int i = 0; i < roomMgr.GetRoomCount(); ++i) + { + Room r = roomMgr.GetRoom(i); + + int vOffset = (padding + lineHeight) * (i + 1); + int hOffset = 0; + + bool keepOpen = GUI.Toggle(new Rect(hOffset, vOffset, lineHeight, lineHeight), r.GetKeepOpen(), ""); + r.SetKeepOpen(keepOpen); + + hOffset += lineHeight + padding; + + if (currentRoom != null && r.GetID() == currentRoom.GetID()) + { + if (GUI.Button(new Rect(hOffset, vOffset, buttonWidth, lineHeight), "Leave")) + { + roomMgr.LeaveRoom(); + } + } + else + { + if (GUI.Button(new Rect(hOffset, vOffset, buttonWidth, lineHeight), "Join")) + { + if (!roomMgr.JoinRoom(r)) + { + Debug.LogWarning("Cannot join room"); + } + } + } + + hOffset += buttonWidth + padding; + + GUI.Label(new Rect(hOffset, vOffset, areaWidth - (buttonWidth + padding), lineHeight), + r.GetName().GetString()); + } + } + } + + // End the ScrollView + GUI.EndScrollView(); + + if (roomMgr != null) + { + Room currentRoom = roomMgr.GetCurrentRoom(); + + if (currentRoom != null) + { + // Display option to upload anchor + anchorScrollVector = GUI.BeginScrollView( + new Rect(areaWidth + 50, 25, areaWidth, areaHeight), + anchorScrollVector, + new Rect(0, 0, areaWidth, areaHeight)); + + anchorName = + GUI.TextField( + new Rect( + buttonWidth + padding, + 0, + areaWidth - (buttonWidth + padding), + lineHeight), + anchorName); + + if (GUI.Button(new Rect(0, 0, buttonWidth, lineHeight), "Create")) + { + if (!roomMgr.UploadAnchor(currentRoom, anchorName, anchorTestData, anchorTestData.Length)) + { + Debug.LogError("Failed to start anchor upload"); + } + } + + for (int i = 0; i < currentRoom.GetAnchorCount(); ++i) + { + int vOffset = (padding + lineHeight) * (i + 1); + + XString currentRoomAnchor = currentRoom.GetAnchorName(i); + + GUI.Label( + new Rect( + buttonWidth + padding, + vOffset, + areaWidth - (buttonWidth + padding), + lineHeight), + currentRoomAnchor); + + if (GUI.Button(new Rect(0, vOffset, buttonWidth, lineHeight), "Download")) + { + if (!roomMgr.DownloadAnchor(currentRoom, currentRoomAnchor)) + { + Debug.LogWarning("Failed to start anchor download"); + } + } + } + + GUI.EndScrollView(); + } + } + } + + private void OnRoomAdded(Room newRoom) + { + Debug.LogFormat("Room {0} added", newRoom.GetName().GetString()); + } + + private void OnRoomClosed(Room room) + { + Debug.LogFormat("Room {0} closed", room.GetName().GetString()); + } + + private void OnUserJoinedRoom(Room room, int user) + { + Debug.LogFormat("User {0} joined Room {1}", user.ToString(), room.GetName().GetString()); + } + + private void OnUserLeftRoom(Room room, int user) + { + Debug.LogFormat("User {0} left Room {1}", user.ToString(), room.GetName().GetString()); + } + + private void OnAnchorsChanged(Room room) + { + Debug.LogFormat("Anchors changed for Room {0}", room.GetName().GetString()); + } + + private void OnAnchorsDownloaded(bool successful, AnchorDownloadRequest request, XString failureReason) + { + if (successful) + { + Debug.LogFormat("Anchors download succeeded for Room {0}", request.GetRoom().GetName().GetString()); + } + else + { + Debug.LogFormat("Anchors download failed: {0}", failureReason.GetString()); + } + } + + private void OnAnchorUploadComplete(bool successful, XString failureReason) + { + if (successful) + { + Debug.Log("Anchors upload succeeded"); + } + else + { + Debug.LogFormat("Anchors upload failed: {0}", failureReason.GetString()); + } + } + } +} diff --git a/Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomTest.cs.meta b/Assets/HoloToolkit/Sharing/Tests/Scripts/RoomTest.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/RoomTest/RoomTest.cs.meta rename to Assets/HoloToolkit/Sharing/Tests/Scripts/RoomTest.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/Scripts/SpawnTestKeyboardSpawning.cs b/Assets/HoloToolkit/Sharing/Tests/Scripts/SpawnTestKeyboardSpawning.cs new file mode 100644 index 00000000000..ebf1595aea2 --- /dev/null +++ b/Assets/HoloToolkit/Sharing/Tests/Scripts/SpawnTestKeyboardSpawning.cs @@ -0,0 +1,48 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +// + +using UnityEngine; +using HoloToolkit.Sharing.Spawning; + +namespace HoloToolkit.Sharing.Tests +{ + /// + /// Class that handles spawning objects on keyboard presses, for the spawning test scene of + /// the HoloToolkit's Sharing component. + /// + public class SpawnTestKeyboardSpawning : MonoBehaviour + { + public GameObject SpawnParent; + public GameObject Prefab; + + public PrefabSpawnManager SpawnManager; + + private void Update() + { + // Spawn a basic spawned object when I is pressed + if (Input.GetKeyDown(KeyCode.I)) + { + Vector3 position = Random.onUnitSphere * 2; + Quaternion rotation = Random.rotation; + + SyncSpawnedObject spawnedObject = new SyncSpawnedObject(); + + SpawnManager.Spawn(spawnedObject, position, rotation, SpawnParent, "SpawnedObject", false); + } + + // Spawn a test sphere when O is pressed + if (Input.GetKeyDown(KeyCode.O)) + { + Vector3 position = Random.onUnitSphere * 2; + Quaternion rotation = Random.rotation; + + SyncSpawnTestSphere spawnedObject = new SyncSpawnTestSphere(); + spawnedObject.TestFloat.Value = Random.Range(0f, 100f); + + SpawnManager.Spawn(spawnedObject, position, rotation, SpawnParent, "SpawnTestSphere", false); + } + } + } +} diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestKeyboardSpawning.cs.meta b/Assets/HoloToolkit/Sharing/Tests/Scripts/SpawnTestKeyboardSpawning.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestKeyboardSpawning.cs.meta rename to Assets/HoloToolkit/Sharing/Tests/Scripts/SpawnTestKeyboardSpawning.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SyncSpawnTestSphere.cs b/Assets/HoloToolkit/Sharing/Tests/Scripts/SyncSpawnTestSphere.cs similarity index 82% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest/SyncSpawnTestSphere.cs rename to Assets/HoloToolkit/Sharing/Tests/Scripts/SyncSpawnTestSphere.cs index af5bac34a29..314663c15ef 100644 --- a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SyncSpawnTestSphere.cs +++ b/Assets/HoloToolkit/Sharing/Tests/Scripts/SyncSpawnTestSphere.cs @@ -4,8 +4,9 @@ // using HoloToolkit.Sharing.Spawning; +using HoloToolkit.Sharing.SyncModel; -namespace HoloToolkit.Sharing.SyncModel +namespace HoloToolkit.Sharing.Tests { [SyncDataClass] public class SyncSpawnTestSphere : SyncSpawnedObject @@ -14,3 +15,4 @@ public class SyncSpawnTestSphere : SyncSpawnedObject public SyncFloat TestFloat; } } + diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SyncSpawnTestSphere.cs.meta b/Assets/HoloToolkit/Sharing/Tests/Scripts/SyncSpawnTestSphere.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Tests/SpawnTest/SyncSpawnTestSphere.cs.meta rename to Assets/HoloToolkit/Sharing/Tests/Scripts/SyncSpawnTestSphere.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestKeyboardSpawning.cs b/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestKeyboardSpawning.cs deleted file mode 100644 index 91a8392354c..00000000000 --- a/Assets/HoloToolkit/Sharing/Tests/SpawnTest/SpawnTestKeyboardSpawning.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. -// - -using HoloToolkit.Sharing.SyncModel; -using HoloToolkit.Sharing.Spawning; -using UnityEngine; - -/// -/// Class that handles spawning objects on keyboard presses, for the spawning test scene of -/// the HoloToolkit's Sharing component. -/// -public class SpawnTestKeyboardSpawning : MonoBehaviour -{ - public GameObject SpawnParent; - public GameObject Prefab; - - public PrefabSpawnManager SpawnManager; - - private void Update() - { - // Spawn a basic spawned object when I is pressed - if (Input.GetKeyDown(KeyCode.I)) - { - Vector3 position = Random.onUnitSphere * 2; - Quaternion rotation = Random.rotation; - - SyncSpawnedObject spawnedObject = new SyncSpawnedObject(); - - SpawnManager.Spawn(spawnedObject, position, rotation, SpawnParent, "SpawnedObject", false); - } - - // Spawn a test sphere when O is pressed - if (Input.GetKeyDown(KeyCode.O)) - { - Vector3 position = Random.onUnitSphere * 2; - Quaternion rotation = Random.rotation; - - SyncSpawnTestSphere spawnedObject = new SyncSpawnTestSphere(); - spawnedObject.TestFloat.Value = Random.Range(0f, 100f); - - SpawnManager.Spawn(spawnedObject, position, rotation, SpawnParent, "SpawnTestSphere", false); - } - } -} diff --git a/Assets/HoloToolkit/Utilities/Editor.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor.meta diff --git a/Assets/HoloToolkit/Utilities/Editor/AutoConfigureMenu.cs b/Assets/HoloToolkit/Utilities/Scripts/Editor/AutoConfigureMenu.cs similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/AutoConfigureMenu.cs rename to Assets/HoloToolkit/Utilities/Scripts/Editor/AutoConfigureMenu.cs diff --git a/Assets/HoloToolkit/Utilities/Editor/AutoConfigureMenu.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor/AutoConfigureMenu.cs.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/AutoConfigureMenu.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor/AutoConfigureMenu.cs.meta diff --git a/Assets/HoloToolkit/Utilities/Editor/AutoConfigureWindow.cs b/Assets/HoloToolkit/Utilities/Scripts/Editor/AutoConfigureWindow.cs similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/AutoConfigureWindow.cs rename to Assets/HoloToolkit/Utilities/Scripts/Editor/AutoConfigureWindow.cs diff --git a/Assets/HoloToolkit/Utilities/Editor/AutoConfigureWindow.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor/AutoConfigureWindow.cs.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/AutoConfigureWindow.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor/AutoConfigureWindow.cs.meta diff --git a/Assets/HoloToolkit/Utilities/Editor/CapabilitySettingsWindow.cs b/Assets/HoloToolkit/Utilities/Scripts/Editor/CapabilitySettingsWindow.cs similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/CapabilitySettingsWindow.cs rename to Assets/HoloToolkit/Utilities/Scripts/Editor/CapabilitySettingsWindow.cs diff --git a/Assets/HoloToolkit/Utilities/Editor/CapabilitySettingsWindow.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor/CapabilitySettingsWindow.cs.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/CapabilitySettingsWindow.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor/CapabilitySettingsWindow.cs.meta diff --git a/Assets/HoloToolkit/Utilities/Editor/EditorGUIExtensions.cs b/Assets/HoloToolkit/Utilities/Scripts/Editor/EditorGUIExtensions.cs similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/EditorGUIExtensions.cs rename to Assets/HoloToolkit/Utilities/Scripts/Editor/EditorGUIExtensions.cs diff --git a/Assets/HoloToolkit/Utilities/Editor/EditorGUIExtensions.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor/EditorGUIExtensions.cs.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/EditorGUIExtensions.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor/EditorGUIExtensions.cs.meta diff --git a/Assets/HoloToolkit/Utilities/Editor/EditorGUILayoutExtensions.cs b/Assets/HoloToolkit/Utilities/Scripts/Editor/EditorGUILayoutExtensions.cs similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/EditorGUILayoutExtensions.cs rename to Assets/HoloToolkit/Utilities/Scripts/Editor/EditorGUILayoutExtensions.cs diff --git a/Assets/HoloToolkit/Utilities/Editor/EditorGUILayoutExtensions.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor/EditorGUILayoutExtensions.cs.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/EditorGUILayoutExtensions.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor/EditorGUILayoutExtensions.cs.meta diff --git a/Assets/HoloToolkit/Utilities/Editor/EnforceEditorSettings.cs b/Assets/HoloToolkit/Utilities/Scripts/Editor/EnforceEditorSettings.cs similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/EnforceEditorSettings.cs rename to Assets/HoloToolkit/Utilities/Scripts/Editor/EnforceEditorSettings.cs diff --git a/Assets/HoloToolkit/Utilities/Editor/EnforceEditorSettings.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor/EnforceEditorSettings.cs.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/EnforceEditorSettings.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor/EnforceEditorSettings.cs.meta diff --git a/Assets/HoloToolkit/Utilities/Editor/LayerMaskExtensions.cs b/Assets/HoloToolkit/Utilities/Scripts/Editor/LayerMaskExtensions.cs similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/LayerMaskExtensions.cs rename to Assets/HoloToolkit/Utilities/Scripts/Editor/LayerMaskExtensions.cs diff --git a/Assets/HoloToolkit/Utilities/Editor/LayerMaskExtensions.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor/LayerMaskExtensions.cs.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/LayerMaskExtensions.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor/LayerMaskExtensions.cs.meta diff --git a/Assets/HoloToolkit/Utilities/Editor/ProjectSettingsWindow.cs b/Assets/HoloToolkit/Utilities/Scripts/Editor/ProjectSettingsWindow.cs similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/ProjectSettingsWindow.cs rename to Assets/HoloToolkit/Utilities/Scripts/Editor/ProjectSettingsWindow.cs diff --git a/Assets/HoloToolkit/Utilities/Editor/ProjectSettingsWindow.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor/ProjectSettingsWindow.cs.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/ProjectSettingsWindow.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor/ProjectSettingsWindow.cs.meta diff --git a/Assets/HoloToolkit/Utilities/Editor/SceneSettingsWindow.cs b/Assets/HoloToolkit/Utilities/Scripts/Editor/SceneSettingsWindow.cs similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/SceneSettingsWindow.cs rename to Assets/HoloToolkit/Utilities/Scripts/Editor/SceneSettingsWindow.cs diff --git a/Assets/HoloToolkit/Utilities/Editor/SceneSettingsWindow.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Editor/SceneSettingsWindow.cs.meta similarity index 100% rename from Assets/HoloToolkit/Utilities/Editor/SceneSettingsWindow.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Editor/SceneSettingsWindow.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/ExternalProcess.cs b/Assets/HoloToolkit/Utilities/Scripts/ExternalProcess.cs similarity index 87% rename from Assets/HoloToolkit/Sharing/Scripts/Utilities/ExternalProcess.cs rename to Assets/HoloToolkit/Utilities/Scripts/ExternalProcess.cs index 2ea514e7ab4..8b0d452e426 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Utilities/ExternalProcess.cs +++ b/Assets/HoloToolkit/Utilities/Scripts/ExternalProcess.cs @@ -9,7 +9,7 @@ using System.Threading; using UnityEngine; -namespace HoloToolkit.Sharing.Utilities +namespace HoloToolkit.Utilities { public class ExternalProcess : IDisposable { @@ -26,7 +26,7 @@ public class ExternalProcess : IDisposable [DllImport("ExternalProcessAPI", CallingConvention = CallingConvention.Cdecl)] public static extern void ExternalProcessAPI_ConfirmOrBeginProcess([MarshalAs(UnmanagedType.LPStr)] string processName); - private IntPtr mHandle = IntPtr.Zero; + private IntPtr mHandle; /* * First some static utility functions, used by some other code as well. @@ -34,7 +34,7 @@ public class ExternalProcess : IDisposable */ private static string sAppDataPath; - static public void Launch(string appName) + public static void Launch(string appName) { // Full or relative paths only. Currently unused. @@ -52,7 +52,7 @@ static public void Launch(string appName) pr.Start(); } - static private string AppDataPath + private static string AppDataPath { get { @@ -65,12 +65,12 @@ static private string AppDataPath } } - static public bool FindAndLaunch(string appName) + public static bool FindAndLaunch(string appName) { return FindAndLaunch(appName, null); } - static public bool FindAndLaunch(string appName, string args) + public static bool FindAndLaunch(string appName, string args) { // Start at working directory, append appName (should read "appRelativePath"), see if it exists. // If not go up to parent and try again till drive level reached. @@ -91,7 +91,7 @@ static public bool FindAndLaunch(string appName, string args) return pr.Start(); } - static public string FindPathToExecutable(string appName) + public static string FindPathToExecutable(string appName) { // Start at working directory, append appName (should read "appRelativePath"), see if it exists. // If not go up to parent and try again till drive level reached. @@ -118,7 +118,7 @@ static public string FindPathToExecutable(string appName) return null; } - static public string MakeRelativePath(string path1, string path2) + public static string MakeRelativePath(string path1, string path2) { // TBD- doesn't really belong in ExternalProcess. @@ -136,12 +136,12 @@ static public string MakeRelativePath(string path1, string path2) /* * The actual ExternalProcess class. */ - static public ExternalProcess CreateExternalProcess(string appName) + public static ExternalProcess CreateExternalProcess(string appName) { return CreateExternalProcess(appName, null); } - static public ExternalProcess CreateExternalProcess(string appName, string args) + public static ExternalProcess CreateExternalProcess(string appName, string args) { // Seems like it would be safer and more informative to call this static method and test for null after. try @@ -170,13 +170,13 @@ private ExternalProcess(string appName, string args) } // This may throw, calling code should catch the exception. - string launchString = (args == null) ? appPath : appPath + " " + args; + string launchString = args == null ? appPath : appPath + " " + args; mHandle = ExternalProcessAPI_CreateProcess(launchString); } ~ExternalProcess() { - this.Dispose(false); + Dispose(false); } public bool IsRunning() @@ -185,15 +185,15 @@ public bool IsRunning() { if (mHandle != IntPtr.Zero) { - return (ExternalProcessAPI_IsRunning(mHandle)); + return ExternalProcessAPI_IsRunning(mHandle); } } catch { - this.Terminate(); + Terminate(); } - return (false); + return false; } public bool WaitForStart(float seconds) @@ -213,7 +213,7 @@ public bool WaitFor(float seconds, Func func) float end = Time.realtimeSinceStartup + seconds; bool hasHappened = false; - while (Time.realtimeSinceStartup < end && !hasHappened) + while (Time.realtimeSinceStartup < end) { hasHappened = func(); if (hasHappened) @@ -236,7 +236,7 @@ public void SendLine(string line) } catch { - this.Terminate(); + Terminate(); } } @@ -246,15 +246,15 @@ public string GetLine() { if (mHandle != IntPtr.Zero) { - return (Marshal.PtrToStringAnsi(ExternalProcessAPI_GetLine(mHandle))); + return Marshal.PtrToStringAnsi(ExternalProcessAPI_GetLine(mHandle)); } } catch { - this.Terminate(); + Terminate(); } - return (null); + return null; } public void Terminate() @@ -268,6 +268,7 @@ public void Terminate() } catch { + // TODO: Should we be catching something here? } mHandle = IntPtr.Zero; @@ -277,13 +278,13 @@ public void Terminate() public void Dispose() { - this.Dispose(true); + Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { - this.Terminate(); + Terminate(); } } } diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/ExternalProcess.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/ExternalProcess.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Scripts/Utilities/ExternalProcess.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/ExternalProcess.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/MathUtils.cs b/Assets/HoloToolkit/Utilities/Scripts/MathUtils.cs similarity index 96% rename from Assets/HoloToolkit/Sharing/Scripts/Utilities/MathUtils.cs rename to Assets/HoloToolkit/Utilities/Scripts/MathUtils.cs index 73ac4c268c4..3252f56e23b 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Utilities/MathUtils.cs +++ b/Assets/HoloToolkit/Utilities/Scripts/MathUtils.cs @@ -5,14 +5,13 @@ using System.Linq; using UnityEngine; -namespace HoloToolkit.Sharing.Utilities +namespace HoloToolkit.Utilities { public static class MathUtils { /// /// Get the horizontal FOV from the stereo camera /// - /// /// public static float GetHorizontalFieldOfViewRadians() { @@ -31,7 +30,7 @@ public static bool IsInFOV(Vector3 position) float horizontalFovHalf = GetHorizontalFieldOfViewRadians() * Mathf.Rad2Deg / 2; Vector3 deltaPos = position - Camera.main.transform.position; - Vector3 headDeltaPos = MathUtils.TransformDirectionFromTo(null, Camera.main.transform, deltaPos).normalized; + Vector3 headDeltaPos = TransformDirectionFromTo(null, Camera.main.transform, deltaPos).normalized; float yaw = Mathf.Asin(headDeltaPos.x) * Mathf.Rad2Deg; float pitch = Mathf.Asin(headDeltaPos.y) * Mathf.Rad2Deg; @@ -377,7 +376,7 @@ public static Vector3 NearestPointToLinesRANSAC(List rays, int ransac_itera { for (int it = 0; it < ransac_iterations; it++) { - Vector3 testPoint = NearestPointToLines(rays[UnityEngine.Random.Range(0, rays.Count)], rays[UnityEngine.Random.Range(0, rays.Count)]); + Vector3 testPoint = NearestPointToLines(rays[Random.Range(0, rays.Count)], rays[Random.Range(0, rays.Count)]); // count inliers int numInliersForIteration = 0; @@ -430,14 +429,14 @@ public static Vector3 NearestPointToLinesLeastSquares(IEnumerable rays) foreach (Ray r in rays) { - Vector4 point = (Vector4)r.origin; + Vector4 point = r.origin; Matrix4x4 directionColumnMatrix = new Matrix4x4(); Vector3 rNormal = r.direction.normalized; - directionColumnMatrix.SetColumn(0, (Vector4)rNormal); + directionColumnMatrix.SetColumn(0, rNormal); Matrix4x4 directionRowMatrix = directionColumnMatrix.transpose; Matrix4x4 product = directionColumnMatrix * directionRowMatrix; - Matrix4x4 identityMinusDirectionProduct = MathUtils.Subtract(Matrix4x4.identity, product); - sumOfProduct = MathUtils.Add(sumOfProduct, identityMinusDirectionProduct); + Matrix4x4 identityMinusDirectionProduct = Subtract(Matrix4x4.identity, product); + sumOfProduct = Add(sumOfProduct, identityMinusDirectionProduct); Vector4 vectorProduct = identityMinusDirectionProduct * point; sumOfProductTimesDirection += vectorProduct; } diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/MathUtils.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/MathUtils.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Scripts/Utilities/MathUtils.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/MathUtils.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/SessionExtensions.cs b/Assets/HoloToolkit/Utilities/Scripts/SessionExtensions.cs similarity index 100% rename from Assets/HoloToolkit/Sharing/Scripts/Utilities/SessionExtensions.cs rename to Assets/HoloToolkit/Utilities/Scripts/SessionExtensions.cs diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/SessionExtensions.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/SessionExtensions.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Scripts/Utilities/SessionExtensions.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/SessionExtensions.cs.meta diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/Utils.cs b/Assets/HoloToolkit/Utilities/Scripts/Utils.cs similarity index 99% rename from Assets/HoloToolkit/Sharing/Scripts/Utilities/Utils.cs rename to Assets/HoloToolkit/Utilities/Scripts/Utils.cs index bd6603d9f47..f91f2280120 100644 --- a/Assets/HoloToolkit/Sharing/Scripts/Utilities/Utils.cs +++ b/Assets/HoloToolkit/Utilities/Scripts/Utils.cs @@ -3,7 +3,7 @@ using UnityEngine; -namespace HoloToolkit.Sharing.Utilities +namespace HoloToolkit.Utilities { public static class Utils { diff --git a/Assets/HoloToolkit/Sharing/Scripts/Utilities/Utils.cs.meta b/Assets/HoloToolkit/Utilities/Scripts/Utils.cs.meta similarity index 100% rename from Assets/HoloToolkit/Sharing/Scripts/Utilities/Utils.cs.meta rename to Assets/HoloToolkit/Utilities/Scripts/Utils.cs.meta