private void UpdateGameObjectData() { DisplayProgressBar("Updating GameObject", "Uploading Data (1/1)", 0.25f); UnityAsyncHelper.UnityMainThreadContext.Post(async o => { try { IGameObjectDataServiceClient client = new GameObjectContentServiceClientFactory().Create(EmptyFactoryContext.Instance); //Just sent the updated model. await client.UpdateGameObjectInstance(GetTarget().GameObjectInstanceId, new GameObjectInstanceModel(BuildNetworkEntityGuid(), GetTarget().GameObjectTemplateId, GetTarget().transform.position, GetTarget().transform.eulerAngles.y)); //Since the data about the creature displayed is probably now stale, we should update it after saving. await RefreshGameObjectData(client); } catch (Exception e) { Debug.LogError($"Failed to update GameObject. Reason: {e.Message}"); throw; } finally { ClearProgressBar(); } }, null); }
private void AuthenticatedOnGUI() { UnityAsyncHelper.InitializeSyncContext(); //There is no creature instance associated with this yet. if (GetTarget().GameObjectInstanceId == -1) { if (GUILayout.Button($"Create GameObject Instance")) { IGameObjectDataServiceClient client = new GameObjectContentServiceClientFactory().Create(EmptyFactoryContext.Instance); WorldDefinitionData worldData = FindObjectOfType <WorldDefinitionData>(); if (worldData == null) { Debug.LogError($"Cannot create GameObject instance until the world is uploaded and the {nameof(WorldDefinitionData)} exists within the scene."); return; } CreateGameObjectInstance(client, worldData); } return; } else { EditorGUILayout.LabelField($"Instance Id: {GetTarget().GameObjectInstanceId}"); GUILayout.Label(CachedGameObjectInfoText, GUI.skin.textArea); //The reason we do this manually is so that it can be hidden before there is an instance id. GetTarget().GameObjectTemplateId = EditorGUILayout.IntField($"Template Id", GetTarget().GameObjectTemplateId); //Now, if the creature template id is not -1 we should try to load the template if (GetTarget().GameObjectTemplateId > 0) { GUILayout.Label(CachedGameObjectTemplateInfoText, GUI.skin.textArea); //TODO: Better handle GameObjectTypes supplmenetal components. //If we have a template we should try to let them change the type if it's visual. if (CachedGameObjectType != GameObjectType.Visual) { INetworkGameObjectBehaviour behaviour = GetTarget().gameObject.GetComponent <INetworkGameObjectBehaviour>(); if (behaviour == null) { new GameObjectBehaviorComponentFactory().Create(new BehaviourAttachmentContext(GetTarget().gameObject, CachedGameObjectType)); } else { //Warn non-matching behavior. if (behaviour.BehaviorType != CachedGameObjectType) { Debug.LogError($"GameObject Id: {GetTarget().GameObjectInstanceId} has Type: {CachedGameObjectType} but does not match Component: {behaviour.GetType().Name}", GetTarget().gameObject); } } } } else { GUILayout.Label($"Unknown GameObject Template: {GetTarget().GameObjectTemplateId}", GUI.skin.textArea); } } if (GUILayout.Button($"Refresh GameObject Data")) { IGameObjectDataServiceClient client = new GameObjectContentServiceClientFactory().Create(EmptyFactoryContext.Instance); RefreshGameObjectData(client); } if (GUILayout.Button("Save Updates")) { UpdateGameObjectData(); } }