Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

開発バージョンをUnity-2019にあげる。および、 Unity-2019 require ApplyRevertGUI call in OnInspectorGUI の修正 #1129

Merged
merged 2 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace UniGLTF
[CustomEditor(typeof(GlbScriptedImporter))]
public class GlbScriptedImporterEditor : RemapScriptedImporterEditorBase
{
GlbScriptedImporter m_importer;
GltfData m_data;

RemapEditorMaterial m_materialEditor;
Expand Down Expand Up @@ -57,15 +56,15 @@ public override void OnInspectorGUI()

case Tabs.Animation:
m_animationEditor.OnGUI(m_importer, m_data);
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;

case Tabs.Materials:
m_materialEditor.OnGUI(m_importer, m_data,
new GltfTextureDescriptorGenerator(m_data),
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures",
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials");
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using UnityEngine;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using VRMShaders;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
Expand All @@ -16,7 +14,6 @@ namespace UniGLTF
[CustomEditor(typeof(GltfScriptedImporter))]
public class GltfScriptedImporterEditor : RemapScriptedImporterEditorBase
{
GltfScriptedImporter m_importer;
GltfData m_data;

RemapEditorMaterial m_materialEditor;
Expand Down Expand Up @@ -57,15 +54,15 @@ public override void OnInspectorGUI()

case Tabs.Animation:
m_animationEditor.OnGUI(m_importer, m_data);
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;

case Tabs.Materials:
m_materialEditor.OnGUI(m_importer, m_data,
new GltfTextureDescriptorGenerator(m_data),
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures",
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials");
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

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 されていない変更を保持する
///
Expand All @@ -33,45 +40,46 @@ protected void SetEditorMap(Dictionary<SubAssetKey, UnityEngine.Object> value)
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()
{
foreach (var kv in m_editMap)
if (m_editMap.Any())
{
if (kv.Object != null)
{
importer.AddRemap(kv.ID, kv.Object);
}
else
{
importer.RemoveRemap(kv.ID);
}
return true;
}
m_editMap.Clear();
AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath);
AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate);
return base.HasModified();
}

public void RevertApplyRemapGUI(ScriptedImporter importer)
/// <summary>
/// Apply
/// </summary>
protected override void Apply()
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
using (new EditorGUI.DisabledScope(m_editMap.Count == 0))
foreach (var kv in m_editMap)
{
if (GUILayout.Button("Revert"))
if (kv.Object != null)
{
RevertRemap();
m_importer.AddRemap(kv.ID, kv.Object);
}
if (GUILayout.Button("Apply"))
else
{
ApplyRemap(importer);
m_importer.RemoveRemap(kv.ID);
}
}
GUILayout.EndHorizontal();
m_editMap.Clear();
AssetDatabase.WriteImportSettingsIfDirty(m_importer.assetPath);
AssetDatabase.ImportAsset(m_importer.assetPath, ImportAssetOptions.ForceUpdate);

base.Apply();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace UniGLTF
[CustomEditor(typeof(ZipArchivedGltfScriptedImporter))]
public class ZipArchivedGltfScriptedImporterEditor : RemapScriptedImporterEditorBase
{
ZipArchivedGltfScriptedImporter m_importer;
GltfData m_data;

RemapEditorMaterial m_materialEditor;
Expand Down Expand Up @@ -55,15 +54,15 @@ public override void OnInspectorGUI()

case Tabs.Animation:
m_animationEditor.OnGUI(m_importer, m_data);
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;

case Tabs.Materials:
m_materialEditor.OnGUI(m_importer, m_data,
new GltfTextureDescriptorGenerator(m_data),
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures",
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials");
RevertApplyRemapGUI(m_importer);
ApplyRevertGUI();
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace UniVRM10
[CustomEditor(typeof(VrmScriptedImporter))]
public class VrmScriptedImporterEditorGUI : RemapScriptedImporterEditorBase
{
VrmScriptedImporter m_importer;
VrmLib.Model m_model;

RemapEditorMaterial m_materialEditor;
Expand Down Expand Up @@ -64,8 +63,9 @@ public override void OnEnable()
{
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;
Expand Down Expand Up @@ -102,6 +102,7 @@ public override void OnInspectorGUI()
{
case Vrm10FileType.Vrm1:
EditorGUILayout.HelpBox(m_result.Message, MessageType.Info);
ApplyRevertGUI();
break;

case Vrm10FileType.Vrm0:
Expand All @@ -111,6 +112,7 @@ public override void OnInspectorGUI()
break;

default:
ApplyRevertGUI();
break;
}
}
Expand All @@ -122,15 +124,15 @@ public override void OnInspectorGUI()
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;

case Tabs.Vrm:
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;
}
Expand Down
3 changes: 2 additions & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
m_EditorVersion: 2018.4.27f1
m_EditorVersion: 2019.4.29f1
m_EditorVersionWithRevision: 2019.4.29f1 (0eeae20b1d82)