diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs index 734810433..86fcd285a 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs @@ -30,6 +30,7 @@ namespace UniGLTF protected override void Initialize() { m_settings = ScriptableObject.CreateInstance(); + m_settings.InverseAxis = UniGLTFPreference.GltfIOAxis; m_settingsInspector = Editor.CreateEditor(m_settings); } diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporter.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporter.cs index dead09d4f..0f05db520 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporter.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporter.cs @@ -1,5 +1,5 @@ - using UnityEngine; +using UnityEditor; #if UNITY_2020_2_OR_NEWER using UnityEditor.AssetImporters; #else @@ -13,10 +13,16 @@ namespace UniGLTF public class GlbScriptedImporter : ScriptedImporter { [SerializeField] - Axises m_reverseAxis = default; + Axises m_reverseAxis; public override void OnImportAsset(AssetImportContext ctx) { + var asset = AssetDatabase.LoadAssetAtPath(ctx.assetPath); + if (asset == null) + { + // first time. set default setting + m_reverseAxis = UniGLTFPreference.GltfIOAxis; + } ScriptedImporterImpl.Import(this, ctx, m_reverseAxis); } } diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporter.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporter.cs index 4719acf33..880827897 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporter.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporter.cs @@ -1,5 +1,5 @@ - using UnityEngine; +using UnityEditor; #if UNITY_2020_2_OR_NEWER using UnityEditor.AssetImporters; #else @@ -17,6 +17,12 @@ namespace UniGLTF public override void OnImportAsset(AssetImportContext ctx) { + var asset = AssetDatabase.LoadAssetAtPath(ctx.assetPath); + if (asset == null) + { + // first time. set default setting + m_reverseAxis = UniGLTFPreference.GltfIOAxis; + } ScriptedImporterImpl.Import(this, ctx, m_reverseAxis); } } diff --git a/Assets/UniGLTF/Editor/UniGLTF/UniGLTFPreference.cs b/Assets/UniGLTF/Editor/UniGLTF/UniGLTFPreference.cs index cd38b973f..c79eeb472 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/UniGLTFPreference.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/UniGLTFPreference.cs @@ -1,6 +1,7 @@ using UnityEngine; using UnityEditor; using System.Linq; +using System; namespace UniGLTF { @@ -13,13 +14,42 @@ namespace UniGLTF // language M17N.LanguageGetter.OnGuiSelectLang(); - EditorGUILayout.HelpBox($"UniGLTF, UniVRM custom editor language setting", MessageType.Info, true); + EditorGUILayout.HelpBox($"Custom editor language setting", MessageType.Info, true); // default axis + GltfIOAxis = (Axises)EditorGUILayout.EnumPopup("Default Invert axis", GltfIOAxis); + EditorGUILayout.HelpBox($"Default invert axis when glb/gltf import/export", MessageType.Info, true); if (EditorGUI.EndChangeCheck()) { } } + + const string AXIS_KEY = "UNIGLTF_IO_AXIS"; + static Axises? s_axis; + public static Axises GltfIOAxis + { + set + { + EditorPrefs.SetString(AXIS_KEY, value.ToString()); + s_axis = value; + } + get + { + if (!s_axis.HasValue) + { + var value = EditorPrefs.GetString(AXIS_KEY, default(Axises).ToString()); + if (Enum.TryParse(value, out Axises parsed)) + { + s_axis = parsed; + } + else + { + s_axis = default(Axises); + } + } + return s_axis.Value; + } + } } }