Exemple #1
0
        private void UpdateCreatureData()
        {
            DisplayProgressBar("Updating Creature", "Uploading Data (1/1)", 0.25f);

            UnityAsyncHelper.UnityMainThreadContext.Post(async o =>
            {
                try
                {
                    ICreatureDataServiceClient client = new CreatureContentServiceClientFactory().Create(EmptyFactoryContext.Instance);

                    //Just sent the updated model.
                    await client.UpdateCreatureInstance(GetTarget().CreatureInstanceId, new CreatureInstanceModel(BuildNetworkEntityGuid(), GetTarget().CreatureTemplateId, 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 RefreshCreatureData(client);
                }
                catch (Exception e)
                {
                    Debug.LogError($"Failed to update creature. Reason: {e.Message}");
                    throw;
                }
                finally
                {
                    ClearProgressBar();
                }
            }, null);
        }
Exemple #2
0
        private void AuthenticatedOnGUI()
        {
            UnityAsyncHelper.InitializeSyncContext();

            //There is no creature instance associated with this yet.
            if (GetTarget().CreatureInstanceId == -1)
            {
                if (GUILayout.Button($"Create Creature Instance"))
                {
                    ICreatureDataServiceClient client = new CreatureContentServiceClientFactory().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;
                    }

                    CreateCreatureInstance(client, worldData);
                }

                return;
            }
            else
            {
                EditorGUILayout.LabelField($"Instance Id: {GetTarget().CreatureInstanceId}");

                GUILayout.Label(CachedCreatureInfoText, GUI.skin.textArea);

                //The reason we do this manually is so that it can be hidden before there is an instance id.
                GetTarget().CreatureTemplateId = EditorGUILayout.IntField($"Template Id", GetTarget().CreatureTemplateId);

                //Now, if the creature template id is not -1 we should try to load the template
                if (GetTarget().CreatureTemplateId > 0)
                {
                    GUILayout.Label(CachedCreatureTemplateInfoText, GUI.skin.textArea);
                }
                else
                {
                    GUILayout.Label($"Unknown Creature Template: {GetTarget().CreatureTemplateId}", GUI.skin.textArea);
                }
            }

            if (GUILayout.Button($"Refresh Creature Data"))
            {
                ICreatureDataServiceClient client = new CreatureContentServiceClientFactory().Create(EmptyFactoryContext.Instance);

                RefreshCreatureData(client);
            }

            if (GUILayout.Button("Save Updates"))
            {
                UpdateCreatureData();
            }
        }