Example #1
0
        public override VisualElement CreateInspectorGUI()
        {
            m_Scenario         = (ScenarioBase)target;
            m_SerializedObject = new SerializedObject(m_Scenario);
            m_Root             = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(
                $"{StaticData.uxmlDir}/ScenarioBaseElement.uxml").CloneTree();

            m_RandomizerListPlaceholder = m_Root.Q <VisualElement>("randomizer-list-placeholder");

            CreatePropertyFields();
            CheckIfConstantsExist();

            var serializeConstantsButton = m_Root.Q <Button>("serialize");

            serializeConstantsButton.clicked += () =>
            {
                m_Scenario.SerializeToFile();
                AssetDatabase.Refresh();
                var newConfigFileAsset = AssetDatabase.LoadAssetAtPath <Object>(m_Scenario.defaultConfigFileAssetPath);
                EditorGUIUtility.PingObject(newConfigFileAsset);
            };

            var deserializeConstantsButton = m_Root.Q <Button>("deserialize");

            deserializeConstantsButton.clicked += () =>
            {
                Undo.RecordObject(m_Scenario, "Deserialized scenario configuration");
                m_Scenario.DeserializeFromFile(m_Scenario.defaultConfigFilePath);
            };

            return(m_Root);
        }
Example #2
0
        public override VisualElement CreateInspectorGUI()
        {
            m_Scenario         = (ScenarioBase)target;
            m_SerializedObject = new SerializedObject(m_Scenario);
            m_Root             = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(
                $"{StaticData.uxmlDir}/ScenarioBaseElement.uxml").CloneTree();

            m_RandomizerListPlaceholder = m_Root.Q <VisualElement>("randomizer-list-placeholder");

            CreatePropertyFields();
            CheckIfConstantsExist();

            var generateConfigButton = m_Root.Q <Button>("generate-json-config");

            generateConfigButton.clicked += () =>
            {
                var filePath = GetSaveFilePath(
                    "Generate Scenario JSON Configuration", Application.dataPath,
                    "scenarioConfiguration", "json", k_ConfigFilePlayerPrefKey);
                if (string.IsNullOrEmpty(filePath))
                {
                    return;
                }
                m_Scenario.SerializeToFile(filePath);
                AssetDatabase.Refresh();
                EditorUtility.RevealInFinder(filePath);
                PlayerPrefs.SetString(k_ConfigFilePlayerPrefKey, filePath);
            };

            var deserializeConstantsButton = m_Root.Q <Button>("import-json-config");

            deserializeConstantsButton.clicked += () =>
            {
                var filePath = GetOpenFilePath(
                    "Import Scenario JSON Configuration", Application.dataPath, "json", k_ConfigFilePlayerPrefKey);
                if (string.IsNullOrEmpty(filePath))
                {
                    return;
                }
                Undo.RecordObject(m_Scenario, "Deserialized scenario configuration");
                m_Scenario.DeserializeFromFile(filePath);
                Debug.Log($"Deserialized scenario configuration from {Path.GetFullPath(filePath)}. " +
                          "Using undo in the editor will revert these changes to your scenario.");
                PlayerPrefs.SetString(k_ConfigFilePlayerPrefKey, filePath);
            };

            return(m_Root);
        }