private void UpdateData() { DisplayProgressBar("Updating PlayerSpawnPoint", "Uploading Data (1/1)", 0.25f); UnityAsyncHelper.UnityMainThreadContext.Post(async o => { try { IPlayerSpawnPointDataServiceClient client = new PlayerSpawnPointContentServiceClientFactory().Create(EmptyFactoryContext.Instance); //TODO: Is it ok to send a fake world id?? //Just sent the updated model. await client.UpdateSpawnPointInstance(GetTarget().PlayerSpawnPointId, new PlayerSpawnPointInstanceModel(GetTarget().PlayerSpawnPointId, GetTarget().transform.position, GetTarget().transform.eulerAngles.y, GetTarget().isInstanceReserved, 1)); //Since the data about the creature displayed is probably now stale, we should update it after saving. await RefreshData(client); } catch (Exception e) { Debug.LogError($"Failed to update PlayerSpawnPoint. Reason: {e.Message}"); throw; } finally { ClearProgressBar(); } }, null); }
private void AuthenticatedOnGUI() { UnityAsyncHelper.InitializeSyncContext(); //There is no instance associated with this yet. if (GetTarget().PlayerSpawnPointId == -1) { if (GUILayout.Button($"Create SpawnPoint Instance")) { IPlayerSpawnPointDataServiceClient client = new PlayerSpawnPointContentServiceClientFactory().Create(EmptyFactoryContext.Instance); WorldDefinitionData worldData = FindObjectOfType <WorldDefinitionData>(); if (worldData == null) { Debug.LogError($"Cannot create creature instance until the world is uploaded and the {nameof(WorldDefinitionData)} exists within the scene."); return; } CreateInstance(client, worldData); } return; } else { GUILayout.Label(CachedInfoText, GUI.skin.textArea); //The reason we do this manually is so that it can be hidden before there is an instance id. GetTarget().isInstanceReserved = EditorGUILayout.Toggle($"IsReserved", GetTarget().isInstanceReserved); } if (GUILayout.Button($"Refresh PlayerSpawnPoint Data")) { IPlayerSpawnPointDataServiceClient client = new PlayerSpawnPointContentServiceClientFactory().Create(EmptyFactoryContext.Instance); RefreshData(client); } if (GUILayout.Button("Save Updates")) { UpdateData(); } }
protected override void GatherConfigurableData(WorldTeleporterDefinitionData target) { target.LocalSpawnPointId = (PlayerStaticSpawnPointDefinition)EditorGUILayout.ObjectField("Local Spawn:", GetTarget().LocalSpawnPointId, typeof(PlayerStaticSpawnPointDefinition), true); //This isn't really used by the data model BUT it is useful for filtering down a list. target.TargetTeleportWorldId = EditorGUILayout.IntField("Target WorldId:", GetTarget().TargetTeleportWorldId); if (CachedRemoteSpawnList.Any()) { int index = EditorGUILayout.Popup("Remote SpawnPoint", CachedRemoteSpawnList.FindIndex(s => Int32.Parse(s) == GetTarget().RemoteSpawnPointId), CachedRemoteSpawnList.ToArray()); if (CachedRemoteSpawnList.Count > index) { GetTarget().RemoteSpawnPointId = Int32.Parse(CachedRemoteSpawnList[index]); } } else { int index = EditorGUILayout.Popup("Remote SpawnPoint", 0, Array.Empty <string>()); } if (GUILayout.Button($"Refresh Spawnpoint List")) { if (GetTarget().TargetTeleportWorldId > 0) { IPlayerSpawnPointDataServiceClient client = new PlayerSpawnPointContentServiceClientFactory().Create(EmptyFactoryContext.Instance); UnityAsyncHelper.UnityMainThreadContext.Post(async o => { try { DisplayProgressBar($"Querying Spawnpoints for World: {GetTarget().TargetTeleportWorldId}", "Querying", 0.5f); ResponseModel <ObjectEntryCollectionModel <PlayerSpawnPointInstanceModel>, ContentEntryCollectionResponseCode> spawnPoints = await client.GetSpawnPointEntriesByWorld(GetTarget().TargetTeleportWorldId); if (!spawnPoints.isSuccessful) { Debug.LogError($"Failed to query SpawnPoints: {spawnPoints.ResultCode}"); return; } //TODO: Handle error. CachedRemoteSpawnList = spawnPoints.Result.Entries .Select(p => p.SpawnPointId.ToString()) .ToList(); //This will prevent some random errors. GetTarget().RemoteSpawnPointId = int.Parse(CachedRemoteSpawnList.First()); } catch (Exception e) { Debug.LogError($"Error: {e.Message}"); throw; } finally { ClearProgressBar(); } }, null); } } }