void DidConnectToRoom(Realtime room) { if (!gameObject.activeInHierarchy || !enabled) { return; } // Create avatar if (_localAvatarPrefab == null) { Debug.LogError("Realtime Avatars local avatar prefab is null. Bailing."); return; } GameObject avatarGameObject = Realtime.Instantiate(_localAvatarPrefab.name, true, true, true, _realtime); if (avatarGameObject == null) { Debug.LogError("RealtimeAvatarManager: Failed to instantiate RealtimeAvatar prefab."); return; } localAvatar = avatarGameObject.GetComponent <RealtimeAvatar>(); if (avatarGameObject == null) { Debug.LogError("RealtimeAvatarManager: Successfully instantiated avatar prefab, but could not find the RealtimeAvatar component."); return; } localAvatar.localPlayer = _localPlayer; localAvatar.deviceType = GetRealtimeAvatarDeviceTypeForLocalPlayer(); }
void Start() { // TODO: Strip this once photon is replaced. It only exists right now because Photon is the one who instantiates this class, not something we control. _application = Application.sharedApplication; _realtime = _application.realtime; _realtime.NetworkPlayerInstantiated(this); _realtime.NetworkPlayerRequestAPIPlayer(this); _realtime.NetworkPlayerInstantiatedAPIPlayer(this); }
void DidConnectToRoom(Realtime room) { if (!gameObject.activeInHierarchy || !enabled) { return; } // Create avatar CreateAvatarIfNeeded(); }
public void DestroyAvatarIfNeeded() { if (localAvatar == null) { return; } Realtime.Destroy(localAvatar.gameObject); localAvatar = null; }
void Awake() { if (_sharedApplication != null) { Debug.Log("Normal: Application already exists! This is a huge bug! Moving forward with new application. Destroying the old one."); DestroyImmediate(_sharedApplication); } _sharedApplication = this; _realtime = GetComponent <Realtime.Realtime>(); }
void Awake() { _realtime = GetComponent <Realtime>(); _realtime.didConnectToRoom += DidConnectToRoom; if (_localPlayer == null) { _localPlayer = new RealtimeAvatar.LocalPlayer(); } avatars = new Dictionary <int, RealtimeAvatar>(); }
public void CreateAvatarIfNeeded() { if (!_realtime.connected) { Debug.LogError("RealtimeAvatarManager: Unable to create avatar. Realtime is not connected to a room."); return; } if (localAvatar != null) { return; } if (_localAvatarPrefab == null) { Debug.LogWarning("Realtime Avatars local avatar prefab is null. No avatar prefab will be instantiated for the local player."); return; } if (localOfflineAvatar != null) { localOfflineAvatar.SetActive(false); } GameObject avatarGameObject = Realtime.Instantiate(_localAvatarPrefab.name, true, true, true, _realtime); if (avatarGameObject == null) { Debug.LogError("RealtimeAvatarManager: Failed to instantiate RealtimeAvatar prefab for the local player."); return; } localAvatar = avatarGameObject.GetComponent <RealtimeAvatar>(); if (avatarGameObject == null) { Debug.LogError("RealtimeAvatarManager: Successfully instantiated avatar prefab, but could not find the RealtimeAvatar component."); return; } localAvatar.transform.position = localOfflineAvatar.transform.position; localAvatar.localPlayer = _localPlayer; localAvatar.deviceType = GetRealtimeAvatarDeviceTypeForLocalPlayer(); string avatarName = PlayerPrefs.GetString("PlayerName", "Avatar"); localAvatar.GetComponent <AvatarAppearance>().SetName(avatarName); localAvatar.GetComponent <AvatarAppearance>().UpdateAvatarName(); }
public void DestroyAvatarIfNeeded() { if (localAvatar == null) { return; } Realtime.Destroy(localAvatar.gameObject); localAvatar = null; if (localOfflineAvatar != null) { localOfflineAvatar.SetActive(true); } }
private void Awake() { _realtime = GetComponent <Realtime>(); string outputDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Normal\\SessionCapture"); if (_mode == Mode.Record) { string outputFileName = "Session_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".realtime"; string outputFilePath = Path.Combine(outputDirectory, outputFileName); Directory.CreateDirectory(outputDirectory); // Create session Debug.Log("Record file path: " + outputFilePath); SessionCapture sessionCapture = new SessionCapture(outputFilePath); // Set on Realtime _realtime.room = new Room(sessionCapture); } else if (_mode == Mode.Playback) { // If no playback files are specified, attempt to find the most recent one in the output directory. if (_playbackCaptureFiles == null || _playbackCaptureFiles.Length <= 0) { FileInfo file = new DirectoryInfo(outputDirectory).GetFiles("*.realtime").OrderByDescending(f => f.CreationTime).FirstOrDefault(); if (file != default(FileInfo)) { _playbackCaptureFiles = new string[] { file.FullName } } ; } if (_playbackCaptureFiles != null) { // Create session SessionCapture sessionCapture = new SessionCapture(_playbackCaptureFiles); // Set on Realtime _realtime.room = new Room(sessionCapture); } else { Debug.LogError("RealtimeSessionCapture: Unable to find any session capture files to play back."); } } } }
public void CreateAvatarIfNeeded() { if (!_realtime.connected) { Debug.LogError("RealtimeAvatarManager: Unable to create avatar. Realtime is not connected to a room."); return; } if (localAvatar != null) { return; } if (_localAvatarPrefab == null) { Debug.LogWarning("Realtime Avatars local avatar prefab is null. No avatar prefab will be instantiated for the local player."); return; } GameObject avatarGameObject = Realtime.Instantiate(_localAvatarPrefab.name, true, true, true, _realtime); if (avatarGameObject == null) { Debug.LogError("RealtimeAvatarManager: Failed to instantiate RealtimeAvatar prefab for the local player."); return; } localAvatar = avatarGameObject.GetComponent <RealtimeAvatar>(); if (localAvatar == null) { Debug.LogError("RealtimeAvatarManager: Successfully instantiated avatar prefab, but could not find the RealtimeAvatar component."); return; } localAvatar.localPlayer = _localPlayer; localAvatar.deviceType = GetRealtimeAvatarDeviceTypeForLocalPlayer(); localAvatar.deviceModel = XRDevice.model; }
#pragma warning restore 0649 private void Start() { // If this is a root scene view, register with Realtime if (isRootSceneView) { if (_realtime == null) { // This can happen if this RealtimeView is a scene view in a scene that's meant to be additively loaded onto a scene that has a Realtime instance in it. Attempt to auto-detect. if (Realtime.instances.Count == 1) { foreach (Realtime instance in Realtime.instances) { if (instance == null) { Debug.LogError("RealtimeView: Realtime.instances contains a null value. This is a bug!"); } _realtime = instance; break; } } else if (Realtime.instances.Count == 0) { Debug.LogError("RealtimeView: Attempting to auto-detect Realtime instance, but none exist in the scene yet. Please make sure there's an instance of Realtime in the scene."); } else if (Realtime.instances.Count > 1) { Debug.LogError("RealtimeView: Attempting to auto-detect Realtime instance, but multiple instances of Realtime exist in the scene. Please wire up a reference to Realtime manually in Advanced Settings on each scene RealtimeView."); } } if (_realtime != null) { _realtime._RegisterSceneRealtimeView(this); } } }
// Used to populate _realtime for prefab RealtimeViews public void _SetRealtime(Realtime realtime) { _realtime = realtime; }
private static void ConfigureRealtimeView(RealtimeView realtimeView, Realtime[] realtimeInstances, ref bool didWarnAboutRealtimeInstancesBeingTooFewOrTooMany) { SerializedObject realtimeViewSerializedObject = new SerializedObject(realtimeView); realtimeViewSerializedObject.Update(); SerializedProperty realtimeProperty = realtimeViewSerializedObject.FindProperty("_realtime"); SerializedProperty sceneViewUUIDProperty = realtimeViewSerializedObject.FindProperty("_sceneViewUUID"); SerializedProperty isRootPrefabViewProperty = realtimeViewSerializedObject.FindProperty("_isRootPrefabView"); // Realtime Instance Realtime realtime = realtimeProperty.objectReferenceValue as Realtime; bool prefab = EditorUtility.IsPersistent(realtimeView.gameObject); if (prefab) { if (realtime != null) { realtimeProperty.objectReferenceValue = null; } } else { if (realtime == null) { if (realtimeInstances.Length == 1) { realtimeProperty.objectReferenceValue = realtimeInstances[0]; } else if (!didWarnAboutRealtimeInstancesBeingTooFewOrTooMany) { if (realtimeInstances.Length == 0) { Debug.LogWarning("RealtimeView: No instances of Realtime exist in the scene. Make sure to create an instance of Realtime otherwise this scene view will not work!"); } else if (realtimeInstances.Length > 1) { Debug.LogWarning("RealtimeView: There are multiple instances of Realtime in the scene. If you plan to use this as a scene view, wire up a reference to Realtime manually under the Advanced Settings panel on the RealtimeView."); } didWarnAboutRealtimeInstancesBeingTooFewOrTooMany = true; } } } // Add realtime components RealtimeComponent[] components = realtimeView.GetComponents <RealtimeComponent>(); foreach (RealtimeComponent component in components) { AddComponentToViewListIfNeeded(realtimeView, component); } // Add to parent RealtimeView if this is a child view bool isRoot = AddChildViewToParentViewIfNeeded(realtimeView, realtimeViewSerializedObject); byte[] sceneViewUUID = GetSceneViewUUIDAsByteArray(sceneViewUUIDProperty); if (isRoot && !prefab) { // Root scene view // Make sure this root scene view exists in our map. If it does, verify the UUID is set properly. byte[] previouslyAssignedUUID; if (_rootSceneViewUUIDMap.TryGetValue(realtimeView, out previouslyAssignedUUID)) { // If previously assigned UUID doesn't match, reset it. This can happen when clicking Apply on a prefab. // This is because the UUID gets stored on the prefab and cleared on the scene view because it inherits the value from the prefab. // Then this script comes in and clears the UUID on the prefab, which then means the scene view will have no UUID because it's inheriting // from the prefab. We'll detect that here and set it back on the scene view. if (!previouslyAssignedUUID.SequenceEqual(sceneViewUUID)) { // Reset scene view UUID sceneViewUUID = SetSceneViewUUIDUsingByteArray(sceneViewUUIDProperty, previouslyAssignedUUID); } } else { // Set scene UUID if needed if (sceneViewUUID == null || sceneViewUUID.Length == 0) { sceneViewUUID = SetSceneViewUUIDUsingByteArray(sceneViewUUIDProperty, Guid.NewGuid().ToByteArray()); } else { // If this view doesn't exist in the UUID map, but it has a scene view UUID, it's possible it's been copy & pasted. Check the map to see if another scene view has the same UUID. If it does, reset it and log a warning. foreach (KeyValuePair <RealtimeView, byte[]> viewUUIDPair in _rootSceneViewUUIDMap) { RealtimeView view = viewUUIDPair.Key; byte[] viewUUID = viewUUIDPair.Value; if (sceneViewUUID.SequenceEqual(viewUUID) && realtimeView != view && realtimeView.gameObject.scene == view.gameObject.scene) { // If we enter this block, it means there's already a realtime view with this UUID loaded, /and/ it exists in the same scene. // As far as I know, the only way for that to happen is to copy & paste a root scene realtime view. In that case, I think it's ok to reset // the UUID on the copy. And since the original is going to be the one that already exists in the map, that means this one is the copy. // For root scene views that have the same UUID as a view in another scene, we'll log an error below. That can happen when a scene is saved // as a copy, and the copy is additively loaded. In that case, we don't know which view the developer will want to keep so we log the error. Debug.LogWarning("Realtime: Found a RealtimeView in scene with a duplicate UUID. Resetting the UUID on the copy."); sceneViewUUID = SetSceneViewUUIDUsingByteArray(sceneViewUUIDProperty, Guid.NewGuid().ToByteArray()); break; } } } // Add to the map _rootSceneViewUUIDMap[realtimeView] = sceneViewUUID; } } else { // Not root scene view // Clear scene UUID if (sceneViewUUID == null || sceneViewUUID.Length != 0) { // Clear the UUID sceneViewUUID = SetSceneViewUUIDUsingByteArray(sceneViewUUIDProperty, new byte[0]); // Remove from map _rootSceneViewUUIDMap.Remove(realtimeView); } } if (isRoot && prefab) { // Root prefab view // Set isRootPrefabView property if (!isRootPrefabViewProperty.boolValue) { isRootPrefabViewProperty.boolValue = true; } } else { // Not root prefab view // Clear isRootPrefabView property if (isRootPrefabViewProperty.boolValue) { isRootPrefabViewProperty.boolValue = false; } } realtimeViewSerializedObject.ApplyModifiedPropertiesWithoutUndo(); }