コード例 #1
0
        protected override void AuthenticatedOnGUI()
        {
            SceneObject = AssetDatabase.LoadAssetAtPath <SceneAsset>(SceneManager.GetActiveScene().path);

            //TODO: Validate scene file
            EditorGUILayout.ObjectField("Scene", SceneObject, typeof(SceneAsset), false);

            //If there is a world definition in the scene we should utilize it.
            //TODO: We should do more than just render it.
            WorldDefinitionData definitionData = FindObjectOfType <WorldDefinitionData>();

            //Let's create a definition if one doesn't already exist.
            if (definitionData == null)
            {
                definitionData = CreateWorldDefinitionData();
            }

            base.OnRenderUploadGUI(definitionData, SceneObject, token =>
            {
                //DO NOT REFERNECE THE ABOVE DEFINITION. IT NO LONGER EXISTS
                //THIS IS DUE TO SCENE RELOAD
                definitionData = FindObjectOfType <WorldDefinitionData>();

                definitionData.ContentGuid = token.ContentGuid;
                definitionData.ContentId   = token.ContentId;

                EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
                EditorUtility.SetDirty(definitionData);
            });
        }
コード例 #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();
            }
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
        private void CreateInstance(IPlayerSpawnPointDataServiceClient client, WorldDefinitionData worldData)
        {
            DisplayProgressBar("Creating PlayerSpawnPoint", "Requesting instance (1/2)", 0.0f);

            UnityAsyncHelper.UnityMainThreadContext.Post(async o =>
            {
                try
                {
                    //If they press this, we need to actually create a creature instance for this world id.
                    var result = await client.CreateSpawnPointInstance(worldData.ContentId);

                    if (result.isSuccessful)
                    {
                        DisplayProgressBar("Creating PlayerSpawnPoint", "Saving Instance (2/2)", 0.5f);

                        GetTarget().PlayerSpawnPointId = result.Result.SpawnPointId;
                        EditorUtility.SetDirty(GetTarget());
                        EditorSceneManager.MarkSceneDirty(GetTarget().gameObject.scene);

                        await RefreshData(client);
                    }
                    else
                    {
                        Debug.LogError($"Failed to create PlayerSpawnPoint Instance. Reason: {result.ResultCode}");
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError($"Failed to create PlayerSpawnPoint Instance. Reason: {e.Message}");
                    throw;
                }
                finally
                {
                    ClearProgressBar();
                }
            }, null);
        }
コード例 #5
0
        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();
            }
        }