Skip to content

Commit

Permalink
Default の Asset をサーチしてまとめて Reimport を発動する
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed May 20, 2021
1 parent 5ffab98 commit 41b411a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace UniGLTF
public class GlbScriptedImporter : ScriptedImporter
{
[SerializeField]
ScriptedImporterAxes m_reverseAxis;
public ScriptedImporterAxes m_reverseAxis;

public override void OnImportAsset(AssetImportContext ctx)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace UniGLTF
public class GltfScriptedImporter : ScriptedImporter
{
[SerializeField]
ScriptedImporterAxes m_reverseAxis = default;
public ScriptedImporterAxes m_reverseAxis = default;

public override void OnImportAsset(AssetImportContext ctx)
{
Expand Down
34 changes: 34 additions & 0 deletions Assets/UniGLTF/Editor/UniGLTF/UniGLTFPreference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,38 @@
using UnityEditor;
using System.Linq;
using System;
using System.IO;
using System.Collections.Generic;

namespace UniGLTF
{
public static class UniGLTFPreference
{
static IEnumerable<string> GetReimportPaths()
{
String[] guids = AssetDatabase.FindAssets("t:GameObject", null);
foreach (var guid in guids)
{
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
if (AssetImporter.GetAtPath(assetPath) is GlbScriptedImporter glb)
{
if (glb.m_reverseAxis == ScriptedImporterAxes.Default)
{
Debug.Log($"[reimport] {assetPath}");
yield return assetPath;
}
}
else if (AssetImporter.GetAtPath(assetPath) is GltfScriptedImporter gltf)
{
if (gltf.m_reverseAxis == ScriptedImporterAxes.Default)
{
Debug.Log($"[reimport] {assetPath}");
yield return assetPath;
}
}
}
}

[PreferenceItem("UniGLTF")]
private static void OnPreferenceGUI()
{
Expand All @@ -20,7 +47,14 @@ private static void OnPreferenceGUI()
EditorGUILayout.HelpBox($"Default invert axis when glb/gltf import/export", MessageType.Info, true);
if (EditorGUI.EndChangeCheck())
{
// global setting
GltfIOAxis = gltfIOAxis;

// apply assets
foreach (var path in GetReimportPaths().ToArray())
{
AssetDatabase.ImportAsset(path, default);
}
}
}

Expand Down

0 comments on commit 41b411a

Please sign in to comment.