ousttrue
2021-08-04 14:37:23 +09:00
parent 192f15cd69
commit cb0c2b7570
5 changed files with 44 additions and 39 deletions

View File

@@ -16,7 +16,6 @@ namespace UniGLTF
[CustomEditor(typeof(GlbScriptedImporter))]
public class GlbScriptedImporterEditor : RemapScriptedImporterEditorBase
{
GlbScriptedImporter m_importer;
GltfData m_data;
RemapEditorMaterial m_materialEditor;
@@ -57,7 +56,7 @@ namespace UniGLTF
case Tabs.Animation:
m_animationEditor.OnGUI(m_importer, m_data);
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;
case Tabs.Materials:
@@ -65,7 +64,7 @@ namespace UniGLTF
new GltfTextureDescriptorGenerator(m_data),
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures",
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials");
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;
}
}

View File

@@ -2,8 +2,6 @@ using UnityEditor;
using UnityEngine;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using VRMShaders;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
@@ -16,7 +14,6 @@ namespace UniGLTF
[CustomEditor(typeof(GltfScriptedImporter))]
public class GltfScriptedImporterEditor : RemapScriptedImporterEditorBase
{
GltfScriptedImporter m_importer;
GltfData m_data;
RemapEditorMaterial m_materialEditor;
@@ -57,7 +54,7 @@ namespace UniGLTF
case Tabs.Animation:
m_animationEditor.OnGUI(m_importer, m_data);
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;
case Tabs.Materials:
@@ -65,7 +62,7 @@ namespace UniGLTF
new GltfTextureDescriptorGenerator(m_data),
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures",
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials");
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;
}
}

View File

@@ -7,8 +7,15 @@ using VRMShaders;
namespace UniGLTF
{
/// <summary>
/// https://github.com/Unity-Technologies/UnityCsReference/blob/2019.4/Modules/AssetPipelineEditor/ImportSettings/AssetImporterEditor.cs
///
/// の作法に合わせる
/// </summary>
public abstract class RemapScriptedImporterEditorBase : ScriptedImporterEditor
{
protected ScriptedImporter m_importer;
/// <summary>
/// Apply されていない変更を保持する
///
@@ -33,45 +40,46 @@ namespace UniGLTF
m_editMap.AddRange(value.Select(kv => new RemapEditorBase.SubAssetPair(kv.Key, kv.Value)));
}
public void RevertRemap()
/// <summary>
/// Revert
/// </summary>
protected override void ResetValues()
{
m_editMap.Clear();
base.ResetValues();
}
public void ApplyRemap(ScriptedImporter importer)
public override bool HasModified()
{
if (m_editMap.Any())
{
return true;
}
return base.HasModified();
}
/// <summary>
/// Apply
/// </summary>
protected override void Apply()
{
foreach (var kv in m_editMap)
{
if (kv.Object != null)
{
importer.AddRemap(kv.ID, kv.Object);
m_importer.AddRemap(kv.ID, kv.Object);
}
else
{
importer.RemoveRemap(kv.ID);
m_importer.RemoveRemap(kv.ID);
}
}
m_editMap.Clear();
AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath);
AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate);
}
AssetDatabase.WriteImportSettingsIfDirty(m_importer.assetPath);
AssetDatabase.ImportAsset(m_importer.assetPath, ImportAssetOptions.ForceUpdate);
public void RevertApplyRemapGUI(ScriptedImporter importer)
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
using (new EditorGUI.DisabledScope(m_editMap.Count == 0))
{
if (GUILayout.Button("Revert"))
{
RevertRemap();
}
if (GUILayout.Button("Apply"))
{
ApplyRemap(importer);
}
}
GUILayout.EndHorizontal();
base.Apply();
}
}
}

View File

@@ -14,7 +14,6 @@ namespace UniGLTF
[CustomEditor(typeof(ZipArchivedGltfScriptedImporter))]
public class ZipArchivedGltfScriptedImporterEditor : RemapScriptedImporterEditorBase
{
ZipArchivedGltfScriptedImporter m_importer;
GltfData m_data;
RemapEditorMaterial m_materialEditor;
@@ -55,7 +54,7 @@ namespace UniGLTF
case Tabs.Animation:
m_animationEditor.OnGUI(m_importer, m_data);
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;
case Tabs.Materials:
@@ -63,7 +62,7 @@ namespace UniGLTF
new GltfTextureDescriptorGenerator(m_data),
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures",
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials");
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;
}
}

View File

@@ -18,7 +18,6 @@ namespace UniVRM10
[CustomEditor(typeof(VrmScriptedImporter))]
public class VrmScriptedImporterEditorGUI : RemapScriptedImporterEditorBase
{
VrmScriptedImporter m_importer;
VrmLib.Model m_model;
RemapEditorMaterial m_materialEditor;
@@ -64,8 +63,9 @@ namespace UniVRM10
{
base.OnEnable();
m_importer = target as VrmScriptedImporter;
if (!Vrm10Parser.TryParseOrMigrate(m_importer.assetPath, m_importer.MigrateToVrm1, out m_result))
var importer = target as VrmScriptedImporter;
m_importer = importer;
if (!Vrm10Parser.TryParseOrMigrate(m_importer.assetPath, importer.MigrateToVrm1, out m_result))
{
// error
return;
@@ -102,6 +102,7 @@ namespace UniVRM10
{
case Vrm10FileType.Vrm1:
EditorGUILayout.HelpBox(m_result.Message, MessageType.Info);
ApplyRevertGUI();
break;
case Vrm10FileType.Vrm0:
@@ -111,6 +112,7 @@ namespace UniVRM10
break;
default:
ApplyRevertGUI();
break;
}
}
@@ -122,7 +124,7 @@ namespace UniVRM10
m_materialEditor.OnGUI(m_importer, m_result.Data, new Vrm10TextureDescriptorGenerator(m_result.Data),
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Textures",
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Materials");
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
}
break;
@@ -130,7 +132,7 @@ namespace UniVRM10
if (m_result.Data != null && m_result.Vrm != null)
{
m_vrmEditor.OnGUI(m_importer, m_result.Data, m_result.Vrm);
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
}
break;
}